var templateOptions = {
hostname:‘api.weixin.qq.com’,
path:’/cgi-bin/message/template/send?access_token=5_KrSRJoRpYPNxh7sgo9FRkXdvXMplrnhwb-3qGeeUKvLvMg1UTdOz6Xny-8Nj9nBgDfLRuxBa_YWbCByha_M6gcMTzCWGVylZzPVUqyi4IWkrg7anhIdZa9b8pdvQ7v5GI6HwaKX9rO01gY-yVJVfAIAGUG’,
method: ‘POST’,
headers: {
‘Content-Type’: ‘application/json’,
}
}
var templateData = JSON.stringify({
“touser”:‘oFGC80z-dJdh34btJGevltpI0cuE’,
“template_id”:“LkggiRmZ6EIY_fVlz3tQ7FWVxew9tsjFWsa6b0xbAT0”,
“url”:“https://map.ipsmap.com?id=lGaWCUtqoj&search=qq” ,
“miniprogram”:{
“appid”:“wx0fb39a1dc27c5e6d”,
“pagepath”:“pages/index?id=lGaWCUtqoj&search=qq”
},
“data”:{
“first”: {
“value”:“aa”,
“color”:"#173177"
},
“keyword1”:{
“value”:“bb”,
“color”:"#173177"
},
“keyword2”: {
“value”:‘qq’,
“color”:"#173177"
},
“keyword3”: {
“value”:“vv”,
“color”:"#173177"
},
“remark”:{
“value”:“dd”,
“color”:"#173177"
}
}
});
//请求发送微信模板
// console.log(‘data:’+data);
requsetWithData(templateOptions, templateData, function(res) {
console.log(res);
})
function requsetWithData (options, data ,callback) {
console.log(‘进来了进来了进来了进来了进来了进来了进来了进来了进来了’+options.hostname)
var req = https.request(options, function(res) {
console.log(‘ss’);
res.setEncoding(‘utf-8’);
var responseString = ‘’;
res.on(‘data’, function(data) {
responseString += data;
});
res.on(‘end’, function() {
var resultObject = JSON.parse(responseString);
if (callback && typeof(callback) === “function”) {
callback(resultObject);
console.log(‘回调了回调了回调了回调了回调了回调了回调了回调了回调了’+options.hostname)
}
})
});
req.write(data);
req.on(‘error’, function(e) {
console.log(’-----error-------’,e);
});
req.end();
})
}
没有任何回调 。想知道原因 请求其他的接口是没有问题的。postman请求该模板是可以的。 可以忽略accesstoken过期的问题。