Skip to content

Commit c6a38ae

Browse files
authored
🎨 #3288【微信支付】修复由于微信签名探测导致的验签错误的问题
1 parent 577f2e6 commit c6a38ae

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.binarywang.wxpay.exception;
2+
3+
/**
4+
* <pre>
5+
* 微信支付签名探测异常类
6+
* </pre>
7+
* @author je45
8+
* @date 2024/11/27 9:35
9+
*/
10+
public class WxSignTestException extends WxPayException {
11+
private static final long serialVersionUID = -303371909244098058L;
12+
13+
/**
14+
* Instantiates a new Wx pay exception.
15+
*
16+
* @param customErrorMsg the custom error msg
17+
*/
18+
public WxSignTestException(String customErrorMsg) {
19+
super(customErrorMsg);
20+
}
21+
22+
/**
23+
* Instantiates a new Wx pay exception.
24+
*
25+
* @param customErrorMsg the custom error msg
26+
* @param tr the tr
27+
*/
28+
public WxSignTestException(String customErrorMsg, Throwable tr) {
29+
super(customErrorMsg, tr);
30+
}
31+
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.github.binarywang.wxpay.constant.WxPayConstants.SignType;
1818
import com.github.binarywang.wxpay.constant.WxPayConstants.TradeType;
1919
import com.github.binarywang.wxpay.exception.WxPayException;
20+
import com.github.binarywang.wxpay.exception.WxSignTestException;
2021
import com.github.binarywang.wxpay.service.*;
2122
import com.github.binarywang.wxpay.util.SignUtils;
2223
import com.github.binarywang.wxpay.util.XmlConfig;
@@ -343,7 +344,11 @@ public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData, String sign
343344
* @param data 通知数据
344345
* @return true:校验通过 false:校验不通过
345346
*/
346-
private boolean verifyNotifySign(SignatureHeader header, String data) {
347+
private boolean verifyNotifySign(SignatureHeader header, String data) throws WxSignTestException {
348+
String wxPaySign = header.getSignature();
349+
if(wxPaySign.startsWith("WECHATPAY/SIGNTEST/")){
350+
throw new WxSignTestException("微信支付签名探测流量");
351+
}
347352
String beforeSign = String.format("%s\n%s\n%s\n",
348353
header.getTimeStamp(),
349354
header.getNonce(),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.github.binarywang.wxpay.bean.payscore.WxPayScoreResult;
88
import com.github.binarywang.wxpay.config.WxPayConfig;
99
import com.github.binarywang.wxpay.exception.WxPayException;
10+
import com.github.binarywang.wxpay.exception.WxSignTestException;
1011
import com.github.binarywang.wxpay.service.PayScoreService;
1112
import com.github.binarywang.wxpay.service.WxPayService;
1213
import com.github.binarywang.wxpay.v3.util.AesUtils;
@@ -327,7 +328,11 @@ public WxPayScoreResult decryptNotifyDataResource(PayScoreNotifyData data) throw
327328
* @param data 通知数据
328329
* @return true:校验通过 false:校验不通过
329330
*/
330-
private boolean verifyNotifySign(SignatureHeader header, String data) {
331+
private boolean verifyNotifySign(SignatureHeader header, String data) throws WxSignTestException {
332+
String wxPaySign = header.getSigned();
333+
if(wxPaySign.startsWith("WECHATPAY/SIGNTEST/")){
334+
throw new WxSignTestException("微信支付签名探测流量");
335+
}
331336
String beforeSign = String.format("%s\n%s\n%s\n", header.getTimeStamp(), header.getNonce(), data);
332337
return payService.getConfig().getVerifier().verify(header.getSerialNo(),
333338
beforeSign.getBytes(StandardCharsets.UTF_8), header.getSigned());

0 commit comments

Comments
 (0)