第三方登录
1.首先就是去互联登录申请了,为什么要申请呢,是应为他会给你分配一个appid和一个appkey给,不然你是没有资格去第三方登录的,申请大概一个星期左右
唯一需要注意的是第二个 回调地址了 这个是可以随时修改的
然后将jar包放入自己的项目
app_ID = 100(请修改此处) app_KEY = (请修改此处) redirect_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(请修改此处) baseURL = https://graph..com/ getUserInfoURL = https://graph..com/user/get_user_info accessTokenURL = https://graph..com/oauth2.0/token authorizeURL = https://graph..com/oauth2.0/authorize getOpenIDURL = https://graph..com/oauth2.0/me addTopicURL = https://graph..com/shuoshuo/add_topic addBlogURL = https://graph..com/blog/add_one_blog addAlbumURL = https://graph..com/photo/add_album uploadPicURL = https://graph..com/photo/upload_pic listAlbumURL = https://graph..com/photo/list_album addShareURL = https://graph..com/share/add_share checkPageFansURL = https://graph..com/user/check_page_fans addTURL = https://graph..com/t/add_t addPicTURL = https://graph..com/t/add_pic_t delTURL = https://graph..com/t/del_t getWeiboUserInfoURL = https://graph..com/user/get_info getWeiboOtherUserInfoURL = https://graph..com/user/get_other_info getFansListURL = https://graph..com/relation/get_fanslist getIdolsListURL = https://graph..com/relation/get_idollist addIdolURL = https://graph..com/relation/add_idol delIdolURL = https://graph..com/relation/del_idol getTenpayAddrURL = https://graph..com/cft_info/get_tenpay_addr getRepostListURL = https://graph..com/t/get_repost_list version = 2.0.0.0
<a href="<%=path%>//login">请使用你的账号登陆
a> <a href="<%=path%>//afterlogin">回调的测试
a>
@RequestMapping("//login") protected void doGet(HttpServletRequest request, HttpServletResponse response, Model model) throws IOException { response.setContentType("text/html;charset=utf-8"); try { /* String authorizeURL = new Oauth().getAuthorizeURL(request);*/ response.sendRedirect(new Oauth().getAuthorizeURL(request)); } catch (ConnectException e) { e.printStackTrace(); } }
授权的话就会进去自己在申请时候设置的回调了(redirect_URI)
@RequestMapping("//afterlogin") public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { try { AccessToken accessTokenObj = (new Oauth()).getAccessTokenByRequest(request); String accessToken = null, openID = null; long tokenExpireIn = 0L; if (accessTokenObj.getAccessToken().equals("")) { System.out.print("没有获取到响应参数"); }else{ accessToken = accessTokenObj.getAccessToken(); tokenExpireIn = accessTokenObj.getExpireIn(); OpenID openIDObj = new OpenID(accessToken); openID = openIDObj.getUserOpenID(); UserInfo qzoneUserInfo = new UserInfo(accessToken, openID); UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo(); } }catch(Exception e){ e.printStackTrace(); } return null; }
谢谢!
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/213241.html原文链接:https://javaforall.net
