zoukankan      html  css  js  c++  java
  • SpringMVC 用http请求的Get和Post请求作为路由的方法的重载方式

    @Controller
    @RequestMapping("/messageProcessing")
    public class WechatPushController {
        
        @Autowired
        private WechatPushService wechatPushService;
        
        @Autowired
        private WechatOAuthService wechatOAuthService;
        
        @Autowired
        private WechatUserService wechatUserService;
        
        
        /**
         * 确认请求来自微信服务器
         */
        @RequestMapping(value="/doGet",method=RequestMethod.GET)
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            // 微信加密签名  
            String signature = request.getParameter("signature");  
            // 时间戳  
            String timestamp = request.getParameter("timestamp");  
            // 随机数  
            String nonce = request.getParameter("nonce");  
            // 随机字符串  
            String echostr = request.getParameter("echostr");  
      
            PrintWriter out = response.getWriter();  
            // 通过检验signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败  
            if (WechatSignUtil.checkSignature(signature, timestamp, nonce)) {  
                out.print(echostr);  
            }  
            out.close();  
            out = null;  
        }
    
        /**
         * 处理微信服务器发来的消息
         */
        @RequestMapping(value="/doGet",method=RequestMethod.POST)
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            // 将请求、响应的编码均设置为UTF-8(防止中文乱码)
            request.setCharacterEncoding("UTF-8");
            response.setCharacterEncoding("UTF-8");
    
            // 调用核心业务类接收消息、处理消息
            String respMessage = wechatPushService.processRequest(request);
    
            // 响应消息
            PrintWriter out = response.getWriter();
            out.print(respMessage);
            out.close();
        }
  • 相关阅读:
    高斯消元学习
    HDU 4596 Yet another end of the world(解一阶不定方程)
    Codeforces Round #318 div2
    HDU 4463 Outlets(一条边固定的最小生成树)
    HDU 4458 Shoot the Airplane(计算几何 判断点是否在n边形内)
    HDU 4112 Break the Chocolate(简单的数学推导)
    HDU 4111 Alice and Bob (博弈)
    POJ 2481 Cows(线段树单点更新)
    HDU 4288 Coder(STL水过)
    zoj 2563 Long Dominoes
  • 原文地址:https://www.cnblogs.com/weixiaole/p/5684490.html
Copyright © 2011-2022 走看看