日期:2014-05-20 浏览次数:21076 次
/**
* 发送消息
*/
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());
}
<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>