微信公众号 Token校验失败 基于spring-boot

最开始是这么写:

@GetMapping(produces = "text/plain;charset=utf-8")

  public String authGet(

      @RequestParam(name = "signature",  required = false) String signature,

      @RequestParam(name = "timestamp", required = false) String timestamp,

      @RequestParam(name = "nonce", required = false) String nonce,

      @RequestParam(name = "echostr", required = false) String echostr) {


    this.logger.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature, timestamp, nonce, echostr);

    if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
      throw new IllegalArgumentException("请求参数非法,请核实!");
    }

    if (this.wxService.checkSignature(timestamp, nonce, signature)) {
      return echostr;
    }
    return "非法请求";
  }

怎么也通不过,于是这么写:

@GetMapping(produces = "text/plain;charset=UTF-8")
public void authGet(
    @RequestParam(name = "signature",
        required = false) String signature,
    @RequestParam(name = "timestamp",
        required = false) String timestamp,
    @RequestParam(name = "nonce", required = false) String nonce,
    @RequestParam(name = "echostr", required = false) String echostr,HttpServletResponse response ) throws IOException {
   

  this.logger.info("\n接收到来自微信服务器的认证消息:[{}, {}, {}, {}]", signature,
      timestamp, nonce, echostr);

  if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
    throw new IllegalArgumentException("请求参数非法,请核实!");
  }

  if (this.wxService.checkSignature(timestamp, nonce, signature)) {
    //------------------------------
    //处理业务完毕
    //------------------------------
    BufferedOutputStream out = new BufferedOutputStream(
            response.getOutputStream());
    out.write(echostr.getBytes());
    out.flush();
    out.close();
  } else {
    logger.info("非法请求");
  }

}

通过了,应该是框架的问题,用return echostr; 输出和BufferedOutStream输出是不一样的。

fuck!!!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值