本文實(shí)例講述了Java編程調(diào)用微信接口實(shí)現(xiàn)圖文信息等推送功能。分享給大家供大家參考,具體如下:
靖江網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,靖江網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為靖江超過千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站建設(shè)公司要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的靖江做網(wǎng)站的公司定做!Java調(diào)用微信接口工具類,包含素材上傳、獲取素材列表、上傳圖文消息內(nèi)的圖片獲取URL、圖文信息推送。
微信圖文信息推送因注意html代碼字符串中將雙引號(hào)(")替換成單引號(hào)('),不然信息頁面中包含圖片將無法顯示且圖片后面的內(nèi)容也不會(huì)顯示
官方文檔: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("http://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("]}");