Php

Javaサードパーティログイン(QQログイン)



Java Third Party Login



Javaサードパーティログイン(QQログイン)

1.最初にQQインターネットログインアプリケーションに移動します。彼がappidとappkeyを割り当てるので、なぜそれを適用する必要があります。これら2つの属性はあなたのキーと同等です。

二。 SDKをダウンロードする



3. Sdk4j-2.0をインポートし、QQログインに必要な構成ファイルqqconnectconfig.propertiesを構成します。

app_ID = **************** 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

4. QqloginControllerクラスを記述し、putメソッドqqLoginを記述します



@RequestMapping(value = '/qqLogin') public void qqLogin(HttpServletRequest request, HttpServletResponse response) throws Exception { response.setContentType('text/htmlcharset=utf-8') try { response.sendRedirect(new Oauth().getAuthorizeURL(request)) } catch (QQConnectException e) { e.printStackTrace() } }

このメソッドを呼び出して、使い慣れたページにアクセスします
画像

5.登録者の基本情報を取得します

@RequestMapping('authqq') public String qqAfterlogin(HttpServletRequest request, HttpSession session ,HttpServletResponse response,Page page,Model model) throws Exception { page = new Page() response.setContentType('text/htmlcharset=utf-8') String accessToken=null,openID=null String qqname=null String gender=null String url50=null long tokenExpireIn = 0L try { AccessToken accessTokenObj=(new Oauth().getAccessTokenByRequest(request)) if(accessTokenObj.getAccessToken().equals('')){ System.out.println('No response parameters were obtained') }else{ accessToken = accessTokenObj.getAccessToken() tokenExpireIn = accessTokenObj.getExpireIn() request.getSession().setAttribute('demo_access_token', accessToken) request.getSession().setAttribute('demo_token_expirein', String.valueOf(tokenExpireIn)) / / Use the obtained accessToken to get the current openid -------- start OpenID openIDObj = new OpenID(accessToken) openID = openIDObj.getUserOpenID() request.getSession().setAttribute('demo_openid', openID) // Use the obtained accessToken to get the current user's openid --------- end UserInfo qzoneUserInfo = new UserInfo(accessToken, openID) UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo() if (userInfoBean.getRet() == 0) { //QQ space name qqname= userInfoBean.getNickname() //QQ space gender gender= userInfoBean.getGender() //QQ space avatar url50= userInfoBean.getAvatar().getAvatarURL50() } else { System.out.println('Sorry, we did not get your information correctly, the reason is:' + userInfoBean.getMsg()) } } } catch (QQConnectException e) { e.printStackTrace() System.out.println('QQ login failed, reason:'+e.getMessage()) return 'login' } }

QQインターネットAPI公式ウェブサイト
QQサードパーティのログインエラーコードの戻り手順