男主失去女主后黑化(男主失去女主后追悔莫及)
0
2025-02-21
关于[qq登录功能实现],如何实现第三方QQ登录,今天就分享给大家。如果对你有帮助,别忘了关注这个网站。
1.2扫码登录。分享完牛皮的内容,记住关键词:qq登录功能流程图,登录qq用什么功能,直接登录qq,可以设置qq登录状态,qq用户登录。目前第三方平台基本都支持扫码登录,因为扫码登录更安全。
而且你不用记住你的账号和密码。
如:微信、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的整体流程如下:
第一步:申请访问,获取appid和apikey;
第二步:开发应用程序,并为测试和调试设置协作者帐户;
第三步:放置QQ登录按钮;
步骤4:访问令牌;是通过用户登录验证和授权获得的;
第五步:获取openid通过访问令牌访问用户;
步骤6:调用OpenAPI请求访问或修改用户授权的资源。
4.项目集成qq登录4.1 maven导入包
& lt!- QQ第三方登录-& gt;
& lt依赖性& gt
& ltgroupId & gtnet.gplatform & lt/groupId & gt;
& ltartifactId & gtSdk4J & lt/artifact id & gt;
& lt版本& gt2.0 & lt/version & gt;
& lt/dependency & gt;
4.2.配置
最好查一下qq给的demo例子。
创建qqconnectconfig.properties并将其放在资源的根目录中。
app_ID = 101543517
app _ KEY = 3d 43255254 a6f 50876661 Fe 2 bec 86684
重定向_ http://javatv.cn/loginAfter = URI
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
base URL = https://graph.qq.com/
getUserInfoURL = https://graph.qq.com/user/get_user_info
access token URL = https://graph.qq.com/oauth2.0/token
authorize URL = https://graph.qq.com/oauth2.0/authorize
getOpenIDURL = https://graph.qq.com/oauth2.0/me
addtopicur = https://graph.qq.com/shuoshuo/add_topic
https://graph.qq.com/blog/add_one_blog
addAlbumURL = https://graph.qq.com/photo/add_album
上传图片URL = https://graph.qq.com/photo/upload_pic
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
德尔图尔= https://graph.qq.com/t/del_t
getWeiboUserInfoURL = https://graph.qq.com/user/get_info
getweibooteruserinfourl = 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
版本= 2.0.0.0
4.3.打包oauth2并扫描它。
& ltcontext:component-scan base-package = " cn . it source . oauth 2 "/& gt;
4.4.编写qqcontroller
@ controller public class QQ controller { @ Autowired rest template rest template;@ Autowired UserService UserService;//将页面重定向到qq第三方@ requestmapping的登录页面(value = "/QQ log in ")public void QQ log in(http servlet请求,http servlet响应response) {try {response。setcontenttype(" text/html;charset = utf-8 ");response.sendRedirect(新Oauth()。getAuthorizeURL(请求));//将页面重定向到qq第三方的登录页面} catch(exception e){ e . printstacktrace();} }//登录后回调地址@ request mapping(value = "/log in After ")公共字符串qqloginafter(http servlet request request,http servlet response response){ try { system .err.println ("= = = = = = = = =登录后的回调地址= = = = = = = ");access token accessTokenObj =(new Oauth())。getAccessTokenByRequest(请求);String accessToken = null,openID = nulllong tokenExpireIn = 0Lif(acceptokenobj。getaccessToken()。等于(" "){/我网站被CSRF攻击或用户取消授权System.out.print("未获得响应参数");} else { access token = accesstokenobj . getaccessstoken();tokenExpireIn = accesstokenobj . getexpirein();//使用获取的accessToken获取当前使用的OpenID-Start OpenID OpenID obj = New OpenID(访问令牌);openID = openID obj . getuser openID();system . err . println(" = = = = = = = = = = = = = = = " openID);//获取qq信息字符串URL = " https://graph . QQ . com/user/Get _ user _ info?access _ token = " access token " & amp;oauth _ consumer _ key = 101543517 " " & amp;openid = " openID " & ampformat = JSON ";string JSON = rest template . getfor object(URL,string . class);object mapper object mapper = new object mapper();HashMap map = object mapper . read value(JSON,HashMap . class);system . err . println(map);system . err . println(map . get(" figure URL _ QQ _ 1 "));//如果用户表中没有当前的openid,则添加一个用户,如果有,则直接跳转到主界面main . JSP \ User User = new User();user . setqqopenid(openID);User u = userService.queryByParam(用户);如果(u!= null){ system . out . println(u);返回“main”;} else {//Add user . setheadimg((string)map . get("图URL _ QQ _ 1 "));user . set log in name(uuid . random uuid()。toString());user . setloginpwd(" 123456 ");userService.insert(用户);返回“main”;} } } catch(异常e){ e . printstacktrace();}返回null}}
4.5登录页面加入QQ登录
页面添加
绑定事件
4.6.修改主机
c:\ Windows \ System32 \ drivers \等
修改主机文件并在末尾添加
127 . 0 . 0 . 1 javatv.cn