1
0
mirror of synced 2025-12-16 03:57:56 +08:00

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

View File

@@ -24,7 +24,7 @@ public class PublicCertificateVerifier implements Verifier{
@Override @Override
public boolean verify(String serialNumber, byte[] message, String signature) { 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); return this.certificateVerifier.verify(serialNumber, message, signature);
} }
try { try {