refactor(index.php): 根据请求token动态更新auth.json响应
修改index.php逻辑,使其能够根据请求中的token参数动态更新auth.json中的Token字段。同时删除不再使用的url.txt文件。
This commit is contained in:
@@ -13,16 +13,23 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
|||||||
// 定义文件路径
|
// 定义文件路径
|
||||||
$authFilePath = 'auth.json';
|
$authFilePath = 'auth.json';
|
||||||
|
|
||||||
// 忽略请求路径和查询参数,直接返回auth.json文件内容
|
// 从请求中获取token参数
|
||||||
// 无论访问路径是什么,都返回相同的固定JSON响应
|
$requestToken = isset($_GET['token']) ? $_GET['token'] : null;
|
||||||
|
|
||||||
|
// 检查auth.json文件是否存在
|
||||||
if (file_exists($authFilePath)) {
|
if (file_exists($authFilePath)) {
|
||||||
// 读取JSON文件内容
|
// 读取JSON文件内容
|
||||||
$jsonContent = file_get_contents($authFilePath);
|
$jsonContent = file_get_contents($authFilePath);
|
||||||
|
|
||||||
// 验证JSON格式是否正确
|
// 验证JSON格式是否正确
|
||||||
if ($jsonContent && json_decode($jsonContent) !== null) {
|
if ($jsonContent && ($jsonData = json_decode($jsonContent, true)) !== null) {
|
||||||
// 直接输出JSON内容
|
// 如果请求中包含token参数,则替换auth.json中的token
|
||||||
echo $jsonContent;
|
if ($requestToken && isset($jsonData['data']['Token'])) {
|
||||||
|
$jsonData['data']['Token'] = $requestToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 输出更新后的JSON内容
|
||||||
|
echo json_encode($jsonData, JSON_UNESCAPED_UNICODE);
|
||||||
exit;
|
exit;
|
||||||
} else {
|
} else {
|
||||||
// JSON格式错误时的响应
|
// JSON格式错误时的响应
|
||||||
|
|||||||
Reference in New Issue
Block a user