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

发送小程序卡片消息 #264

Open
wants to merge 1 commit 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
101 changes: 101 additions & 0 deletions lib/api_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,104 @@ exports._sendCardFromCs = function (openid,cs_account, card, callback) {
that.request(url, postJSON(data), wrapper(callback));
});
};

/**
* 客服消息,发送小程序卡片消息
* 详细细节 http://mp.weixin.qq.com/wiki/1/70a29afed17f56d537c833f89be979c9.html#.E5.AE.A2.E6.9C.8D.E6.8E.A5.E5.8F.A3-.E5.8F.91.E6.B6.88.E6.81.AF
* Examples:
* ```
* var miniprogrampage = {
* title: 'title', // 小程序卡片的标题,可选
* appid: 'appid', // 小程序的appid,要求小程序的appid需要与公众号有关联关系
* pagepath: 'pagepath', // 小程序的页面路径,跟app.json对齐,支持参数,比如pages/index/index?foo=bar
* thumb_media_id: 'thumb_media_id' // 小程序卡片图片的媒体ID
* };
* api.sendMiniProgramPage('openid', miniprogrampage, callback);
* ```
* Callback:
*
* - `err`, 调用失败时得到的异常
* - `result`, 调用正常时得到的对象
*
* @param {String} openid 用户的openid
* @param {Object} miniprogrampage 小程序页面
* @param {Function} callback 回调函数
*/
exports.sendMiniProgramPage = function (openid, miniprogrampage, callback) {
this.preRequest(this._sendMiniProgramPage, arguments);
};

/*!
* 客服消息,发送小程序卡片消息的未封装版本
*/
exports._sendMiniProgramPage = function (openid, miniprogrampage, callback) {
// {
// "touser":"OPENID",
// "msgtype":"miniprogrampage",
// "miniprogrampage": {
// "title":"title", // 可选
// "appid":"appid",
// "pagepath":"pagepath",
// "thumb_media_id":"thumb_media_id"
// }
// }
var url = this.endpoint + '/cgi-bin/message/custom/send?access_token=' + this.token.accessToken;
var data = {
'touser': openid,
'msgtype':'miniprogrampage',
'miniprogrampage': miniprogrampage
};
this.request(url, postJSON(data), wrapper(callback));
};

/**
* 客服消息,发送小程序卡片消息,带客服账号
* 详细细节 http://mp.weixin.qq.com/wiki/1/70a29afed17f56d537c833f89be979c9.html#.E5.AE.A2.E6.9C.8D.E6.8E.A5.E5.8F.A3-.E5.8F.91.E6.B6.88.E6.81.AF
* Examples:
* ```
* var miniprogrampage = {
* title: 'title', // 小程序卡片的标题,可选
* appid: 'appid', // 小程序的appid,要求小程序的appid需要与公众号有关联关系
* pagepath: 'pagepath', // 小程序的页面路径,跟app.json对齐,支持参数,比如pages/index/index?foo=bar
* thumb_media_id: 'thumb_media_id' // 小程序卡片图片的媒体ID
* };
* api.sendMiniProgramPage('openid', miniprogrampage, callback);
* ```
* Callback:
*
* - `err`, 调用失败时得到的异常
* - `result`, 调用正常时得到的对象
*
* @param {String} openid 用户的openid
* @param {Object} miniprogrampage 小程序页面
* @param {Function} callback 回调函数
*/
exports.sendMiniProgramPageFromCs = function (openid, cs_account, miniprogrampage, callback) {
this.preRequest(this._sendMiniProgramPageFromCs, arguments);
};

/*!
* 客服消息,发送小程序卡片消息的未封装版本
*/
exports._sendMiniProgramPageFromCs = function (openid ,cs_account, miniprogrampage, callback) {
// {
// "touser":"OPENID",
// "msgtype":"miniprogrampage",
// "miniprogrampage": {
// "title":"title", // 可选
// "appid":"appid",
// "pagepath":"pagepath",
// "thumb_media_id":"thumb_media_id"
// }
// }
var url = this.endpoint + '/cgi-bin/message/custom/send?access_token=' + this.token.accessToken;
var data = {
'touser': openid,
'msgtype':'miniprogrampage',
'miniprogrampage': miniprogrampage,
'customservice':{
'kf_account': cs_account
}
};
this.request(url, postJSON(data), wrapper(callback));
};