public SocialUserAccountInfo newAccountInfo(SocialUserAccount socialUserAccount) { SocialUserAccountInfo info = new SocialUserAccountInfo(); info.setType(DictDef.dict("tencent")); info.setValueType(DictDef.dictInt("string")); info.setAccountId(socialUserAccount.getId()); return info; }
public void createSocialUserAccountInfo(SocialUserAccountInfo socialUserAccountInfo) { SocialUserAccountInfo s = queryExist(socialUserAccountInfo); if (s == null) { socialUserAccountInfo.setId(rep.getNextId()); rep.insert(socialUserAccountInfo); } else { socialUserAccountInfo.setId(s.getId()); updateSocialUserAccountInfo(socialUserAccountInfo); } }
private SocialUserAccountInfo queryExist(SocialUserAccountInfo socialUserAccountInfo) { SocialUserAccountInfoQuery query = new SocialUserAccountInfoQuery(); query .setKey(socialUserAccountInfo.getKey()) .setAccountId(socialUserAccountInfo.getAccountId()) .setType(socialUserAccountInfo.getType()) .setUserId(socialUserAccountInfo.getUserId()) .setEntityId(socialUserAccountInfo.getEntityId()); List<SocialUserAccountInfo> infos = findSocialUserAccountInfoByQueryCriteria(query, null); if (infos != null && infos.size() > 0) { return infos.get(0); } return null; }
public OAuthV2 queryAccountToken(String accountId) { // 取数据库中的accesToken和openId SocialUserAccountInfo tok = socialUserAccountInfoService.findAccountOfInfoByKey(DictDef.dict("accessToken"), accountId); String assessToken = tok.getValue(); SocialUserAccountInfo openIdInfo = socialUserAccountInfoService.findAccountOfInfoByKey(DictDef.dict("openId"), accountId); String openId = openIdInfo.getValue(); OAuthV2 oAuth = TencentSociaTool.getQQAuthV2(); oAuth.setAccessToken(assessToken); oAuth.setOpenid(openId); return oAuth; }
/** * 我的所有微博 * * @param ac * @param oAuth * @param pBroadcastTime */ public void homeWeiboToDb( SocialUserAccount ac, OAuthV2 oAuth, TimelineParameter pBroadcastTime, boolean sign) { String response = ""; try { response = new StatusesAPI(oAuth.getOauthVersion()).homeTimeline(pBroadcastTime); } catch (Exception e) { e.printStackTrace(); } if (StringTool.judgeBlank(response)) { WeiboHandleResult r = weiboSaveDb(response, ac, DictDef.dictInt("weibo_public_timeline")); if (r.isSuccess() && r.getInfoSize() > 0) { pBroadcastTime.lastid = r.getLastid(); pBroadcastTime.pagetime = r.getPagetime(); if (!sign) { // 保存微博的最后时间 sign = true; SocialUserAccountInfo info = new SocialUserAccountInfo(); info.setKey("weibo_last_time"); // 微博最后更新时间 Date d = new Date(Long.parseLong(r.getPagetime()) * 1000); info.setAccountId(ac.getId()); info.setType(DictDef.dict("user_account_info_type")); // 帐号类型 info.setValue(StringDateUtil.parseString(d, 4)); info.setValueType(DictDef.dictInt("date")); info.setValueDate(d); socialUserAccountInfoService.createSocialUserAccountInfo(info); } homeWeiboToDb(ac, oAuth, pBroadcastTime, sign); } } }
/** * 设置用户帐号信息 * * @param socialUserAccount * @param key * @param value */ public void setEntityInfo(String entityId, String entityType, String key, String value) { SocialUserAccountInfo info = new SocialUserAccountInfo(); info.setKey(key); // info.setEntityId(entityId); info.setType(entityType); // 帐号类型 info.setValue(value); info.setValueString(value); info.setValueType(DictDef.dictInt("string")); createSocialUserAccountInfo(info); }
/** * 设置用户信息 * * @param socialUserAccount * @param key * @param value */ public void setSocialUserInfo(String userId, String key, String value) { SocialUserAccountInfo info = new SocialUserAccountInfo(); info.setKey(key); // info.setUserId(userId); info.setType(DictDef.dict("user_info_type")); // 用户类型 info.setValue(value); info.setValueString(value); info.setValueType(DictDef.dictInt("string")); createSocialUserAccountInfo(info); }
/** * 设置用户帐号信息 * * @param socialUserAccount * @param key * @param value */ public void setSocialUserAccountInfo( SocialUserAccount socialUserAccount, String key, String value) { SocialUserAccountInfo info = new SocialUserAccountInfo(); info.setKey(key); // info.setAccountId(socialUserAccount.getId()); info.setType(DictDef.dict("user_account_info_type")); // 帐号类型 info.setValue(value); info.setValueString(value); info.setValueType(DictDef.dictInt("string")); createSocialUserAccountInfo(info); }
public void updateSocialUserInfo(JSONObject userInfo, SocialUserAccount socialUserAccount) { SocialUserAccountInfo info = new SocialUserAccountInfo(); info.setType(DictDef.dict("tencent")); info.setValue(userInfo.getString("fansnum")); info.setKey(DictDef.dict("followersCount")); info.setValueType(DictDef.dictInt("int")); info.setAccountId(socialUserAccount.getId()); socialUserAccountInfoService.createSocialUserAccountInfo(info); }
public int updateSocialUserAccountInfo(SocialUserAccountInfo socialUserAccountInfo) { Date lastUpdate = StringDateUtil.now(); socialUserAccountInfo.setLastUpdate(lastUpdate); return rep.update(socialUserAccountInfo); }
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); }