效果
1、申请智谱AI
登录官网,添加ApiKey即可
代码
@GetMapping(produces = "text/plain;charset=utf-8")
public String validate(@PathVariable String appid,
@RequestParam(value = "signature", required = false) String signature,
@RequestParam(value = "timestamp", required = false) String timestamp,
@RequestParam(value = "nonce", required = false) String nonce,
@RequestParam(value = "echostr", required = false) String echostr) {
try {
logger.info("微信公众号验签信息{}开始 {}, {}, {}, {}", appid, signature, timestamp, nonce, echostr);
if (StringUtils.isAnyBlank(signature, timestamp, nonce, echostr)) {
throw new IllegalArgumentException("请求参数非法!");
}
boolean check = weiXinValidateService.checkSign(signature, timestamp, nonce);
logger.info("微信公众号验签信息{}完成", appid);
if (!check) {
return null;
}
return echostr;
} catch (Exception e) {
logger.error("微信公众号验签信息{}失败 [{}, {}, {}, {}]", appid, signature, timestamp, nonce, echostr, e);
return null;
}
}