JWT怎么传递toekn获取id等信息

bdh169

https://www.workerman.net/plugin/10
JWT

怎么实现传递token获取id等信息

不通过header头部传递

和使用JwtToken::getCurrentId()

比如

$xx = wewrewrwer23(这里是token)

调用某个方法
$xxx = XXXXXX($xx)

echo $xxx;

151 2 0
2个回答

kylin87

读一下插件的源码就知道了啊,把方法复制出来,自己写一个方法,就可以用了。
下面是从源码中复制出来的方法。

private static function verifyToken(string $token, int $tokenType): array
    {
        $config = self::_getConfig();
        $publicKey = self::ACCESS_TOKEN == $tokenType ? self::getPublicKey($config['algorithms']) : self::getPublicKey($config['algorithms'], self::REFRESH_TOKEN);
        JWT::$leeway = $config['leeway'];

        $decoded = JWT::decode($token, new Key($publicKey, $config['algorithms']));
        $decodeToken = json_decode(json_encode($decoded), true);
        if ($config['is_single_device'] && self::ACCESS_TOKEN == $tokenType) {
            RedisHandler::verifyToken($config['cache_token_pre'], (string) $decodeToken['extend']['id'], $token);
        }
        return $decodeToken;
    }
  • 暂无评论
Tinywan

截图

  • 暂无评论
×
🔝