Display Alipay cashier QR directly
This commit is contained in:
1 parent
91abad4066
commit
804e539932
6 files changed
+66
-15
No files matched your search
+5
-2
@@ -2,6 +2,7 @@ const $ = (selector) => document.querySelector(selector);
|
||||
const query = new URLSearchParams(location.search);
|
||||
const state = { user: null, packages: [], selectedPackage: null, selectedGateway: null, currentOrder: null };
|
||||
let pollTimer = null;
|
||||
let qrRefreshTimer = null;
|
||||
const userId = query.get('user_id') || '';
|
||||
const amountParam = query.get('amount') || '';
|
||||
const orderNo = query.get('merchant_order_no') || `PAY${Date.now().toString().slice(-10)}`;
|
||||
@@ -80,15 +81,17 @@ function renderQr() {
|
||||
$('#chooseView').classList.add('hidden'); $('#qrView').classList.remove('hidden'); $('#qrImage').src = `/api/checkout/orders/${encodeURIComponent(state.currentOrder.id)}/qrcode?t=${Date.now()}`;
|
||||
const badge = $('#channelBadge'); badge.className = `channel-badge channel-${state.currentOrder.channel}`; badge.textContent = channelName(state.currentOrder.channel);
|
||||
const link = $('#paymentLink');
|
||||
if (state.currentOrder.paymentUrl) { link.href = state.currentOrder.paymentUrl; link.textContent = '打开支付宝官方收银台 →'; link.classList.remove('hidden'); $('.qr-copy h3').textContent = '打开官方收银台扫码'; $('.qr-copy p').textContent = '请在电脑上打开支付宝官方收银台,页面会展示付款二维码;支付完成后此页面会自动更新。'; }
|
||||
link.classList.add('hidden');
|
||||
if (state.currentOrder.channel === 'alipay') { $('.qr-copy h3').textContent = '请使用支付宝扫码'; $('.qr-copy p').textContent = '当前显示支付宝官方收银台的真实付款码;支付完成后本页面会自动更新。'; }
|
||||
else if (state.currentOrder.channel === 'mock') { link.href = `/mock-pay/${encodeURIComponent(state.currentOrder.id)}`; link.textContent = '打开模拟支付页 →'; link.classList.remove('hidden'); }
|
||||
const expires = new Date(state.currentOrder.expiresAt).getTime();
|
||||
const tick = () => { const left = Math.max(0, Math.floor((expires - Date.now()) / 1000)); $('#countdown').textContent = `${String(Math.floor(left / 60)).padStart(2, '0')}:${String(left % 60).padStart(2, '0')}`; if (left <= 0) { clearInterval(pollTimer); $('#statusLine').textContent = '二维码已过期,请重新发起充值'; } };
|
||||
if (state.currentOrder.channel === 'alipay') qrRefreshTimer = setInterval(() => { $('#qrImage').src = `/api/checkout/orders/${encodeURIComponent(state.currentOrder.id)}/qrcode?t=${Date.now()}`; }, 60_000);
|
||||
tick(); setInterval(tick, 1000); pollTimer = setInterval(checkStatus, 2000);
|
||||
}
|
||||
|
||||
async function checkStatus() {
|
||||
try { const data = await fetch(`/api/checkout/orders/${encodeURIComponent(state.currentOrder.id)}`).then((response) => response.json()); if (data.order?.status === 'paid') { clearInterval(pollTimer); showSuccess(data.order); } else if (['failed', 'closed'].includes(data.order?.status)) { clearInterval(pollTimer); showError('订单已关闭或支付失败'); } } catch { /* keep polling */ }
|
||||
try { const data = await fetch(`/api/checkout/orders/${encodeURIComponent(state.currentOrder.id)}`).then((response) => response.json()); if (data.order?.status === 'paid') { clearInterval(pollTimer); clearInterval(qrRefreshTimer); showSuccess(data.order); } else if (['failed', 'closed'].includes(data.order?.status)) { clearInterval(pollTimer); clearInterval(qrRefreshTimer); showError('订单已关闭或支付失败'); } } catch { /* keep polling */ }
|
||||
}
|
||||
|
||||
async function refreshUserBalance() {
|
||||
|
||||
Reference in new issue
Block a user