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
df69147d
authored
Jul 10, 2025
by
wzxjohn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: for AI review problems
parent
38021383
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
31 deletions
+20
-31
common/hash.go
+5
-5
controller/topup_stripe.go
+5
-5
model/user.go
+1
-1
web/src/pages/Setting/Payment/SettingsPaymentGatewayStripe.js
+6
-7
web/src/pages/TopUp/index.js
+3
-13
No files found.
common/hash.go
View file @
df69147d
...
@@ -7,20 +7,20 @@ import (
...
@@ -7,20 +7,20 @@ import (
"encoding/hex"
"encoding/hex"
)
)
func
Sha256Raw
(
data
string
)
[]
byte
{
func
Sha256Raw
(
data
[]
byte
)
[]
byte
{
h
:=
sha256
.
New
()
h
:=
sha256
.
New
()
h
.
Write
(
[]
byte
(
data
)
)
h
.
Write
(
data
)
return
h
.
Sum
(
nil
)
return
h
.
Sum
(
nil
)
}
}
func
Sha1Raw
(
data
[]
byte
)
[]
byte
{
func
Sha1Raw
(
data
[]
byte
)
[]
byte
{
h
:=
sha1
.
New
()
h
:=
sha1
.
New
()
h
.
Write
(
[]
byte
(
data
)
)
h
.
Write
(
data
)
return
h
.
Sum
(
nil
)
return
h
.
Sum
(
nil
)
}
}
func
Sha1
(
data
string
)
string
{
func
Sha1
(
data
[]
byte
)
string
{
return
hex
.
EncodeToString
(
Sha1Raw
(
[]
byte
(
data
)
))
return
hex
.
EncodeToString
(
Sha1Raw
(
data
))
}
}
func
HmacSha256Raw
(
message
,
key
[]
byte
)
[]
byte
{
func
HmacSha256Raw
(
message
,
key
[]
byte
)
[]
byte
{
...
...
controller/topup_stripe.go
View file @
df69147d
...
@@ -57,8 +57,8 @@ func (*StripeAdaptor) RequestPay(c *gin.Context, req *StripePayRequest) {
...
@@ -57,8 +57,8 @@ func (*StripeAdaptor) RequestPay(c *gin.Context, req *StripePayRequest) {
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"不支持的支付渠道"
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
"error"
,
"data"
:
"不支持的支付渠道"
})
return
return
}
}
if
req
.
Amount
<
int64
(
setting
.
StripeMinTopUp
)
{
if
req
.
Amount
<
getStripeMinTopup
(
)
{
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
setting
.
StripeMinTopUp
),
"data"
:
10
})
c
.
JSON
(
200
,
gin
.
H
{
"message"
:
fmt
.
Sprintf
(
"充值数量不能小于 %d"
,
getStripeMinTopup
()
),
"data"
:
10
})
return
return
}
}
if
req
.
Amount
>
10000
{
if
req
.
Amount
>
10000
{
...
@@ -71,7 +71,7 @@ func (*StripeAdaptor) RequestPay(c *gin.Context, req *StripePayRequest) {
...
@@ -71,7 +71,7 @@ func (*StripeAdaptor) RequestPay(c *gin.Context, req *StripePayRequest) {
chargedMoney
:=
GetChargedAmount
(
float64
(
req
.
Amount
),
*
user
)
chargedMoney
:=
GetChargedAmount
(
float64
(
req
.
Amount
),
*
user
)
reference
:=
fmt
.
Sprintf
(
"new-api-ref-%d-%d-%s"
,
user
.
Id
,
time
.
Now
()
.
UnixMilli
(),
randstr
.
String
(
4
))
reference
:=
fmt
.
Sprintf
(
"new-api-ref-%d-%d-%s"
,
user
.
Id
,
time
.
Now
()
.
UnixMilli
(),
randstr
.
String
(
4
))
referenceId
:=
"ref_"
+
common
.
Sha1
(
reference
)
referenceId
:=
"ref_"
+
common
.
Sha1
(
[]
byte
(
reference
)
)
payLink
,
err
:=
genStripeLink
(
referenceId
,
user
.
StripeCustomer
,
user
.
Email
,
req
.
Amount
)
payLink
,
err
:=
genStripeLink
(
referenceId
,
user
.
StripeCustomer
,
user
.
Email
,
req
.
Amount
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -181,7 +181,7 @@ func sessionExpired(event stripe.Event) {
...
@@ -181,7 +181,7 @@ func sessionExpired(event stripe.Event) {
return
return
}
}
if
""
==
referenceId
{
if
len
(
referenceId
)
==
0
{
log
.
Println
(
"未提供支付单号"
)
log
.
Println
(
"未提供支付单号"
)
return
return
}
}
...
@@ -257,7 +257,7 @@ func getStripePayMoney(amount float64, group string) float64 {
...
@@ -257,7 +257,7 @@ func getStripePayMoney(amount float64, group string) float64 {
if
!
common
.
DisplayInCurrencyEnabled
{
if
!
common
.
DisplayInCurrencyEnabled
{
amount
=
amount
/
common
.
QuotaPerUnit
amount
=
amount
/
common
.
QuotaPerUnit
}
}
//
别问为什么用float64,问就是这么点钱没必要
//
Using float64 for monetary calculations is acceptable here due to the small amounts involved
topupGroupRatio
:=
common
.
GetTopupGroupRatio
(
group
)
topupGroupRatio
:=
common
.
GetTopupGroupRatio
(
group
)
if
topupGroupRatio
==
0
{
if
topupGroupRatio
==
0
{
topupGroupRatio
=
1
topupGroupRatio
=
1
...
...
model/user.go
View file @
df69147d
...
@@ -43,7 +43,7 @@ type User struct {
...
@@ -43,7 +43,7 @@ type User struct {
LinuxDOId
string
`json:"linux_do_id" gorm:"column:linux_do_id;index"`
LinuxDOId
string
`json:"linux_do_id" gorm:"column:linux_do_id;index"`
Setting
string
`json:"setting" gorm:"type:text;column:setting"`
Setting
string
`json:"setting" gorm:"type:text;column:setting"`
Remark
string
`json:"remark,omitempty" gorm:"type:varchar(255)" validate:"max=255"`
Remark
string
`json:"remark,omitempty" gorm:"type:varchar(255)" validate:"max=255"`
StripeCustomer
string
`json:"stripe_customer" gorm:"column:stripe_customer;index"`
StripeCustomer
string
`json:"stripe_customer" gorm:"
type:varchar(64);
column:stripe_customer;index"`
}
}
func
(
user
*
User
)
ToBaseUser
()
*
UserBase
{
func
(
user
*
User
)
ToBaseUser
()
*
UserBase
{
...
...
web/src/pages/Setting/Payment/SettingsPaymentGatewayStripe.js
View file @
df69147d
...
@@ -14,7 +14,6 @@ import {
...
@@ -14,7 +14,6 @@ import {
removeTrailingSlash
,
removeTrailingSlash
,
showError
,
showError
,
showSuccess
,
showSuccess
,
verifyJSON
,
}
from
'../../../helpers'
;
}
from
'../../../helpers'
;
import
{
useTranslation
}
from
'react-i18next'
;
import
{
useTranslation
}
from
'react-i18next'
;
...
@@ -60,19 +59,19 @@ export default function SettingsPaymentGateway(props) {
...
@@ -60,19 +59,19 @@ export default function SettingsPaymentGateway(props) {
try
{
try
{
const
options
=
[]
const
options
=
[]
if
(
inputs
.
StripeApiSecret
!==
undefined
&&
inputs
.
StripeApiSecret
!==
''
)
{
if
(
inputs
.
StripeApiSecret
&&
inputs
.
StripeApiSecret
!==
''
)
{
options
.
push
({
key
:
'StripeApiSecret'
,
value
:
inputs
.
StripeApiSecret
});
options
.
push
({
key
:
'StripeApiSecret'
,
value
:
inputs
.
StripeApiSecret
});
}
}
if
(
inputs
.
StripeWebhookSecret
!==
undefined
&&
inputs
.
StripeWebhookSecret
!==
''
)
{
if
(
inputs
.
StripeWebhookSecret
&&
inputs
.
StripeWebhookSecret
!==
''
)
{
options
.
push
({
key
:
'StripeWebhookSecret'
,
value
:
inputs
.
StripeWebhookSecret
});
options
.
push
({
key
:
'StripeWebhookSecret'
,
value
:
inputs
.
StripeWebhookSecret
});
}
}
if
(
inputs
.
StripePriceId
!==
''
)
{
if
(
inputs
.
StripePriceId
!==
''
)
{
options
.
push
({
key
:
'StripePriceId'
,
value
:
inputs
.
StripePriceId
,});
options
.
push
({
key
:
'StripePriceId'
,
value
:
inputs
.
StripePriceId
,});
}
}
if
(
inputs
.
StripeUnitPrice
!==
''
)
{
if
(
inputs
.
StripeUnitPrice
!==
undefined
&&
inputs
.
StripeUnitPrice
!==
null
)
{
options
.
push
({
key
:
'StripeUnitPrice'
,
value
:
inputs
.
StripeUnitPrice
.
toString
()
});
options
.
push
({
key
:
'StripeUnitPrice'
,
value
:
inputs
.
StripeUnitPrice
.
toString
()
});
}
}
if
(
inputs
.
StripeMinTopUp
!==
''
)
{
if
(
inputs
.
StripeMinTopUp
!==
undefined
&&
inputs
.
StripeMinTopUp
!==
null
)
{
options
.
push
({
key
:
'StripeMinTopUp'
,
value
:
inputs
.
StripeMinTopUp
.
toString
()
});
options
.
push
({
key
:
'StripeMinTopUp'
,
value
:
inputs
.
StripeMinTopUp
.
toString
()
});
}
}
...
@@ -96,7 +95,7 @@ export default function SettingsPaymentGateway(props) {
...
@@ -96,7 +95,7 @@ export default function SettingsPaymentGateway(props) {
showSuccess
(
t
(
'更新成功'
));
showSuccess
(
t
(
'更新成功'
));
// 更新本地存储的原始值
// 更新本地存储的原始值
setOriginInputs
({
...
inputs
});
setOriginInputs
({
...
inputs
});
props
.
refresh
&&
props
.
refresh
();
props
.
refresh
?.
();
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
showError
(
t
(
'更新失败'
));
showError
(
t
(
'更新失败'
));
...
@@ -135,7 +134,7 @@ export default function SettingsPaymentGateway(props) {
...
@@ -135,7 +134,7 @@ export default function SettingsPaymentGateway(props) {
<
/Text
>
<
/Text
>
<
Banner
<
Banner
type
=
'info'
type
=
'info'
description
=
{
`Webhook 填:
${
props
.
options
.
ServerAddress
?
props
.
options
.
ServerAddress
:
'网站地址'
}
/api/stripe/webhook`
}
description
=
{
`Webhook 填:
${
props
.
options
.
ServerAddress
?
removeTrailingSlash
(
props
.
options
.
ServerAddress
)
:
t
(
'网站地址'
)
}
/api/stripe/webhook`
}
/
>
/
>
<
Banner
<
Banner
type
=
'warning'
type
=
'warning'
...
...
web/src/pages/TopUp/index.js
View file @
df69147d
...
@@ -293,7 +293,7 @@ const TopUp = () => {
...
@@ -293,7 +293,7 @@ const TopUp = () => {
}
}
const
processStripeCallback
=
(
data
)
=>
{
const
processStripeCallback
=
(
data
)
=>
{
location
.
href
=
data
.
pay_link
;
window
.
open
(
data
.
pay_link
,
'_blank'
)
;
};
};
const
getUserQuota
=
async
()
=>
{
const
getUserQuota
=
async
()
=>
{
...
@@ -938,21 +938,11 @@ const TopUp = () => {
...
@@ -938,21 +938,11 @@ const TopUp = () => {
<>
<>
{
/* 桌面端显示的自定义金额和支付按钮 */
}
{
/* 桌面端显示的自定义金额和支付按钮 */
}
<
div
className
=
'hidden md:block space-y-4'
>
<
div
className
=
'hidden md:block space-y-4'
>
{
!
enableOnlineTopUp
?(
<
Divider
style
=
{{
margin
:
'24px 0'
}}
>
<
Divider
style
=
{{
margin
:
'24px 0'
}}
>
<
Text
className
=
'text-sm font-medium'
>
<
Text
className
=
'text-sm font-medium'
>
{
t
(
'或输入自定义金额'
)}
{
t
(
!
enableOnlineTopUp
?
'或输入自定义金额'
:
'Stripe'
)}
<
/Text
>
<
/Divider
>
)
:
(
<
Divider
style
=
{{
margin
:
'24px 0'
}}
>
<
Text
className
=
'text-sm font-medium'
>
{
t
(
'Stripe'
)}
<
/Text
>
<
/Text
>
<
/Divider
>
<
/Divider
>
)
}
<
div
>
<
div
>
<
div
className
=
'flex justify-between mb-2'
>
<
div
className
=
'flex justify-between mb-2'
>
...
@@ -968,7 +958,7 @@ const TopUp = () => {
...
@@ -968,7 +958,7 @@ const TopUp = () => {
)}
)}
<
/div
>
<
/div
>
<
InputNumber
<
InputNumber
disabled
=
{
!
enable
Onlin
eTopUp
}
disabled
=
{
!
enable
Strip
eTopUp
}
placeholder
=
{
placeholder
=
{
t
(
'充值数量,最低 '
)
+
renderQuotaWithAmount
(
stripeMinTopUp
)
t
(
'充值数量,最低 '
)
+
renderQuotaWithAmount
(
stripeMinTopUp
)
}
}
...
...
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