订阅消息API请求一直为47001?
var post_data = {
"touser": "oxukb0TyXMUURIV2QY******",
"template_id": "ZplaClWWqON9X9qRTh5CDApSD_zcr4ekIWd0029NYeY",
"miniprogram_state":"developer",
"data": {
"phrase2": {
"value": "成功"
},
"date4": {
"value":"2018-01-01"
}
}
};
var content = JSON.stringify(post_data);
var options = {
hostname: 'api.weixin.qq.com',
port: 443,
path: '/cgi-bin/message/subscribe/send?access_token='+access_token,
method: 'POST',
headers:{
'Content-Length':content.length
}
};
返回的消息:BODY: {“errcode”:47001,“errmsg”:“data format error hint: [a7JhBa0072shc1]”}
试了很多遍,没发现JSON数据有问题啊?
1 回复
整改正常了,原先用NodeJS作为后台,使用的是原生的https模块进行的post请求,不知道为什么,请求的JSON字符串中不能含有中文,有中文就发送不出去,后来改用superagent,解决了此问题,代码如下:
var queryData={
grant_type:"client_credential",
appid:"wxe3d86d4*****",
secret:"5c56d4a6e05ab1c2e4a688******"
};
var postData = {
"touser": "oxukb0TyXMUURIV2Q******",
"template_id": "ZplaClWWqON9X9qRTh5CDApSD_zcr4ekIWd0029NYeY",
"data": {
"phrase2": {
"value": "成功"
},
"date4": {
"value":"2018-01-01"
}
}
};
superagent
.get("https://api.weixin.qq.com/cgi-bin/token")
.query(queryData)
.end(function(err,res){
console.log(res.body.access_token);
var access_token=res.body.access_token;
superagent
.post("https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="+access_token)
.send(postData)
.end(function(error,result){
console.log(result.body);
})
});