diff --git a/app/http/entities/front/pay.go b/app/http/entities/front/pay.go index 95e2beb..ee688c3 100644 --- a/app/http/entities/front/pay.go +++ b/app/http/entities/front/pay.go @@ -18,6 +18,7 @@ type PayCommonReqBody struct { Amount int `json:"amount" validate:"required" label:"支付金额,单位分"` ExtJson string `json:"ext_json" label:"扩展参数"` Desc string `json:"desc" validate:"max=100" label:"商品描述"` + ReturnUrl string `json:"return_url" validate:"required,max=1024" label:"支付成功后跳转的地址"` } type PayReqs struct { diff --git a/app/services/thirdpay/do/pay.go b/app/services/thirdpay/do/pay.go index f2a32ed..c954d7b 100644 --- a/app/services/thirdpay/do/pay.go +++ b/app/services/thirdpay/do/pay.go @@ -23,6 +23,7 @@ type PayParam struct { ExtJson string Desc string ClientIp string + ReturnUrl string } type Pay struct { @@ -47,6 +48,7 @@ func NewPayWithPayCheck(paycheck *PayCheck) *Pay { ExtJson: paycheck.Reqs.ExtJson, Desc: paycheck.Reqs.Desc, ClientIp: paycheck.AppCheck.Ip, + ReturnUrl: paycheck.Reqs.ReturnUrl, }, RelationOrder: paycheck.OldOrder, PayCode: errorcode.Success, @@ -102,6 +104,7 @@ func (w *Pay) PayUrl() (url string) { Description: w.Order.Desc, Amount: w.Order.Amount, PayerClientIp: w.PayParam.ClientIp, + ReturnUrl: w.PayParam.ReturnUrl, } if payFunc, ok = PayWayList[w.PayParam.Channel.ChannelType]; !ok { w.PayCode = errorcode.PayChannelNotBuild diff --git a/app/third/paymentService/ali_service.go b/app/third/paymentService/ali_service.go index cd71b2b..fb7034e 100644 --- a/app/third/paymentService/ali_service.go +++ b/app/third/paymentService/ali_service.go @@ -67,6 +67,9 @@ func ALiH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, e Set("total_amount", amount). Set("subject", payOrderRequest.Description). Set("notify_url", fmt.Sprintf(envConfig.PayService.Host+payCommon.ALI_NOTIFY_URL_TEST+"%d", payOrderRequest.PayChannelId)) + if payOrderRequest.ReturnUrl != "" { + bm.Set("return_url", payOrderRequest.ReturnUrl) + } aliRsp, err := aliClient.TradeWapPay(c, bm) if err != nil { diff --git a/app/third/paymentService/payment_service.go b/app/third/paymentService/payment_service.go index 4d53f72..b6f5869 100644 --- a/app/third/paymentService/payment_service.go +++ b/app/third/paymentService/payment_service.go @@ -19,6 +19,7 @@ type PayOrderRequest struct { Description string `json:"description"` // 商品描述 Amount int `json:"amount"` // 金额单位为分 PayerClientIp string `json:"payer_client_ip"` // 终端IP + ReturnUrl string `json:"return_url"` // 支付成功后回调地址 Wx WxPay `json:"wx"` Ali AliPay `json:"ali"` } diff --git a/app/third/paymentService/wechat_service.go b/app/third/paymentService/wechat_service.go index 8f2fd9e..7e7d1bb 100644 --- a/app/third/paymentService/wechat_service.go +++ b/app/third/paymentService/wechat_service.go @@ -13,6 +13,7 @@ import ( "github.com/go-pay/gopay" "github.com/go-pay/gopay/wechat/v3" "github.com/qit-team/snow-core/log/logger" + "net/url" "strconv" "time" ) @@ -85,6 +86,12 @@ func WxH5PayInfo(c context.Context, payOrderRequest PayOrderRequest) (string, er logger.Error(c, "WxH5PayInfo 发生错误", fmt.Sprintf("错误状态码:%d, 错误信息:%s", wxRsp.Code, wxRsp.Error)) return "", errors.New(fmt.Sprintf("发起支付失败,失败状态码:%d, 失败原因:%s", wxRsp.Code, wxRsp.Error)) } + if payOrderRequest.ReturnUrl != "" { + values := url.Values{} + values.Set("redirect_url", payOrderRequest.ReturnUrl) + encodedStr := values.Encode() + wxRsp.Response.H5Url = wxRsp.Response.H5Url + "&" + encodedStr + } return wxRsp.Response.H5Url, nil } @@ -229,8 +236,8 @@ func WxOrderRefund(ctx context.Context, orderRefundRequest OrderRefundRequest) ( SetBodyMap("amount", func(bm gopay.BodyMap) { // 退款金额:单位是分 bm.Set("refund", orderRefundRequest.RefundAmount). //实际退款金额 - Set("total", orderRefundRequest.RefundAmount). // 折扣前总金额(不是实际退款数) - Set("currency", "CNY") + Set("total", orderRefundRequest.RefundAmount). // 折扣前总金额(不是实际退款数) + Set("currency", "CNY") }) // body:参数Body refund, err := wxClient.V3Refund(ctx, bm)