fix
This commit is contained in:
Binary file not shown.
@@ -63,6 +63,7 @@ type WxpayConfig struct {
|
||||
MchPrivateKeyPath string
|
||||
MchPublicKeyID string
|
||||
MchPublicKeyPath string
|
||||
MchPlatformRAS string // 微信支付平台证书序列号(用于回调验证)
|
||||
NotifyUrl string
|
||||
RefundNotifyUrl string
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"ycc-server/app/main/api/internal/config"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/pkg/lzkit/lzUtils"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
"ycc-server/app/main/api/internal/config"
|
||||
"ycc-server/app/main/model"
|
||||
"ycc-server/common/ctxdata"
|
||||
"ycc-server/pkg/lzkit/lzUtils"
|
||||
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
|
||||
@@ -137,10 +137,21 @@ func newWechatPayServiceWithWxPayPubKey(c config.Config, userAuthModel model.Use
|
||||
}
|
||||
|
||||
// 初始化 notify.Handler
|
||||
// 使用本地公钥直接验证,不依赖证书下载器(适用于2025年后新商户或平台证书过期的情况)
|
||||
// SHA256WithRSACombinedVerifier 会先尝试从证书下载器获取证书,如果找不到且序列号匹配则使用本地公钥
|
||||
// 注意:回调通知中的序列号需要与 publicKeyID 匹配才能使用本地公钥
|
||||
// 如果配置了 MchPlatformRAS,使用它作为公钥ID(因为回调通知使用的序列号通常是平台证书序列号)
|
||||
publicKeyIDForVerify := mchPublicKeyID
|
||||
if c.Wxpay.MchPlatformRAS != "" {
|
||||
// 如果配置了平台证书序列号,使用它作为验证时的公钥ID
|
||||
// 这样回调通知中的序列号就能匹配上
|
||||
publicKeyIDForVerify = c.Wxpay.MchPlatformRAS
|
||||
logx.Infof("使用平台证书序列号作为公钥ID进行回调验证: %s", publicKeyIDForVerify)
|
||||
}
|
||||
certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
|
||||
notifyHandler := notify.NewNotifyHandler(
|
||||
mchAPIv3Key,
|
||||
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, mchPublicKeyID, *mchPublicKey))
|
||||
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, publicKeyIDForVerify, *mchPublicKey))
|
||||
|
||||
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)")
|
||||
return &WechatPayService{
|
||||
|
||||
Reference in New Issue
Block a user