🎨 #3530 【微信支付】修复未设置平台证书引起的v3请求构造异常

This commit is contained in:
SynchPj
2025-04-07 13:01:53 +08:00
committed by GitHub
parent b225afbd68
commit dd407141b0
2 changed files with 9 additions and 5 deletions

View File

@@ -347,10 +347,14 @@ public class WxPayConfig {
}
private Verifier getVerifier(PrivateKey merchantPrivateKey, WxPayHttpProxy wxPayHttpProxy, PublicKey publicKey) {
Verifier certificatesVerifier = new AutoUpdateCertificatesVerifier(
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
this.getPayBaseUrl(), wxPayHttpProxy);
Verifier certificatesVerifier = null;
// 如果配置了平台证书则初始化验证器以备v2版本接口验签公钥灰度实现
if (this.getPrivateCertPath() != null && this.getPrivateKeyPath() != null) {
certificatesVerifier = new AutoUpdateCertificatesVerifier(
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
this.getPayBaseUrl(), wxPayHttpProxy);
}
if (publicKey != null) {
Verifier publicCertificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
publicCertificatesVerifier.setOtherVerifier(certificatesVerifier);

View File

@@ -24,7 +24,7 @@ public class PublicCertificateVerifier implements Verifier{
@Override
public boolean verify(String serialNumber, byte[] message, String signature) {
if (!serialNumber.contains("PUB_KEY_ID")) {
if (!serialNumber.contains("PUB_KEY_ID") && this.certificateVerifier != null) {
return this.certificateVerifier.verify(serialNumber, message, signature);
}
try {