From b26e3cc3745499d354a5290ffb2fad4c810dfb5b Mon Sep 17 00:00:00 2001 From: Leonardo-Cosmos Date: Wed, 29 Dec 2021 00:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=8D=A1=E7=89=87=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/api_message.js | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/lib/api_message.js b/lib/api_message.js index bf0ec31..964a249 100644 --- a/lib/api_message.js +++ b/lib/api_message.js @@ -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)); +};