猿问

springmvc 如何配置微信公众号服务器controller。

调用接口发送消息成功,那服务器配置肯定是对的,但是收不到微信推送的消息,比如关注事件。


    @RequestMapping(value = "/", method = {RequestMethod.GET})

    public String wx(@RequestParam String signature, @RequestParam String timestamp, @RequestParam String nonce, String echostr, HttpServletRequest request, HttpServletResponse response) {

        if (!wxMpService.checkSignature(timestamp, nonce, signature)) {

            LOGGER.info("非法请求, signature:{}", signature);

            return "非法请求";

        }


        if (StringUtils.isNotBlank(echostr)) {

            LOGGER.info("验证:{}", echostr);

            return echostr;

        }


        LOGGER.info("wx:", JSON.toJSONString(request));

        return null;

    }


    @RequestMapping(value = "/", method = {RequestMethod.POST})

    public String service( HttpServletRequest request, HttpServletResponse response) throws Exception {

        LOGGER.info("service, request: {},", JSON.toJSONString(request));


        WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(request.getInputStream());

        WxMpXmlOutMessage outMessage = wxMpMessageRouter.route(inMessage);

        if(outMessage == null) {

            LOGGER.info("outMessage is null");

            return "";

        }

        return outMessage.toXml();

    }

    


get请求验证配置是通过的,post请求接不到数据,求问题所在,谢谢了


BIG阳
浏览 629回答 5
5回答

交互式爱情

很明显 你指定了 method = {RequestMethod.GET}

杨魅力

produces:指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;

慕斯王

谢谢大家回答了,问题已经解决了,是因为项目里使用了security,CROS受限,请求被挡住了,写法什么的没问题
随时随地看视频慕课网APP

相关分类

Java
我要回答