Package com.appspot.piment.api.tqq.model

Examples of com.appspot.piment.api.tqq.model.Response


    WeiboMap weiboMap = this.weiboMapDao.getBySinaWeiboId(sinaWeiboId, user.getId());

    if (weiboMap != null && StringUtils.isNotBlank(String.valueOf(weiboMap.getTqqWeiboId()))) {

    Response response = null;
    Throwable throwable = null;

    TqqWeiboApi tqqApi = null;

    String commentUserId = String.valueOf(comment.getUser().getId());
    String tqqWeiboId = String.valueOf(weiboMap.getTqqWeiboId());
    String commentMsg = comment.getText();

    if (commentUserId.equals(this.tqqWeiboApi.getUsetId())) {
      tqqApi = this.tqqWeiboApi;
    } else {
      UserMap userMap = this.userMapDao.getUserMap(commentUserId);
      if (userMap != null && StringUtils.isNotBlank(userMap.getTqqUserId())) {
      AuthToken tempAuthToken = this.authTokenDao.getByUserId(userMap.getTqqUserId(), WeiboSource.Tqq);
      this.tqqTempWeiboApi.setAuthToken(tempAuthToken);
      tqqApi = this.tqqTempWeiboApi;
      } else {
      tqqApi = this.tqqRobotWeiboApi;
      commentMsg = "Sina @" + comment.getUser().getScreenName() + "//" + commentMsg;
      }
    }

    try {
      response = tqqApi.sendComment(tqqWeiboId, commentMsg, null);
    } catch (Exception e) {
      throwable = e;
    }

    // 処理成功ならば、同期化レコードをデータストアへ保存する
    if (response != null && response.isOK()) {
      // 同期成功情報を履歴レコードに反映
      commentMap.setStatus(WeiboStatus.SUCCESSED);
      commentMap.setTqqCommentId(Long.valueOf(response.getData().getId()));
      log.info("Sina comment --> コメント同期化成功!!!");
      log.info("Sina comment --> コメントメッセージID:" + comment.getId());
      result = true;
    } else {

      log.warning("Sina comment --> コメント同期化失敗!!!");
      log.warning("Sina comment --> メッセージID:" + comment.getId());

      String msg001 = "Sina comment --> [" + commentMap.getSinaCommentId() + "]をTQQへの送信が失敗しました。";
      log.severe(msg001);

      String errorDetail = throwable != null ? JSON.encode(throwable, true) : response.toString();
      log.severe(errorDetail);

      // 13 重复发表
      // 10 发表太快,被频率限制
      if ("10".equals(response.getErrcode())) {
      System.out.println("DOT NOT SEND EMAIL!");
      commentMap.setStatus(WeiboStatus.FAILED);
      throw new ApiLimitedException("发表太快,被频率限制:" + errorDetail);
      } else if ("13".equals(response.getErrcode())) {
      System.out.println("DOT NOT SEND EMAIL!");
      } else {
      MailUtils.sendErrorReport(msg001 + "\n\n処理コメント:" + comment.toString() + "\n\nTQQからのレスポンス:\n" + errorDetail + "\n\n");
      }
View Full Code Here


    weiboMap.setUserMapId(userMap.getId());
    weiboMap.setSource(WeiboSource.Sina);
    weiboMap.setStatus(WeiboStatus.UNKNOW);

    // 同じメッセージをtqqへ発表する
    Response response = null;
    Response middleResponse = null;
    Throwable throwable = null;
    String originalMsg = null;
    try {
      // 转发微博的处理
      if (status.isRetweet()) {

      String retweetId = null;
      Status retweetedStatus = status.getRetweeted_status();
      log.info("Sina Message --> Retweet [" + retweetedStatus.getId() + "]");

      WeiboMap processedWeibo = this.weiboMapDao.getBySinaWeiboId(retweetedStatus.getId(), userMap.getId());
      if (processedWeibo != null) {
        retweetId = String.valueOf(processedWeibo.getTqqWeiboId());
      } else {

        originalMsg = sinaWeiboApi.getOriginalMsg(retweetedStatus.getText().trim());

        StringBuilder retweetMsg = new StringBuilder();
        retweetMsg.append("Sina@").append(retweetedStatus.getUser().getName()).append("//");
        retweetMsg.append(originalMsg);
       
        // 長調整
        if(retweetMsg.length() > 140){
          String sinaURL = "... " + SinaWeiboApi.getStatusPageURL(retweetedStatus.getUser().getId(), retweetedStatus.getId());
          retweetMsg = retweetMsg.delete((140 - sinaURL.length()), retweetMsg.length());
          retweetMsg.append(sinaURL);
        }
       
        try {
          middleResponse = tqqRobotWeiboApi.sendMessage(originalMsg, retweetMsg.toString(), retweetedStatus.getBmiddle_pic(), null);
        } catch (Exception e) {
          middleResponse = new Response();
          middleResponse.setMsg(e.getMessage());
          log.warning("Retweet --> 例外!!!" + e.getMessage());
        }
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~X");
        if (middleResponse != null && middleResponse.isOK()) {
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Y");
        log.info("Sina Message --> Retweet Successed!!!");
        // データストアへ保存する

        // 同期化履歴レコードの初期化
        WeiboMap retweetWeiboMap = new WeiboMap();
        retweetWeiboMap.setSinaWeiboId(retweetedStatus.getId());
        retweetWeiboMap.setTqqWeiboId(Long.valueOf(middleResponse.getData().getId()));
        retweetWeiboMap.setUserMapId(null);
        retweetWeiboMap.setSource(WeiboSource.Sina);
        retweetWeiboMap.setStatus(WeiboStatus.SUCCESSED);
        weiboMapDao.save(retweetWeiboMap);
        retweetId = middleResponse.getData().getId();
        }
      }
      log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Q");
      if (retweetId != null) {
        log.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Z");
View Full Code Here

  String postPayload = getSignedPayload(Constants.HTTP_POST, url, params);
  log.info("postPayload = " + postPayload);
  String response = HttpClient.doPost(url, postPayload);

  log.info("result --> \n" + response);
  Response responseObj = JSON.decode(response, Response.class);
 
  return responseObj;
  }
View Full Code Here

    String postPayload = getSignedPayload(Constants.HTTP_POST, url, params);
    log.info("postPayload = " + postPayload);
    response = HttpClient.doPost(url, postPayload);
  }
  log.info("result --> \n" + response);
  Response responseObj = JSON.decode(response, Response.class);
   
  return responseObj;
  }
View Full Code Here

TOP

Related Classes of com.appspot.piment.api.tqq.model.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.