收藏
回答

微信服务器向公众号推送消息或事件后,得到的回应不合法?返回格式都是正确的

想请问一下这个返回哪里不合法了 格式都是正确的

用的是binarywang的返回message


@PostMapping(produces = "application/xml; charset=UTF-8")
public String post(
        @RequestBody String requestBody,
        @RequestParam("signature") String signature,
        @RequestParam("timestamp") String timestamp,
        @RequestParam("nonce") String nonce,
        @RequestParam("openid") String openid,
        @RequestParam(name = "encrypt_type", required = false) String encType,
        @RequestParam(name = "msg_signature", required = false) String msgSignature, HttpServletResponse response) {
    String appid = "";

    log.info("\n接收微信请求:[openid=[{}], [signature=[{}], encType=[{}], msgSignature=[{}],"
                    + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
            openid, signature, encType, msgSignature, timestamp, nonce, requestBody);

    if (!wxService.checkSignature(timestamp, nonce, signature)) {
        throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
    }

    String out = null;
    if (encType == null) {
        // 明文传输的消息
        WxMpXmlMessage inMessage = WxMpXmlMessage.fromXml(requestBody);
        WxMpXmlOutMessage outMessage = this.route(inMessage);
        if (outMessage == null) {
            return "";
        }

        out = outMessage.toXml();
    } else if ("aes".equalsIgnoreCase(encType)) {
        // aes加密的消息
        WxMpXmlMessage inMessage = WxMpXmlMessage.fromEncryptedXml(requestBody, wxService.getWxMpConfigStorage(),
                timestamp, nonce, msgSignature);
        log.debug("\n消息解密后内容为:\n{} ", inMessage.toString());
        WxMpXmlOutMessage outMessage = this.route(inMessage);
        if (outMessage == null) {
            return "";
        }

        out = outMessage.toEncryptedXml(wxService.getWxMpConfigStorage());
    }

    log.debug("\n组装回复信息:{}", out);
    response.setContentType(ContentType.XML.getValue());
    return out;
}
回答关注问题邀请回答
收藏

2 个回答

  • showms
    showms
    02-11

    带上这两个参数试试

    02-11
    有用 1
    回复 1
    • 松丶
      松丶
      02-11
      感谢,是缺少了这2个参数,看的网上的框架demo,看官网文档时不够仔细,下次一定注意
      02-11
      回复
  • 风清雾散云开见日出
    风清雾散云开见日出
    02-11

    xml的前面2个参数去哪儿了

    02-11
    有用 1
    回复 1
    • 松丶
      松丶
      02-11
      感谢,是缺少了这2个参数,看的网上的框架demo,看官网文档时不够仔细,下次一定注意
      02-11
      回复
登录 后发表内容