第三方qq登录接口

编程知识 更新时间:2023-05-03 03:38:25

QQ第三方登录
1.首先就是去QQ互联登录申请了,为什么要申请呢,是应为他会给你分配一个appid和一个appkey给,不然你是没有资格去第三方登录的,申请大概一个星期左右

**
唯一需要注意的是第二个 回调地址了 这个是可以随时修改的

2.获取到了appid和appkey然后我们就需要开发后台了
我们先去获取java sdk 记得是java sdk不是js sdk
java SDk 下载
解压:


然后将jar包放入自己的项目

有兴趣的可以读一下 ReadMe.txt 了解更详细 我们继续下一步
打开qqconnectconfig.properties

app_ID = 100****(请修改此处)
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/
getUserInfoURL = https://graph.qq/user/get_user_info
accessTokenURL = https://graph.qq/oauth2.0/token
authorizeURL = https://graph.qq/oauth2.0/authorize
getOpenIDURL = https://graph.qq/oauth2.0/me
addTopicURL = https://graph.qq/shuoshuo/add_topic
addBlogURL = https://graph.qq/blog/add_one_blog
addAlbumURL = https://graph.qq/photo/add_album
uploadPicURL = https://graph.qq/photo/upload_pic
listAlbumURL = https://graph.qq/photo/list_album
addShareURL = https://graph.qq/share/add_share
checkPageFansURL = https://graph.qq/user/check_page_fans
addTURL = https://graph.qq/t/add_t
addPicTURL = https://graph.qq/t/add_pic_t
delTURL = https://graph.qq/t/del_t
getWeiboUserInfoURL = https://graph.qq/user/get_info
getWeiboOtherUserInfoURL = https://graph.qq/user/get_other_info
getFansListURL = https://graph.qq/relation/get_fanslist
getIdolsListURL = https://graph.qq/relation/get_idollist
addIdolURL = https://graph.qq/relation/add_idol
delIdolURL = https://graph.qq/relation/del_idol
getTenpayAddrURL = https://graph.qq/cft_info/get_tenpay_addr
getRepostListURL = https://graph.qq/t/get_repost_list
version = 2.0.0.0

上面是需要修改四处的根据自己的信息来修改
app_ID 申请下来的 appid
app_KEY 申请下来的 appkey
redirect_URI 自己申请时候填写的回调地址 所以说
scope

我们一般的话第一个就可以 会获取到qq的名称性别和头像,如果需要其他的话也可以自己去申请 。你自己有什么权限的你就可以早scope后面添加

到这里我们的准备工作就准备好了,开始直接测试吧,
先测试一下自己的接口能不能用

<a href="<%=path%>/qq/QQlogin">请使用你的QQ账号登陆</a> 
<a href="<%=path%>/qq/afterlogin">回调的测试</a>
@RequestMapping("/qq/QQlogin")
    protected void doGet(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        try {
           /* String authorizeURL = new Oauth().getAuthorizeURL(request);*/
            response.sendRedirect(new Oauth().getAuthorizeURL(request));
        } catch (QQConnectException e) {
            e.printStackTrace();
        }
    }

new Oauth().getAuthorizeURL(request) jar包提供的方法哦 会读取你在qqconnectconfig.properties 里面的信息 然后拼接出来成一URL,具体是什么样的可以去官方文档去看,

授权的话就会进去自己在申请时候设置的回调了(redirect_URI)

 @RequestMapping("/qq/afterlogin")
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
            try {
                AccessToken accessTokenObj = (new Oauth()).getAccessTokenByRequest(request);
                String accessToken   = null,
                        openID        = null;
                long tokenExpireIn = 0L;
                if (accessTokenObj.getAccessToken().equals("")) {
                    System.out.print("没有获取到响应参数");
                }else{
                    accessToken = accessTokenObj.getAccessToken();
                    tokenExpireIn = accessTokenObj.getExpireIn();
                    OpenID openIDObj =  new OpenID(accessToken);
                    openID = openIDObj.getUserOpenID();
                    UserInfo qzoneUserInfo = new UserInfo(accessToken, openID);
                    UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo();
                }
            }catch(Exception e){
                e.printStackTrace();
            }
            return null;
        }

这样就可以获取到信息了,这里所有的方法都是已经封装好的,下载好sdk就可以获取了,写的很简单,但是绝对没那么简单,最基本的登录,有兴趣课可以去看官方的详细文档
http://wiki.connect.qq/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token

谢谢!

更多推荐

第三方qq登录接口

本文发布于:2023-04-30 10:22:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/bb51e4f9b0f67cd5bfcd342af27d9316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:第三方   接口   qq

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!

  • 114013文章数
  • 28898阅读数
  • 0评论数