<xml> <ToUserName>owW7Ns7iz7KxhMdywxkHKkviuw0E</ToUserName> <FromUserName>gh_d44f5b13d5ab</FromUserName> <CreateTime>1432878361740</CreateTime> <MsgType>test</MsgType> <Content>您发送的消息是hg</Content> </xml>
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
PrintWriter out = resp.getWriter();
try {
Map<String,String> map = MassageUtil.xmlToMap(req);
String fromUserName = map.get("ToUserName");
String toUserName = map.get("FromUserName");
String createTime = map.get("CreateTime");
String msgType = map.get("MsgType");
String content = map.get("Content");
String msgId = map.get("MsgId");
String message =null;
if("text".equals(msgType)){
Textmessage text = new Textmessage();
text.setFromUserName(fromUserName);
text.setToUserName(toUserName);
text.setMsgType("test");
text.setCreateTime(new Date().getTime());
//text.setMsgId(msgId);
text.setContent("您发送的消息是"+content);
message = MassageUtil.textMessageToXml(text);
}
System.out.println(message);
out.print(message);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
out.close();
}
}我也不知道什么原因,文本,图文都可以,图片和音乐就不行
textMessage.setFromUserName(toUserName); textMessage.setToUserName(fromUserName);
仔细看,我是这样改好的
楼上说的对啊,
text.setFromUserName(fromUserName);
text.setToUserName(toUserName);
from 和 to 调一下位子
http://testweb.tunnel.mobi/Weixin/wx.do
返回结果:
200 OK
Date: Fri, 29 May 2015 05:55:09 GMT
Server: Apache-Coyote/1.1
Content-Length: 228
<xml> <ToUserName>gh_d44f5b13d5ab</ToUserName> <FromUserName>owW7Ns7iz7KxhMdywxkHKkviuw0E</FromUserName> <CreateTime>1432878909063</CreateTime> <MsgType>test</MsgType> <Content>您发送的消息是808</Content> </xml>
提示:
请求成功
调试都是成功了的