Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature getmedialist #90

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions lib/api_media.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,68 @@ 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('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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMedias

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>
Expand Down