This commit is contained in:
2025-12-02 22:31:37 +08:00
parent 57943700ba
commit 00cd6a1e6e
2 changed files with 5 additions and 15 deletions

View File

@@ -63,7 +63,6 @@ type WxpayConfig struct {
MchPrivateKeyPath string MchPrivateKeyPath string
MchPublicKeyID string MchPublicKeyID string
MchPublicKeyPath string MchPublicKeyPath string
MchPlatformRAS string // 微信支付平台证书序列号(用于回调验证)
NotifyUrl string NotifyUrl string
RefundNotifyUrl string RefundNotifyUrl string
} }

View File

@@ -137,22 +137,13 @@ func newWechatPayServiceWithWxPayPubKey(c config.Config, userAuthModel model.Use
} }
// 初始化 notify.Handler // 初始化 notify.Handler
// 使用本地公钥直接验证不依赖证书下载器适用于2025年后新商户或平台证书过期的情况 // certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
// SHA256WithRSACombinedVerifier 会先尝试从证书下载器获取证书,如果找不到且序列号匹配则使用本地公钥 // notifyHandler := notify.NewNotifyHandler(
// 注意:回调通知中的序列号需要与 publicKeyID 匹配才能使用本地公钥 // mchAPIv3Key,
// 如果配置了 MchPlatformRAS使用它作为公钥ID因为回调通知使用的序列号通常是平台证书序列号 // verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, mchPublicKeyID, *mchPublicKey))
publicKeyIDForVerify := mchPublicKeyID
if c.Wxpay.MchPlatformRAS != "" {
// 如果配置了平台证书序列号使用它作为验证时的公钥ID
// 这样回调通知中的序列号就能匹配上
publicKeyIDForVerify = c.Wxpay.MchPlatformRAS
logx.Infof("使用平台证书序列号作为公钥ID进行回调验证: %s", publicKeyIDForVerify)
}
certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
notifyHandler := notify.NewNotifyHandler( notifyHandler := notify.NewNotifyHandler(
mchAPIv3Key, mchAPIv3Key,
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, publicKeyIDForVerify, *mchPublicKey)) verifiers.NewSHA256WithRSAPubkeyVerifier(mchPublicKeyID, *mchPublicKey))
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)") logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)")
return &WechatPayService{ return &WechatPayService{
config: c, config: c,