这是我写的回调函数,也触发了,但是从有错误提示。echostr参数不存在
21:45:54.609 [http-nio-9001-exec-1] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2
1:45:54.673 [http-nio-9001-exec-1] ERROR c.d.f.w.e.GlobalExceptionHandler - [handleException,80] - 请求地址'/changde/wechat',发生系统异常.
org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'echostr' for method parameter type String is not present
代码
@RequestMapping(value = "/wechat", method = {RequestMethod.GET, RequestMethod.POST})
@ResponseBody
public String verifyWeChatServer(
@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) {
if (signature != null && timestamp != null && nonce != null && echostr != null) {
System.out.println("接收到的参数:signature=" + signature +
", timestamp=" + timestamp +
", nonce=" + nonce +
", echostr=" + echostr);
if (checkSignature(signature, timestamp, nonce)) {
System.out.println("签名验证成功,返回echostr:" + echostr);
return echostr;
} else {
System.err.println("签名验证失败!");
return "Invalid signature";
}
} else {
System.out.println("非微信服务器验证请求或缺少必要参数,暂不处理");
return "Non-verification request or missing parameters";
}
}
没看懂,网页授权跟echostr有啥关系。提问问题,可别害羞内向不说话啊