token; } public function setToken($token) { $this->token=$token; return $this; } //Uid public function getUid() { return (string)$this->uid; } public function setUid($uid) { $this->uid=$uid; return $this; } //人员编号 public function setRybh($rybh) { $this->rybh=$rybh; return $this; } public function getRybh() { return $this->rybh; } //$groupname public function setGroupname($groupname) { $this->groupname=$groupname; return $this; } public function getGroupname() { return $this->groupname; } //name public function setName($name) { $this->name=$name; return $this; } public function getName() { return $this->name; } //人员名称 public function setRymc($rymc) { $this->rymc=$rymc; return $this; } public function getRymc() { return $this->rymc; } //企业代码 public function setQydm($qydm) { $this->qydm=$qydm; return $this; } public function getQydm() { return $this->qydm; } /** * @return $this */ public function encode(): JwtAuth { //设置签发人、接收人、唯一标识、签发时间、立即生效、过期时间、用户id、签名 $time=time(); $this->token = (new Builder()) ->setHeader('alg', 'HS256') ->setIssuer(config('jwt.issuer')) ->setAudience(config('jwt.audience')) ->setExpiration($time + config('jwt.expiration')) ->set('uid',$this->uid) ->set('name', $this->name) ->set('rymc', $this->rymc) ->set('groupname', $this->groupname) ->set('rybh',$this->rybh) ->set('qydm',$this->qydm) ->sign(new Sha256(),config('jwt.secret')) ->getToken(); return $this; } /** * @return Token|void */ public function decode() { if (!$this->decodeToken) { $this->decodeToken = (new Parser())->parse((string)$this->token); $this->uid = $this->decodeToken->getClaim('uid'); $this->rybh = $this->decodeToken->getClaim('rybh'); $this->qydm = $this->decodeToken->getClaim('qydm'); $this->name = $this->decodeToken->getClaim('name'); $this->rymc = $this->decodeToken->getClaim('rymc'); $this->groupname = $this->decodeToken->getClaim('groupname'); } return $this->decodeToken; } /** * verify token * @return bool */ public function verify(): bool { $result = $this->decode()->verify(new Sha256(), config('jwt.secret')); return $result; } /** * validate * @return bool */ public function validate(): bool { $data = new ValidationData(); $data->setIssuer(config('jwt.issuer')); $data->setAudience(config('jwt.audience')); return $this->decode()->validate($data); } }