🎉 make some improvements

This commit is contained in:
Song
2020-09-01 20:06:41 +08:00
parent fb47fd61e5
commit 6ead15bdc1
4 changed files with 56 additions and 25 deletions

View File

@@ -18,4 +18,28 @@ module.exports = {
});
return token;
},
pushMessage: function (req, res, content) {
// Reference: https://mp.weixin.qq.com/debug/cgi-bin/readtmpl?t=tmplmsg/faq_tmpl
let access_token = req.app.access_token;
let request_data = {
touser: process.env.OPEN_ID,
template_id: process.env.TEMPLATE_ID,
};
request_data.data = { text: { value: content } };
axios
.post(
`https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=${access_token}`,
request_data
)
.then((response) => {
if (response.data && response.data.errcode === "40001") {
requestToken(req.app);
}
res.json(response.data);
})
.catch((error) => {
res.json(error);
});
},
};