async function sendTemplateMessage (rbody2,accessToken) {
let body = JSON.parse(rbody2.body);
//let openids =body.data.openid;
//console.log('云函数成功 body ==>', body);
for(let j=0;j <body.data.openid.length;j++){
let openid = body.data.openid[j];
//console.log('云函数成功 openid ==>', openid);
//console.log('云函数成功 openids ==>', openids);
var openids = openid ;
//console.log('云函数成功 openids ==>', openids);
}
if(openids ==[])return;
var form = {
"touser":openids,
"template_id":"_hwFtzTUdLBiWR16hA2i5NudzhIMztEnPVVVx0ZXn1Y",
//"url":"http://weixin.qq.com/download",
"data": {
"first": {
"value": "新冠疫苗第一针接种通知",
"color": "#173177"
},
"keyword1": {
"value": "新冠第一针次未接种市民群众",
"color": "#173177"
},
"keyword2": {
"value": "2021年7月1日上午08:00-11:30,下午02:00-05:00",
"color": "#173177"
},
"keyword3": {
"value": "惠东吉隆安康医院",
"color": "#173177"
},
"keyword4": {
"value": "医院大门左侧预防接种门诊",
"color": "#173177"
},
"remark": {
"value": "只接待预约成功者接种新冠疫苗第一针次",
"color": "#173177"
}
},
};
var options = {
method: 'POST',
url: `https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=${accessToken}`,
json: true,
headers: { "content-type": "application/json", },
body:form
}
const rp = options =>
new Promise((resolve, reject) => {
request(options, (error, response, body) => {
if (error) {
reject(error);
console.log('error: ', error);
}
resolve(response);
console.log(' ---- 模板消息 body: ', body);
});
});
const result = await rp(options)
let sed = (typeof result === 'object') ? result : JSON.parse(result);
console.log('云函数成功 sed ==>', sed);
return sed
}