fix(web): 拉取交易即刻贴标ack,防止SSL断路器后重复扣费

This commit is contained in:
2026-07-14 11:27:46 +08:00
parent a118aac18c
commit 89fa765351
+23
View File
@@ -6201,6 +6201,11 @@ public class WebManager {
plugin.getLogger().info("[Web交易] 提取交易 #" + txCount + ": ID=" + txId + ", 玩家=" + playerName + ", 类型=" + type + ", 金额=" + amount);
// ★ 2026-07-14 关键修复:拉取即贴标 —— 立即ack防止重复处理
// 之前:拉取→processing→处理→confirm,中间任何环节失败都会导致重拉重复扣费
// 现在:拉取→立即ack(写confirmed表)→处理→confirm(保险)
ackTransaction(txId);
// 在主线程处理交易
final String fTxId = txId;
final String fName = playerName;
@@ -6886,6 +6891,24 @@ public class WebManager {
return result;
}
/**
* ★ 2026-07-14 新增:拉取即贴标 —— 立即标记交易已读到PHP
* 在处理交易之前调用,确保即使后续处理失败/服务器重启,PHP也不会重新下发该交易
* 双重保险:confirmedTxIds(内存) + confirmed_transactions(PHP DB) + web_transactions.status=processed
*/
private void ackTransaction(String txId) {
try {
confirmedTxIds.add(txId); // ★ 内存标记(当前会话防重)
String bodyJson = "{\"tx_id\":\"" + txId + "\"}";
String postUrl = webBaseUrl + "/api/sync.php?action=ack_transaction&secret="
+ java.net.URLEncoder.encode(secretKey, "UTF-8");
doPost(postUrl, bodyJson);
plugin.getLogger().info("[Web交易] 已贴标ack交易: ID=" + txId);
} catch (Exception e) {
plugin.getLogger().warning("[Web交易] 贴标ack交易 " + txId + " 失败(已标记本地内存,不会重复处理): " + e.getMessage());
}
}
/**
* 确认交易已处理(同步调用,确保PHP收到确认后才返回,防止重启后重复发货)
*/