fix(payment): 修正扫呗签名并自动查询支付结果

This commit is contained in:
yml
2026-11-11 16:32:22 +08:00
parent d403ffc734
commit 0963e58fa3
6 changed files with 125 additions and 14 deletions
@@ -76,6 +76,7 @@ export function OrderActionPanel({
const [busy, setBusy] = useState<string | null>(null)
const [payURL, setPayURL] = useState('')
const autoPayTriggered = useRef(false)
const payPolling = useRef<number | null>(null)
const actions = getOrderActionAvailability(order, user?.id)
const checkout = order.checkout
@@ -144,6 +145,42 @@ export function OrderActionPanel({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [autoPay, actions.canPay])
useEffect(() => {
if (dialog !== 'pay' || !payURL) return
let cancelled = false
let attempts = 0
const poll = async () => {
if (cancelled) return
attempts += 1
try {
const payment = await queryOrderPayment(order.id)
if (cancelled) return
if (payment.paid) {
message.success('支付成功,订单已进入待交接')
setDialog(null)
setPayURL('')
await onChanged()
return
}
} catch {
// 自动轮询不打断用户;保留手动检查作为明确反馈。
}
if (!cancelled && attempts < 200) {
payPolling.current = window.setTimeout(() => void poll(), 3000)
}
}
payPolling.current = window.setTimeout(() => void poll(), 3000)
return () => {
cancelled = true
if (payPolling.current !== null) {
window.clearTimeout(payPolling.current)
payPolling.current = null
}
}
}, [dialog, message, onChanged, order.id, payURL])
const run = async (key: string, fn: () => Promise<void>) => {
setBusy(key)
try {
@@ -174,7 +211,7 @@ export function OrderActionPanel({
const url = payment.jspay_url || payment.td_code || payment.jspay_info || ''
if (url) {
setPayURL(url)
message.info('支付单已创建,请打开支付页面完成付款')
message.info('支付单已创建,系统会自动检查支付结果')
} else {
message.warning('支付单已创建,但渠道没有返回支付链接,请稍后检查支付状态')
}
@@ -493,7 +530,7 @@ export function OrderActionPanel({
type="info"
showIcon
message="选择支付方式"
description="支付成功后才进入交接流程;支付完成后回到本页点击「检查支付状态」。"
description="支付成功后才进入交接流程;二维码创建后系统会自动检查支付结果。"
/>
<Form form={form} layout="vertical" style={{ marginTop: 16 }}>
<Form.Item name="payWay" label="支付方式">
@@ -511,7 +548,7 @@ export function OrderActionPanel({
description={
<Space direction="vertical" align="center">
<QRCode value={payURL} size={180} />
<span>请使用微信、支付宝或云闪付扫码付款,完成后回到本页检查支付状态。</span>
<span>请使用微信、支付宝或云闪付扫码付款,支付成功后本页会自动刷新。</span>
<Button type="primary" href={payURL} target="_blank">
在支付应用中打开
</Button>