{ "articles": [{ "title": TITLE, "thumb_media_id": THUMB_MEDIA_ID, "author": AUTHOR, "digest": DIGEST, "show_cover_pic": SHOW_COVER_PIC(0 / 1), "content": CONTENT, "content_source_url": CONTENT_SOURCE_URL }, //若新增的是多图文素材,则此处应有几段articles结构,最多8段 ] }
以上是官方给的参数示例。
其中thumb_media_id,并不是像网上有的人说的那样(通过接口 http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=thumb 获得),我因为网上的说话,浪费了一下午时间调试,最后发现是自己httpclient传参数的方式有问题,这个参数就是正常的上传永久图片素材后得到的media_id。
具体测试代码如下
public static void upload_persistent_news(HttpServletRequest request, HttpServletResponse response){
List<Article> articles = new ArrayList<Article>();
Article article = new Article();
article.setTitle("测试上传");
article.setThumb_media_id("qsMKvEkcZKfj9lPLuJNhGPhEDaz25GVTwR0kgYg1wLc");
article.setShow_cover_pic(1);
article.setDigest("摘要");
article.setContent_source_url("https://www.baidu.com");
article.setContent("我看到一个东西哈哈!");
article.setAuthor("qiao");
articles.add(article);
List<Article> list = new ArrayList<Article>();
list.add(article);
String accessToken = new AccessTokenUtil().getAccessToken();
String url_upload = String.format(MaterialInterface.upload_persistent_news_url, accessToken);
Map<String, Object> params = new HashMap<String, Object>();
params.put("articles", list);
String responsetext = null;
try {
responsetext = HttpUtil.post(url_upload, JSONObject.fromObject(params).toString());
System.out.println(responsetext);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
部分摘自 微信开发 者文档......