Skip to content

Commit 457a2c5

Browse files
committed
🎨 binarywang#3530 【微信支付】修复未设置平台证书引起的v3请求构造异常
1 parent b225afb commit 457a2c5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java

+8-4
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,14 @@ public CloseableHttpClient initApiV3HttpClient() throws WxPayException {
347347
}
348348

349349
private Verifier getVerifier(PrivateKey merchantPrivateKey, WxPayHttpProxy wxPayHttpProxy, PublicKey publicKey) {
350-
Verifier certificatesVerifier = new AutoUpdateCertificatesVerifier(
351-
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
352-
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
353-
this.getPayBaseUrl(), wxPayHttpProxy);
350+
Verifier certificatesVerifier = null;
351+
// 如果配置了平台证书,则初始化验证器以备v2版本接口验签(公钥灰度实现)
352+
if (this.getPrivateCertPath() != null && this.getPrivateKeyPath() != null) {
353+
certificatesVerifier = new AutoUpdateCertificatesVerifier(
354+
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
355+
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
356+
this.getPayBaseUrl(), wxPayHttpProxy);
357+
}
354358
if (publicKey != null) {
355359
Verifier publicCertificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
356360
publicCertificatesVerifier.setOtherVerifier(certificatesVerifier);

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/PublicCertificateVerifier.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void setOtherVerifier(Verifier verifier) {
2424

2525
@Override
2626
public boolean verify(String serialNumber, byte[] message, String signature) {
27-
if (!serialNumber.contains("PUB_KEY_ID")) {
27+
if (!serialNumber.contains("PUB_KEY_ID") && this.certificateVerifier != null) {
2828
return this.certificateVerifier.verify(serialNumber, message, signature);
2929
}
3030
try {

0 commit comments

Comments
 (0)