企业微信配置位置 应用管理》需要回调的应用》API》接收事件服务器设置
我这里配置的回调应用是审批
保存这两个参数 Token、EncodingAESKey,还需要企业ID(位置:我的企业》企业信息》企业ID)
下载企业微信加解密库,注意事项 注意事项 注意事项
https://open.work.weixin.qq.com/api/doc/90000/90138/90307
接口 feedbackFromWx 两个请求类型Get Post具体为啥要两个看官方文档解释,主要是post接受数据我这里接收的是流程审批数据
我需要的就四个值看你们的业务需求
AgentID 应用ID
TemplateId 模版ID
SpNo 流程编号
SpStatus 流程状态
@GetMapping("/feedbackFromWx")
public String feedbackFromWxVerifyURL(String msg_signature, String timestamp, String nonce, String echostr) throws AesException {
log.info("-------feedbackFromWx ------ msg_signature:{}, Long timestamp:{}, String nonce:{}, String echostr:{}",
msg_signature, timestamp, nonce, echostr);
String sToken = "QDG6eK";
String sEncodingAESKey = "jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C";
String sCorpID = "wx5823bf96d3bd56c7";
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID);
String sMsg = wxcpt.VerifyURL(msg_signature, timestamp, nonce, echostr);
log.info("sMsg:{}", sMsg);
return sMsg;
}
@PostMapping("/feedbackFromWx")
public BaseResponse<Date> feedbackFromWxData(String msg_signature, String timestamp, String nonce, @RequestBody String data)
throws AesException, ParserConfigurationException, IOException, SAXException {
log.info("-------feedbackFromWx ------ msg_signature:{}, Long timestamp:{}, String nonce:{}, String data:{}",
msg_signature, timestamp, nonce, data);
String sToken = "QDG6eK";
String sEncodingAESKey = "jWmYm7qr5nMoAUwZRjGtBxmz3KA1tkAj3ykkR6q2B2C";
String sCorpID = "wx5823bf96d3bd56c7";
WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID);
String sMsg = wxcpt.DecryptMsg(msg_signature, timestamp, nonce, data);
log.info("sMsg:{}", sMsg);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
StringReader sr = new StringReader(sMsg);
InputSource is = new InputSource(sr);
Document document = db.parse(is);
Element root = document.getDocumentElement();
log.info("AgentID:{}",root.getElementsByTagName("AgentID").item(0).getTextContent());
log.info("SpNo:{}",root.getElementsByTagName("SpNo").item(0).getTextContent());
log.info("SpStatus:{}",root.getElementsByTagName("SpStatus").item(0).getTextContent());
log.info("TemplateId:{}",root.getElementsByTagName("TemplateId").item(0).getTextContent());
return BaseResponse.successInstance(sMsg);
}
测试一下