where(['wx_openid'=>$openid])->find(); $token=[ 'iss'=>url("/"), 'iat'=>$time, 'exp'=>$time+7200*24*3600, 'data'=>[ 'userid'=>$user_id, 'major'=>$major ] ]; return self::encode($token,static::$key); } static public function verify($token){ $message=[]; try{ self::$leeway=60; $decoded=self::decode($token,static::$key,static::$type); $arr=(array)$decoded; $message=[ 'code'=>1, 'message'=>$arr ]; }catch (SignatureInvalidException $e){ $message=[ 'code'=>0, 'message'=>"签名错误" ]; } catch (BeforeValidException $e){ $message=[ 'code'=>0, 'message'=>"签名在某个时段才能运行" ]; }catch(ExpiredException $e){ $message=[ 'code'=>0, 'message'=>"登录过期" ]; }catch (\Exception $e){ $message=[ 'code'=>0, 'message'=>'签名异常错误' ]; } return $message; } }