声明、使用JDK9、idea2018.02 、maven3.5.4、tomcat9
maven的web工程QQ第三方登录接口引入,听起来简单,做完以后也很简单,这里使用 java SDK ;
写的文字比较多,查了好多文章,写的模模糊糊的,只有自己写清楚了供大家参考,其实很简单的一个调用;
maven的 web 开发qq接口引入,文档地址:http://wiki.connect.qq.com/
该处测试使用servlet注解方式,官方demo使用配置web.xml方式【重中之重一点需要更改Tomcat中context.xml配置】;
<!-- 配置qq登录的文档库 -->
<Context docBase="web" path="/" privileged="true" antiResourceLocking="false">
</Context>
(1)申请审核5天左右,获得对应的 appid与appkey ,创建应用,填写回调接口 (下面有图);
(2) js SDK下载 http://wiki.connect.qq.com/sdk%E4%B8%8B%E8%BD%BD;
java SDK下载 http://wiki.open.qq.com/wiki/website/SDK%E4%B8%8B%E8%BD%BD
(3)log下载 图标下载;
(4)调用登录 和回调 函数,搭建 demo servlet 和依赖;
2018/10/16 审核通过;
在基本信息中填写回调接口,由于仅作为测试使用,所以填写的回调接口为 http://localhost:8080/afterLoginRedirectServlet
和回调的 servlet的 urlPatterns=" /afterLoginRedirectServlet " 要保持一致【重点】;
如下图:
到此为止所需参数获取完毕,配置文件如下;
app_ID = 你的appid
app_KEY = 你的key,下面的回调url根据个人情况更改,scope权限根据需求改【需要有这权限才能配置】
redirect_URI = http://localhost:8080/afterLoginRedirectServlet
scope = get_user_info
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
声明,使用的maven工程,Tomcat9.0.10 ,JDK9进行测试;
开始调用接口测试 ,可以改写成基于baseSeverlet来测试,为了方便直接 coding:
逻辑说明 ,点击按钮,调用 IndexServlet 进行调用登录qq的功能;点击登录 qq ,会重定向调用回调 AfterLoginRedirectServlet ,用于获取用户信息;这里用于测试仅仅开通了