mirror of
https://github.com/songquanpeng/message-pusher.git
synced 2025-10-20 22:40:02 +08:00
🎉 make some improvements
This commit is contained in:
24
utils.js
24
utils.js
@@ -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);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user