返回的状态码是response.statusCode == 200,但是却报错
{
errcode: 48001,
errmsg: 'api unauthorized rid: 60b8496c-03f941fe-77255e74'
}
没看懂什么api未授权,小程序这边使用wx.requestSubscribeMessage授权成功了,但还是报这个错,有大佬知道这个怎么解决吗?
这个是调用后台的接口报出来的吧,access_token的问题,要检查下是否过期,是否是对应的小程序的
request({
url: url,
method: 'post',
body: requestData,
json: true,
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log('模板消息推送成功');
console.log(body)
}
});
const url = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='+access_token; //发送模板消息的接口
const requestData = { //发送模板消息的数据
"touser": openid,
"access_token":access_token,
"template_id": "模板id",
'data': {
'phrase1': {
'value': '成功'
},
'thing2': {
'value': '维修审核'
},
'thing5': {
'value': '您可以进行后续操作'
},
'character_string6': {
'value': '13'
},
'date3': {
'value': dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss")
}
}
};
request({
url: url,
method: 'post',
body: requestData,
json: true,
headers: {
"content-type": "application/json",
},
}, function(error, response, body) {
console.log(body)
});
最终得到解决了,前面access_token成功获取到之后进行如上步骤,希望能帮到和我遇到类似问题的人