From a1a7ddbc8395d416979032a21401534567028824 Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Fri, 20 Jun 2025 17:48:55 +0800 Subject: [PATCH] fix: update payment method handling in topup controller - Refactored payment method validation to check against available methods. - Changed payment method types from "zfb" to "alipay" and "wx" to "wxpay" for consistency. - Updated the purchase request to use the validated payment method directly. --- controller/topup.go | 14 ++++++-------- setting/payment.go | 4 ++-- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/controller/topup.go b/controller/topup.go index 951b2cf2..827dda39 100644 --- a/controller/topup.go +++ b/controller/topup.go @@ -97,14 +97,12 @@ func RequestEpay(c *gin.Context) { c.JSON(200, gin.H{"message": "error", "data": "充值金额过低"}) return } - payType := "wxpay" - if req.PaymentMethod == "zfb" { - payType = "alipay" - } - if req.PaymentMethod == "wx" { - req.PaymentMethod = "wxpay" - payType = "wxpay" + + if !setting.ContainsPayMethod(req.PaymentMethod) { + c.JSON(200, gin.H{"message": "error", "data": "支付方式不存在"}) + return } + callBackAddress := service.GetCallbackAddress() returnUrl, _ := url.Parse(setting.ServerAddress + "/console/log") notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify") @@ -116,7 +114,7 @@ func RequestEpay(c *gin.Context) { return } uri, params, err := client.Purchase(&epay.PurchaseArgs{ - Type: payType, + Type: req.PaymentMethod, ServiceTradeNo: tradeNo, Name: fmt.Sprintf("TUC%d", req.Amount), Money: strconv.FormatFloat(payMoney, 'f', 2, 64), diff --git a/setting/payment.go b/setting/payment.go index 4ffa4381..3fc0f14a 100644 --- a/setting/payment.go +++ b/setting/payment.go @@ -13,12 +13,12 @@ var PayMethods = []map[string]string{ { "name": "支付宝", "color": "rgba(var(--semi-blue-5), 1)", - "type": "zfb", + "type": "alipay", }, { "name": "微信", "color": "rgba(var(--semi-green-5), 1)", - "type": "wx", + "type": "wxpay", }, }