1.JWT 出现的问题
此类引入 use Firebase\JWT\Key;
/**
* 验证token
* @return \think\response\Json
*/
public function verifyjwt()
{
$jwt= input("jwt");
$key = md5('dd'); //jwt的签发密钥,验证token的时候需要用到
try{
$jwtAuth = json_encode(JWTUtil::decode($jwt,$key,array("HS256")));
//修改
$jwtAuth = json_encode(JWTUtil::decode($jwt,new Key($key,'HS256')));
$authInfo = json_decode($jwtAuth,true);
if (!$authInfo['user_id']){
return show(0,"用户不存在");
}
return show(0,"ok");
}catch (ExpiredException $e){
return show(0,"token过期");
}catch (\Exception $e){
return show(0,$e->getMessage());
}
}
参考 https://blog.csdn.net/arlene12345/article/details/123147868