GeezerVison is showing github.com — 商家转账回调报错,版本4.7.4B · Issue #3545 · binarywang/WxJava
Description简要描述
商家转账回调的接口报错
模块版本情况
- WxJava 模块名: weixin-java-pay
- WxJava 版本号: 4.7.4B
详细描述
4.7.3B运行正常,升级到v4.7.4B报错,排查原因发现新版本代码调整了WxPayConfig中的getVerifier()方法,其中Verifier:certificatesVerifier的初始化判定逻辑是
“if (this.getPrivateCertPath() != null && this.getPrivateKeyPath() != null) {” 这样存在不是通过服务器文件初始化的方式,这两个属性为空,导致Verifier空指针,是否调整为 “if (this.getPrivateCertContent() != null && this.getPrivateKeyContent() != null) {” 更为合适
日志
java.lang.NullPointerException: Cannot invoke "com.github.binarywang.wxpay.v3.auth.Verifier.verify(String, byte[], String)" because the return value of "com.github.binarywang.wxpay.config.WxPayConfig.getVerifier()" is null
at com.github.binarywang.wxpay.service.impl.BaseWxPayServiceImpl.verifyNotifySign(BaseWxPayServiceImpl.java:362)
at com.github.binarywang.wxpay.service.impl.BaseWxPayServiceImpl.baseParseOrderNotifyV3Result(BaseWxPayServiceImpl.java:378)
at com.github.binarywang.wxpay.service.impl.TransferServiceImpl.parseTransferBillsNotifyResult(TransferServiceImpl.java:125)
at com.liduoma.lmp.core.goods.service.WxPayMerchantTransferService.transferBillsNotify(WxPayMerchantTransferService.java:90)
Activitybinarywang commented on Apr 8, 2025 SynchPj commented on Apr 10, 2025 binarywang commented on Apr 10, 2025 liuyn001 commented on Apr 10, 2025
是单独使用的公钥吗
通过解析p12文件 直接设置 PrivateCertContent PrivateKeyContent属性 SynchPj commented on Apr 10, 2025 TamakoT commented on Apr 11, 2025 我遇到了同样的问题,debug也是找到了WxPayConfig#getVerifier方法,这里应该先判断publicKey是不是空,不为空直接使用publickKey,而不是先尝试去获取平台证书,新开通的商户就没有平台证书,新版商户直接就提示404没有平台证书
我看4.7.0版本的判断逻辑是这么写的:
Verifier certificatesVerifier;
if (publicKey == null) {
certificatesVerifier =
new AutoUpdateCertificatesVerifier(
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
this.getPayBaseUrl(), wxPayHttpProxy);
} else {
certificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
}
到了4.7.4B新版本变成这样了:
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);
certificatesVerifier = publicCertificatesVerifier;
}
return certificatesVerifier;binarywang commented on Apr 11, 2025
我遇到了同样的问题,debug也是找到了WxPayConfig#getVerifier方法,这里应该先判断publicKey是不是空,不为空直接使用publickKey,而不是先尝试去获取平台证书,新开通的商户就没有平台证书,新版商户直接就提示404没有平台证书
我看4.7.0版本的判断逻辑是这么写的:
Verifier certificatesVerifier;
if (publicKey == null) {
certificatesVerifier =
new AutoUpdateCertificatesVerifier(
new WxPayCredentials(mchId, new PrivateKeySigner(certSerialNo, merchantPrivateKey)),
this.getApiV3Key().getBytes(StandardCharsets.UTF_8), this.getCertAutoUpdateTime(),
this.getPayBaseUrl(), wxPayHttpProxy);
} else {
certificatesVerifier = new PublicCertificateVerifier(publicKey, publicKeyId);
}
到了4.7.4B新版本变成这样了:
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);
certificatesVerifier = publicCertificatesVerifier;
}
return certificatesVerifier;
欢迎基于#3547 提供你的代码,谢谢
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|