Browse Source

优化及规范部分新提交代码

master
Binary Wang 5 years ago
parent
commit
cea482a762
2 changed files with 22 additions and 81 deletions
  1. +2
    -5
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
  2. +20
    -76
      weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

+ 2
- 5
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java View File

@@ -313,7 +313,7 @@ public interface WxPayService {
* 请求方式:POST * 请求方式:POST
* </pre> * </pre>
* *
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890
* @param request 红包查询请求
* @return the wx pay redpack query result * @return the wx pay redpack query result
* @throws WxPayException the wx pay exception * @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 * 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_17&index=10
* </pre> * </pre>
* *
* @param beginDate 开始时间
* @param endDate 结束时间
* @param offset 位移
* @param limit 条数,建议填null,否则接口会报签名错误
* @param request 查询请求
* @return the string * @return the string
* @throws WxPayException the wx pay exception * @throws WxPayException the wx pay exception
*/ */


+ 20
- 76
weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java View File

@@ -1,29 +1,8 @@
package com.github.binarywang.wxpay.service.impl; 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.utils.qrcode.QrcodeUtils;
import com.github.binarywang.wxpay.bean.WxPayApiData; 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.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult; 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.WxPayMpOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult; import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; 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.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants.BillType; import com.github.binarywang.wxpay.constant.WxPayConstants.BillType;
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType; 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.base.Joiner;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import jodd.io.ZipUtil; 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.QUERY_COMMENT_DATE_FORMAT;
import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; 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"; String url = this.getPayBaseUrl() + "/secapi/pay/refund";
if (this.getConfig().isUseSandboxEnv()) { 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); 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 { public WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException {
WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest(); WxPayRedpackQueryRequest request = new WxPayRedpackQueryRequest();
request.setMchBillNo(mchBillNo); 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 @Override
public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException { public WxPayRedpackQueryResult queryRedpack(WxPayRedpackQueryRequest request) throws WxPayException {
request.setBillType(BillType.MCHT); request.setBillType(BillType.MCHT);
@@ -820,25 +773,16 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
request.setEndTime(QUERY_COMMENT_DATE_FORMAT.format(endDate)); request.setEndTime(QUERY_COMMENT_DATE_FORMAT.format(endDate));
request.setOffset(offset); request.setOffset(offset);
request.setLimit(limit); 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 @Override
public String queryComment(WxPayQueryCommentRequest request) throws WxPayException { public String queryComment(WxPayQueryCommentRequest request) throws WxPayException {
request.checkAndSign(this.getConfig()); request.checkAndSign(this.getConfig());
request.setSignType(SignType.HMAC_SHA256); 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); String responseContent = this.post(url, request.toXML(), true);
if (responseContent.startsWith("<")) { if (responseContent.startsWith("<")) {
throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class)); throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));


Loading…
Cancel
Save