From 02c8ace29b258d91f684db5ce40b2a91755ae917 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Wed, 19 Nov 2025 19:50:16 +0800 Subject: [PATCH] fix --- app/main/api/internal/service/wechatpayService.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/main/api/internal/service/wechatpayService.go b/app/main/api/internal/service/wechatpayService.go index cfd0ac1..614ece5 100644 --- a/app/main/api/internal/service/wechatpayService.go +++ b/app/main/api/internal/service/wechatpayService.go @@ -137,15 +137,10 @@ func newWechatPayServiceWithWxPayPubKey(c config.Config, userAuthModel model.Use } // 初始化 notify.Handler - // 使用公钥方式时,certificateVisitor 可能为 nil,直接使用公钥验证器 + // 使用微信支付公钥方式时,使用 NewSHA256WithRSAPubkeyVerifier notifyHandler := notify.NewNotifyHandler( mchAPIv3Key, - verifiers.NewSHA256WithRSACombinedVerifier(nil, mchPublicKeyID, *mchPublicKey)) - - if notifyHandler == nil { - logx.Errorf("创建 notifyHandler 失败") - panic("初始化失败,服务停止: notifyHandler 为 nil") - } + verifiers.NewSHA256WithRSAPubkeyVerifier(mchPublicKeyID, *mchPublicKey)) logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)") return &WechatPayService{ @@ -299,9 +294,6 @@ func (w *WechatPayService) CreateWechatOrder(ctx context.Context, amount float64 // HandleWechatPayNotification 处理微信支付回调 func (w *WechatPayService) HandleWechatPayNotification(ctx context.Context, req *http.Request) (*payments.Transaction, error) { - if w.notifyHandler == nil { - return nil, fmt.Errorf("微信支付通知处理器未初始化") - } transaction := new(payments.Transaction) _, err := w.notifyHandler.ParseNotifyRequest(ctx, req, transaction) if err != nil { @@ -313,9 +305,6 @@ func (w *WechatPayService) HandleWechatPayNotification(ctx context.Context, req // HandleRefundNotification 处理微信退款回调 func (w *WechatPayService) HandleRefundNotification(ctx context.Context, req *http.Request) (*refunddomestic.Refund, error) { - if w.notifyHandler == nil { - return nil, fmt.Errorf("微信支付通知处理器未初始化") - } refund := new(refunddomestic.Refund) _, err := w.notifyHandler.ParseNotifyRequest(ctx, req, refund) if err != nil {