Browse Source

能输出结果的

master
xyiege 1 year ago
parent
commit
20381e7a5f
  1. 42
      app/api/controller/Index.php

42
app/api/controller/Index.php

@ -57,26 +57,32 @@ class Index extends BaseController
$signer = new Sha256(); $signer = new Sha256();
$key = InMemory::plainText(config('jwt.secret')); $key = InMemory::plainText(config('jwt.secret'));
$builder = new Builder(); //
// 设置发行时间和过期时间 $config = Configuration::forSymmetricSigner($signer,$key);
$now = new DateTimeImmutable(); // 当前时间 $now = new DateTimeImmutable(); // 当前时间
// 设置发行时间和过期时间 $token = $config->builder()
$secondsToAdd = (int) config('jwt.token_ttl'); // 签发人
$expiresAt = $now->add(new \DateInterval('PT' . $secondsToAdd . 'S')); ->issuedBy('https://douyin.xingtongworld.com/')
// 受众
->permittedFor('https://douyin.xingtongworld.com/')
// JWT ID 编号 唯一标识
->identifiedBy($claims['id'])
// 签发时间
->issuedAt($now)
// 在1分钟后才可使用
// ->canOnlyBeUsedAfter($now->modify('+1 minute'))
// 过期时间1小时
->expiresAt($now->modify('+1 hour'))
// 自定义uid 额外参数
->withClaim('uid', $claims['id'])
->withClaim('name',$claims['nick_name'])
// 自定义header 参数
// ->withHeader('foo', 'bar')
// 生成token
->getToken($config->signer(), $config->signingKey());
$token = $builder // base64
->issuedAt($now) // iat: 发行时间 return $token->toString();
->expiresAt($expiresAt) // exp: 过期时间
->withIssuer('iss', 'xtt') // iss: 发行人
->withSubject('sub', 'xtoken') // sub: 主题
->withAudience('aud', 'ttc'); // aud: 受众
foreach ($claims as $key => $value) {
$token = $token->withClaim($key, $value);
}
return (string) $token->sign($signer, $key);
} }
} }
Loading…
Cancel
Save