expire) $payload['exp'] = time()+$this->expire; if ($this->iss) $payload['iss'] = $this->iss; if ($this->sub) $payload['sub'] = $this->sub; if ($this->aud) $payload['aud'] = $this->aud; if ($this->jti) $payload['jti'] = $this->jti; if ($data) $payload = array_merge($payload, $data); return JWT::encode($payload, $this->getJwtKey(), $this->alg); } public function getJwtDecode($jwt) { include_once(SERVER_ROOT."/vendor/autoload.php"); $keyOrKeyArray = new Key($this->getJwtKey(), $this->alg); JWT::$leeway = 60; // $leeway in seconds try { return (array)JWT::decode($jwt, $keyOrKeyArray); } catch (ExpiredException $e) { // 当JWT过期时,你可以选择重新登录或者其他逻辑处理 $this->setError("token过期"); return false; } catch (Exception $e) { // 其他JWT相关的异常处理 $this->setError("token无效"); return false; } } }