修复支付系统核心问题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:
@@ -524,6 +524,7 @@ function queryOrder($token) {
|
||||
'money' => $row['money'],
|
||||
'bonds' => (int)$row['bond_amount'],
|
||||
'paid_at' => $row['paid_at'],
|
||||
'created_at' => $row['created_at'],
|
||||
], $message);
|
||||
}
|
||||
|
||||
@@ -542,6 +543,9 @@ try {
|
||||
case 'pay_redirect':
|
||||
handlePayRedirect(); // 内部已 exit
|
||||
break;
|
||||
case 'sync_poller':
|
||||
syncPoller(getParam('token'));
|
||||
break;
|
||||
case 'query_order':
|
||||
queryOrder(getParam('token'));
|
||||
break;
|
||||
|
||||
@@ -85,11 +85,16 @@ function getSQLite() {
|
||||
function getPlatformDB() {
|
||||
static $pdo = null;
|
||||
if ($pdo === null) {
|
||||
try {
|
||||
$dsn = "mysql:host={$GLOBALS['PLATFORM_DB_HOST']};dbname={$GLOBALS['PLATFORM_DB_NAME']};charset=utf8mb4";
|
||||
$pdo = new PDO($dsn, $GLOBALS['PLATFORM_DB_USER'], $GLOBALS['PLATFORM_DB_PASS'], [
|
||||
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;
|
||||
}
|
||||
@@ -267,5 +272,10 @@ function markNotified($pdo, $tradeNo) {
|
||||
// 不在此处自动执行补单(由调用方自行决定何时触发)。
|
||||
if (!defined('POLLER_NO_AUTO_RUN')) {
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
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
@@ -1113,6 +1113,17 @@ if ($currentVersion !== $BUILD_VERSION) {
|
||||
btn.textContent = '✅ 支付完成';
|
||||
btn.onclick = null;
|
||||
} 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.onclick = async function() {
|
||||
@@ -1141,6 +1152,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>';
|
||||
document.getElementById('rechargeQueryBtn').style.display = 'block';
|
||||
}
|
||||
}
|
||||
// 如果是 expired 或其他状态,不处理,保持默认按钮
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user