コード例 #1
0
  /** 被动回复(暂时只支持文本Key) */
  public static SentMsg getSentMsg(ReceivedMsg msg, String tenantId, WcEventType type) {
    WcEvent response = null;
    if (msg instanceof NormalMsg) {
      String content = ((NormalMsg) msg).getContent();
      response = WcEventService.getEventByContentKey(tenantId, type, content);
    } else {
      response = WcEventService.getEventByEventType(tenantId, type);
    }

    // 如果根据关键字没有匹配上的话就获取该广场默认的回复事件
    if (response == null) {
      response = WcEventService.getDefaultMsg(tenantId);
    }

    SentMsg sentMsg = null;
    if (response == null) {
      sentMsg = new SentMsg(msg);
      sentMsg.setContent(defaultOutMsg);
    } else {
      MsgType msgType =
          MsgType.get(WcMaterialType.get(response.getStr("reply_type")).name().toLowerCase());
      sentMsg = MsgSentBuilder.getSentMsg(msg, msgType);
      preSentMsg(response, sentMsg, tenantId);
    }
    return sentMsg;
  }
コード例 #2
0
  /** 给用户发送客服消息。 */
  private static void preSentMsg(WcEvent event, SentMsg sentMsg, String tenantId) {
    switch (WcMaterialType.get(event.getStr("reply_type"))) {

        // 文字
      case TEXT:
        sentMsg.setContent(event.getStr("content"));
        break;

        // 图文,若果是图文就直接发送,jfianl 发送的
      case NEWS:
        List<NewsArticle> list = NewsArticleService.getArticles(event.getInt("content"));
        NewsMsg newsMsg = (NewsMsg) sentMsg;

        String domain = WcCache.getWxBase(tenantId).getDomain();
        for (NewsArticle detail : list) {
          newsMsg.addNews(
              detail.getStr("title"),
              detail.getStr("digest"),
              detail.getStr("cover_pic_url"),
              domain.concat("/msg/index?newsId=") + detail.getInt("id"));
        }

        break;

      default:
    }
  }