From 463487b9399354e00ae2715bf3c611cbefe512a5 Mon Sep 17 00:00:00 2001 From: fantasticbin Date: Thu, 17 Nov 2022 11:22:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E5=AE=8C=E5=96=84JWT?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E9=80=BB=E8=BE=91=EF=BC=8C=E5=8F=8A=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E5=BC=82=E5=B8=B8=E8=BF=94=E5=9B=9E=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/AuthController.php | 11 ----------- app/Controller/PunchCard/User/UserController.php | 4 ++-- app/Exception/Handler/AppExceptionHandler.php | 12 +++++++++--- config/autoload/jwt.php | 3 ++- config/autoload/middlewares.php | 1 + 5 files changed, 14 insertions(+), 17 deletions(-) delete mode 100644 app/Controller/AuthController.php diff --git a/app/Controller/AuthController.php b/app/Controller/AuthController.php deleted file mode 100644 index 8f04c28..0000000 --- a/app/Controller/AuthController.php +++ /dev/null @@ -1,11 +0,0 @@ -logger->error(sprintf('%s[%s] in %s', $throwable->getMessage(), $throwable->getLine(), $throwable->getFile())); - $this->logger->error($throwable->getTraceAsString()); - return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream('Internal Server Error.')); + $message = $throwable->getMessage(); + $error = explode('|', $message, 2); + $code = $error[1] ?? $throwable->getCode() ?: ErrorCode::COMMON_ERROR; + $data = Result::error($code, $error[0]); + $responseStr = json_encode($data, JSON_UNESCAPED_UNICODE); + + return $response->withHeader('Content-Type', 'application/json')->withBody(new SwooleStream($responseStr)); } public function isValid(Throwable $throwable): bool diff --git a/config/autoload/jwt.php b/config/autoload/jwt.php index eb21313..52853bf 100644 --- a/config/autoload/jwt.php +++ b/config/autoload/jwt.php @@ -17,7 +17,8 @@ return [ * 正则写法:["**", "/api/{name:.+}"] 支持模块化不做jwt token的校验,例如:/api/login/login */ 'no_check_route' => [ - ["**", "/**"], +// ["**", "/**"], + ["**", "/kq/auth/code2OpenID"] ], 'login_type' => env('JWT_LOGIN_TYPE', 'mpop'), // 登录方式,sso为单点登录,同一个用户只能登录一个端,mpop为多点登录 diff --git a/config/autoload/middlewares.php b/config/autoload/middlewares.php index 49bdec2..b4ad4af 100644 --- a/config/autoload/middlewares.php +++ b/config/autoload/middlewares.php @@ -11,5 +11,6 @@ declare(strict_types=1); */ return [ 'http' => [ + Phper666\JWTAuth\Middleware\JWTAuthDefaultSceneMiddleware::class ], ];