String token=""; //获取token
// 上传永久素材
HashMap<String, Object> paramMap = new HashMap<>();
//文件上传只需将参数中的键指定(默认file),值设为文件对象即可,对于使用者来说,文件上传与普通表单提交并无区别
paramMap.put("media", FileUtil.file("C:\\Users\\cs-hg-293\\Desktop\\232\\111.jpg"));
String imgResult= HttpUtil.post("https://api.weixin.qq.com/cgi-bin/material/add_material?type=thumb&access_token="+token, paramMap);
JSONObject tokenJson= JSONUtil.parseObj(imgResult);
// 获取mediaid
String mediaId= tokenJson.get("media_id").toString();
System.out.println(imgResult);
// 新增草稿
//String addDraftUrl="https://api.weixin.qq.com/cgi-bin/draft/add?access_token="+token ;
String addDraftUrl="https://api.weixin.qq.com/cgi-bin/draft/add?access_token="+token ;
String title ="2023-07-31标题";
String digest ="2023-07-31欢迎关注!";
String content="测试内容";
String obi="{\n" +
" \"articles\": [\n" +
" {\n" +
" \"title\":"+title+",\n" +
" \"author\":小明,\n" +
" \"digest\":"+digest+",\n" +
" \"content\":"+content+",\n" +
" \"content_source_url\":,\n" +
" \"thumb_media_id\":"+mediaId+",\n" +
" \"need_open_comment\":0,\n" +
" \"only_fans_can_comment\":0\n" +
" }\n" +
" ]\n" +
"}";
System.out.println(HttpUtil.post(addDraftUrl,obi));
提示错误
{"errcode":40007,"errmsg":"invalid media_id hint: [R7m970627p493] rid: 64c74f8b-5e5173f2-6febad5e"}