>  Q&A  >  본문

java - 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请求接不到数据,求问题所在,谢谢了

迷茫迷茫2715일 전909

모든 응답(5)나는 대답할 것이다

  • 迷茫

    迷茫2017-04-17 17:55:06

    분명히 메소드를 지정하셨습니다 = {RequestMethod.GET}

    회신하다
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:55:06

    produces: 반환할 콘텐츠 유형을 지정합니다. request 요청 헤더의 (수락) 유형에 지정된 유형이 포함된 경우에만 반환됩니다.

    회신하다
    0
  • 迷茫

    迷茫2017-04-17 17:55:06

    request.getInputStream의 효과를 시도하지 않았습니다. 제가 쓴 내용은 다음과 같습니다.

    으아아아

    방금 검색해 봤습니다. spring-mvc가 이미 사용하고 있기 때문에 inputStream을 사용할 수 없습니다.
    참조 http://hw1287789687.iteeye.com/blog/2199295

    회신하다
    0
  • 迷茫

    迷茫2017-04-17 17:55:06

    답변 감사드립니다. security가 프로젝트에 사용이 제한되어 있어 글 작성에는 문제가 없습니다.

    회신하다
    0
  • 迷茫

    迷茫2017-04-17 17:55:06

    안녕하세요, 저도 같은 문제를 겪었습니다. 구체적인 검색 아이디어는 무엇인가요? 보안을 설정하지 않았는데 요청을 받을 수 없을 경우 어디서부터 해결해야 하나요? 내 이메일: jtmjx@163.com, QQ: 253552550, 제 이름을 알려주세요. 감사합니다.

    회신하다
    0
  • 취소회신하다