微信被动回复用户消息-文本消息-填坑
一个大坑
private void replyTextMessage(Scan scan, HttpServletResponse response) { String reply = getReplyByInput(scan.getContent()); StringBuffer str = new StringBuffer(); str.append("<xml>"); str.append("<ToUserName><![CDATA[" + scan.getFromUserName() + "]]></ToUserName>"); str.append("<FromUserName><![CDATA[" + scan.getToUserName() + "]]></FromUserName>"); str.append("<CreateTime>" + Calendar.getInstance().getTimeInMillis() / 1000 + "</CreateTime>"); str.append("<MsgType><![CDATA[text]]></MsgType>"); str.append("<Content><![CDATA[" + reply + "]]></Content>"); str.append("</xml>"); System.out.println(str.toString()); try { //response.getWriter().write(str.toString()); // 响应消息 PrintWriter out = response.getWriter(); out.print(str.toString()); out.flush(); out.close(); // 这里是个大坑 } catch (IOException e) { e.printStackTrace(); } }