1.點(diǎn)擊左上角頭像,打開微信管理平臺
2.創(chuàng)建應(yīng)用
3.獲取五個參數(shù)
3.1獲取應(yīng)用的AgentId、Secret
3.2獲取企業(yè)ID
配置接收消息服務(wù)器URL
企業(yè)微信限制過多,公司域名所有權(quán)檢驗(yàn)不通過。采用接收消息服務(wù)器URL的方式。
3.3 獲取token、EncodingAESKey
4.1 內(nèi)網(wǎng)穿透、本地開發(fā)
先將請求打到公網(wǎng)服務(wù)器ngnix、再轉(zhuǎn)發(fā)給內(nèi)網(wǎng)穿透地址,請求Java后端。
免費(fèi)的內(nèi)網(wǎng)穿透
一分鐘圖文快速上手
4.2 企業(yè)微信相關(guān)
企業(yè)微信加解密文檔
企業(yè)微信加解密官方代碼
4.3 IDEA 引入依賴官方代碼的jar包
4.4 將官方代碼粘貼進(jìn)項(xiàng)目
4.5 bug: Error:(1, 1) java: 非法字符: ‘\ufeff’
使用vscode,將UTF-8 BOM文本編碼改為UTF-8
編寫代碼參考的文章文章來源:http://www.zghlxwxcb.cn/news/detail-440441.html
4.6 編寫代碼
//token
public final static String TOKEN = "n5SHOwoXKo9UTQg2zv3Vs2B";
// encodingAESKey
public final static String ENCODINGAES_KEY = "wVdvdhBY6EDWG96S7EjU6hg9BR3v7M5SS9a4jK";
//企業(yè)ID
public final static String CORP_ID = "wwec27f62ca8";
//應(yīng)用的憑證密鑰
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");
// 隨機(jī)數(shù)
String nonce = request.getParameter("nonce");
// 隨機(jī)字符串
String echostr = request.getParameter("echostr");
System.out.println("request=" + request.getRequestURL());
PrintWriter out = response.getWriter();
// 通過檢驗(yàn)msg_signature對請求進(jìn)行校驗(yàn),若校驗(yàn)成功則原樣返回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;
}
設(shè)置成功文章來源地址http://www.zghlxwxcb.cn/news/detail-440441.html
到了這里,關(guān)于企業(yè)微信消息推送(一)接收消息服務(wù)器URL的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!