This commit is contained in:
2026-01-05 15:49:25 +08:00
parent baf3e66aaf
commit 7068fa69c2
9 changed files with 63 additions and 652 deletions
+4 -3
View File
@@ -1,6 +1,7 @@
<?php
namespace app\middleware;
use app\common\model\User;
use app\common\utils\Jwt;
use ReflectionClass;
use Webman\MiddlewareInterface;
@@ -22,7 +23,8 @@ class AuthCheck implements MiddlewareInterface
} else {
try {
$authHeader = $request->header('Fdesk-Auth-Token');
if (!$authHeader || !preg_match('/Bearer\s(\S+)/', $authHeader, $matches)) {
$user = User::where('union_id',$authHeader)->first();
if (!$user) {
$body = [
'status' => 'fail',
'code' => 401,
@@ -31,8 +33,7 @@ class AuthCheck implements MiddlewareInterface
];
return response(json_encode($body, JSON_UNESCAPED_UNICODE), 401, ['Content-Type' => 'application/json']);
}
$token = $matches[1];
$request->user = (new Jwt())->verifyToken($token);
$request->user = $user;
return $handler($request);
} catch (\Throwable $e) {
$body = [