天天看點

java微信公衆号開發推送,java實作微信公衆平台推送圖文消息解決方法

java實作微信公衆平台推送圖文消息

目前程式已經實作了模拟登陸微信公衆平台,和文本消息的發送。

但是不知道那種有圖又有文字和連接配接的消息怎麼發送,望大神們指點指點。

下面是我發送文本消息的一段代碼。希望文圖消息的風格和這個差不多,不然怎麼程式變動太大就不好了。

public static void sendMsg(Map cookie, String content,

String fakeId) throws IOException {

HashMap map = new HashMap();

map.put("tofakeid", fakeId);

map.put("content", content);

map.put("error", "false");

map.put("token", TOKEN);

map.put("type", "1");

map.put("ajax", "1");

String referrerUrl = "https://mp.weixin.qq.com/cgi-bin/singlesendpage?t=message/send&action=index&tofakeid="+fakeId+"&token="+TOKEN+"&;

Document document = Jsoup.connect(SEND_MSG).header(USER_AGENT_H, USER_AGENT).header(REFERER_H, INDEX_URL2).referrer(referrerUrl).data(map).cookies(cookie)

.post();

Element body = document.body();

document.hashCode();

document.hasText();

System.out.println(body.text());

}

------解決方案--------------------

http://blog.csdn.net/lyq8479/article/details/9393195

這個人的blog寫得不錯

------解決方案--------------------

那種有圖又有文字和連接配接的消息怎麼發送

================

看看API,回複有支援既有文本和圖檔一起發送的:

12345678

2

1

參數 描述

ToUserName 接收方帳号(收到的OpenID)

FromUserName 開發者微信号

CreateTime 消息建立時間

MsgType news

ArticleCount 圖文消息個數,限制為10條以内

Articles 多條圖文消息資訊,預設第一個item為大圖

Title 圖文消息标題

Description 圖文消息描述

PicUrl 圖檔連結,支援JPG、PNG格式,較好的效果為大圖640*320,小圖80*80,限制圖檔連結的域名需要與開發者填寫的基本資料中的Url一緻

Url 點選圖文消息跳轉連結