/**
* 用于验证微信服务器发来的get请求,进行签名验证
* https://33186bde.r1.cpolar.top/wx/portal/wxe136919795d575a1
*
* @param appid 这个是通过微信服务器访问的url路径上的appId进行获取,
* @param signature 微信加密签名
* @param timestamp 时间戳
* @param nonce 随机数
* @param echostr 随机字符串,这个验证成功返回即可
* @return echostr 随机字符串,这个验证成功返回即可
* @description @GetMapping(produces = "text/plain; charset=UTF-8")这个意思是返回一个用于指定请求处理方法返回的响应内容类型和字符编码
*/
@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 {
//首先先进行判断参数是否为null
log.info("微信公众号验签信息{}开始 [{}, {}, {}, {}]", appid, signature, timestamp, nonce, echostr);
if (StrUtil.isAllBlank(signature, timestamp, nonce, echostr)) {
log.error("微信验证签名参数非法为空");
}
System.out.println(echostr);
return echostr;
} catch (Exception e) {
log.error("微信验证签名异常{} [{}{}{}{}]", appid, signature, timestamp, nonce, echostr);
return null;
}