composer require bjyyb/hyperf-accesstoken:dev-main
php bin/hyperf.php vendor:publish bjyyb/hyperf-accesstoken
$tokenService = $this->container->get(\Bjyyb\AccessToken\Contract\TokenInterface::class);
$payload = [
"user_id" => 1,
"name" => "xx",
];
$result = $tokenService->iss($payload);
/** 返回如下格式数据:*/
[
"access_token" => "xxx",
"refresh_token" => "xxx",
];
$tokenService = $this->container->get(\Bjyyb\AccessToken\Contract\TokenInterface::class);
$token = "xx";
$payload = $tokenService->verify($token);
/** 返回如下格式数据:*/
[
"user_id" => 1,
"name" => "xx",
];
/** 如果验证失败抛出异常 */
$tokenService = $this->container->get(\Bjyyb\AccessToken\Contract\TokenInterface::class);
$refreshToken = "xx";
$result = $tokenService->refresh($refreshToken);
/** 返回新的令牌:*/
[
"access_token" => "xxx",
"refresh_token" => "xxx",
];
$tokenService = $this->container->get(\Bjyyb\AccessToken\Contract\TokenInterface::class);
$token = "xx";
$result = $tokenService->remove($token);
composer require bjyyb/hyperf-jwt:dev-main
[
'webtoken' => [
// 签名算法
'alg' => 'HS256',
// 实体内容
'payload' => [
],
// 加密密钥
'key' => 'abcd1234abcd',
// 允许算法
'allowed_algs' => ['HS256'],
],
];
$token = 'xxx';
$tokenService = $this->container->get(\Bjyyb\AccessToken\WebToken::class);
$data = $tokenService->verify($token);
var_dump($data);