diff --git a/lib/api_media.js b/lib/api_media.js index 2232692..6139f2b 100644 --- a/lib/api_media.js +++ b/lib/api_media.js @@ -90,6 +90,68 @@ exports.getMedia = async function (mediaId) { }; return this.request(url, opts); }; + +/** + * 获取素材列表 + * 详情请见: + * Examples: + * ``` + * api.getMediaList('news', 0, 15); + * ``` + * 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之间 + */ +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 * 详情请见: