Пример #1
0
  public MaterialPagination list(int agentId, MediaType type, int offset, int size) {
    String request = "{\"type\":\"%s\",\"agentid\":%s,\"offset\":%s,\"count\":%s}";
    String url = WxEndpoint.get("url.material.list");
    String response =
        wxClient.post(url, String.format(request, type.name(), agentId, offset, size));

    return toMaterialSearchResult(
        JsonMapper.defaultMapper().fromJson(response, QyMaterialSearchResult.class));
  }
Пример #2
0
  public MpNewsPagination listMpNews(int agentId, int offset, int size) {
    String request = "{\"type\":\"%s\",\"agentid\":%s,\"offset\":%s,\"count\":%s}";
    String url = WxEndpoint.get("url.material.list");
    String response =
        wxClient.post(url, String.format(request, MediaType.mpnews.name(), agentId, offset, size));

    logger.debug("list mpnews: {}", response);

    return JsonMapper.defaultMapper().fromJson(response, MpNewsPagination.class);
  }
Пример #3
0
 public MpNews getMpNews(int agent, String mediaId) {
   String url = WxEndpoint.get("url.material.mpnews.get");
   String response = wxClient.get(String.format(url, agent, mediaId));
   GetMpNewsResponse getMpNewsResponse =
       JsonMapper.defaultMapper().fromJson(response, GetMpNewsResponse.class);
   if (getMpNewsResponse != null) {
     return getMpNewsResponse.getMpNews();
   } else {
     return null;
   }
 }
Пример #4
0
  public void updateMpNews(int agent, String mediaId, MpNews mpNews) {
    String url = WxEndpoint.get("url.material.mpnews.update");
    Map<String, Object> request = new HashMap<>();
    request.put("agentid", agent);
    request.put("mpnews", mpNews);
    request.put("mediaId", mediaId);

    String json = JsonMapper.nonEmptyMapper().toJson(request);
    logger.info("update mpnews: {}", json);
    wxClient.post(url, json);
  }
Пример #5
0
  public String addMpNews(int agent, MpNews mpNews) {
    String url = WxEndpoint.get("url.material.mpnews.add");

    Map<String, Object> request = new HashMap<>();
    request.put("agentid", agent);
    request.put("mpnews", mpNews);

    String json = JsonMapper.nonEmptyMapper().toJson(request);
    logger.info("add mpnews: {}", json);
    return wxClient.post(url, json);
  }
Пример #6
0
  /**
   * 图文消息的content里面如果有图片,该图片需要使用本方法上传,图片仅支持jpg/png格式,大小必须在2MB以下,每天最多200张
   *
   * @param inputStream 图片流
   * @param fileName 文件名
   * @return 图片的url, 可以在图文消息的content里面使用
   */
  public String addMpNewsImage(InputStream inputStream, String fileName) {
    String url = WxEndpoint.get("url.mpnews.image.upload");
    String response = wxClient.post(url, inputStream, fileName);

    Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response);
    if (result.containsKey("url")) {
      return result.get("url").toString();
    } else {
      logger.warn("mpnews image upload failed: {}", response);
      throw new WxRuntimeException(999, response);
    }
  }
Пример #7
0
  public String upload(int agent, MediaType type, InputStream inputStream, String fileName) {
    String url = WxEndpoint.get("url.material.binary.upload");

    String response = wxClient.post(String.format(url, agent, type.name()), inputStream, fileName);

    Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response);
    if (result.containsKey("errcode") && "0".equals(result.get("errcode").toString())) {
      return result.get("media_id").toString();
    } else {
      logger.warn("material upload failed: {}", response);
      throw new WxRuntimeException(998, response);
    }
  }
Пример #8
0
 public File download(int agent, String mediaId) {
   return wxClient.download(
       String.format(WxEndpoint.get("url.material.binary.get"), agent, mediaId));
 }
Пример #9
0
 public Counts count(int agent) {
   String response = wxClient.get(String.format(WxEndpoint.get("url.material.count"), agent));
   return JsonMapper.defaultMapper().fromJson(response, Counts.class);
 }
Пример #10
0
 public void delete(int agent, String mediaId) {
   String response =
       wxClient.get(String.format(WxEndpoint.get("url.material.delete"), agent, mediaId));
   logger.info("material delete result: {}", response);
 }