猿问

该公众号提供的服务出现故障,请稍后再试

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>


qq_光年一夏_0
浏览 2531回答 0
0回答
随时随地看视频慕课网APP

相关分类

Java
我要回答