QQ快速登录

qq互联的配置:

app_ID = 
app_KEY = 
redirect_URI = 

只需要改以上三个
scope = get_user_info,add_topic,add_one_blog,add_album,upload_pic,list_album,add_share,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idollist,add_idol,del_ido,get_tenpay_addr
baseURL = https://graph.qq.com/
getUserInfoURL = https://graph.qq.com/user/get_user_info
accessTokenURL = https://graph.qq.com/oauth2.0/token
authorizeURL = https://graph.qq.com/oauth2.0/authorize
getOpenIDURL = https://graph.qq.com/oauth2.0/me
addTopicURL = https://graph.qq.com/shuoshuo/add_topic
addBlogURL = https://graph.qq.com/blog/add_one_blog
addAlbumURL = https://graph.qq.com/photo/add_album
uploadPicURL = https://graph.qq.com/photo/upload_pic
listAlbumURL = https://graph.qq.com/photo/list_album
addShareURL = https://graph.qq.com/share/add_share
checkPageFansURL = https://graph.qq.com/user/check_page_fans
addTURL = https://graph.qq.com/t/add_t
addPicTURL = https://graph.qq.com/t/add_pic_t
delTURL = https://graph.qq.com/t/del_t
getWeiboUserInfoURL = https://graph.qq.com/user/get_info
getWeiboOtherUserInfoURL = https://graph.qq.com/user/get_other_info
getFansListURL = https://graph.qq.com/relation/get_fanslist
getIdolsListURL = https://graph.qq.com/relation/get_idollist
addIdolURL = https://graph.qq.com/relation/add_idol
delIdolURL = https://graph.qq.com/relation/del_idol
getTenpayAddrURL = https://graph.qq.com/cft_info/get_tenpay_addr
getRepostListURL = https://graph.qq.com/t/get_repost_list
version = 2.0.0.0

server

从数据库中查询openid的用户信息

如果数据库中没有openid代表没有关联qq

//查询openid用户信息
    @Override
    public ResponseBase findByopenidUser(@RequestParam("openid") String openid) {
        // 验证参数
        if(StringUtils.isEmpty(openid))
        {
            return  setResultErro("系统错误");
            
        }
        //使用openid查找数据库对象的user表的信息
         UserEntity openid2 = userDao.openid(openid);
        if(openid2==null)
        {
        return    setResultErro(Constants.HTTP_RES_CODE_201, "改openid没有关联");    
        }
        //自动登录
        return logintoke(openid2);

//授权QQ登录

得到用户的openid如果查找到opendd先进行账号验证,如果验证正确开始自动登录获取token信息

从数据库查找用户userid修改数据库对应的id,修改成功就代表关联成功

    @Override
    public ResponseBase findBytokenUser(@RequestParam("token") String token) {
         //验证参数
        if(StringUtils.isEmpty(token))
        {
             return setResultErro("token不能为空");
                     
            
        }
      //从redis中 使用tocken 查找对应userid
        String stuserid = (String) baseRedissService.getString(token);
        if(StringUtils.isEmpty(stuserid))
        {
              return setResultErro("tocken无效或者已过期");
            
        }
        //使用userid 数据库查询用户返回信息给客户端
           Long parseLong = Long.parseLong(stuserid); 
           UserEntity findById = userDao.findById(parseLong);
           if(findById==null)
           {
               return setResultErro("你查找的用户不存在");
               
           }
        return setResultSuccess(findById);
    }

//授权QQ登录
    @Override
    public ResponseBase qqlogin(@RequestBody UserEntity entity) {
           //验证参数
        String openid = entity.getOpenid();
        if(StringUtils.isEmpty(openid))
        {
            return setResultErro("openid不能为空");
        }
        
        //先进行账号登录   需要验证
        ResponseBase Logintoke = login(entity);
        if(!Logintoke.getRtncode().equals(Constants.HTTP_RES_CODE_200))
        {
            return Logintoke;
            
            
            
        }
        // 自动登录
        JSONObject data =(JSONObject) Logintoke.getData();
        //获取token信息
        String string = data.getString("matoken");
        ResponseBase FindBytokenUser = findBytokenUser(string);
        if(!FindBytokenUser.getRtncode().equals(Constants.HTTP_RES_CODE_200))
        {
            return FindBytokenUser;
            
        }
        UserEntity data2 = (UserEntity) FindBytokenUser.getData();
        //修改对应的数据库id
        Integer id = data2.getId();
          Integer Upadopeniduser = userDao.upadopeniduser(openid, id);
          if(Upadopeniduser<=0)
          {
              return setResultErro("qq账号管理失败");
              
          }
        return Logintoke;
    }
contllen

    //生成qq授权登录连接

@RequestMapping("/LocaQQlogin")
    public String locaQQlogin(HttpServletRequest request ) throws QQConnectException
    {
         //生成授权连接
         String authorizeURL = new Oauth().getAuthorizeURL(request);
        return "redirect:"+authorizeURL;
        
    }

获取授权码使用授权码查询accctoken 拿到acctoken 使用acctoken获取openid

//调用会员服务接口 使用useropenid 查找是否已经关联账号

//如果已经绑定账号了 自动登录,将token信息存在cokke中

public String QQloginCall(HttpServletRequest request,HttpSession httpSession,HttpServletResponse respons) throws QQConnectException
    {
        //获取授权码
        //使用授权码或去acceetoken
        AccessToken accessTokenByRequest = new Oauth().getAccessTokenByRequest(request);
        if(accessTokenByRequest==null)
        {
            request.setAttribute("error", "QQ授权失败");
            return "errro";
        }
        //拿到accken
        String accessToken = accessTokenByRequest.getAccessToken();
        if(accessToken==null)
        {
            request.setAttribute("error", "ACCtokennull");
            return "errro";
        }
        
        //使用acceetoken获取openid
        OpenID openID = new OpenID(accessToken);
        String userOpenID = openID.getUserOpenID();
        if(userOpenID==null)
        {
            
            request.setAttribute("openID", "openID不能为空");
            return "errro";
        }

//qq授权关联页面 没有账号

  //得到openid,调用登录接口

  public String  qqRelation(UserEntity entity,HttpServletResponse respons,HttpServletRequest reques,HttpSession httpSession)
        {
                 //得到openid
        String attribute = (String) httpSession.getAttribute("qqrelation");
        if(StringUtils.isEmpty(attribute))
        {
            reques.setAttribute("error", "没有获取opid");
            return  "error";
            
        }
            //调用登录接口,
        entity.setOpenid(attribute);
        ResponseBase login = memberServicE.qqlogin(entity);
    
        if(!login.getRtncode().equals(Constants.HTTP_RES_CODE_200))
        {
            
            reques.setAttribute("error", "账号或者密码错误");
            return Longin;
            
        }
    
        
         //将token信息存放在cookeie里面
        LinkedHashMap logindata = (LinkedHashMap) login.getData();
        String  toke = (String) logindata.get("token");
           if(StringUtils.isEmpty(toke))
           {
               reques.setAttribute("error", "会话失效!");
                return Longin ;       
           }
        setcookie(toke, respons);
           return CHAXUN;
           
       }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小笛子1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值