There are two ways
The first
the easiest:
When you click submit, the WeChat official account will send a get request to your url,
There is an echostr parameter in it, just return it directly,
The second type:
It is based on the signature sent by WeChat, and then you encrypt the data, compare the data, and then return the echostr
directly on the code
@RequestMapping("/wx")
@ResponseBody
public String wxGZHGetMsg(HttpServletRequest request){
// 获取随机数
String echostr = request.getParameter("echostr");
// 加密签名
String signature = request.getParameter("signature");
//随机数
String nonce = request.getParameter("nonce");
//时间戳
String timestamp = request.getParameter("timestamp");
// 自己在微信开发那里设置的
String token ="aaa";
List<String> list = new ArrayList<>();
list.add(token);
list.add(timestamp);
list.add(nonce);
Collections.sort(list);
String join = String.join("", list);
String s = DigestUtils.sha1DigestAsHex(join);
System.out.println(s);
System.out.println(signature);
return request.getParameter("echostr");
}