最开始是这么写:
@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!!!