response = $response; $this->request = $request; $this->jwt = $jwt; } public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $isValidToken = true; // 获取请求token $token = $request->getHeaderLine('Authorization') ?? $this->request->input('token', ''); if (!empty($token)) { try { $token = JWTUtil::handleToken($token); if ($token !== false && $this->jwt->checkToken($token)) { $isValidToken = true; } } catch (\Exception $e) { $isValidToken = false; } } if (!$isValidToken) { return $this->response->withStatus(401)->json([ 'code' => 401, 'message' => 'Token authentication does not pass', 'data' => [] ]); } return $handler->handle($request); } }