介绍
企业微信,私有化企业微信接口 spring-boot-starter
使用说明
-
maven
<dependency> <groupId>org.zhuang.hui.jian</groupId> <artifactId>qywx-spring-boot-starter</artifactId> <version>1.0.0</version> </dependency>
-
application.yml
# 企业微信配置 wechat: cp: corpId: wwa1efd****** baseApiUrl: https://ip appConfigs: - agentId: 1 secret: *********** token: 1 aesKey: 1
3.业务模块
IBaseQywxService提供获取调用企业微信所有api的能力
@Autowired private IBaseQywxService baseQywxService;
接收事件
在方法上使用@EventListtener注解,condition指定需要监听的事件,classes=WxCpXmlMessageEvent.class
如下代码示例是:监控上报地理位置事件
@Component @Slf4j public class GenericEventListener { /** * 接收上报地理位置事件 * @param event */ @EventListener(classes = WxCpXmlMessageEvent.class,condition = "#root.args[0].msgType.equalsIgnoreCase('event') && #root.args[0].event.equalsIgnoreCase('LOCATION')") public void locationEevnt2(GenericEvent<WxCpXmlMessage> event){ log.info("======2"+event.getData().toString()); } @EventListener(classes = WxCpXmlMessageEvent.class,condition = "#root.args[0].msgType.equalsIgnoreCase('event') && #root.args[0].event.equalsIgnoreCase('LOCATION')") public void locationEevnt1(GenericEvent<WxCpXmlMessage> event){ log.info("======1"+event.getData().toString()); } }
文件安全检测
定义一个类,实现监听事件,获取企业微信推送过来的数据,进行业务处理,最后调用【异步上传检测结果】接口返回检测结果
@Component public class TestListener { /** * 不能写死,通过构造器等其他方式传入 */ private String agentName="test"; @Autowired private IFileSecurityService fileSecurityService; @EventListener(classes = FileSecurityEvent.class,condition = "#root.args[0].msgType.equalsIgnoreCase('event') && #root.args[0].event.equalsIgnoreCase('fileSecurity')") public void test(GenericEvent<FileSecurityVo> event) throws Exception { // 下载文件 File file = fileSecurityService.getFile(agentName, event.getData().getFileInfo()); // todo 对file对象,进行安全性检测,检测结果,通过fileCheckResult方法返回给企业微信 // 对文件进行检测后,对文件有无问题,可以回复信息给企业微信 FileCheckResultVo fileCheckResultVo = new FileCheckResultVo(); fileCheckResultVo.setCheckId(event.getData().getCheckId()); fileCheckResultVo.setResult(new FileCheckResultVo.Result(1,"检测通过")); fileSecurityService.fileCheckResult(agentName,fileCheckResultVo); // 流程结束 } }
回调地址:/qywx/filesecurity/{agentName}
在线预览文档接入
1.配置在线预览服务器地址:/qywx/onlinepreview/{agentName}
2.在resource\templates文件夹下创建onlinePreview.html文件,文件内容如下
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <title th:text="${fileName}"></title> <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> </head> <body> <div th:utext="${data}"></div> </body> </html>
集成已有帐号体系
1.http回调登录
接口地址:/http/callback/login/{agentName}
2.h5登录(第三方登录)
接口地址:/th3h5/callback/{agentName}
会话存档
配置信息
1.sdk文件(绝对路径)linux和window环境,多个文件逗号分开
msgAuditLibPath=/www/osfile/libcrypto-1_1-x64.dll,libssl-1_1-x64.dll,libcurl-x64.dll,WeWorkFinanceSdk.dll,libWeWorkFinanceSdk_Java.so
2.私钥文件路径msgAuditPriKeyPath或者私钥字符串msgAuditPriKeyData
3.接口类:org.zhuang.hui.jian.sessioncontentarchiving.service.ISessionContentArchivingService
项目地址:qywx-spring-boot-starter: 企业微信,私有化企业微信接口 spring-boot-starter