protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
String time;
Date date=new Date();
time=String.valueOf(date.getTime());
PrintWriter out=response.getWriter();
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
try {
Map<String,String> map= MessageUtil.xmlToMap(request);
String fromUserName=map.get("FromUserName");
String toUserName=map.get("ToUserName");
String msgType=map.get("MsgType");
String content=map.get("Content");
String message=null;
if ("text".equals(msgType)){
TextMessage text=new TextMessage();
text.setFromUserNmae(toUserName);
text.setToUserName(fromUserName);
text.setMsgType("text");
text.setCreateTime(time);
text.setContent("您发送的消息是:"+content);
message=MessageUtil.textMessageToXml(text);
System.out.print(message+"\n\n\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
}
}catch (DocumentException e){
e.printStackTrace();
}finally {
out.close();
}
}控制台返回的消息<xml>
<ToUserName>oNOiOwNQHWc-bAzTfXq0k2GIbntU</ToUserName>
<FromUserNmae>gh_f2e1eb1abb3a</FromUserNmae>
<CreateTime>1522719221085</CreateTime>
<MsgType>text</MsgType>
<Content>您发送的消息是:啊啊啊</Content>
</xml>
添加回答
举报
0/150
提交
取消