Exemplo n.º 1
0
  /**
   * 把微博保存到数据库
   *
   * @param ac
   * @param weiType
   * @return
   */
  @Override
  public int weiboToDb(SocialUserAccount ac) {
    String ownerUserId = ac.getOwnUser();
    int updateSize = 0;
    if (ac != null) {
      String accountId = ac.getId();
      OAuthV2 oAuth = queryAccountToken(accountId);

      // 我的微博
      String webFetchTime = queryMyWeiboTime(ac);
      TimelineParameter pBroadcastTime = new TimelineParameter(oAuth);
      pBroadcastTime.pagetime = webFetchTime;
      // pBroadcastTime.reqnum = "2";
      myWeiboToDb(ac, oAuth, pBroadcastTime);

      // @我的微博
      TimelineParameter pBroadcastTime2 = new TimelineParameter(oAuth);
      String webFetchTime2 = queryMentionWeiboTime(ac);
      pBroadcastTime2.pagetime = webFetchTime2;
      mentionsWeiboToDb(ac, oAuth, pBroadcastTime2);

      // 我关注的所有人的微博
      TimelineParameter pBroadcastTime3 = new TimelineParameter(oAuth);
      String webFetchTime3 = queryHomeWeiboTime(ac);
      pBroadcastTime3.pagetime = webFetchTime3;
      homeWeiboToDb(ac, oAuth, pBroadcastTime3, false);
    }
    return updateSize;
  }
Exemplo n.º 2
0
 public void updateSocialUserAccountByThird(
     SocialUserAccount socialUserAccount, JSONObject userInfo) {
   String name = userInfo.getString("name");
   String nick = userInfo.getString("nick");
   String uid = userInfo.getString("openid");
   String url = userInfo.getString("homepage");
   socialUserAccount.setWeiboUid(uid);
   socialUserAccount.setName(name);
   socialUserAccount.setUrl(url);
   socialUserAccount.setUserScreenName(nick);
   socialUserAccount.setType(getSocialTypeInt());
   socialUserAccountService.updateSocialUserAccount(socialUserAccount);
 }
Exemplo n.º 3
0
 /**
  * 我的所有微博
  *
  * @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);
     }
   }
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
  /**
   * 将微博内容放到数据库
   *
   * @param response
   * @param ac
   * @return
   */
  private WeiboHandleResult weiboSaveDb(String response, SocialUserAccount ac, Integer weiboType) {
    WeiboHandleResult result = new WeiboHandleResult();
    JSONArray infoList = null;
    String ownerUserId = ac.getOwnUser();
    Object responseJsonObject = TencentSociaTool.getJsonDataObject(response);
    if (judgeNull(responseJsonObject) || ((JSONObject) responseJsonObject).get("info") == null) {
      result.setSuccess(false);
      return result;
    }
    infoList = ((JSONObject) responseJsonObject).getJSONArray("info");
    boolean sign = false;
    for (int i = 0; i < infoList.size(); i++) { // 没一条的微博
      JSONObject infoObj = infoList.getJSONObject(i);
      SocialUserWeibo dbWeibo = handlerNewSocialUserWeibo(ownerUserId, ac, infoObj, weiboType);
      logger.info(
          i
              + "+++timestamp:"
              + infoObj.getString("timestamp")
              + "++++++++++++++++"
              + "id:"
              + infoObj.getString("id"));
      if (i == 0) { //
        result.setPagetime(infoObj.getString("timestamp"));
        result.setLastid(infoObj.getString("id"));
      }
      String type = infoObj.getString("type");
      SocialUserWeibo soruceWeibo = null;
      JSONObject source = infoObj.getJSONObject("source");
      if (source != null && !(source.toString().equals("null"))) { // 有原帖内容
        soruceWeibo = handlerNewSocialUserWeibo(ownerUserId, ac, source, weiboType);
        soruceWeibo.setWeiboHandleType(1); // 表明为原始贴
        if (saveWeiboUserEntity(soruceWeibo)) { // 插入原帖id
          dbWeibo.setRetweetedId(soruceWeibo.getId());
        } else {
          SocialUserWeibo queryWeibo =
              socialUserWeiboService.queryByAccountAndWeiboId(
                  soruceWeibo.getUserAccountId(), soruceWeibo.getWeiboId());
          dbWeibo.setRetweetedId(queryWeibo.getId());
        }
      }

      if (type.equals("7")) { // 7-评论
        dbWeibo.setWeiboHandleType(2); // 表明为品论贴
        SocialUserWeiboComment comment = tranlateWeiboToComment(dbWeibo, soruceWeibo, weiboType);
        initWeiboCommentByAccount(comment, ac);
        socialUserWeiboCommentService.createSocialUserWeiboComment(comment);
      }

      // 插进本帖
      saveWeiboUserEntity(dbWeibo);
    }
    if (infoList != null) { // 记录数
      result.setInfoSize(infoList.size());
    }
    result.setSuccess(true);
    return result;
  }
Exemplo n.º 6
0
 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);
 }
Exemplo n.º 7
0
 private org.activiti.engine.identity.User updateSocialInfo(
     SocialUserAccount c, JSONObject userInfo, OAuthV2 oAuth) {
   org.activiti.engine.identity.User la =
       identityService.createUserQuery().userId(c.getOwnUser()).singleResult();
   // updateSocialInfos(c, accessTokenObj);
   updateSocialUserAccountByThird(c, userInfo);
   updateSocialUserInfo(userInfo, c);
   addTokenInfos(oAuth, c);
   return la;
 }
 /**
  * 设置用户帐号信息
  *
  * @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);
 }
Exemplo n.º 9
0
 @Override
 public void sendWeibo(SocialUserAccount socialUserAccount, String text, String type) {
   String accountId = socialUserAccount.getId();
   OAuthV2 oAuth = queryAccountToken(accountId);
   int ret = 0;
   TAPI tAPI = new TAPI(oAuth.getOauthVersion()); // 根据oAuth配置对应的连接管理器
   try {
     String response = tAPI.add(new AddParameter(oAuth, text));
     ret = 1;
   } catch (Exception e) {
     e.printStackTrace();
   }
   if (ret == 1) {
     saveSendWeiboRecord(socialUserAccount, text, type);
   }
 }
Exemplo n.º 10
0
  public SocialUserAccount addSocialUserAccountByThird(
      org.activiti.engine.identity.User user, JSONObject userInfo) {
    String name = userInfo.getString("name");
    String nick = userInfo.getString("nick");
    String uid = userInfo.getString("openid");
    String url = userInfo.getString("homepage");

    SocialUserAccount socialUserAccount = new SocialUserAccount();
    socialUserAccount.setWeiboUid(uid);
    socialUserAccount.setName(name);
    socialUserAccount.setUrl(url);
    socialUserAccount.setUserScreenName(nick);
    socialUserAccount.setType(getSocialTypeInt());
    socialUserAccount.setOwnUser(user.getId());
    socialUserAccountService.createSocialUserAccount(socialUserAccount);
    return socialUserAccount;
  }
Exemplo n.º 11
0
 private void initWeiboCommentByAccount(
     SocialUserWeiboComment socialUserWeiboComment, SocialUserAccount ac) {
   socialUserWeiboComment.setUserAccountId(ac.getId());
   socialUserWeiboComment.setOwner(ac.getOwnUser());
   socialUserWeiboComment.setType(ac.getType());
 }