From f21a71eb6fee0fccc45b70cbf358f06f70c762de Mon Sep 17 00:00:00 2001 From: Kubbo <390378816@qq.com> Date: Sun, 22 Dec 2024 13:29:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(api):=20=E4=BC=98=E5=8C=96=20JSON=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 exit(json_encode($data)) 替换为 returnJson($data) 函数 - 在 switch 语句中添加 break 语句,避免代码执行顺序错误 - 统一 JSON 返回格式,提高代码可维护性 --- api.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/api.php b/api.php index 3d912af..9620096 100644 --- a/api.php +++ b/api.php @@ -973,7 +973,8 @@ switch ($act) { $data = $result->fetch_array(); $result->free_result(); $stmt2->close(); - exit(json_encode($data)); + returnJson($data); + break; case 'link': $stmt = $mySQLi->prepare('select player_id from player_connect_threeparty where type=`linuxdo` and connect_id=?'); $stmt->bind_param('s', input('connect_id')); @@ -988,10 +989,11 @@ switch ($act) { $getPlayer->execute(); $res = $getPlayer->get_result(); $account = $res->fetch_array(); - exit(json_encode(['code' => 0, 'data' => $res])); + returnJson(['code' => 0, 'data' => $res]); } else { - exit(json_encode(['code' => '1'])); + returnJson(['code' => '1']); } + break; default: echo 'success'; } \ No newline at end of file