v1.0.0
This commit is contained in:
@@ -81,7 +81,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
prepayID, createOrderErr = l.svcCtx.WechatPayService.CreateWechatOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
||||
} else if req.PayMethod == "alipay" {
|
||||
outTradeNo = l.svcCtx.AlipayService.GenerateOutTradeNo()
|
||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product.ProductName, outTradeNo)
|
||||
prepayID, createOrderErr = l.svcCtx.AlipayService.CreateAlipayOrder(l.ctx, amount, product, outTradeNo)
|
||||
} else if req.PayMethod == "appleiap" {
|
||||
outTradeNo = l.svcCtx.ApplePayService.GenerateOutTradeNo()
|
||||
prepayID = l.svcCtx.ApplePayService.GetIappayAppID(product.ProductEn)
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
mathrand "math/rand"
|
||||
"net/http"
|
||||
"qnc-server/app/user/cmd/api/internal/config"
|
||||
"qnc-server/app/user/model"
|
||||
"qnc-server/pkg/lzkit/lzUtils"
|
||||
"strconv"
|
||||
"time"
|
||||
@@ -59,26 +60,20 @@ func (a *AliPayService) CreateAlipayAppOrder(amount float64, subject string, out
|
||||
}
|
||||
|
||||
// CreateAlipayH5Order 创建支付宝H5支付订单
|
||||
func (a *AliPayService) CreateAlipayH5Order(amount float64, subject string, outTradeNo string) (string, error) {
|
||||
func (a *AliPayService) CreateAlipayH5Order(amount float64, subject string, outTradeNo string, returnUrlPath string) (string, error) {
|
||||
client := a.AlipayClient
|
||||
totalAmount := lzUtils.ToAlipayAmount(amount)
|
||||
// 构造H5支付请求
|
||||
p := alipay.TradeWapPay{
|
||||
//Trade: alipay.Trade{
|
||||
// Subject: subject,
|
||||
// OutTradeNo: outTradeNo,
|
||||
// TotalAmount: totalAmount,
|
||||
// ProductCode: "QUICK_WAP_PAY", // H5支付专用产品码
|
||||
// NotifyURL: a.config.NotifyUrl, // 异步回调通知地址
|
||||
// ReturnURL: a.config.ReturnURL,
|
||||
//},
|
||||
Trade: alipay.Trade{
|
||||
Subject: subject,
|
||||
OutTradeNo: outTradeNo,
|
||||
TotalAmount: totalAmount,
|
||||
ProductCode: "QUICK_WAP_PAY", // H5支付专用产品码
|
||||
NotifyURL: a.config.NotifyUrl, // 异步回调通知地址
|
||||
ReturnURL: fmt.Sprintf("%s/%s", a.config.ReturnURL, returnUrlPath),
|
||||
},
|
||||
}
|
||||
p.Subject = subject
|
||||
p.OutTradeNo = outTradeNo
|
||||
p.TotalAmount = totalAmount
|
||||
p.ProductCode = "QUICK_WAP_PAY"
|
||||
p.NotifyURL = a.config.NotifyUrl
|
||||
p.ReturnURL = fmt.Sprintf("%s?callback=true", a.config.ReturnURL)
|
||||
// 获取H5支付请求字符串,这里会签名
|
||||
payUrl, err := client.TradeWapPay(p)
|
||||
if err != nil {
|
||||
@@ -89,7 +84,7 @@ func (a *AliPayService) CreateAlipayH5Order(amount float64, subject string, outT
|
||||
}
|
||||
|
||||
// CreateAlipayOrder 根据平台类型创建支付宝支付订单
|
||||
func (a *AliPayService) CreateAlipayOrder(ctx context.Context, amount float64, subject string, outTradeNo string) (string, error) {
|
||||
func (a *AliPayService) CreateAlipayOrder(ctx context.Context, amount float64, product *model.Product, outTradeNo string) (string, error) {
|
||||
// 根据 ctx 中的 platform 判断平台
|
||||
platform, platformOk := ctx.Value("platform").(string)
|
||||
if !platformOk {
|
||||
@@ -98,10 +93,10 @@ func (a *AliPayService) CreateAlipayOrder(ctx context.Context, amount float64, s
|
||||
switch platform {
|
||||
case "app":
|
||||
// 调用App支付的创建方法
|
||||
return a.CreateAlipayAppOrder(amount, subject, outTradeNo)
|
||||
return a.CreateAlipayAppOrder(amount, product.ProductName, outTradeNo)
|
||||
case "h5":
|
||||
// 调用H5支付的创建方法,并传入 returnUrl
|
||||
return a.CreateAlipayH5Order(amount, subject, outTradeNo)
|
||||
return a.CreateAlipayH5Order(amount, product.ProductName, outTradeNo, product.ProductEn)
|
||||
default:
|
||||
return "", fmt.Errorf("不支持的支付平台: %s", platform)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user