1. Click on the avatar in the upper left corner to open the WeChat management platform
2. Create an application
3. Get five parameters
3.1 Get the AgentId and Secret of the application
3.2 Get enterprise ID
There are too many restrictions on configuring the receiving message server URL
for WeChat Enterprise, and the company domain name ownership check fails. Use the method of receiving the URL of the message server.
3.3 Get token, EncodingAESKey
4.1 Intranet penetration, local development
First send the request to the public network server ngnix, and then forward it to the internal network penetration address to request the Java backend.
Free intranet penetration
for one minute to get started quickly
4.2 Enterprise WeChat related
Enterprise WeChat encryption and decryption documents
Enterprise WeChat encryption and decryption official code
4.3 IDEA introduces jar packages that depend on official code
4.4 Paste the official code into the project
4.5 bug: Error:(1, 1) java: Illegal character: '\ufeff'
Using vscode, change the UTF-8 BOM text encoding to UTF-8
to write code reference articles
4.6 Writing code
//token
public final static String TOKEN = "n5SHOwoXKo9UTQg2zv3Vs2B";
// encodingAESKey
public final static String ENCODINGAES_KEY = "wVdvdhBY6EDWG96S7EjU6hg9BR3v7M5SS9a4jK";
//企业ID
public final static String CORP_ID = "wwec27f62ca8";
//应用的凭证密钥
public final static String CORPSECRET = "PdDcN-ZjInXNsvNuzlPl55qZrLLVJvDvcIp3wZNt";
@GetMapping("/wei")
public void list(HttpServletRequest request, HttpServletResponse response) throws IOException {
// 微信加密签名
String msg_signature = request.getParameter("msg_signature");
// 时间戳
String timestamp = request.getParameter("timestamp");
// 随机数
String nonce = request.getParameter("nonce");
// 随机字符串
String echostr = request.getParameter("echostr");
System.out.println("request=" + request.getRequestURL());
PrintWriter out = response.getWriter();
// 通过检验msg_signature对请求进行校验,若校验成功则原样返回echostr,表示接入成功,否则接入失败
String result = null;
try {
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(TOKEN, ENCODINGAES_KEY, CORP_ID);
result = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr);
} catch (AesException e) {
e.printStackTrace();
}
if (result == null) {
result = TOKEN;
}
out.print(result);
out.close();
out = null;
}
successfully set