/** * 功能:微信首页 * * @throws Exception */ @RequestMapping(value = "/wechat/home") public void home(Signer signer, HttpServletRequest request, HttpServletResponse response) throws Exception { // 防止中文乱码 request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); // 随机字符串 String echostr = signer.getEchostr(); // 初始化用于判断微信请求方法GET/POST String method = request.getMethod(); PrintWriter out = null; try { out = response.getWriter(); if (SignUtil.checkSignature(signer)) { if ("GET".equals(method)) { out.print(echostr); } else { // 调用核心服务类接收处理请求 String respXml = wechatService.processRequest(request); out.print(respXml); } } } catch (Exception e) { e.printStackTrace(); } finally { out.close(); out = null; } }