单点登录

 

            # 单点检测
            $this->verifySignLogin($admin->id, $params['mobile'], $token);
            



  /**
     * @param $uid
     * @param $token
     */
    private function verifySignLogin($uid, $mobile ,$token)
    {
        # 获取当前登陆ip
        $request = Request::instance();
        $ip      = $request->ip();
        $redis   = Cache::store('redis')->handler();
        $redis->select(1);
        $info    = $redis->hGetAll($uid . '-' . $mobile);

        if (!$info) {
            $redis->hSet($uid . '-' . $mobile, 'token', $token);
            $redis->hSet($uid . '-' . $mobile, 'ip', $ip);
        } else {
            if ($info['ip'] != $ip) {
                # 添加黑名单
                JWTAuth::invalidate($info['token']);
                # 重置缓存
                $redis->hSet($uid . '-' . $mobile, 'token', $token);
                $redis->hSet($uid . '-' . $mobile, 'ip', $ip);
            }else{
                $redis->hSet($uid . '-' . $mobile, 'token', $token);
            }
        }
    }
    

 

posted @ 2023-11-07 18:07  现世中的素人  阅读(4)  评论(0编辑  收藏  举报