refactor(api): 优化 JSON 返回逻辑
- 将 exit(json_encode($data)) 替换为 returnJson($data) 函数 - 在 switch 语句中添加 break 语句,避免代码执行顺序错误 - 统一 JSON 返回格式,提高代码可维护性
This commit is contained in:
8
api.php
8
api.php
@@ -973,7 +973,8 @@ switch ($act) {
|
|||||||
$data = $result->fetch_array();
|
$data = $result->fetch_array();
|
||||||
$result->free_result();
|
$result->free_result();
|
||||||
$stmt2->close();
|
$stmt2->close();
|
||||||
exit(json_encode($data));
|
returnJson($data);
|
||||||
|
break;
|
||||||
case 'link':
|
case 'link':
|
||||||
$stmt = $mySQLi->prepare('select player_id from player_connect_threeparty where type=`linuxdo` and connect_id=?');
|
$stmt = $mySQLi->prepare('select player_id from player_connect_threeparty where type=`linuxdo` and connect_id=?');
|
||||||
$stmt->bind_param('s', input('connect_id'));
|
$stmt->bind_param('s', input('connect_id'));
|
||||||
@@ -988,10 +989,11 @@ switch ($act) {
|
|||||||
$getPlayer->execute();
|
$getPlayer->execute();
|
||||||
$res = $getPlayer->get_result();
|
$res = $getPlayer->get_result();
|
||||||
$account = $res->fetch_array();
|
$account = $res->fetch_array();
|
||||||
exit(json_encode(['code' => 0, 'data' => $res]));
|
returnJson(['code' => 0, 'data' => $res]);
|
||||||
} else {
|
} else {
|
||||||
exit(json_encode(['code' => '1']));
|
returnJson(['code' => '1']);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
echo 'success';
|
echo 'success';
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user