Laravel Jwt-auth 获取 token中的 payload 信息

composer.json中是 "tymon/jwt-auth": "1.0.0-rc.1"

1
2
3
4
5
use Tymon\JWTAuth\Facades\JWTAuth; //use this library
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Tymon\JWTAuth\Exceptions\JWTException;
use Tymon\JWTAuth\Exceptions\TokenBlacklistedException;
use Tymon\JWTAuth\Exceptions\TokenInvalidException;

尝试:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
try {
//Illuminate\Http\Request $request
//get token from request
$token = $request->input('token','');
//get token form header Authorization
//$token = JWTAuth::getToken();
$payload = JWTAuth::setToken($token)->getPayload();
} catch (TokenExpiredException $e) {

} catch (JWTException $e) {

} catch (TokenBlacklistedException $e){

} catch (TokenInvalidException $e){

}

如果直接使用$payload = JWTAuth::getPayload($request->input('token'));,会提示类似A token is required /home/vagrant/code/demoapi/vendor/tymon/jwt-auth/src/JWT.php325 的错误信息