Validation.txt protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubString signature = req.getParameter("signature");String timestamp = req.getParamete
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub String signature = req.getParameter("signature"); String timestamp = req.getParameter("timestamp"); String nonce = req.getParameter("nonce"); String echostr = req.getParameter("echostr"); System.out.println("验证签名"+signature); System.out.println("时间戳"+timestamp); System.out.println("随机数"+nonce); System.out.println("随机字符串"+echostr); //输出流 PrintWriter out = resp.getWriter(); if(ValidationTools.checkSignature(signature, timestamp, nonce)) { out.print(echostr);// } out.close(); out=null; } protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // TODO Auto-generated method stub req.setCharacterEncoding("utf-8"); resp.setContentType("text/xml;charset=utf-8"); resp.setCharacterEncoding("utf-8"); PrintWriter out=resp.getWriter(); try { Mapmap = MessageUtil.xmlToMap(req); String toUserName = map.get("ToUserName"); String fromUserName = map.get("FromUserName"); String msgType = map.get("MsgType"); String content = map.get("Content"); String createtime=map.get("CreateTime"); String message = null ; if("text".equals(msgType)) { TextMessage text = new TextMessage(); text.setToUserName(fromUserName); text.setFromUserName(toUserName); text.setCreateTime(new Date().getTime()); text.setMsgType("text"); text.setConetent(""+content); message = MessageUtil.textMessageToXML(text); } System.out.println(message); out.print(message);//将返回的信息放在输出流里面 }catch(DocumentException e) { e.printStackTrace(); } finally{ out.close(); }