Java编程调用微信接口实现图文信息推送功能-创新互联
本文实例讲述了Java编程调用微信接口实现图文信息等推送功能。分享给大家供大家参考,具体如下:

Java调用微信接口工具类,包含素材上传、获取素材列表、上传图文消息内的图片获取URL、图文信息推送。
微信图文信息推送因注意html代码字符串中将双引号(")替换成单引号('),不然信息页面中包含图片将无法显示且图片后面的内容也不会显示
官方文档:http://mp.weixin.qq.com/wiki/home/
StringBuilder sb=new StringBuilder();
sb.append("{\"articles\":[");
boolean t=false;
for(MicroWechatInfo info:list){
if(t)sb.append(",");
Pattern p = Pattern.compile("src\\s*=\\s*'(.*?)'",Pattern.CASE_INSENSITIVE);
String content = info.getMicrowechatcontent().replace("\"", "'");
Matcher m = p.matcher(content);
while (m.find()) {
String[] str = m.group().split("'");
if(str.length>1){
try {
if(!str[1].contains("//mmbiz.")){
content = content.replace(str[1], uploadImg(UrlToFile(str[1]),getAccessToken(wx.getAppid(), wx.getAppkey())).getString("url"));
}
} catch (Exception e) {
}
}
}
sb.append("{\"thumb_media_id\":\""+uploadMedia(new File(info.getMicrowechatcover()), getAccessToken(wx.getAppid(), wx.getAppkey()), "image").get("media_id")+"\"," +
"\"author\":\""+info.getMicrowechatauthor()+"\"," +
"\"title\":\""+info.getMicrowechattitle()+"\"," +
"\"content_source_url\":\""+info.getOriginallink()+"\"," +
"\"digest\":\""+info.getMicrowechatabstract()+"\"," +
"\"show_cover_pic\":\""+info.getShowcover()+"\"," +
"\"content\":\""+content+"\"}");
t=true;
}
sb.append("]}");
网站标题:Java编程调用微信接口实现图文信息推送功能-创新互联
浏览地址:http://www.jxjierui.cn/article/dsecdc.html


咨询
建站咨询
