添加支付宝和微信充值功能,重构交易处理逻辑,优化资源创建与支付链接生成

This commit is contained in:
2025-04-18 16:22:38 +08:00
parent f6a97545c5
commit a7e59fb1d7
14 changed files with 939 additions and 224 deletions

View File

@@ -5,6 +5,8 @@ import (
"platform/pkg/env"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
"github.com/wechatpay-apiv3/wechatpay-go/core/notify"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
@@ -14,10 +16,12 @@ var WechatPay *WechatPayClient
type WechatPayClient struct {
Native *native.NativeApiService
Notify *notify.Handler
}
func InitWechatPay() {
// 加载 rsa 密钥文件
appPrivateKey, err := utils.LoadPrivateKey(env.WechatPayMchPrivateKeyPath)
if err != nil {
panic(err)
@@ -28,6 +32,7 @@ func InitWechatPay() {
panic(err)
}
// 创建 WechatPay 客户端
client, err := core.NewClient(context.Background(),
option.WithWechatPayPublicKeyAuthCipher(
env.WechatPayMchId,
@@ -41,7 +46,18 @@ func InitWechatPay() {
panic(err)
}
// 创建 WechatPay 通知处理器
handler, err := notify.NewRSANotifyHandler(env.WechatPayApiCert, verifiers.NewSHA256WithRSAPubkeyVerifier(
env.WechatPayPublicKeyId,
*wechatPublicKey,
))
if err != nil {
panic(err)
}
// 创建 WechatPay 服务
WechatPay = &WechatPayClient{
Native: &native.NativeApiService{Client: client},
Notify: handler,
}
}