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