第58批续25修复:sync_push 兼容 getParam 已解码数组(PHP8 json_decode(数组) 抛 TypeError)

根因:Java pushCreditToPhp 发 JSON body {players:{...},records:[...]},
getParam 对 JSON body 直接返回已解码数组,原代码再 json_decode()
在 PHP8 下 TypeError 500。

修复:getParam 拿到后仅当 is_string 才 json_decode,否则直接用。
另修复生产服 PHP 端 credit.php 未部署导致 sync_pull 返回「未知操作」的问题。
This commit is contained in:
ypsdf1
2026-10-28 21:12:17 +08:00
parent 82d352f1c3
commit 638755df29
+10 -6
View File
@@ -296,12 +296,17 @@ switch ($action) {
$syncSecret = getParam('secret', '');
if (!$syncSecret || $syncSecret !== SECRET_KEY) error('同步密钥无效', 401);
$playersJson = getParam('players', '');
$recordsJson = getParam('records', '');
// ★ getParam 对 JSON body 直接返回已解码数组,无需再 json_decode(PHP8 json_decode(数组) 抛 TypeError)
$playerData = getParam('players', null);
if (is_string($playerData)) $playerData = json_decode($playerData, true);
if (!is_array($playerData)) $playerData = [];
$recordData = getParam('records', null);
if (is_string($recordData)) $recordData = json_decode($recordData, true);
if (!is_array($recordData)) $recordData = [];
// 批量更新玩家积分
$playerData = json_decode($playersJson, true);
if (is_array($playerData) && !empty($playerData)) {
if (!empty($playerData)) {
$db->beginTransaction();
foreach ($playerData as $pname => $score) {
// 确保玩家存在
@@ -325,8 +330,7 @@ switch ($action) {
}
// 批量插入/更新积分记录(去重:同 target+source+created_at 的记录跳过)
$recordData = json_decode($recordsJson, true);
if (is_array($recordData) && !empty($recordData)) {
if (!empty($recordData)) {
foreach ($recordData as $rec) {
$target = $rec['target_player'] ?? '';
$reporter = $rec['reporter_player'] ?? '';