日期:2014-05-20  浏览次数:21052 次

java实现微信公众平台推送图文消息
目前程序已经实现了模拟登陆微信公众平台,和文本消息的发送。
但是不知道那种有图又有文字和连接的消息怎么发送,望大神们指点指点。
下面是我发送文本消息的一段代码。希望文图消息的风格和这个差不多,不然怎么程序变动太大就不好了。
/**
 *  发送消息
 */
public static void sendMsg(Map<String, String> cookie, String content,
String fakeId) throws IOException {

HashMap<String, String> map = new HashMap<String, String>();
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+"&lang=zh_CN";
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,回复有支持既有文本和图片一起发送的:

 <xml>
 <ToUserName><![CDATA[toUser]]></ToUserName>
 <FromUserName><![CDATA[fromUser]]></FromUserName>
 <CreateTime>12345678</CreateTime>
 <MsgType><![CDATA[news]]></MsgType>
 <ArticleCount>2</ArticleCount>
 <Articles>
 <item>
 <Title><![CDATA[title1]]></Title> 
 <Description><![CDATA[description1]]></Description>
 <PicUrl><![CDATA[picurl]]></PicUrl>
 <Url><![CDATA[url]]></Url>
 </item>
 <item>
 <Title><![CDATA[title]]></Title>
 <Description><![CDATA[description]]></Description>
 <PicUrl><![CDATA[picurl]]></PicUrl>
 <Url><![CDATA[url]]></Url>
 </item>
 </Articles>
 <FuncFlag>1</FuncFlag>
 </xml> 


参数  描述
ToUserName  接收方帐号(收到的OpenID)
FromUserName  开发者微信号
CreateTime  消息创建时间
MsgType  news
ArticleCount  图文消息个数,限制为10条以内
Articles  多条图文消息信息,默认第一个item为大图
Title  图文消息标题
Description  图文消息描述
PicUrl  图片链接,支持JPG、PNG格式,较好的效果为大图640*320,小图80*80,限制图片链接的域名需要与开发者填写的基本资料中的Url一致
Url  点击图文消息跳转链接