This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
wangpu_auth/index.php
T
wsh5485 9b9d1b9b64 refactor(index.php): 根据请求token动态更新auth.json响应
修改index.php逻辑,使其能够根据请求中的token参数动态更新auth.json中的Token字段。同时删除不再使用的url.txt文件。
2025-11-25 17:46:08 +08:00

55 lines
1.6 KiB
PHP

<?php
// 设置响应头,允许所有来源的跨域请求
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
header('Content-Type: application/json');
// 处理OPTIONS预检请求
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
exit(0);
}
// 定义文件路径
$authFilePath = 'auth.json';
// 从请求中获取token参数
$requestToken = isset($_GET['token']) ? $_GET['token'] : null;
// 检查auth.json文件是否存在
if (file_exists($authFilePath)) {
// 读取JSON文件内容
$jsonContent = file_get_contents($authFilePath);
// 验证JSON格式是否正确
if ($jsonContent && ($jsonData = json_decode($jsonContent, true)) !== null) {
// 如果请求中包含token参数,则替换auth.json中的token
if ($requestToken && isset($jsonData['data']['Token'])) {
$jsonData['data']['Token'] = $requestToken;
}
// 输出更新后的JSON内容
echo json_encode($jsonData, JSON_UNESCAPED_UNICODE);
exit;
} else {
// JSON格式错误时的响应
$errorResponse = array(
'status' => 'error',
'message' => 'JSON文件格式错误或内容为空'
);
echo json_encode($errorResponse, JSON_UNESCAPED_UNICODE);
exit;
}
} else {
// 文件不存在时的响应
$errorResponse = array(
'status' => 'error',
'message' => 'auth.json文件不存在'
);
echo json_encode($errorResponse, JSON_UNESCAPED_UNICODE);
exit;
}
// 终止脚本执行
exit;
?>