Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
53d25cc6
authored
Mar 02, 2024
by
1808837298@qq.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 可自定义支付回调地址及最低购买数量
parent
5e0bd0f0
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
22 deletions
+76
-22
common/constants.go
+9
-4
controller/misc.go
+1
-0
controller/topup.go
+8
-8
model/option.go
+6
-0
service/epay.go
+10
-0
web/src/components/SystemSetting.js
+27
-8
web/src/pages/TopUp/index.js
+15
-2
No files found.
common/constants.go
View file @
53d25cc6
...
@@ -9,14 +9,19 @@ import (
...
@@ -9,14 +9,19 @@ import (
"github.com/google/uuid"
"github.com/google/uuid"
)
)
var
StartTime
=
time
.
Now
()
.
Unix
()
// unit: second
// Pay Settings
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
PayAddress
=
""
var
CustomCallbackAddress
=
""
var
EpayId
=
""
var
EpayId
=
""
var
EpayKey
=
""
var
EpayKey
=
""
var
Price
=
7.3
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
Footer
=
""
var
Footer
=
""
var
Logo
=
""
var
Logo
=
""
var
TopUpLink
=
""
var
TopUpLink
=
""
...
...
controller/misc.go
View file @
53d25cc6
...
@@ -27,6 +27,7 @@ func GetStatus(c *gin.Context) {
...
@@ -27,6 +27,7 @@ func GetStatus(c *gin.Context) {
"wechat_login"
:
common
.
WeChatAuthEnabled
,
"wechat_login"
:
common
.
WeChatAuthEnabled
,
"server_address"
:
common
.
ServerAddress
,
"server_address"
:
common
.
ServerAddress
,
"price"
:
common
.
Price
,
"price"
:
common
.
Price
,
"min_topup"
:
common
.
MinTopUp
,
"turnstile_check"
:
common
.
TurnstileCheckEnabled
,
"turnstile_check"
:
common
.
TurnstileCheckEnabled
,
"turnstile_site_key"
:
common
.
TurnstileSiteKey
,
"turnstile_site_key"
:
common
.
TurnstileSiteKey
,
"top_up_link"
:
common
.
TopUpLink
,
"top_up_link"
:
common
.
TopUpLink
,
...
...
controller/topup.go
View file @
53d25cc6
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"net/url"
"net/url"
"one-api/common"
"one-api/common"
"one-api/model"
"one-api/model"
"one-api/service"
"strconv"
"strconv"
"time"
"time"
)
)
...
@@ -55,14 +56,14 @@ func RequestEpay(c *gin.Context) {
...
@@ -55,14 +56,14 @@ func RequestEpay(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
err
.
Error
(),
"data"
:
10
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
err
.
Error
(),
"data"
:
10
})
return
return
}
}
if
req
.
Amount
<
1
{
if
req
.
Amount
<
common
.
MinTopUp
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"充值金额不能小于1"
,
"data"
:
10
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
common
.
MinTopUp
)
,
"data"
:
10
})
return
return
}
}
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
user
,
_
:=
model
.
GetUserById
(
id
,
false
)
user
,
_
:=
model
.
GetUserById
(
id
,
false
)
amount
:=
GetAmount
(
float64
(
req
.
Amount
),
*
user
)
payMoney
:=
GetAmount
(
float64
(
req
.
Amount
),
*
user
)
var
payType
epay
.
PurchaseType
var
payType
epay
.
PurchaseType
if
req
.
PaymentMethod
==
"zfb"
{
if
req
.
PaymentMethod
==
"zfb"
{
...
@@ -72,11 +73,10 @@ func RequestEpay(c *gin.Context) {
...
@@ -72,11 +73,10 @@ func RequestEpay(c *gin.Context) {
req
.
PaymentMethod
=
"wxpay"
req
.
PaymentMethod
=
"wxpay"
payType
=
epay
.
WechatPay
payType
=
epay
.
WechatPay
}
}
callBackAddress
:=
service
.
GetCallbackAddress
()
returnUrl
,
_
:=
url
.
Parse
(
common
.
ServerAddress
+
"/log"
)
returnUrl
,
_
:=
url
.
Parse
(
common
.
ServerAddress
+
"/log"
)
notifyUrl
,
_
:=
url
.
Parse
(
c
ommon
.
Server
Address
+
"/api/user/epay/notify"
)
notifyUrl
,
_
:=
url
.
Parse
(
c
allBack
Address
+
"/api/user/epay/notify"
)
tradeNo
:=
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
)
tradeNo
:=
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
(),
10
)
payMoney
:=
amount
client
:=
GetEpayClient
()
client
:=
GetEpayClient
()
if
client
==
nil
{
if
client
==
nil
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"当前管理员未配置支付信息"
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"当前管理员未配置支付信息"
})
...
@@ -169,8 +169,8 @@ func RequestAmount(c *gin.Context) {
...
@@ -169,8 +169,8 @@ func RequestAmount(c *gin.Context) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"参数错误"
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"参数错误"
})
return
return
}
}
if
req
.
Amount
<
1
{
if
req
.
Amount
<
common
.
MinTopUp
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"充值金额不能小于1"
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
common
.
MinTopUp
)
})
return
return
}
}
id
:=
c
.
GetInt
(
"id"
)
id
:=
c
.
GetInt
(
"id"
)
...
...
model/option.go
View file @
53d25cc6
...
@@ -56,9 +56,11 @@ func InitOptionMap() {
...
@@ -56,9 +56,11 @@ func InitOptionMap() {
common
.
OptionMap
[
"Logo"
]
=
common
.
Logo
common
.
OptionMap
[
"Logo"
]
=
common
.
Logo
common
.
OptionMap
[
"ServerAddress"
]
=
""
common
.
OptionMap
[
"ServerAddress"
]
=
""
common
.
OptionMap
[
"PayAddress"
]
=
""
common
.
OptionMap
[
"PayAddress"
]
=
""
common
.
OptionMap
[
"CustomCallbackAddress"
]
=
""
common
.
OptionMap
[
"EpayId"
]
=
""
common
.
OptionMap
[
"EpayId"
]
=
""
common
.
OptionMap
[
"EpayKey"
]
=
""
common
.
OptionMap
[
"EpayKey"
]
=
""
common
.
OptionMap
[
"Price"
]
=
strconv
.
FormatFloat
(
common
.
Price
,
'f'
,
-
1
,
64
)
common
.
OptionMap
[
"Price"
]
=
strconv
.
FormatFloat
(
common
.
Price
,
'f'
,
-
1
,
64
)
common
.
OptionMap
[
"MinTopUp"
]
=
strconv
.
Itoa
(
common
.
MinTopUp
)
common
.
OptionMap
[
"TopupGroupRatio"
]
=
common
.
TopupGroupRatio2JSONString
()
common
.
OptionMap
[
"TopupGroupRatio"
]
=
common
.
TopupGroupRatio2JSONString
()
common
.
OptionMap
[
"GitHubClientId"
]
=
""
common
.
OptionMap
[
"GitHubClientId"
]
=
""
common
.
OptionMap
[
"GitHubClientSecret"
]
=
""
common
.
OptionMap
[
"GitHubClientSecret"
]
=
""
...
@@ -194,12 +196,16 @@ func updateOptionMap(key string, value string) (err error) {
...
@@ -194,12 +196,16 @@ func updateOptionMap(key string, value string) (err error) {
common
.
ServerAddress
=
value
common
.
ServerAddress
=
value
case
"PayAddress"
:
case
"PayAddress"
:
common
.
PayAddress
=
value
common
.
PayAddress
=
value
case
"CustomCallbackAddress"
:
common
.
CustomCallbackAddress
=
value
case
"EpayId"
:
case
"EpayId"
:
common
.
EpayId
=
value
common
.
EpayId
=
value
case
"EpayKey"
:
case
"EpayKey"
:
common
.
EpayKey
=
value
common
.
EpayKey
=
value
case
"Price"
:
case
"Price"
:
common
.
Price
,
_
=
strconv
.
ParseFloat
(
value
,
64
)
common
.
Price
,
_
=
strconv
.
ParseFloat
(
value
,
64
)
case
"MinTopUp"
:
common
.
MinTopUp
,
_
=
strconv
.
Atoi
(
value
)
case
"TopupGroupRatio"
:
case
"TopupGroupRatio"
:
err
=
common
.
UpdateTopupGroupRatioByJSONString
(
value
)
err
=
common
.
UpdateTopupGroupRatioByJSONString
(
value
)
case
"GitHubClientId"
:
case
"GitHubClientId"
:
...
...
service/epay.go
0 → 100644
View file @
53d25cc6
package
service
import
"one-api/common"
func
GetCallbackAddress
()
string
{
if
common
.
CustomCallbackAddress
==
""
{
return
common
.
ServerAddress
}
return
common
.
CustomCallbackAddress
}
web/src/components/SystemSetting.js
View file @
53d25cc6
...
@@ -20,8 +20,10 @@ const SystemSetting = () => {
...
@@ -20,8 +20,10 @@ const SystemSetting = () => {
EpayId
:
''
,
EpayId
:
''
,
EpayKey
:
''
,
EpayKey
:
''
,
Price
:
7.3
,
Price
:
7.3
,
MinTopUp
:
1
,
TopupGroupRatio
:
''
,
TopupGroupRatio
:
''
,
PayAddress
:
''
,
PayAddress
:
''
,
CustomCallbackAddress
:
''
,
Footer
:
''
,
Footer
:
''
,
WeChatAuthEnabled
:
''
,
WeChatAuthEnabled
:
''
,
WeChatServerAddress
:
''
,
WeChatServerAddress
:
''
,
...
@@ -280,7 +282,7 @@ const SystemSetting = () => {
...
@@ -280,7 +282,7 @@ const SystemSetting = () => {
更新服务器地址
更新服务器地址
<
/Form.Button
>
<
/Form.Button
>
<
Divider
/>
<
Divider
/>
<
Header
as
=
'h3'
>
支付设置(当前仅支持易支付接口,使用上方服务器地址作为回调地址!)
<
/Header
>
<
Header
as
=
'h3'
>
支付设置(当前仅支持易支付接口,
默认
使用上方服务器地址作为回调地址!)
<
/Header
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
Input
<
Form
.
Input
label
=
'支付地址,不填写则不启用在线支付'
label
=
'支付地址,不填写则不启用在线支付'
...
@@ -303,14 +305,31 @@ const SystemSetting = () => {
...
@@ -303,14 +305,31 @@ const SystemSetting = () => {
name
=
'EpayKey'
name
=
'EpayKey'
onChange
=
{
handleInputChange
}
onChange
=
{
handleInputChange
}
/
>
/
>
<
Form
.
Input
label
=
'充值价格(x元/美金)'
placeholder
=
'例如:7,就是7元/美金'
value
=
{
inputs
.
Price
}
name
=
'Price'
min
=
{
0
}
<
/Form.Group
>
onChange
=
{
handleInputChange
}
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
Input
label
=
'回调地址,不填写则使用上方服务器地址作为回调地址'
placeholder
=
'例如:https://yourdomain.com'
value
=
{
inputs
.
CustomCallbackAddress
}
name
=
'CustomCallbackAddress'
onChange
=
{
handleInputChange
}
/
>
<
Form
.
Input
label
=
'充值价格(x元/美金)'
placeholder
=
'例如:7,就是7元/美金'
value
=
{
inputs
.
Price
}
name
=
'Price'
min
=
{
0
}
onChange
=
{
handleInputChange
}
/
>
<
Form
.
Input
label
=
'最低充值数量'
placeholder
=
'例如:2,就是最低充值2$'
value
=
{
inputs
.
MinTopUp
}
name
=
'MinTopUp'
min
=
{
1
}
onChange
=
{
handleInputChange
}
/
>
/
>
<
/Form.Group
>
<
/Form.Group
>
<
Form
.
Group
widths
=
'equal'
>
<
Form
.
Group
widths
=
'equal'
>
...
...
web/src/pages/TopUp/index.js
View file @
53d25cc6
...
@@ -10,6 +10,7 @@ const TopUp = () => {
...
@@ -10,6 +10,7 @@ const TopUp = () => {
const
[
topUpCount
,
setTopUpCount
]
=
useState
(
10
);
const
[
topUpCount
,
setTopUpCount
]
=
useState
(
10
);
const
[
minTopupCount
,
setMinTopUpCount
]
=
useState
(
1
);
const
[
minTopupCount
,
setMinTopUpCount
]
=
useState
(
1
);
const
[
amount
,
setAmount
]
=
useState
(
0.0
);
const
[
amount
,
setAmount
]
=
useState
(
0.0
);
const
[
minTopUp
,
setMinTopUp
]
=
useState
(
1
);
const
[
topUpLink
,
setTopUpLink
]
=
useState
(
''
);
const
[
topUpLink
,
setTopUpLink
]
=
useState
(
''
);
const
[
enableOnlineTopUp
,
setEnableOnlineTopUp
]
=
useState
(
false
);
const
[
enableOnlineTopUp
,
setEnableOnlineTopUp
]
=
useState
(
false
);
const
[
userQuota
,
setUserQuota
]
=
useState
(
0
);
const
[
userQuota
,
setUserQuota
]
=
useState
(
0
);
...
@@ -61,6 +62,10 @@ const TopUp = () => {
...
@@ -61,6 +62,10 @@ const TopUp = () => {
if
(
amount
===
0
)
{
if
(
amount
===
0
)
{
await
getAmount
();
await
getAmount
();
}
}
if
(
topUpCount
<
minTopUp
)
{
showInfo
(
'充值数量不能小于'
+
minTopUp
);
return
;
}
setPayWay
(
payment
)
setPayWay
(
payment
)
setOpen
(
true
);
setOpen
(
true
);
}
}
...
@@ -69,6 +74,10 @@ const TopUp = () => {
...
@@ -69,6 +74,10 @@ const TopUp = () => {
if
(
amount
===
0
)
{
if
(
amount
===
0
)
{
await
getAmount
();
await
getAmount
();
}
}
if
(
topUpCount
<
minTopUp
)
{
showInfo
(
'充值数量不能小于'
+
minTopUp
);
return
;
}
setOpen
(
false
);
setOpen
(
false
);
try
{
try
{
const
res
=
await
API
.
post
(
'/api/user/pay'
,
{
const
res
=
await
API
.
post
(
'/api/user/pay'
,
{
...
@@ -132,6 +141,9 @@ const TopUp = () => {
...
@@ -132,6 +141,9 @@ const TopUp = () => {
if
(
status
.
top_up_link
)
{
if
(
status
.
top_up_link
)
{
setTopUpLink
(
status
.
top_up_link
);
setTopUpLink
(
status
.
top_up_link
);
}
}
if
(
status
.
min_topup
)
{
setMinTopUp
(
status
.
min_topup
);
}
if
(
status
.
enable_online_topup
)
{
if
(
status
.
enable_online_topup
)
{
setEnableOnlineTopUp
(
status
.
enable_online_topup
);
setEnableOnlineTopUp
(
status
.
enable_online_topup
);
}
}
...
@@ -239,12 +251,13 @@ const TopUp = () => {
...
@@ -239,12 +251,13 @@ const TopUp = () => {
disabled
=
{
!
enableOnlineTopUp
}
disabled
=
{
!
enableOnlineTopUp
}
field
=
{
'redemptionCount'
}
field
=
{
'redemptionCount'
}
label
=
{
'实付金额:'
+
renderAmount
()}
label
=
{
'实付金额:'
+
renderAmount
()}
placeholder
=
'充值数量'
placeholder
=
{
'充值数量,最低'
+
minTopUp
+
'$'
}
name
=
'redemptionCount'
name
=
'redemptionCount'
type
=
{
'number'
}
type
=
{
'number'
}
value
=
{
topUpCount
}
value
=
{
topUpCount
}
suffix
=
{
'$'
}
suffix
=
{
'$'
}
min
=
{
1
}
min
=
{
minTopUp
}
defaultValue
=
{
minTopUp
}
max
=
{
100000
}
max
=
{
100000
}
onChange
=
{
async
(
value
)
=>
{
onChange
=
{
async
(
value
)
=>
{
if
(
value
<
1
)
{
if
(
value
<
1
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment