/** 接收腾讯微博授权的返回数据 */ @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub if (requestCode == REQUEST_CODE) { // 对应之前设置的的myRequsetCode if (resultCode == OAuthV2AuthorizeWebView.RESULT_CODE) { // 取得返回腾讯的OAuthV2类实例,再转成通用token并存储 tencentAuthV2 = (OAuthV2) data.getExtras().getSerializable("oauth"); CommonOAuth2AccessToken token = new CommonOAuth2AccessToken(); token.setToken(tencentAuthV2.getAccessToken()); // 腾讯的过期时间需要转换 token.setExpiresIn( System.currentTimeMillis() + Long.parseLong(tencentAuthV2.getExpiresIn()) * 1000 + ""); token.setOpenId(tencentAuthV2.getOpenid()); token.setOpenKey(tencentAuthV2.getOpenkey()); AccessTokenKeeper.keepAccessToken( this, token, AccessTokenKeeper.PREFERENCES_NAME_TOKEN_TENCENT); // 更改运行时数据 RunningData.tencentTokenState = Constants.oauth.HAS_AUTHORIZED; RunningData.tencentAccessToken = token; // 更改运行时腾讯接口调用对象 RunningData.oAuthV2 = new OAuthV2( Constants.tencent.clientId, Constants.tencent.clientSecret, Constants.tencent.redirectUri); RunningData.oAuthV2.setAccessToken(token.getToken()); RunningData.oAuthV2.setOpenid(token.getOpenId()); RunningData.oAuthV2.setOpenkey(token.getOpenKey()); // 发送更新UI的消息 tencentOAuthCallbackHandler.sendEmptyMessage(TENCENT_OAUTH_SUCCESS); } } }
private void addTokenInfos(OAuthV2 oAuth, SocialUserAccount socialUserAccount) { SocialUserAccountInfo info = newAccountInfo(socialUserAccount); info.setKey("accessToken"); info.setValue(oAuth.getAccessToken()); info.setValueType(DictDef.dictInt("string")); socialUserAccountInfoService.createSocialUserAccountInfo(info); String expireIn = oAuth.getExpiresIn(); // 失效时间 Date expiredTime = StringDateUtil.addSecond(new Date(), Integer.parseInt(expireIn)); SocialUserAccountInfo expireInfo = newAccountInfo(socialUserAccount); expireInfo.setKey("expiredTime"); expireInfo.setValue(expireIn); expireInfo.setValueDate(expiredTime); expireInfo.setValueType(DictDef.dictInt("date")); socialUserAccountInfoService.createSocialUserAccountInfo(expireInfo); SocialUserAccountInfo oInfo = newAccountInfo(socialUserAccount); oInfo.setKey("openId"); oInfo.setValue(oAuth.getOpenid()); oInfo.setValueType(DictDef.dictInt("string")); socialUserAccountInfoService.createSocialUserAccountInfo(oInfo); oInfo = newAccountInfo(socialUserAccount); oInfo.setKey("openKey"); oInfo.setValue(oAuth.getOpenkey()); oInfo.setValueType(DictDef.dictInt("string")); socialUserAccountInfoService.createSocialUserAccountInfo(oInfo); // refresh_token oInfo = newAccountInfo(socialUserAccount); oInfo.setKey("refreshToken"); oInfo.setValue(oAuth.getRefreshToken()); oInfo.setValueType(DictDef.dictInt("string")); socialUserAccountInfoService.createSocialUserAccountInfo(oInfo); }