2 qq 20344357 qq_20344357 于 2016.04.14 16:23 提问

微信 群发 上传图文素材44003
// 存放所有文章结合list的map
    HashMap allMap = new HashMap();

    // 存放所有文章的list
    List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();

    // 各个文章的map
    HashMap<String, String> map;
    HashMap<String, String> map1;

    // 缩略图的id
    String thumb_media_id = "qQqbYn8mE_ZkajO3m2RCzZWUobzFSMbILv7KoY1lzyKEK_ypL1WcLFAXtcI6oVxp";

    map = new HashMap<String, String>();
    map.put("thumb_media_id", thumb_media_id);
    map.put("author", "xiaojin");
    map.put("title", "上传群发测试");
    map.put("content_source_url", "www.eupwood.com");
    map.put("content", "这是测试内容1");
    map.put("digest", "测试用描述");
    map.put("show_cover_pic", "1");

    map1 = new HashMap<String, String>();
    map1.put("thumb_media_id", thumb_media_id);
    map1.put("author", "xiaojin");
    map1.put("title", "上传群发测试1");
    map1.put("content_source_url", "www.eupwood.com");
    map1.put("content", "这是测试内容2");
    map1.put("digest", "测试用描述1");
    map1.put("show_cover_pic", "0");
    list.add(map);
    list.add(map1);
    allMap.put("articles", list);

    JSONArray postData = JSONArray.fromObject(allMap);

    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=" + token);
    StringEntity se = new StringEntity(postData.toString());
    httpPost.setEntity(se);
    HttpResponse response = httpClient.execute(httpPost);
    int result = response.getStatusLine().getStatusCode();
    if (result == HttpStatus.SC_OK)
    {
        System.out.println("OK");
        HttpEntity resEntity = response.getEntity();
        System.out.println(EntityUtils.toString(resEntity));
        System.out.println(resEntity.getContent());
        EntityUtils.consume(resEntity);
    }

代码如上,图文内容是有的,难道是我post的有问题????

2个回答

CSDNXIAON
CSDNXIAON   2016.04.20 22:00

微信那些事-群发图文(一)
----------------------同志你好,我是CSDN问答机器人小N,奉组织之命为你提供参考答案,编程尚未成功,同志仍需努力!

xxmvzeetbb
xxmvzeetbb   2016.10.08 01:41

> list = new ArrayList>();

// 各个文章的map
HashMap<String, String> map;
HashMap<String, String> map1;

// 缩略图的id
String thumb_media_id = "qQqbYn8mE_ZkajO3m2RCzZWUobzFSMbILv7KoY1lzyKEK_ypL1WcLFAXtcI6oVxp";

map = new HashMap<String, String>();
map.put("thumb_media_id", thumb_media_id);
map.put("author", "xiaojin");
map.put("title", "上传群发测试");
map.put("content_source_url", "www.eupwood.com");
map.put("content", "这是测试内容1");
map.put("digest", "测试用描述");
map.put("show_cover_pic", "1");

map1 = new HashMap<String, String>();
map1.put("thumb_media_id", thumb_media_id);
map1.put("author", "xiaojin");
map1.put("title", "上传群发测试1");
map1.put("content_source_url", "www.eupwood.com");
map1.put("content", "这是测试内容2");
map1.put("digest", "测试用描述1");
map1.put("show_cover_pic", "0");
list.add(map);
list.add(map1);
allMap.put("articles", list);
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!