继续完善JWT认证逻辑,及调整异常返回逻辑
This commit is contained in:
parent
4ec5166f50
commit
463487b939
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthDefaultSceneMiddleware;
|
||||
|
||||
#[Middleware(JWTAuthDefaultSceneMiddleware::class)]
|
||||
class AuthController extends BaseController
|
||||
{
|
||||
}
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\PunchCard\User;
|
||||
|
||||
use App\Controller\AuthController;
|
||||
use App\Controller\BaseController;
|
||||
use App\JsonRpc\PunchCardSystemExternalServiceInterface;
|
||||
use App\JsonRpc\UserExternalServiceInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@ -13,7 +13,7 @@ use Hyperf\HttpServer\Annotation\GetMapping;
|
||||
use Hyperf\HttpServer\Annotation\PostMapping;
|
||||
|
||||
#[Controller(prefix: "kq")]
|
||||
class UserController extends AuthController
|
||||
class UserController extends BaseController
|
||||
{
|
||||
/**
|
||||
* 用户中心对外RPC服务
|
||||
|
@ -11,6 +11,8 @@ declare(strict_types=1);
|
||||
*/
|
||||
namespace App\Exception\Handler;
|
||||
|
||||
use App\Constants\ErrorCode;
|
||||
use App\Helper\Result;
|
||||
use Hyperf\Contract\StdoutLoggerInterface;
|
||||
use Hyperf\ExceptionHandler\ExceptionHandler;
|
||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||
@ -25,9 +27,13 @@ class AppExceptionHandler extends ExceptionHandler
|
||||
|
||||
public function handle(Throwable $throwable, ResponseInterface $response)
|
||||
{
|
||||
$this->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
|
||||
|
@ -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为多点登录
|
||||
|
@ -11,5 +11,6 @@ declare(strict_types=1);
|
||||
*/
|
||||
return [
|
||||
'http' => [
|
||||
Phper666\JWTAuth\Middleware\JWTAuthDefaultSceneMiddleware::class
|
||||
],
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user