Ejemplo n.º 1
0
 /** 删除永久素材 */
 public static WcResult deleteAbidingMedia(String tenantId, String mediaId) {
   WcResult rs = getClient(tenantId).deleteMaterial(WcCache.getAccessToken(tenantId), mediaId);
   if (rs != null && rs.isSuccess()) {
     WcMedia.me.delete(tenantId, mediaId);
   }
   return rs;
 }
Ejemplo n.º 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:
    }
  }
Ejemplo n.º 3
0
  /** 上传文件到upyun和微信服务器 */
  public static String upload(String tenantId, MediaType type, File file, boolean isForever) {
    Media media = null;

    // 上传到upyun TODO
    String url = "";

    // 上传到微信服务器
    String accessToken = WcCache.getAccessToken(tenantId);
    if (isForever) {
      media = getClient(tenantId).uploadAbidingMedia(type, file, accessToken);
    } else {
      media = getClient(tenantId).uploadTempMedia(type, file, accessToken);
    }

    // 删除临时文件
    file.delete();

    // 回调校验accessToken是否有效
    WcCache.refreshAccessTokenIfInvalid(media, tenantId);
    Assert.isTrue(media != null && media.isSuccess(), "media upload to wechat fail");

    // 将信息存库
    WcMedia wm = new WcMedia();
    wm.set("tenant_id", tenantId);
    wm.set("media_id", media.getMedia_id());
    wm.set("type", type.getFlag());
    wm.set("url", url);
    if (!isForever) {
      // 临时素材 3 * 24 * 60 * 60 * 1000
      wm.set("expires_time", new Date(media.getCreated_at() + 3 * 24 * 60 * 60 * 1000L - 5L));
    }

    wm.set("create_time", new Date(media.getCreated_at()));
    Assert.isTrue(wm.save(), "save wxmedia");

    return media.getMedia_id();
  }
Ejemplo n.º 4
0
 private static MaterialClient getClient(String tenantId) {
   return WcClientFactory.getClient(MaterialClient.class, WcCache.getWxBase(tenantId));
 }