token加密算法:
use Tymon\JWTAuth\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
protected function setAuthenticationHeader($response, $token = null)
{
$token = $token ?: $this->auth->refresh();
$response->headers->set('Authorization', 'Bearer '.$token);
return $response;
}
token解密使用authenticate方法,注意要先setToken:
use Tymon\JWTAuth\JWTAuth;
class VerifySign extends JWTAuth
{
public function xxxx(){
$app_token = $request->header('Authorization', '');
if (empty($app_token)) {
$user = '';
}else{
$token = explode(' ', $app_token);
$this->setToken($token[1]);
$user = $this->authenticate();
}
$user_info = [];
if (!empty($user)) {
$user->toArray();
$user_info['id'] = $user['id'];
$user_info['name'] = $user['name'];
$user_info['email'] = $user['email'];
}
$user_info = json_encode($user_info);
}
}