fix
This commit is contained in:
@@ -2,14 +2,14 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"tydata-server/app/main/api/internal/config"
|
|
||||||
"tydata-server/app/main/model"
|
|
||||||
"tydata-server/common/ctxdata"
|
|
||||||
"tydata-server/pkg/lzkit/lzUtils"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"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"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
|
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
|
||||||
@@ -137,10 +137,15 @@ func newWechatPayServiceWithWxPayPubKey(c config.Config, userAuthModel model.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 初始化 notify.Handler
|
// 初始化 notify.Handler
|
||||||
certificateVisitor := downloader.MgrInstance().GetCertificateVisitor(mchID)
|
// 使用公钥方式时,certificateVisitor 可能为 nil,直接使用公钥验证器
|
||||||
notifyHandler := notify.NewNotifyHandler(
|
notifyHandler := notify.NewNotifyHandler(
|
||||||
mchAPIv3Key,
|
mchAPIv3Key,
|
||||||
verifiers.NewSHA256WithRSACombinedVerifier(certificateVisitor, mchPublicKeyID, *mchPublicKey))
|
verifiers.NewSHA256WithRSACombinedVerifier(nil, mchPublicKeyID, *mchPublicKey))
|
||||||
|
|
||||||
|
if notifyHandler == nil {
|
||||||
|
logx.Errorf("创建 notifyHandler 失败")
|
||||||
|
panic("初始化失败,服务停止: notifyHandler 为 nil")
|
||||||
|
}
|
||||||
|
|
||||||
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)")
|
logx.Infof("微信支付客户端初始化成功(微信支付公钥方式)")
|
||||||
return &WechatPayService{
|
return &WechatPayService{
|
||||||
@@ -294,6 +299,9 @@ func (w *WechatPayService) CreateWechatOrder(ctx context.Context, amount float64
|
|||||||
|
|
||||||
// HandleWechatPayNotification 处理微信支付回调
|
// HandleWechatPayNotification 处理微信支付回调
|
||||||
func (w *WechatPayService) HandleWechatPayNotification(ctx context.Context, req *http.Request) (*payments.Transaction, error) {
|
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)
|
transaction := new(payments.Transaction)
|
||||||
_, err := w.notifyHandler.ParseNotifyRequest(ctx, req, transaction)
|
_, err := w.notifyHandler.ParseNotifyRequest(ctx, req, transaction)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -305,6 +313,9 @@ func (w *WechatPayService) HandleWechatPayNotification(ctx context.Context, req
|
|||||||
|
|
||||||
// HandleRefundNotification 处理微信退款回调
|
// HandleRefundNotification 处理微信退款回调
|
||||||
func (w *WechatPayService) HandleRefundNotification(ctx context.Context, req *http.Request) (*refunddomestic.Refund, error) {
|
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)
|
refund := new(refunddomestic.Refund)
|
||||||
_, err := w.notifyHandler.ParseNotifyRequest(ctx, req, refund)
|
_, err := w.notifyHandler.ParseNotifyRequest(ctx, req, refund)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user