1. 配置ip白名单
用来获取access_token接口调用
开发->基本配置->IP白名单
- 配置服务器Ip
2. 配置消息推送
配置响应微信服务器消息
开发->基本配置->服务器配置->修改配置
URL:服务器接口地址
Token:自己填
EncodingAESKey: 随机生成
需要后台进行token验证
@ResponseBody
@GetMapping(value = "/dealwith/event")
public Object getToken(HttpServletRequest request, HttpServletResponse response) {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
System.out.println("收到微信参数:" + signature + "," + timestamp + "," + nonce + "," + echostr);
DdSysInfo sysInfo = ddSysInfoService.getSysSettingInfo().getData();
if (sysInfo == null || signature == null || timestamp == null || nonce == null || echostr == null) {
return null;
}
String token = sysInfo.getToken();
System.out.println("token:" + token);
String[] arr = {token, timestamp, nonce};
if (arr == null) {
return null;
}
Arrays.sort(arr);
//比较数据字典与验证信息是否正确
boolean flag = ddSysInfoService.checkSign(arr, signature);
System.out.println("check flag:" + flag);
if (flag == false) {
return null;
}
if (echostr != null) {
PrintWriter out;
try {
out = response.getWriter();
if (flag == true) {
out.print(echostr);
System.out.println("println:" + echostr);
}
out.flush();
out.close();
out = null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
3. 配置网页授权域名和业务域名等
配置域名之后才能正常进行访问微信的功能,网页授权,小程序中业务域名下的h5页面显示
设置->公众号设置->功能设置
此配置需要将下载文件
下载之后,配置在服务器的根目录,正常情况下www.xxx.com/MP_verify_XF2DQ5lcomORLnQJ.txt
可以访问到此文件就可以保存成功了