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 94dd3a4e05 feat: 添加旺铺授权系统初始文件
添加url.txt、index.php和auth.json三个初始文件
index.php实现跨域请求处理和授权信息读取
auth.json包含3000+旺铺授权数据
2025-11-25 17:19:49 +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);
}
// 定义文件路径
$urlFilePath = 'c:\\Users\\吴展鹏\\wangpu_auth\\url.txt';
$authFilePath = 'c:\\Users\\吴展鹏\\wangpu_auth\\auth.json';
// 读取并返回auth.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;
?>