Fetch the repository succeeded.
This action will force synchronization from 如梦技术/JFinal-oauth2.0-login, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
##对第三方登陆的基础封装
集成qq
、sina
、baidu
、renren
、osc
、豆瓣
等,第三方登陆api!
并非只有jfinal
中可以使用
也可用户其他构架中!具体可参看Test.java测试
注意
·oauth.properties· 中含有我的网站的appkey可用来测试
测试时先更改hosts
(具体可以google
)
127.0.0.1 www.dreamlu.net
测试过程为
调用getAuthorizeUrl()
获取url
,在浏览器访问url,拿到回调的code
参数
调用getUserInfoByCode()
传入刚获取的code
!
有不明白的可以联系本人,QQ:596392912
//OAuth2.0标准协议建议,利用state参数来防止CSRF攻击。可存储于session或其他cache中
private static final String SESSION_STATE = "_SESSION_STATE_QQ_";
/**
* 构造授权请求url
* @param 设定文件
* @return void 返回类型
* @throws
*/
public void index() {
try {
String state = TokenUtil.randomState();
setSessionAttr(SESSION_STATE, state);
redirect(OauthQQ.me().getAuthorizeUrl(state));
} catch (Exception e) {
log.error(e.getMessage());
redirect("/");
}
}
/**
* 腾讯回调
* @Title: callback
* @param 设定文件
* @return void 返回类型
* @throws
* 返回json:<url>http://wiki.connect.qq.com/get_user_info</url>
*/
public void callback() {
String code = getPara("code");
String state = getPara("state");
String session_state = getSessionAttr(SESSION_STATE);
// 取消了授权
if (StringKit.isBlank(state) || StringKit.isBlank(session_state) || !state.equals(session_state) || StringKit.isBlank(code)) {
redirect("/admin");
return;
}
removeSessionAttr(SESSION_STATE);
try{
JSONObject userInfo = OauthQQ.me().getUserInfoByCode(code);
log.error(userInfo);
String type = "qq";
String openid = userInfo.getString("openid");
String nickname = userInfo.getString("nickname");
String photoUrl = userInfo.getString("figureurl_2");
// 将相关信息存储数据库...
}catch(Exception e){
log.error(e);
}
redirect("/admin");
}
申请期间可以添加测试账号
为了快速的申请通过,请使用QQ官方的最大的那个(图标素材)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。