@Test public void testAddMpNews(){ InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("media/image.png"); String mediaId = Materials.defaultMaterials().addImage(inputStream, "image.png").getMediaId(); 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(mpNews); System.out.println(mpNewsMedia); }
public String addMpNews(MpNews mpNews) { String url = WxEndpoint.get("url.material.mpnews.add"); String json = JsonMapper.nonEmptyMapper().toJson(mpNews); 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(MpNews mpNews) { String url = WxEndpoint.get("url.material.mpnews.add"); String json = JsonMapper.nonEmptyMapper().toJson(mpNews); 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(MpNews mpNews) { String url = WxEndpoint.get("url.material.mpnews.add"); String json = JsonMapper.nonEmptyMapper().toJson(mpNews); 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(MpNews mpNews) { String url = WxEndpoint.get("url.material.mpnews.add"); String json = JsonMapper.nonEmptyMapper().toJson(mpNews); 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(AppSetting appSetting); void setWxClient(WxClient wxClient); String addMpNewsImage(InputStream inputStream, String fileName); String addMpNews(MpNews mpNews); MpNews getMpNews(String mediaId); void updateMpNews(String mediaId, int index, MpArticle article); Material addVoice(InputStream inputStream, String fileName); InputStream getVoice(String mediaId); Material addImage(InputStream inputStream, String fileName); InputStream getImage(String mediaId); Material addThumb(InputStream inputStream, String fileName); InputStream getThumb(String mediaId); Material addVideo(InputStream inputStream, String fileName, String title, String description); Video getVideo(String mediaId); Counts count(); MaterialPagination list(MediaType mediaType, int offset, int count); MpNewsPagination listMpNews(int offset, int count); void delete(String mediaId); }
Materials { public String addMpNews(MpNews mpNews) { String url = WxEndpoint.get("url.material.mpnews.add"); String json = JsonMapper.nonEmptyMapper().toJson(mpNews); 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(AppSetting appSetting); void setWxClient(WxClient wxClient); String addMpNewsImage(InputStream inputStream, String fileName); String addMpNews(MpNews mpNews); MpNews getMpNews(String mediaId); void updateMpNews(String mediaId, int index, MpArticle article); Material addVoice(InputStream inputStream, String fileName); InputStream getVoice(String mediaId); Material addImage(InputStream inputStream, String fileName); InputStream getImage(String mediaId); Material addThumb(InputStream inputStream, String fileName); InputStream getThumb(String mediaId); Material addVideo(InputStream inputStream, String fileName, String title, String description); Video getVideo(String mediaId); Counts count(); MaterialPagination list(MediaType mediaType, int offset, int count); MpNewsPagination listMpNews(int offset, int count); void delete(String mediaId);  }