From cea482a762e33fe91490486b30deddeab703ca4e Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Tue, 2 Apr 2019 12:09:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8F=8A=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=96=B0=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wxpay/service/WxPayService.java | 7 +- .../service/impl/BaseWxPayServiceImpl.java | 96 ++++--------------- 2 files changed, 22 insertions(+), 81 deletions(-) diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java index 08b59e21..51d46512 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java @@ -313,7 +313,7 @@ public interface WxPayService { * 请求方式:POST * * - * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 + * @param request 红包查询请求 * @return the wx pay redpack query result * @throws WxPayException the wx pay exception */ @@ -691,10 +691,7 @@ public interface WxPayService { * 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=10 * * - * @param beginDate 开始时间 - * @param endDate 结束时间 - * @param offset 位移 - * @param limit 条数,建议填null,否则接口会报签名错误 + * @param request 查询请求 * @return the string * @throws WxPayException the wx pay exception */ diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index 39645d69..b202e180 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -1,29 +1,8 @@ package com.github.binarywang.wxpay.service.impl; -import java.io.File; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Date; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipException; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.github.binarywang.utils.qrcode.QrcodeUtils; import com.github.binarywang.wxpay.bean.WxPayApiData; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest; -import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult; +import com.github.binarywang.wxpay.bean.coupon.*; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult; @@ -31,39 +10,8 @@ import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; -import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest; -import com.github.binarywang.wxpay.bean.request.WxPayDefaultRequest; -import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest; -import com.github.binarywang.wxpay.bean.request.WxPayDownloadFundFlowRequest; -import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest; -import com.github.binarywang.wxpay.bean.request.WxPayOrderCloseRequest; -import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest; -import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest; -import com.github.binarywang.wxpay.bean.request.WxPayQueryCommentRequest; -import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest; -import com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest; -import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest; -import com.github.binarywang.wxpay.bean.request.WxPayReportRequest; -import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest; -import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest; -import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; -import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; -import com.github.binarywang.wxpay.bean.result.WxPayAuthcode2OpenidResult; -import com.github.binarywang.wxpay.bean.result.WxPayBillResult; -import com.github.binarywang.wxpay.bean.result.WxPayCommonResult; -import com.github.binarywang.wxpay.bean.result.WxPayFundFlowBaseResult; -import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult; -import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult; -import com.github.binarywang.wxpay.bean.result.WxPayOrderCloseResult; -import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult; -import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult; -import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult; -import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult; -import com.github.binarywang.wxpay.bean.result.WxPayRefundResult; -import com.github.binarywang.wxpay.bean.result.WxPaySandboxSignKeyResult; -import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult; -import com.github.binarywang.wxpay.bean.result.WxPayShorturlResult; -import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult; +import com.github.binarywang.wxpay.bean.request.*; +import com.github.binarywang.wxpay.bean.result.*; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; @@ -75,6 +23,17 @@ import com.github.binarywang.wxpay.util.SignUtils; import com.google.common.base.Joiner; import com.google.common.collect.Maps; import jodd.io.ZipUtil; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; +import java.util.zip.ZipException; import static com.github.binarywang.wxpay.constant.WxPayConstants.QUERY_COMMENT_DATE_FORMAT; import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; @@ -142,7 +101,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { String url = this.getPayBaseUrl() + "/secapi/pay/refund"; if (this.getConfig().isUseSandboxEnv()) { - url = PAY_BASE_URL + "/sandboxnew/pay/refund"; + url = PAY_BASE_URL + "/sandboxnew/pay/refund"; } String responseContent = this.post(url, request.toXML(), true); @@ -242,15 +201,9 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException { WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); request.setMchBillNo(mchBillNo); - request.setBillType(BillType.MCHT); - request.checkAndSign(this.getConfig()); - - String url = this.getPayBaseUrl() + "/mmpaymkttransfers/gethbinfo"; - String responseContent = this.post(url, request.toXML(), true); - WxPayRedpackQueryResult result = BaseWxPayResult.fromXML(responseContent, WxPayRedpackQueryResult.class); - result.checkResult(this, request.getSignType(), true); - return result; + return this.queryRedpack(request); } + @Override public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException { request.setBillType(BillType.MCHT); @@ -820,25 +773,16 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { request.setEndTime(QUERY_COMMENT_DATE_FORMAT.format(endDate)); request.setOffset(offset); request.setLimit(limit); - request.setSignType(SignType.HMAC_SHA256); - - request.checkAndSign(this.getConfig()); - String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment"; - - String responseContent = this.post(url, request.toXML(), true); - if (responseContent.startsWith("<")) { - throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class)); - } - - return responseContent; + return this.queryComment(request); } + @Override public String queryComment(WxPayQueryCommentRequest request) throws WxPayException { request.checkAndSign(this.getConfig()); request.setSignType(SignType.HMAC_SHA256); - String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment"; + String url = this.getPayBaseUrl() + "/billcommentsp/batchquerycomment"; String responseContent = this.post(url, request.toXML(), true); if (responseContent.startsWith("<")) { throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));