登陆

章鱼彩票竞猜-怎么完成第三方QQ登录

admin 2019-12-14 179人围观 ,发现0个评论

1.1 第三方登录

所谓的第三方登录,便是APP识别到用户将第三方的账号绑定到自己渠道的 ID上直接完结登录的进程,简略来说,是指根据用户在第三方渠道上已有的账号和暗码来快速完结己方使用的登录或许注册的功用。常见的第三方登录渠道,一般是现已具有很多用户的渠道,国内的便是各大厂:微信、微博、QQ 等,国外有 Facebook、Twitter。


1.2 扫码登录天谕

现在的第三方渠道根本都支撑扫码登录,由于扫码登录愈加安全,

并且不必记账号和暗码

如:微信、qq、支付宝


2. QQ第三方登录

2.1 qq互联

https://connect.qq.com/



2.2 注册开发者




2.3 文档



3. OAuth2.0 介绍


3.1. QQ登录OAuth2.0整体处理流程

QQ登录OAuth2.0整体处理流程如下:

Step1:恳求接入,获取appid和apikey;

Step2:开发使用,并设置协作者帐号进行测验联调;

Step3:放置QQ登录按钮;

Step4:经过用户登录验证和授权,获取Access Token;

Step5:经过Access Token获取用户的OpenID;

Step6:调用OpenAPI,来恳求拜访或修正用户授权的资源。


4. 项目集成qq登录

4.1 maven导入包

net.gplatform

Sdk4J

2.0

4.2. 装备

最好检查qq给出的demo比如

创立 qqconnectconfig.properties放在resources根目录下

app_ID = 101543517

app_KEY = 3d43255254a6f50876661fe2bec86684

redirect_URI = http://javatv.cn/loginAfter

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/photo/add_album

uploa章鱼彩票竞猜-怎么完成第三方QQ登录dPicURL = 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


4.3. 建包oauth2并扫描


4.4. 编写qqcontroller

 @Controller章鱼彩票竞猜-怎么完成第三方QQ登录
public class QQController {
@Autowired
RestTemplate restTemplate;

@Autowired
UserService u章鱼彩票竞猜-怎么完成第三方QQ登录serService;

// 将页面重定向到qq第三方的登录页面
@RequestMapping(value = "/qqLogin")
public void qqLogin(HttpServletRequest request, HttpServletResponse response) {
try {
response.setContentType("text/html;charset=utf-8");
response.sendRedirect(new Oauth().getAuthorizeURL(request));//将页面重定向到qq第三方的登录页面
} catch (Exception e) {
e.printStackTrace();
}
}
// 登录之后回调地址
@RequestMapping(value = "/loginAfter")
public String qqLoginAfter(HttpServletRequest request, HttpServletResponse response) {
try {
System.err.println("============登录之后回调地址==========");
AccessToken accessTokenObj = (new Oauth()).getAccessTokenByRequest(request);
String accessToken = null,
openID = null;
long tokenExpireIn = 0L;
if (accessTokenObj.getAccessToken().equals("")) {
// 咱们的网站被CSRF进犯了或许用户取消了授权
System.out.print("没有获取到呼应参数");
} else {
accessToken = accessTo章鱼彩票竞猜-怎么完成第三方QQ登录kenObj.getAccessToken();
tokenExpireIn = accessTokenObj.getExpireIn();
// 使用获取到的accessToken 去获取当时用的openid -------- start
OpenID openIDObj = new章鱼彩票竞猜-怎么完成第三方QQ登录 OpenID(accessToken);
openID = openIDObj.getUserOpenID();
System.err.println("===============" + openID);
// 获取qq信息
String url = "https://graph.qq.com/user/get_user_info?access_token="
+ accessToken + "&oauth_consumer_key=101543517" + "&openid=" + openID + "&format=json ";
String json = restTemplate.getForObject(url, St章鱼彩票竞猜-怎么完成第三方QQ登录ring.class);
ObjectMapper objectMapper = new ObjectMapper();
HashMap map = objectMapper.readValue(json, HashMap.class);
System.err.println(map);
System.err.println(map.get("figureurl_qq_1"));
// 假如用户表没有当时openid,那就增加用户,假如就有就直接跳转主界面main.jsp\
User user = new User();
user.setQqOpenId(openID);
User u = userService.queryByParam(user);
if (u != null) {
System.out.println(u);
return "main";
} else {
// 增加用户
user.setHeadImg((String) map.get("figureurl_qq_1"));
user.setLoginName(UUID.randomUUID().toString());
user.setLoginPwd("123456");
userService.insert(user);
return "main";
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}


4.5 登录页面参加QQ登录

页面参加


绑定事情


4.6. 修正 hosts

C:\Windows\System32\drivers\etc

修正hosts文件,在结尾参加

127.0.0.1 javatv.cn


  • 融创我国:昆明文旅城估计将于12月21日开业
  • 章鱼彩票竞猜-美团点评-W(03690)第三季度总收入同比增44.1%至275亿元 经调整溢利净额19亿元
  • 请关注微信公众号
    微信二维码
    不容错过
    Powered By Z-BlogPHP