QQ第三方登录简明实例

2019-09-20 18:37:37  卢浮宫  阅读量:171  版权声明:本文为站长原创文章,转载请写明出处


一、背景

    每次操作都输入用户名密码,是一件很繁琐的事情,那就引入QQ第三方登录吧

    QQ都好了,微信...还会远吗?

二、准备工作(这里写下官方说明)

   1、申请appid和appkey

     申请地址:
        申请流程:
        1. 点击页面上的“申请加入”按钮,申请成为开发者;
        2. 申请appid(oauth_consumer_key/client_id)和appkey(auth_consumer_secret/client_secret);
        (1)进入 http://connect.qq.com/manage/ 页面,点击应用管理--创建应用,选择需要创建的应用类型,在弹出的对话框中填写网站或应用的详细资料(名称,域名,回调地址);
        (2)点击“确定”按钮,提交资料后,获取appid和appkey。
        注意:申请appid时,登录的QQ号码将与申请到的appid绑定,后续维护均需要使用该号码。

        保证连接畅通

        接入QQ登录时,网站需要不停的和手机Qzone进行交互,发送请求和接受响应。
        PC网站:在你的服务器上ping graph.qq.com,保证连接畅通。

    
    

    

    2、导入qqconnectconfig.properties文件到你的项目。内容如下

        注意:内容需要三处修改!!!

    app_ID = XXX
app_KEY = XXX
redirect_URI = https://www.guangmuhua.comXXX
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/phgraph.qq.comoto/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


    3、在你的页面某处放置快捷登录入口,例如

        <a href="/qq/doLogin"><img src="../static/images/qqlogin.png"/>QQ登录</a>

    4、开始代码操作一番(主要是登录页面执向和回调处理)

        <!--QQ第三方登录所需-->

    <dependency>
     <groupId>net.gplatform</groupId>
     <artifactId>Sdk4J</artifactId>
     <version>2.0</version>
    </dependency>

    登录页面处理核心代码如下:

    private static final String QQ_ACCESS_TOKEN = "accessToken";
private static final String QQ_OPENID = "openid";

/**
* 功能描述:qq登录页面跳转
* Param: [request]
* Return: java.lang.String
*/
@RequestMapping(value = "doLogin", method = {RequestMethod.GET})
public String toQQLoginPage(HttpServletRequest request) {
String authorizeURL = null;
try {
authorizeURL = new Oauth().getAuthorizeURL(request);
} catch (QQConnectException e) {
e.printStackTrace();
}
authorizeURL = new StringBuffer("redirect:").append(authorizeURL).toString();
return authorizeURL;
}
    /**
* 功能描述:注销QQ登录
* Param: [request]
* Return: java.lang.String
*/
@RequestMapping(value = "/out", method = {RequestMethod.GET})
public String toLoutoutPage(HttpServletRequest request) {
request.getSession().removeAttribute(QQ_ACCESS_TOKEN);
request.getSession().removeAttribute(QQ_OPENID);
return "index";
}

三、最后

    1、这里做了功能实现,持续更新中

    2、大致看下效果,这些参数信息就不一一说明了,看下官方文档就行(yellowYeaarVip[污]

        

    

    

最新评论: