@Test public void testAddMpNews(){ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("media/image.png"); String mediaId = Medias.defaultMedias().upload(MediaType.image, inputStream, "image.png"); MpNews mpNews = new MpNews(); MpArticle mpArticle1 = new MpArticle(); mpArticle1.author("riversoft").digest("我所理解的大数据个性化推荐(1)").showCover().title("我所理解的大数据个性化推荐(1)").thumbMediaId(mediaId); mpArticle1.content("这里是内容，据说可以支持html").contentSourceUrl("http: mpNews.add(mpArticle1); MpArticle mpArticle2 = new MpArticle(); mpArticle2.author("riversoft").digest("我所理解的大数据个性化推荐(2)").showCover().title("我所理解的大数据个性化推荐(2)").thumbMediaId(mediaId); mpArticle2.content("这里是内容，据说可以支持html").contentSourceUrl("http: mpNews.add(mpArticle2); String mpNewsMedia = Materials.defaultMaterials().addMpNews(84, mpNews); System.out.println(mpNewsMedia); }
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); String response = wxClient.post(url, json); Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response); if (result.containsKey("media_id")) { return result.get("media_id").toString(); } else { logger.warn("mpnews add failed: {}", response); throw new WxRuntimeException(999, response); } }
Materials { 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); String response = wxClient.post(url, json); Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response); if (result.containsKey("media_id")) { return result.get("media_id").toString(); } else { logger.warn("mpnews add failed: {}", response); throw new WxRuntimeException(999, response); } } }
Materials { 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); String response = wxClient.post(url, json); Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response); if (result.containsKey("media_id")) { return result.get("media_id").toString(); } else { logger.warn("mpnews add failed: {}", response); throw new WxRuntimeException(999, response); } }  }
Materials { 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); String response = wxClient.post(url, json); Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response); if (result.containsKey("media_id")) { return result.get("media_id").toString(); } else { logger.warn("mpnews add failed: {}", response); throw new WxRuntimeException(999, response); } }  static Materials defaultMaterials(); static Materials with(CorpSetting corpSetting); void setWxClient(WxClient wxClient); String addMpNews(int agent, MpNews mpNews); void updateMpNews(int agent, String mediaId, MpNews mpNews); MpNews getMpNews(int agent, String mediaId); void deleteMpNews(int agentId, String mediaId); String upload(int agent, MediaType type, InputStream inputStream, String fileName); File download(int agent, String mediaId); void delete(int agent, String mediaId); String addMpNewsImage(InputStream inputStream, String fileName); Counts count(int agent); MaterialPagination list(int agentId, MediaType type, int offset, int size); MpNewsPagination listMpNews(int agentId, int offset, int size); }
Materials { 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); String response = wxClient.post(url, json); Map<String, Object> result = JsonMapper.defaultMapper().json2Map(response); if (result.containsKey("media_id")) { return result.get("media_id").toString(); } else { logger.warn("mpnews add failed: {}", response); throw new WxRuntimeException(999, response); } }  static Materials defaultMaterials(); static Materials with(CorpSetting corpSetting); void setWxClient(WxClient wxClient); String addMpNews(int agent, MpNews mpNews); void updateMpNews(int agent, String mediaId, MpNews mpNews); MpNews getMpNews(int agent, String mediaId); void deleteMpNews(int agentId, String mediaId); String upload(int agent, MediaType type, InputStream inputStream, String fileName); File download(int agent, String mediaId); void delete(int agent, String mediaId); String addMpNewsImage(InputStream inputStream, String fileName); Counts count(int agent); MaterialPagination list(int agentId, MediaType type, int offset, int size); MpNewsPagination listMpNews(int agentId, int offset, int size);  }