日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第三方qq登录接口

發(fā)布時間:2023/12/8 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第三方qq登录接口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

QQ第三方登錄
1.首先就是去QQ互聯登錄申請了,為什么要申請呢,是應為他會給你分配一個appid和一個appkey給,不然你是沒有資格去第三方登錄的,申請大概一個星期左右

**
唯一需要注意的是第二個 回調地址了 這個是可以隨時修改的

2.獲取到了appid和appkey然后我們就需要開發(fā)后臺了
我們先去獲取java sdk 記得是java sdk不是js sdk
java SDk 下載
解壓:


然后將jar包放入自己的項目

有興趣的可以讀一下 ReadMe.txt 了解更詳細 我們繼續(xù)下一步
打開qqconnectconfig.properties

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.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 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

上面是需要修改四處的根據自己的信息來修改
app_ID 申請下來的 appid
app_KEY 申請下來的 appkey
redirect_URI 自己申請時候填寫的回調地址 所以說
scope

我們一般的話第一個就可以 會獲取到qq的名稱性別和頭像,如果需要其他的話也可以自己去申請 。你自己有什么權限的你就可以早scope后面添加

到這里我們的準備工作就準備好了,開始直接測試吧,
先測試一下自己的接口能不能用

<a href="<%=path%>/qq/QQlogin">請使用你的QQ賬號登陸</a> <a href="<%=path%>/qq/afterlogin">回調的測試</a> @RequestMapping("/qq/QQlogin")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 (QQConnectException e) {e.printStackTrace();}}

new Oauth().getAuthorizeURL(request) jar包提供的方法哦 會讀取你在qqconnectconfig.properties 里面的信息 然后拼接出來成一URL,具體是什么樣的可以去官方文檔去看,

授權的話就會進去自己在申請時候設置的回調了(redirect_URI)

@RequestMapping("/qq/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;}

這樣就可以獲取到信息了,這里所有的方法都是已經封裝好的,下載好sdk就可以獲取了,寫的很簡單,但是絕對沒那么簡單,最基本的登錄,有興趣課可以去看官方的詳細文檔
http://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token

謝謝!

總結

以上是生活随笔為你收集整理的第三方qq登录接口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。