今天第一次调用微信开放平台调用模板消息的接口,遇到 invalid openid 这个错误。请求内容如下:
{
"data": {
"Status": {
"color": "#2B2B2B",
"value": "处理完成"
},
"RowCreateDate": {
"color": "#2B2B2B",
"value": "2020-01-08 18:18:58"
},
"LogType": {
"color": "#2B2B2B",
"value": "待购买"
},
"HandleType": {
"color": "#2B2B2B",
"value": "小视频"
},
"remark": {
"color": "#2B2B2B",
"value": "\n请您及时查看!"
},
"first": {
"color": "#1AAD19",
"value": "您好,您有一个新的视频,请查看!"
}
},
"template_id": "FjsPYtVaHD2bJKaeG1D_wFaOZoSwV5KOqbccJNHnJbI",
"toUser": "OPENID**************************",
"url": "https://****.***.***/***/***/"
}
在度娘身上翻了五页,历时两个半小时,依然没有试出结果。
反复确认以下操作无误:
1.OPENID确实属于此APPID对应的公众号(此微信号关注了此公众号)
2.生成ACCESS_TOKEN的APPID确实是此公众号的APPID
2.ACCESS_TOKEN确实没有过期
可以使用微信公众平台接口调试工具: https://mp.weixin.qq.com/debug/.
说明在这个APPID下是可以获取这个OPENID的用户信息的。
然后果断按微信官方文档上的参数顺序重新提交了一次:
{
"touser":"OPENID**************************",
"template_id":"FjsPYtVaHD2bJKaeG1D_wFaOZoSwV5KOqbccJNHnJbI",
"url":"https://****.***.***/***/***/",
"data": {
"Status": {
"color": "#2B2B2B",
"value": "处理完成"
},
"RowCreateDate": {
"color": "#2B2B2B",
"value": "2020-01-08 18:18:58"
},
"LogType": {
"color": "#2B2B2B",
"value": "待购买"
},
"HandleType": {
"color": "#2B2B2B",
"value": "AI小视频"
},
"remark": {
"color": "#2B2B2B",
"value": "\n请您及时查看!"
},
"first": {
"color": "#1AAD19",
"value": "您好,您有一个新的视频,请查看!"
}
}
}
{
"errcode": 0,
"errmsg": "ok",
"msgid": 1155853474064777216
}
参考文档:
发送模板消息
https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#5