修复实名认证后的状态更新 & 使用sse方式解决支付轮询两次完成问题 & 修复账户总览图标展示 & 白名单新增获取当前用户IP地址功能 & 购买套餐添加白名单链接
This commit is contained in:
@@ -33,33 +33,28 @@ export function PaymentModal(props: PaymentModalProps) {
|
||||
}
|
||||
}
|
||||
|
||||
// 轮询检查支付状态
|
||||
// SSE处理方式检查支付状态
|
||||
useEffect(() => {
|
||||
const pollInterval = 2000
|
||||
const maxRetries = 30
|
||||
let retries = 0
|
||||
|
||||
const interval = setInterval(async () => {
|
||||
try {
|
||||
await props.onConfirm(false)
|
||||
return
|
||||
const eventSource = new EventSource(
|
||||
`${process.env.NEXT_PUBLIC_API_BASE_URL}/api/trade/check?trade_no=${props.inner_no}&method=${props.method}`,
|
||||
)
|
||||
eventSource.onmessage = async (event) => {
|
||||
console.log(event, 'eventeventevent')
|
||||
switch (event.data) {
|
||||
case '1':
|
||||
props.onConfirm?.(true)
|
||||
case '2':
|
||||
props.onClose?.()
|
||||
}
|
||||
catch (error) {
|
||||
console.error('支付状态检查失败:', error)
|
||||
}
|
||||
finally {
|
||||
console.log('进入轮询支付状态')
|
||||
retries++
|
||||
if (retries >= maxRetries) {
|
||||
clearInterval(interval)
|
||||
}
|
||||
}
|
||||
}, pollInterval)
|
||||
}
|
||||
eventSource.onerror = (error) => {
|
||||
console.error('SSE 连接错误:', error)
|
||||
}
|
||||
|
||||
return () => {
|
||||
clearInterval(interval)
|
||||
eventSource.close()
|
||||
}
|
||||
}, [props])
|
||||
}, [props.inner_no, props.method, props.onConfirm])
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
|
||||
Reference in New Issue
Block a user