2019-09-20 10:37:37 卢浮宫 版权声明:本文为站长原创文章,转载请写明出处
每次操作都输入用户名密码,是一件很繁琐的事情,那就引入QQ第三方登录吧
QQ都好了,微信...还会远吗?
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";
}