From 5474d17e22bc10df4712621a5a6598cec9e2c17f Mon Sep 17 00:00:00 2001 From: air <30444667+sszdot@users.noreply.github.com> Date: Tue, 6 May 2025 21:57:01 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E7=B1=BB=20=20=E5=9E=8B=E3=80=91?= =?UTF-8?q?=EF=BC=9A=20=E3=80=90=E5=8E=9F=20=20=E5=9B=A0=E3=80=91=EF=BC=9A?= =?UTF-8?q?=20=E3=80=90=E8=BF=87=20=20=E7=A8=8B=E3=80=91=EF=BC=9A=20?= =?UTF-8?q?=E3=80=90=E5=BD=B1=20=20=E5=93=8D=E3=80=91=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 类型 包含: # feat:新功能(feature) # fix:修补bug # docs:文档(documentation) # style: 格式(不影响代码运行的变动) # refactor:重构(即不是新增功能,也不是修改bug的代码变动) # test:增加测试 # chore:构建过程或辅助工具的变动 --- FlyCube/MpApi/Controller/LoginController.class.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/FlyCube/MpApi/Controller/LoginController.class.php b/FlyCube/MpApi/Controller/LoginController.class.php index 8aa8d9e..fa8a1ab 100644 --- a/FlyCube/MpApi/Controller/LoginController.class.php +++ b/FlyCube/MpApi/Controller/LoginController.class.php @@ -15,8 +15,18 @@ class LoginController extends Controller */ public function login() { - header("Access-Control-Allow-Origin: *"); // 允许所有来源 - header('Access-Control-Allow-Headers:Token'); //token请求头 + // 允许所有域名访问(如需限制来源请指定域名) + header("Access-Control-Allow-Origin: *"); + // 允许的请求头 + header("Access-Control-Allow-Headers: Content-Type, Authorization, Token"); + // 允许的请求方法 + header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); + + // 如果是 OPTIONS 预检请求,直接返回即可,不要继续处理 + if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') { + http_response_code(200); // 返回200避免浏览器报错 + exit(); + } if (!$_POST['username']) { echo json_encode(array('status' => 0, 'msg' => '用户名不能为空'), JSON_UNESCAPED_UNICODE);