第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:
+10
-6
@@ -296,12 +296,17 @@ switch ($action) {
|
|||||||
$syncSecret = getParam('secret', '');
|
$syncSecret = getParam('secret', '');
|
||||||
if (!$syncSecret || $syncSecret !== SECRET_KEY) error('同步密钥无效', 401);
|
if (!$syncSecret || $syncSecret !== SECRET_KEY) error('同步密钥无效', 401);
|
||||||
|
|
||||||
$playersJson = getParam('players', '');
|
// ★ getParam 对 JSON body 直接返回已解码数组,无需再 json_decode(PHP8 json_decode(数组) 抛 TypeError)
|
||||||
$recordsJson = getParam('records', '');
|
$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 (!empty($playerData)) {
|
||||||
if (is_array($playerData) && !empty($playerData)) {
|
|
||||||
$db->beginTransaction();
|
$db->beginTransaction();
|
||||||
foreach ($playerData as $pname => $score) {
|
foreach ($playerData as $pname => $score) {
|
||||||
// 确保玩家存在
|
// 确保玩家存在
|
||||||
@@ -325,8 +330,7 @@ switch ($action) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 批量插入/更新积分记录(去重:同 target+source+created_at 的记录跳过)
|
// 批量插入/更新积分记录(去重:同 target+source+created_at 的记录跳过)
|
||||||
$recordData = json_decode($recordsJson, true);
|
if (!empty($recordData)) {
|
||||||
if (is_array($recordData) && !empty($recordData)) {
|
|
||||||
foreach ($recordData as $rec) {
|
foreach ($recordData as $rec) {
|
||||||
$target = $rec['target_player'] ?? '';
|
$target = $rec['target_player'] ?? '';
|
||||||
$reporter = $rec['reporter_player'] ?? '';
|
$reporter = $rec['reporter_player'] ?? '';
|
||||||
|
|||||||
Reference in New Issue
Block a user