wechat/weixin extend api.
$ npm install wx-extend-api
const { WeixinApi, ApiExtend } = require('wx-extend-api');
let MessageExtend = class MessageExtend extends ApiExtend {
async send(to, content) {
return await this.invoke(
'https://api.weixin.qq.com/cgi-bin/message/custom/send',
{
body: {
touser: to, msgtype: 'text',
text: { content }
}
}, 'POST');
}
};
let api = new WeixinApi('appId', 'appSecret');
// register
api.extend('message', MessageExtend);
api.message.send('openId', 'content')
.then(function (result) {
// ..
}).catch(function (err) {
// ..
});
// or
// await api.message.send('openId', 'content');