0
点赞
收藏
分享

微信扫一扫

$keyOrKeyArray must be an instance of Firebase\\JWT\\Key key or an array of Firebase\\JWT\\Key keys

MaxWen 2022-03-19 阅读 97
php

1.JWT 出现的问题

在这里插入图片描述

 /**
     * 验证token
     * @return \think\response\Json
     */
    public function verifyjwt()
    {
        $jwt= input("jwt");
        $key = md5('dd'); //jwt的签发密钥,验证token的时候需要用到
        try{
            $jwtAuth = json_encode(JWTUtil::decode($jwt,$key,array("HS256")));
            //修改
             $jwtAuth = json_encode(JWTUtil::decode($jwt,new Key($key,'HS256')));
            $authInfo = json_decode($jwtAuth,true);
            if (!$authInfo['user_id']){
                return show(0,"用户不存在");
            }
            return show(0,"ok");
        }catch (ExpiredException $e){
            return show(0,"token过期");
        }catch (\Exception $e){
            return show(0,$e->getMessage());
        }

    }

在这里插入图片描述
参考 https://blog.csdn.net/arlene12345/article/details/123147868

举报

相关推荐

0 条评论