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 71e0d3ed7e feat: 添加.htaccess文件并简化index.php逻辑
添加.htaccess文件实现URL重写规则,将所有请求重定向到index.php
修改index.php逻辑,忽略请求路径直接返回固定JSON响应
2025-11-25 17:26:11 +08:00

48 lines
1.4 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';
// 忽略请求路径和查询参数,直接返回auth.json文件内容
// 无论访问路径是什么,都返回相同的固定JSON响应
if (file_exists($authFilePath)) {
// 读取JSON文件内容
$jsonContent = file_get_contents($authFilePath);
// 验证JSON格式是否正确
if ($jsonContent && json_decode($jsonContent) !== null) {
// 直接输出JSON内容
echo $jsonContent;
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;
?>