https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html 我已经按照这种方式去获取了所有的,但是取出来的不是最新的。
try {
String token = WeiXinUtil.getWxAppToken();
Map<String, Object> accessToken = (Map<String, Object>) JSON.parseObject(token);
String access_token = accessToken.get("access_token").toString();
//获取素材总数,若图文数量为0则停止下一步操作
String path = "https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token="+access_token;
Map<String, Object> map = new HashMap<>();
map.put("offset", (officialContentVO.getPageNo() - 1) * officialContentVO.getPageSize()); //分页内容起始index
map.put("count", officialContentVO.getPageSize()); //显示内容数量
map.put("type", "news"); //1 表示不返回 content 字段,0 表示正常返回,默认为 0
String paramBody = JSON.toJSONString(map);
// 将map转换成json字符串
JSONObject parseObject = JSON.parseObject(paramBody);
JSONObject json = sendJsonByPost(path, parseObject);
//取出json中的item
String item = json.getString("item");
//查看返回的总数
String total = json.getString("total_count");
log.info("活力校园AS公众号中总共有 {} 条新闻", total);
List<News> newsList = new ArrayList<>();
//如果返回的列表总数为0就没必要解析了
if (Integer.valueOf(total) > 0) {
//item为数组json类型,这时需要转换成JSONArray
JSONArray jsonArray = JSONObject.parseArray(item);
for (int i = 0; i < jsonArray.size(); i++) {
// log.info("jsonArray:{}", jsonArray.get(i));
JSONObject itemObj = jsonArray.getJSONObject(i);
Integer update_timestamp = (Integer) itemObj.get("update_time");
long time = Long.parseLong(update_timestamp + "000");
Date updateTime = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String datetime = sdf.format(updateTime);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
Date date = formatter.parse(datetime);
JSONObject itemContent = (JSONObject) itemObj.get("content");
JSONArray newsItem = (JSONArray) itemContent.get("news_item");
for (int j = 0; j < newsItem.size(); j++) {
JSONObject articleItem = (JSONObject) newsItem.get(j);
News news = new News();
news.setId(IdWorker.getIdStr()); //随机分配一个id作为主键
// log.info("title = {}", articleItem.getString("title"));
news.setTitle((String) articleItem.get("title")); //标题
news.setDescription((String) articleItem.get("digest")); //摘要
news.setChannel("普通新闻");
news.setBody((String) articleItem.get("content")); //图文消息的具体内容,支持HTML标签
news.setThumb((String) articleItem.get("url")); //封面图片地址
news.setPdf((String) articleItem.get("content_source_url")); //图文地址
news.setPubDate(date); //图文所属素材的最后编辑时间
newsList.add(news);
}
}
if (null != newsList && !newsList.isEmpty()) {
newsMapper.batchInsert(newsList);
}
}

/cgi-bin/material/batchget_material 为获取永久素材的列表接口, type: "news" 时获取的是【内容管理——草稿箱——历史图文素材】里面的内容(即草稿箱功能上线之前所编辑的图文素材)。
目前有一个接口可以获取到【未开启群发通知】的发表内容:https://developers.weixin.qq.com/doc/offiaccount/Publish/Get_publication_records.html ;若想要获取【开启群发通知】的内容,目前没有相关接口。