使用微信公众号发送图文消息
http请求方式: POST
http请求url:https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN
所需json数据包:
{
"touser":"OPENID",
"msgtype":"news",
"news":{
"articles": [
{
"title":"Happy Day",
"description":"Is Really A Happy Day",
"url":"URL",
"picurl":"PIC_URL"
}
]
}
}
遇到问题:
返回错误 invalid openID错误 errcode:40003,同样的数据包在接口调试工具里可以发送。
解决办法:
picurl 在文档中的参数要求是
picurl 为必须参数并且图片格式须按要求!
关注公众号,发送图文消息代码 java;
//关注公众号 自动发送
if (EventKey.equals("<![CDATA[subscribe]]>")) {
String urlStr = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="+ token;
// 图文回复
String title = "感谢关注!";//标题
String Description = "高效安全,方便快捷。";//描述
String Url = "https://mp.weixin.qq.com/s?__biz=****==&mid=**********&idx=1&sn=*********";//点击图文消息跳转链接
String PicUrl = "http://*********/img/1.jpg";//图片地址
//拼接json包
String jsonstr = "{\"touser\":\""
+ FromUserName
+ "\",\"msgtype\":\"news\",\"news\":{\"articles\":[{\"title\":\""+ title + "\",\"description\":\""+ Description
+ "\",\"url\":\""+ Url+ "\",\"picurl\":\""+ PicUrl+"\"}]}";
//发送post请求
httpDownloader.uploadjson(urlStr, jsonstr);
}