补充微信支付官方手机端接口支持

This commit is contained in:
2026-03-11 13:08:15 +08:00
parent 7fe415de63
commit 3dc9bc5b1d
3 changed files with 22 additions and 90 deletions

View File

@@ -10,6 +10,7 @@ import (
"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/partnerpayments/h5"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
"github.com/wechatpay-apiv3/wechatpay-go/utils"
)
@@ -18,6 +19,7 @@ var WechatPay *WechatPayClient
type WechatPayClient struct {
Native *native.NativeApiService
H5 *h5.H5ApiService
Notify *notify.Handler
}
@@ -71,6 +73,7 @@ func initWechatPay() error {
// 创建 WechatPay 服务
WechatPay = &WechatPayClient{
Native: &native.NativeApiService{Client: client},
H5: &h5.H5ApiService{Client: client},
Notify: handler,
}
return nil

View File

@@ -21,6 +21,7 @@ import (
wecahtpaycore "github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/smartwalle/alipay/v3"
"github.com/wechatpay-apiv3/wechatpay-go/services/partnerpayments/h5"
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
"gorm.io/gorm"
)
@@ -150,6 +151,24 @@ func (s *tradeService) CreateTrade(uid int32, now time.Time, data *CreateTradeDa
}
paymentUrl = *resp.CodeUrl
// 微信 + 手机网站
case method == m.TradeMethodWechat && platform == m.TradePlatformMobile:
resp, _, err := g.WechatPay.H5.Prepay(context.Background(), h5.PrepayRequest{
SpAppid: &env.WechatPayAppId,
SpMchid: &env.WechatPayMchId,
OutTradeNo: &tradeNo,
Description: &subject,
TimeExpire: &expire,
NotifyUrl: &env.WechatPayCallbackUrl,
Amount: &h5.Amount{
Total: u.P(amountReal.Mul(decimal.NewFromInt(100)).Round(0).IntPart()),
},
})
if err != nil {
return nil, err
}
paymentUrl = *resp.H5Url
// 商福通 + 电脑网站
case
method == m.TradeMethodSftAlipay && platform == m.TradePlatformPC,