From 72194bda98bcb3ea3ca8fcd730a4d46042a73ef4 Mon Sep 17 00:00:00 2001
From: "1808837298@qq.com" <1808837298@qq.com>
Date: Sat, 2 Mar 2024 22:07:32 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8F=AF=E8=87=AA=E5=AE=9A=E4=B9=89?=
=?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83=E5=9C=B0=E5=9D=80=E5=8F=8A?=
=?UTF-8?q?=E6=9C=80=E4=BD=8E=E8=B4=AD=E4=B9=B0=E6=95=B0=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
common/constants.go | 13 +++++++----
controller/misc.go | 1 +
controller/topup.go | 16 ++++++-------
model/option.go | 6 +++++
service/epay.go | 10 +++++++++
web/src/components/SystemSetting.js | 35 ++++++++++++++++++++++-------
web/src/pages/TopUp/index.js | 17 ++++++++++++--
7 files changed, 76 insertions(+), 22 deletions(-)
create mode 100644 service/epay.go
diff --git a/common/constants.go b/common/constants.go
index e11d7fe..8352d14 100644
--- a/common/constants.go
+++ b/common/constants.go
@@ -9,14 +9,19 @@ import (
"github.com/google/uuid"
)
+// Pay Settings
+
+var PayAddress = ""
+var CustomCallbackAddress = ""
+var EpayId = ""
+var EpayKey = ""
+var Price = 7.3
+var MinTopUp = 1
+
var StartTime = time.Now().Unix() // unit: second
var Version = "v0.0.0" // this hard coding will be replaced automatically when building, no need to manually change
var SystemName = "New API"
var ServerAddress = "http://localhost:3000"
-var PayAddress = ""
-var EpayId = ""
-var EpayKey = ""
-var Price = 7.3
var Footer = ""
var Logo = ""
var TopUpLink = ""
diff --git a/controller/misc.go b/controller/misc.go
index 3ed3c5e..b992a0c 100644
--- a/controller/misc.go
+++ b/controller/misc.go
@@ -27,6 +27,7 @@ func GetStatus(c *gin.Context) {
"wechat_login": common.WeChatAuthEnabled,
"server_address": common.ServerAddress,
"price": common.Price,
+ "min_topup": common.MinTopUp,
"turnstile_check": common.TurnstileCheckEnabled,
"turnstile_site_key": common.TurnstileSiteKey,
"top_up_link": common.TopUpLink,
diff --git a/controller/topup.go b/controller/topup.go
index 961ffa2..3203eb8 100644
--- a/controller/topup.go
+++ b/controller/topup.go
@@ -9,6 +9,7 @@ import (
"net/url"
"one-api/common"
"one-api/model"
+ "one-api/service"
"strconv"
"time"
)
@@ -55,14 +56,14 @@ func RequestEpay(c *gin.Context) {
c.JSON(200, gin.H{"message": err.Error(), "data": 10})
return
}
- if req.Amount < 1 {
- c.JSON(200, gin.H{"message": "充值金额不能小于1", "data": 10})
+ if req.Amount < common.MinTopUp {
+ c.JSON(200, gin.H{"message": fmt.Sprintf("充值数量不能小于 %d", common.MinTopUp), "data": 10})
return
}
id := c.GetInt("id")
user, _ := model.GetUserById(id, false)
- amount := GetAmount(float64(req.Amount), *user)
+ payMoney := GetAmount(float64(req.Amount), *user)
var payType epay.PurchaseType
if req.PaymentMethod == "zfb" {
@@ -72,11 +73,10 @@ func RequestEpay(c *gin.Context) {
req.PaymentMethod = "wxpay"
payType = epay.WechatPay
}
-
+ callBackAddress := service.GetCallbackAddress()
returnUrl, _ := url.Parse(common.ServerAddress + "/log")
- notifyUrl, _ := url.Parse(common.ServerAddress + "/api/user/epay/notify")
+ notifyUrl, _ := url.Parse(callBackAddress + "/api/user/epay/notify")
tradeNo := strconv.FormatInt(time.Now().Unix(), 10)
- payMoney := amount
client := GetEpayClient()
if client == nil {
c.JSON(200, gin.H{"message": "error", "data": "当前管理员未配置支付信息"})
@@ -169,8 +169,8 @@ func RequestAmount(c *gin.Context) {
c.JSON(200, gin.H{"message": "error", "data": "参数错误"})
return
}
- if req.Amount < 1 {
- c.JSON(200, gin.H{"message": "error", "data": "充值金额不能小于1"})
+ if req.Amount < common.MinTopUp {
+ c.JSON(200, gin.H{"message": "error", "data": fmt.Sprintf("充值数量不能小于 %d", common.MinTopUp)})
return
}
id := c.GetInt("id")
diff --git a/model/option.go b/model/option.go
index 03c0230..c2aeecd 100644
--- a/model/option.go
+++ b/model/option.go
@@ -56,9 +56,11 @@ func InitOptionMap() {
common.OptionMap["Logo"] = common.Logo
common.OptionMap["ServerAddress"] = ""
common.OptionMap["PayAddress"] = ""
+ common.OptionMap["CustomCallbackAddress"] = ""
common.OptionMap["EpayId"] = ""
common.OptionMap["EpayKey"] = ""
common.OptionMap["Price"] = strconv.FormatFloat(common.Price, 'f', -1, 64)
+ common.OptionMap["MinTopUp"] = strconv.Itoa(common.MinTopUp)
common.OptionMap["TopupGroupRatio"] = common.TopupGroupRatio2JSONString()
common.OptionMap["GitHubClientId"] = ""
common.OptionMap["GitHubClientSecret"] = ""
@@ -194,12 +196,16 @@ func updateOptionMap(key string, value string) (err error) {
common.ServerAddress = value
case "PayAddress":
common.PayAddress = value
+ case "CustomCallbackAddress":
+ common.CustomCallbackAddress = value
case "EpayId":
common.EpayId = value
case "EpayKey":
common.EpayKey = value
case "Price":
common.Price, _ = strconv.ParseFloat(value, 64)
+ case "MinTopUp":
+ common.MinTopUp, _ = strconv.Atoi(value)
case "TopupGroupRatio":
err = common.UpdateTopupGroupRatioByJSONString(value)
case "GitHubClientId":
diff --git a/service/epay.go b/service/epay.go
new file mode 100644
index 0000000..7ce4aad
--- /dev/null
+++ b/service/epay.go
@@ -0,0 +1,10 @@
+package service
+
+import "one-api/common"
+
+func GetCallbackAddress() string {
+ if common.CustomCallbackAddress == "" {
+ return common.ServerAddress
+ }
+ return common.CustomCallbackAddress
+}
diff --git a/web/src/components/SystemSetting.js b/web/src/components/SystemSetting.js
index 197050e..e622574 100644
--- a/web/src/components/SystemSetting.js
+++ b/web/src/components/SystemSetting.js
@@ -20,8 +20,10 @@ const SystemSetting = () => {
EpayId: '',
EpayKey: '',
Price: 7.3,
+ MinTopUp: 1,
TopupGroupRatio: '',
PayAddress: '',
+ CustomCallbackAddress: '',
Footer: '',
WeChatAuthEnabled: '',
WeChatServerAddress: '',
@@ -280,7 +282,7 @@ const SystemSetting = () => {
更新服务器地址