From 179cf3625ff34697230544f2d96c5f258e3af6b1 Mon Sep 17 00:00:00 2001
From: "Jon.Xia" <xiajia@vip.qq.com>
Date: Fri, 18 May 2018 12:48:18 +0800
Subject: [PATCH 1/2] Add API:getMediaList

---
 lib/api_media.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/lib/api_media.js b/lib/api_media.js
index 2232692..8e6b17c 100644
--- a/lib/api_media.js
+++ b/lib/api_media.js
@@ -90,6 +90,31 @@ exports.getMedia = async function (mediaId) {
   };
   return this.request(url, opts);
 };
+
+/**
+ * 获取素材列表
+ * 详情请见:<https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738734>
+ * Examples:
+ * ```
+ * api.getMediaList('');
+ * ```
+ * - `result`, 调用正常时得到的文件Buffer对象
+ * - `res`, HTTP响应对象
+ * @param {String} type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
+ * @param {Integer} offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
+ * @param {Integer} offset 返回素材的数量,取值在1到20之间
+ */
+exports.getMediaList = async function (type, offset, count) {
+  const { accessToken } = await this.ensureAccessToken();
+  var url = this.prefix + 'material/batchget_material?access_token=' + accessToken;
+  var data = {
+    type: type,
+    offset: offset,
+    count: count
+  };
+  return this.request(url, postJSON(data));
+};
+
 /**
  * 上传图文消息内的图片获取URL
  * 详情请见:<http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html>

From e2051ef9c7938517f11227372b493034609ce192 Mon Sep 17 00:00:00 2001
From: "Jon.Xia" <xiajia@vip.qq.com>
Date: Fri, 18 May 2018 12:58:41 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E5=96=84=E6=96=87=E6=A1=A3?=
 =?UTF-8?q?=E4=BF=A1=E6=81=AF?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 lib/api_media.js | 43 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/lib/api_media.js b/lib/api_media.js
index 8e6b17c..6139f2b 100644
--- a/lib/api_media.js
+++ b/lib/api_media.js
@@ -96,10 +96,47 @@ exports.getMedia = async function (mediaId) {
  * 详情请见:<https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1444738734>
  * Examples:
  * ```
- * api.getMediaList('');
+ * api.getMediaList('news', 0, 15);
  * ```
- * - `result`, 调用正常时得到的文件Buffer对象
- * - `res`, HTTP响应对象
+ * result:
+ * new 类型如下
+ * {
+ * "total_count": TOTAL_COUNT,
+ * "item_count": ITEM_COUNT,
+ * "item": [{
+ *     "media_id": MEDIA_ID,
+ *     "content": {
+ *         "news_item": [{
+ *             "title": TITLE,
+ *             "thumb_media_id": THUMB_MEDIA_ID,
+ *             "show_cover_pic": SHOW_COVER_PIC(0 / 1),
+ *             "author": AUTHOR,
+ *             "digest": DIGEST,
+ *             "content": CONTENT,
+ *             "url": URL,
+ *             "content_source_url": CONTETN_SOURCE_URL
+ *         },
+ *         //多图文消息会在此处有多篇文章
+ *         ]
+ *      },
+ *      "update_time": UPDATE_TIME
+ *  },
+ *  //可能有多个图文消息item结构
+ *  ]
+ * }
+ * 其他类型(图片、语音、视频)的返回如下:
+ *  {
+ *     "total_count": TOTAL_COUNT,
+ *     "item_count": ITEM_COUNT,
+ *     "item": [{
+ *         "media_id": MEDIA_ID,
+ *         "name": NAME,
+ *         "update_time": UPDATE_TIME,
+ *         "url":URL
+ *     },
+ *     //可能会有多个素材
+ *     ]
+ *  }
  * @param {String} type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
  * @param {Integer} offset 从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
  * @param {Integer} offset 返回素材的数量,取值在1到20之间