|
|
|
@ -75,12 +75,24 @@ class UserService { |
|
|
|
*/ |
|
|
|
private function makeToken(int $userId): string |
|
|
|
{ |
|
|
|
$signer = new Sha256(); |
|
|
|
$key = InMemory::plainText(config('jwt.secret')); |
|
|
|
// |
|
|
|
$config = Configuration::forSymmetricSigner($signer,$key); |
|
|
|
$now = new DateTimeImmutable(); // 当前时间 |
|
|
|
// |
|
|
|
$token = $config->builder() |
|
|
|
->issuedAt($now) // iat: 发行时间 |
|
|
|
->expiresAt($now->add(new \DateInterval('PT' . config('jwt.token_ttl') . 'S'))) // exp: 过期时间 |
|
|
|
->withClaim('user_id', $userId) // 自定义声明 |
|
|
|
->getToken($config->signer(), $config->signingKey()); // 签名 |
|
|
|
return $token->toString(); |
|
|
|
// 生成一个不会重复的随机字符串 |
|
|
|
$guid = \get_guid_v4(); |
|
|
|
// 当前时间戳 (精确到毫秒) |
|
|
|
$timeStamp = \microtime(true); |
|
|
|
// 自定义一个盐 |
|
|
|
$salt = makeSalt(12); |
|
|
|
return md5("{$timeStamp}_{$userId}_{$guid}_{$salt}"); |
|
|
|
// $guid = \get_guid_v4(); |
|
|
|
// // 当前时间戳 (精确到毫秒) |
|
|
|
// $timeStamp = \microtime(true); |
|
|
|
// // 自定义一个盐 |
|
|
|
// $salt = makeSalt(12); |
|
|
|
// return md5("{$timeStamp}_{$userId}_{$guid}_{$salt}"); |
|
|
|
} |
|
|
|
} |