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)); }
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); } }