This commit is contained in:
2025-11-19 19:45:00 +08:00
parent 8c1a072f5c
commit 35094559a0

View File

@@ -2,14 +2,14 @@ package service
import (
"context"
"tydata-server/app/main/api/internal/config"
"tydata-server/app/main/model"
"tydata-server/common/ctxdata"
"tydata-server/pkg/lzkit/lzUtils"
"fmt"
"net/http"
"strconv"
"time"
"tydata-server/app/main/api/internal/config"
"tydata-server/app/main/model"
"tydata-server/common/ctxdata"
"tydata-server/pkg/lzkit/lzUtils"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
@@ -137,10 +137,15 @@ func newWechatPayServiceWithWxPayPubKey(c config.Config, userAuthModel model.Use
}
// 初始化 notify.Handler
certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
// 使用公钥方式时,certificateVisitor 可能为 nil直接使用公钥验证器
notifyHandler := notify.NewNotifyHandler(
mchAPIv3Key,
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, mchPublicKeyID, *mchPublicKey))
verifiers.NewSHA256WithRSACombinedVerifier(nil, mchPublicKeyID, *mchPublicKey))
if notifyHandler == nil {
logx.Errorf("创建 notifyHandler 失败")
panic("初始化失败,服务停止: notifyHandler 为 nil")
}
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)")
return &WechatPayService{
@@ -294,6 +299,9 @@ 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 {
@@ -305,6 +313,9 @@ 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 {