答案 0 :(得分:6)
use Tymon\JWTAuth\Facades\JWTAuth; //use this library
试试这个
$token = JWTAuth::getToken();
$apy = JWTAuth::getPayload($token)->toArray();
你也可以得到这样的其他信息
try {
// attempt to verify the credentials and create a token for the user
$token = JWTAuth::getToken();
$apy = JWTAuth::getPayload($token)->toArray();
} catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
return response()->json(['token_expired'], 500);
} catch (\Tymon\JWTAuth\Exceptions\TokenInvalidException $e) {
return response()->json(['token_invalid'], 500);
} catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
return response()->json(['token_absent' => $e->getMessage()], 500);
}