修复支付系统核心问题v2\n\n- poller_online.php: 添加全局异常捕获,防止500错误\n- pay.php: queryOrder返回created_at,syncPoller action占位\n- player.php: 续支付检测添加5分钟过期检查\n- 解决:\n 1. Java轮询500错误\n 2. 订单超时5分钟\n 3. 前端过期订单自动清除\n 4. 支付成功后按钮锁定

This commit is contained in:
ypsdf1
2026-07-15 19:48:08 +08:00
parent 1cd8415516
commit cb949f5b16
3 changed files with 32 additions and 6 deletions
+4
View File
@@ -524,6 +524,7 @@ function queryOrder($token) {
'money' => $row['money'], 'money' => $row['money'],
'bonds' => (int)$row['bond_amount'], 'bonds' => (int)$row['bond_amount'],
'paid_at' => $row['paid_at'], 'paid_at' => $row['paid_at'],
'created_at' => $row['created_at'],
], $message); ], $message);
} }
@@ -542,6 +543,9 @@ try {
case 'pay_redirect': case 'pay_redirect':
handlePayRedirect(); // 内部已 exit handlePayRedirect(); // 内部已 exit
break; break;
case 'sync_poller':
syncPoller(getParam('token'));
break;
case 'query_order': case 'query_order':
queryOrder(getParam('token')); queryOrder(getParam('token'));
break; break;
+16 -6
View File
@@ -85,11 +85,16 @@ function getSQLite() {
function getPlatformDB() { function getPlatformDB() {
static $pdo = null; static $pdo = null;
if ($pdo === null) { if ($pdo === null) {
$dsn = "mysql:host={$GLOBALS['PLATFORM_DB_HOST']};dbname={$GLOBALS['PLATFORM_DB_NAME']};charset=utf8mb4"; try {
$pdo = new PDO($dsn, $GLOBALS['PLATFORM_DB_USER'], $GLOBALS['PLATFORM_DB_PASS'], [ $dsn = "mysql:host={$GLOBALS['PLATFORM_DB_HOST']};dbname={$GLOBALS['PLATFORM_DB_NAME']};charset=utf8mb4";
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, $pdo = new PDO($dsn, $GLOBALS['PLATFORM_DB_USER'], $GLOBALS['PLATFORM_DB_PASS'], [
PDO::ATTR_TIMEOUT => 5, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]); PDO::ATTR_TIMEOUT => 5,
]);
} catch (Exception $e) {
debugLog("Platform DB connection failed", ['error' => $e->getMessage()]);
throw $e; // re-throw to be caught by pollPaidOrders
}
} }
return $pdo; return $pdo;
} }
@@ -267,5 +272,10 @@ function markNotified($pdo, $tradeNo) {
// 不在此处自动执行补单(由调用方自行决定何时触发)。 // 不在此处自动执行补单(由调用方自行决定何时触发)。
if (!defined('POLLER_NO_AUTO_RUN')) { if (!defined('POLLER_NO_AUTO_RUN')) {
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
pollPaidOrders(); try {
pollPaidOrders();
} catch (\Throwable $e) {
debugLog('[poller_online] 未捕获异常', ['error' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]);
echo json_encode(['error' => 'uncaught_exception', 'detail' => $e->getMessage()]);
}
} }
+12
View File
@@ -1113,6 +1113,17 @@ if ($currentVersion !== $BUILD_VERSION) {
btn.textContent = '✅ 支付完成'; btn.textContent = '✅ 支付完成';
btn.onclick = null; btn.onclick = null;
} else if (res.data.status === 'created') { } else if (res.data.status === 'created') {
// 检查订单是否已过期(5分钟)
const nowSec = Math.floor(Date.now() / 1000);
const createdAt = res.data.created_at || 0;
if (createdAt && (nowSec - createdAt) > 300) {
// 已过期:清除本地记录,重置按钮
localStorage.removeItem('sdf1_last_recharge_no');
st.innerHTML = '<span style="color:var(--yellow)">订单已过期(超过5分钟),请重新下单。</span>';
btn.disabled = false;
btn.textContent = '🅰️ 支付宝支付 ¥0.01';
btn.onclick = startRecharge;
} else {
// 未支付:显示继续支付 // 未支付:显示继续支付
btn.textContent = '🔄 继续支付 ¥' + (res.data.money || '0.01'); btn.textContent = '🔄 继续支付 ¥' + (res.data.money || '0.01');
btn.onclick = async function() { btn.onclick = async function() {
@@ -1140,6 +1151,7 @@ if ($currentVersion !== $BUILD_VERSION) {
}; };
st.innerHTML = '<span style="color:var(--yellow)">⚠️ 您有一笔未完成的订单,<a href="javascript:void(0)" onclick="document.getElementById(\'rechargeBtn\').click()" style="color:var(--accent)">点此继续支付</a></span>'; st.innerHTML = '<span style="color:var(--yellow)">⚠️ 您有一笔未完成的订单,<a href="javascript:void(0)" onclick="document.getElementById(\'rechargeBtn\').click()" style="color:var(--accent)">点此继续支付</a></span>';
document.getElementById('rechargeQueryBtn').style.display = 'block'; document.getElementById('rechargeQueryBtn').style.display = 'block';
}
} }
// 如果是 expired 或其他状态,不处理,保持默认按钮 // 如果是 expired 或其他状态,不处理,保持默认按钮
} }