Ejemplo n.º 1
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);
     }
   }
 }
Ejemplo n.º 2
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);
   }
 }
Ejemplo n.º 3
0
 /**
  * 我发表的微博
  *
  * @param ac
  * @param oAuth
  * @param pBroadcastTime
  */
 public void myWeiboToDb(SocialUserAccount ac, OAuthV2 oAuth, TimelineParameter pBroadcastTime) {
   String response = "";
   try {
     response = new StatusesAPI(oAuth.getOauthVersion()).broadcastTimeline(pBroadcastTime);
   } catch (Exception e) {
     e.printStackTrace();
   }
   if (StringTool.judgeBlank(response)) {
     WeiboHandleResult r = weiboSaveDb(response, ac, DictDef.dictInt("weibo_user_timeline"));
     if (r.isSuccess() && r.getInfoSize() > 0) {
       pBroadcastTime.lastid = r.getLastid();
       pBroadcastTime.pagetime = r.getPagetime();
       myWeiboToDb(ac, oAuth, pBroadcastTime);
     }
   }
 }
Ejemplo n.º 4
0
  @Override
  public Map queryUserInfoByCode(String code, String openid, String openkey) {
    HashMap map = new HashMap();
    OAuthV2 oAuth = TencentSociaTool.getQQAuthV2();
    oAuth.setAuthorizeCode(code);
    oAuth.setOpenid(openid);
    oAuth.setOpenkey(openkey);

    String accessToken = null, userOpenID = null;
    long tokenExpireIn = 0L;

    // 换取access token
    oAuth.setGrantType("authorize_code");
    try {
      OAuthV2Client.accessToken(oAuth);
    } catch (Exception e1) {
      e1.printStackTrace();
    }

    // 检查是否正确取得access token
    if (oAuth.getStatus() == 3) {
      System.out.println("Get Access Token failed!");
      return null;
    }

    UserAPI userAPI = new UserAPI(oAuth.getOauthVersion());
    String userInfoJson = "";
    try {
      userInfoJson = userAPI.info(oAuth, "json");
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    Object userInfoObject = TencentSociaTool.getJsonDataObject(userInfoJson);
    if (judgeNull(userInfoObject)) {
      return null;
    }

    JSONObject userInfo = ((JSONObject) userInfoObject);
    map.put("user", userInfo);
    map.put("token", accessToken);
    map.put("oAuth", oAuth);
    map.put("code", code);
    return map;
  }
Ejemplo n.º 5
0
 /** 评论 */
 @Override
 public int discussWeibo(WeiboForwardSend weiboForwardSend) {
   String accountId = weiboForwardSend.getUserAccountId();
   OAuthV2 oAuth = queryAccountToken(accountId);
   int ret = 0;
   TAPI tAPI = new TAPI(oAuth.getOauthVersion()); // 根据oAuth配置对应的连接管理器
   try {
     String response =
         tAPI.comment(
             new AddParameter(oAuth, weiboForwardSend.getContent(), weiboForwardSend.getWeibId()));
     boolean isRplyOk = JSONObject.fromObject(response).getString("msg").equals("ok");
     if (isRplyOk) {
       ret = 1;
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return ret;
 }