jwt
Posted huliangqing
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jwt相关的知识,希望对你有一定的参考价值。
class BaseApi extends Controller
{
protected $userId = 0;
protected $userName = ‘‘;
protected $noLoginAction = [];
protected $endTIme = 30000000;
public function _initialize()
{
parent::_initialize();
$sign = Request::instance()->header(‘sign‘);
$token = Request::instance()->header(‘token‘);
$requestTime = Request::instance()->header(‘requestTime‘);
if(!$sign || !$requestTime ){
$this ->error(‘sign or requestTime not found‘);
}
if(md5($requestTime) != $sign){
$this ->error(‘Sign verification failed‘);
}
if($requestTime < (time()-$this ->endTIme)){
$this ->error(‘request timeout‘);
}
$controller = Request::instance()->controller() ;
$action = Request::instance()->action() ;
//token : eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOlwvXC9tbC5jbiIsImF1ZCI6Imh0dHA6XC9cL21sLmNuIiwiaWF0IjoxNTg1NjY4NzIxLCJuYmYiOjE1ODU2Njg3MjEsImV4cCI6MTU5NDMwODcyMSwiZGF0YSI6IntcInVzZXJfaWRcIjoxLFwidXNlcl9uYW1lXCI6XCJ0ZXN0TmFtZVwifSJ9.XrfKRfCGIxmc4A5BF2fSwqqhLVC86jhxWh9yjvOzw_A
if(!in_array($action , $this ->noLoginAction )){
if(!$token) $this ->error(‘Please login again‘,‘‘,300);
}
if($token){
$token_info = $this ->checkToken($token);
$user_info = json_decode($token_info[‘data‘] ,true);
$this ->userId = $user_info[‘user_id‘];
$this ->userName = $user_info[‘user_name‘];
$member_state=db(‘member‘)