Skip to content

Commit df8dcb0

Browse files
committed
#752 修复微信支付拉取支付评价的接口(limit不参与签名)
1 parent cc6dd65 commit df8dcb0

File tree

13 files changed

+222
-114
lines changed

13 files changed

+222
-114
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayBankRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ protected void checkConstraints() throws WxPayException {
117117
}
118118

119119
@Override
120-
protected boolean ignoreSignType() {
121-
return true;
120+
protected String[] getIgnoredParamsForSign() {
121+
return new String[]{"sign_type"};
122122
}
123123

124124
@Override

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayQueryRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public String toString() {
5454
}
5555

5656
@Override
57-
protected boolean ignoreSignType() {
58-
return true;
57+
protected String[] getIgnoredParamsForSign() {
58+
return new String[]{"sign_type"};
5959
}
6060
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/entpay/EntPayRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ public String toString() {
198198
}
199199

200200
@Override
201-
protected boolean ignoreSignType() {
202-
return true;
201+
protected String[] getIgnoredParamsForSign() {
202+
return new String[]{"sign_type"};
203203
}
204204
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/BaseWxPayRequest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ public String toXML() {
188188
}
189189

190190
/**
191-
* 签名时,是否忽略signType.
191+
* 签名时,是否忽略appid.
192192
*/
193-
protected boolean ignoreSignType() {
193+
protected boolean ignoreAppid() {
194194
return false;
195195
}
196196

197197
/**
198-
* 签名时,是否忽略appid.
198+
* 签名时,忽略的参数.
199199
*/
200-
protected boolean ignoreAppid() {
201-
return false;
200+
protected String[] getIgnoredParamsForSign() {
201+
return new String[0];
202202
}
203203

204204
/**
@@ -248,7 +248,6 @@ public void checkAndSign(WxPayConfig config) throws WxPayException {
248248
}
249249

250250
//设置签名字段的值
251-
this.setSign(SignUtils.createSign(this, this.getSignType(), config.getMchKey(),
252-
this.ignoreSignType()));
251+
this.setSign(SignUtils.createSign(this, this.getSignType(), config.getMchKey(), this.getIgnoredParamsForSign()));
253252
}
254253
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayDefaultRequest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ public class WxPayDefaultRequest extends BaseWxPayRequest {
1616
protected void checkConstraints() {
1717
//do nothing
1818
}
19+
20+
@Override
21+
protected boolean ignoreAppid() {
22+
return true;
23+
}
1924
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPayQueryCommentRequest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
/**
99
* <pre>
10-
* 拉取订单评价数据接口的请求参数封装类
10+
* 拉取订单评价数据接口的请求参数封装类.
1111
* Created by BinaryWang on 2017/9/2.
1212
* </pre>
1313
*
@@ -20,14 +20,11 @@
2020
@AllArgsConstructor
2121
@XStreamAlias("xml")
2222
public class WxPayQueryCommentRequest extends BaseWxPayRequest {
23-
@Override
24-
protected boolean ignoreSignType() {
25-
return true;
26-
}
23+
private static final long serialVersionUID = 2633600418272768186L;
2724

2825
/**
2926
* <pre>
30-
* 字段名:开始时间
27+
* 字段名:开始时间.
3128
* 变量名:begin_time
3229
* 是否必填:是
3330
* 类型:String(19)
@@ -41,7 +38,7 @@ protected boolean ignoreSignType() {
4138

4239
/**
4340
* <pre>
44-
* 字段名:结束时间
41+
* 字段名:结束时间.
4542
* 变量名:end_time
4643
* 是否必填:是
4744
* 类型:String(19)
@@ -55,7 +52,7 @@ protected boolean ignoreSignType() {
5552

5653
/**
5754
* <pre>
58-
* 字段名:位移
55+
* 字段名:位移.
5956
* 变量名:offset
6057
* 是否必填:是
6158
* 类型:uint(64)
@@ -69,7 +66,7 @@ protected boolean ignoreSignType() {
6966

7067
/**
7168
* <pre>
72-
* 字段名:条数
69+
* 字段名:条数.
7370
* 变量名:limit
7471
* 是否必填:否
7572
* 类型:uint(32)
@@ -81,11 +78,14 @@ protected boolean ignoreSignType() {
8178
private Integer limit;
8279

8380
/**
84-
* 检查约束情况
81+
* 检查约束情况.
8582
*/
8683
@Override
8784
protected void checkConstraints() throws WxPayException {
88-
8985
}
9086

87+
@Override
88+
protected String[] getIgnoredParamsForSign() {
89+
return new String[]{"limit","sign_type"};
90+
}
9191
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxPaySendRedpackRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
@XStreamAlias("xml")
2222
public class WxPaySendRedpackRequest extends BaseWxPayRequest {
2323
@Override
24-
protected boolean ignoreSignType() {
25-
return true;
24+
protected String[] getIgnoredParamsForSign() {
25+
return new String[]{"sign_type"};
2626
}
2727

2828
/**

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,46 @@
11
package com.github.binarywang.wxpay.service;
22

3+
import java.io.File;
4+
import java.util.Date;
5+
import java.util.Map;
6+
37
import com.github.binarywang.wxpay.bean.WxPayApiData;
4-
import com.github.binarywang.wxpay.bean.coupon.*;
8+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest;
9+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult;
10+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest;
11+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult;
12+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest;
13+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult;
514
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
615
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
716
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult;
8-
import com.github.binarywang.wxpay.bean.request.*;
9-
import com.github.binarywang.wxpay.bean.result.*;
17+
import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest;
18+
import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest;
19+
import com.github.binarywang.wxpay.bean.request.WxPayDownloadFundFlowRequest;
20+
import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest;
21+
import com.github.binarywang.wxpay.bean.request.WxPayOrderCloseRequest;
22+
import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest;
23+
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest;
24+
import com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest;
25+
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
26+
import com.github.binarywang.wxpay.bean.request.WxPayReportRequest;
27+
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
28+
import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest;
29+
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
30+
import com.github.binarywang.wxpay.bean.result.WxPayBillResult;
31+
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult;
32+
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
33+
import com.github.binarywang.wxpay.bean.result.WxPayOrderCloseResult;
34+
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
35+
import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult;
36+
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
37+
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
38+
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
39+
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
40+
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
1041
import com.github.binarywang.wxpay.config.WxPayConfig;
1142
import com.github.binarywang.wxpay.exception.WxPayException;
1243

13-
import java.io.File;
14-
import java.util.Date;
15-
import java.util.Map;
16-
1744
/**
1845
* <pre>
1946
* 微信支付相关接口.
@@ -530,7 +557,7 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
530557
* @param beginDate 开始时间
531558
* @param endDate 结束时间
532559
* @param offset 位移
533-
* @param limit 条数
560+
* @param limit 条数,建议填null,否则接口会报签名错误
534561
*/
535562
String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException;
536563
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,70 @@
11
package com.github.binarywang.wxpay.service.impl;
22

3+
import java.io.File;
4+
import java.nio.charset.StandardCharsets;
5+
import java.nio.file.Files;
6+
import java.nio.file.Path;
7+
import java.nio.file.Paths;
8+
import java.util.Date;
9+
import java.util.HashMap;
10+
import java.util.LinkedList;
11+
import java.util.List;
12+
import java.util.Map;
13+
import java.util.zip.ZipException;
14+
15+
import org.apache.commons.lang3.StringUtils;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
18+
319
import com.github.binarywang.utils.qrcode.QrcodeUtils;
420
import com.github.binarywang.wxpay.bean.WxPayApiData;
5-
import com.github.binarywang.wxpay.bean.coupon.*;
21+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest;
22+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult;
23+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest;
24+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult;
25+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest;
26+
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult;
627
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
728
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
829
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult;
930
import com.github.binarywang.wxpay.bean.order.WxPayAppOrderResult;
1031
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
1132
import com.github.binarywang.wxpay.bean.order.WxPayMwebOrderResult;
1233
import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult;
13-
import com.github.binarywang.wxpay.bean.request.*;
14-
import com.github.binarywang.wxpay.bean.result.*;
34+
import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest;
35+
import com.github.binarywang.wxpay.bean.request.WxPayDefaultRequest;
36+
import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest;
37+
import com.github.binarywang.wxpay.bean.request.WxPayDownloadFundFlowRequest;
38+
import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest;
39+
import com.github.binarywang.wxpay.bean.request.WxPayOrderCloseRequest;
40+
import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest;
41+
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest;
42+
import com.github.binarywang.wxpay.bean.request.WxPayQueryCommentRequest;
43+
import com.github.binarywang.wxpay.bean.request.WxPayRedpackQueryRequest;
44+
import com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest;
45+
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
46+
import com.github.binarywang.wxpay.bean.request.WxPayReportRequest;
47+
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
48+
import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest;
49+
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
50+
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
51+
import com.github.binarywang.wxpay.bean.result.WxPayAuthcode2OpenidResult;
52+
import com.github.binarywang.wxpay.bean.result.WxPayBillBaseResult;
53+
import com.github.binarywang.wxpay.bean.result.WxPayBillResult;
54+
import com.github.binarywang.wxpay.bean.result.WxPayCommonResult;
55+
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowBaseResult;
56+
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowResult;
57+
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
58+
import com.github.binarywang.wxpay.bean.result.WxPayOrderCloseResult;
59+
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
60+
import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult;
61+
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
62+
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
63+
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
64+
import com.github.binarywang.wxpay.bean.result.WxPaySandboxSignKeyResult;
65+
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
66+
import com.github.binarywang.wxpay.bean.result.WxPayShorturlResult;
67+
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
1568
import com.github.binarywang.wxpay.config.WxPayConfig;
1669
import com.github.binarywang.wxpay.constant.WxPayConstants.BillType;
1770
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType;
@@ -23,17 +76,6 @@
2376
import com.google.common.base.Joiner;
2477
import com.google.common.collect.Maps;
2578
import jodd.io.ZipUtil;
26-
import org.apache.commons.lang3.StringUtils;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
29-
30-
import java.io.File;
31-
import java.nio.charset.StandardCharsets;
32-
import java.nio.file.Files;
33-
import java.nio.file.Path;
34-
import java.nio.file.Paths;
35-
import java.util.*;
36-
import java.util.zip.ZipException;
3779

3880
import static com.github.binarywang.wxpay.constant.WxPayConstants.QUERY_COMMENT_DATE_FORMAT;
3981
import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType;
@@ -291,7 +333,7 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
291333
configMap.put("appid", appId);
292334

293335
final WxPayAppOrderResult result = WxPayAppOrderResult.builder()
294-
.sign(SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false))
336+
.sign(SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), null))
295337
.prepayId(prepayId)
296338
.partnerId(partnerId)
297339
.appId(appId)
@@ -317,7 +359,7 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
317359
.signType(signType)
318360
.build();
319361

320-
payResult.setPaySign(SignUtils.createSign(payResult, signType, this.getConfig().getMchKey(), false));
362+
payResult.setPaySign(SignUtils.createSign(payResult, signType, this.getConfig().getMchKey(), null));
321363
return (T) payResult;
322364
}
323365

@@ -368,7 +410,7 @@ public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws W
368410
configMap.put("noncestr", nonceStr);
369411
configMap.put("appid", appId);
370412
// 此map用于客户端与微信服务器交互
371-
payInfo.put("sign", SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), false));
413+
payInfo.put("sign", SignUtils.createSign(configMap, null, this.getConfig().getMchKey(), null));
372414
payInfo.put("prepayId", prepayId);
373415
payInfo.put("partnerId", partnerId);
374416
payInfo.put("appId", appId);
@@ -382,7 +424,7 @@ public Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws W
382424
payInfo.put("nonceStr", nonceStr);
383425
payInfo.put("package", "prepay_id=" + prepayId);
384426
payInfo.put("signType", SignType.MD5);
385-
payInfo.put("paySign", SignUtils.createSign(payInfo, null, this.getConfig().getMchKey(), false));
427+
payInfo.put("paySign", SignUtils.createSign(payInfo, null, this.getConfig().getMchKey(), null));
386428
}
387429

388430
return payInfo;
@@ -406,7 +448,7 @@ public String createScanPayQrcodeMode1(String productId) {
406448
params.put("time_stamp", String.valueOf(System.currentTimeMillis() / 1000));
407449
params.put("nonce_str", String.valueOf(System.currentTimeMillis()));
408450

409-
String sign = SignUtils.createSign(params, null, this.getConfig().getMchKey(), false);
451+
String sign = SignUtils.createSign(params, null, this.getConfig().getMchKey(), null);
410452
params.put("sign", sign);
411453

412454
for (String key : params.keySet()) {
@@ -632,7 +674,7 @@ private String handleGzipFundFlow(String url, String requestStr) throws WxPayExc
632674
}
633675
} catch (WxPayException wxPayException) {
634676
throw wxPayException;
635-
} catch (Exception e){
677+
} catch (Exception e) {
636678
this.log.error("解析对账单文件时出错", e);
637679
throw new WxPayException("解压zip文件出错");
638680
}

0 commit comments

Comments
 (0)