yuanzhihai / think-jwt

JSON Web Token (JWT) for Think plugin
6 stars 1 forks source link

Call to a member function getToken() on string #4

Open hulang opened 5 months ago

hulang commented 5 months ago

使用示例10一直提示这个错误... 配置config里面里面,我把app改成了api use yzh52521\Jwt\JWT;

    protected $jwt;
    protected function initialize()
    {
        parent::initialize();
        $this->jwt = JWT::class;
    }
    public function login()
    {
        $username = 'tt120';
        $password = 'ss555140a';
        if ($username && $password) {
            $userData = [
                'uid' => 1, // 如果使用单点登录,必须存在配置文件中的sso_key的值,一般设置为用户的id
                'username' => 'xx',
            ];
            // 使用默认场景登录
            $token = $this->jwt->getToken('api', $userData);
            $data = [
                'code' => 0,
                'msg' => 'success',
                'data' => [
                    'token' => $token->toString(),
                    'expires_in' => $this->jwt->getTTL($token->toString()),
                ]
            ];
            return json($data);
        }
        return json(['code' => 0, 'msg' => '登录失败', 'data' => []]);
    }
hulang commented 5 months ago

JWT.php的597行getSceneConfigByToken返回的是array,你的@return string导致行:280,387,477提示有波浪线 行509也有波浪线....JWTUtil::getToken返回的是array。。。$this->tokenToPlain($token)参数是string。。。