添加验证包和晚上事件回调
This commit is contained in:
parent
248d87f637
commit
5a1a61aa22
11
pom.xml
11
pom.xml
|
@ -251,6 +251,17 @@
|
|||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype-nexus-staging</id>
|
||||
<name>Sonatype Nexus Staging</name>
|
||||
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<pluginRepositories>
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.snow.web.controller.dingtalk;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.dingtalk.oapi.lib.aes.DingTalkEncryptor;
|
||||
import com.snow.dingtalk.common.EventNameEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
@ -13,11 +16,10 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
* @Description:
|
||||
* @date 2020/11/3 17:11
|
||||
*/
|
||||
@RestController
|
||||
@RestController("/dingTalk")
|
||||
@Slf4j
|
||||
public class DingTalkCallBack {
|
||||
|
||||
|
||||
/**
|
||||
* 钉钉回调
|
||||
* @param signature
|
||||
|
@ -36,7 +38,7 @@ public class DingTalkCallBack {
|
|||
String params = "signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " body:" + body;
|
||||
try {
|
||||
log.info("begin callback:" + params);
|
||||
DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor(Constant.TOKEN, Constant.ENCODING_AES_KEY, Constant.SUITE_KEY);
|
||||
DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor("","","");
|
||||
|
||||
// 从post请求的body中获取回调信息的加密数据进行解密处理
|
||||
String encrypt = body.getString("encrypt");
|
||||
|
@ -45,19 +47,16 @@ public class DingTalkCallBack {
|
|||
|
||||
// 根据回调事件类型做不同的业务处理
|
||||
String eventType = callBackContent.getString("EventType");
|
||||
if (EVENT_CHECK_CREATE_SUITE_URL.equals(eventType)) {
|
||||
log.info("验证新创建的回调URL有效性: " + plainText);
|
||||
} else if (EVENT_CHECK_UPADTE_SUITE_URL.equals(eventType)) {
|
||||
|
||||
if (EventNameEnum.org_dept_create.equals(eventType)) {
|
||||
log.info("部门创建回调数据: " + callBackContent);
|
||||
} else if (EventNameEnum.org_dept_modify.equals(eventType)) {
|
||||
log.info("验证更新回调URL有效性: " + plainText);
|
||||
} else if (EVENT_SUITE_TICKET.equals(eventType)) {
|
||||
} else if (EventNameEnum.org_dept_remove.equals(eventType)) {
|
||||
// suite_ticket用于用签名形式生成accessToken(访问钉钉服务端的凭证),需要保存到应用的db。
|
||||
// 钉钉会定期向本callback url推送suite_ticket新值用以提升安全性。
|
||||
// 应用在获取到新的时值时,保存db成功后,返回给钉钉success加密串(如本demo的return)
|
||||
log.info("应用suite_ticket数据推送: " + plainText);
|
||||
} else if (EVENT_TMP_AUTH_CODE.equals(eventType)) {
|
||||
// 本事件应用应该异步进行授权开通企业的初始化,目的是尽最大努力快速返回给钉钉服务端。用以提升企业管理员开通应用体验
|
||||
// 即使本接口没有收到数据或者收到事件后处理初始化失败都可以后续再用户试用应用时从前端获取到corpId并拉取授权企业信息,进而初始化开通及企业。
|
||||
log.info("企业授权开通应用事件: " + plainText);
|
||||
} else {
|
||||
// 其他类型事件处理
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package com.snow.web.controller.system;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.snow.framework.util.ShiroUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -86,6 +88,7 @@ public class DingtalkCallBackController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult addSave(DingtalkCallBack dingtalkCallBack)
|
||||
{
|
||||
dingtalkCallBack.setCreateBy(ShiroUtils.getLoginName());
|
||||
return toAjax(dingtalkCallBackService.insertDingtalkCallBack(dingtalkCallBack));
|
||||
}
|
||||
|
||||
|
@ -109,6 +112,7 @@ public class DingtalkCallBackController extends BaseController
|
|||
@ResponseBody
|
||||
public AjaxResult editSave(DingtalkCallBack dingtalkCallBack)
|
||||
{
|
||||
dingtalkCallBack.setUpdateBy(ShiroUtils.getLoginName());
|
||||
return toAjax(dingtalkCallBackService.updateDingtalkCallBack(dingtalkCallBack));
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
<label class="col-sm-3 control-label">通讯录事件回调:</label>
|
||||
<div class="col-sm-8" th:with="type=${@dict.getType('address_book')}">
|
||||
<label th:each="dict : ${type}" class="check-box">
|
||||
<input name="eventName" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}">
|
||||
<input name="eventNameList" type="checkbox" th:value="${dict.dictValue}" th:text="${dict.dictLabel}">
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -24,9 +24,9 @@
|
|||
</div>
|
||||
|
||||
<div class="btn-group-sm" id="toolbar" role="group">
|
||||
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:back:add">
|
||||
<!-- <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:back:add">
|
||||
<i class="fa fa-plus"></i> 添加
|
||||
</a>
|
||||
</a>-->
|
||||
<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:back:edit">
|
||||
<i class="fa fa-edit"></i> 修改
|
||||
</a>
|
||||
|
@ -62,7 +62,7 @@
|
|||
{
|
||||
field: 'id',
|
||||
title: 'ID',
|
||||
visible: false
|
||||
visible: true
|
||||
},
|
||||
/* {
|
||||
field: 'token',
|
||||
|
@ -72,14 +72,15 @@
|
|||
field: 'aesKey',
|
||||
title: '数据加密密钥'
|
||||
},*/
|
||||
{
|
||||
field: 'callBackName',
|
||||
title: '回调名称'
|
||||
},
|
||||
{
|
||||
field: 'url',
|
||||
title: '回调url'
|
||||
},
|
||||
{
|
||||
field: 'callBackName',
|
||||
title: '回调名称'
|
||||
},
|
||||
|
||||
{
|
||||
title: '操作',
|
||||
align: 'center',
|
||||
|
|
|
@ -10,40 +10,35 @@
|
|||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">回调名称:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="callBackName" th:field="*{callBackName}" class="form-control" type="text">
|
||||
<input name="callBackName" th:field="*{callBackName}" class="form-control" type="text" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">加解密token:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="token" th:field="*{token}" class="form-control" type="text">
|
||||
<input name="token" th:field="*{token}" class="form-control" type="text" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">数据加密密钥:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="aesKey" th:field="*{aesKey}" class="form-control" type="text">
|
||||
<input name="aesKey" th:field="*{aesKey}" class="form-control" type="text" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">事件回调url:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="url" th:field="*{url}" class="form-control" type="text">
|
||||
<input name="url" th:field="*{url}" class="form-control" type="text" required>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">app_key:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="appKey" th:field="*{appKey}" class="form-control" type="text">
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">通讯录事件回调:</label>
|
||||
<div class="col-sm-8" th:with="type=${@dict.getType('address_book')}">
|
||||
<label th:each="dict : ${type}" class="check-box">
|
||||
<input name="eventNameList" type="checkbox" th:value="${dict.dictValue}" th:checked="${dict.dictValue}" th:text="${dict.dictLabel}" required>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">app_secret:</label>
|
||||
<div class="col-sm-8">
|
||||
<input name="appSecret" th:field="*{appSecret}" class="form-control" type="text">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
<th:block th:include="include :: footer" />
|
||||
|
|
|
@ -25,6 +25,13 @@
|
|||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.taobao.top</groupId>
|
||||
<artifactId>lippi-oapi-encrpt</artifactId>
|
||||
<version>dingtalk-SNAPSHOT</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${pom.basedir}/src/main/resources/lib/lippi-oapi-encrpt.jar</systemPath>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package com.snow.dingtalk.common;
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title:
|
||||
* @Description:
|
||||
* @date 2020/11/5 15:04
|
||||
*/
|
||||
public enum EventNameEnum {
|
||||
|
||||
org_dept_create,
|
||||
|
||||
org_dept_modify,
|
||||
|
||||
org_dept_remove
|
||||
}
|
Binary file not shown.
|
@ -1,9 +1,11 @@
|
|||
package com.snow.system.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.snow.common.enums.DingTalkListenerType;
|
||||
import com.snow.common.utils.DateUtils;
|
||||
import com.snow.common.utils.StringUtils;
|
||||
import com.snow.system.domain.DingtalkCallBackEvent;
|
||||
import com.snow.system.event.SyncEvent;
|
||||
import com.snow.system.mapper.DingtalkCallBackEventMapper;
|
||||
|
@ -15,6 +17,7 @@ import com.snow.system.mapper.DingtalkCallBackMapper;
|
|||
import com.snow.system.domain.DingtalkCallBack;
|
||||
import com.snow.system.service.IDingtalkCallBackService;
|
||||
import com.snow.common.core.text.Convert;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
|
@ -44,7 +47,17 @@ public class DingtalkCallBackServiceImpl implements IDingtalkCallBackService
|
|||
@Override
|
||||
public DingtalkCallBack selectDingtalkCallBackById(Long id)
|
||||
{
|
||||
return dingtalkCallBackMapper.selectDingtalkCallBackById(id);
|
||||
DingtalkCallBack dingtalkCallBack = dingtalkCallBackMapper.selectDingtalkCallBackById(id);
|
||||
if(StringUtils.isNotNull(dingtalkCallBack)){
|
||||
DingtalkCallBackEvent dingtalkCallBackEvent=new DingtalkCallBackEvent();
|
||||
dingtalkCallBackEvent.setCallBanckId(id);
|
||||
List<DingtalkCallBackEvent> dingtalkCallBackEvents = dingtalkCallBackEventMapper.selectDingtalkCallBackEventList(dingtalkCallBackEvent);
|
||||
List<String> eventNameList = dingtalkCallBackEvents.stream()
|
||||
.map(DingtalkCallBackEvent::getEventName)
|
||||
.collect(Collectors.toList());
|
||||
dingtalkCallBack.setEventNameList(eventNameList);
|
||||
}
|
||||
return dingtalkCallBack;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,6 +79,7 @@ public class DingtalkCallBackServiceImpl implements IDingtalkCallBackService
|
|||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int insertDingtalkCallBack(DingtalkCallBack dingtalkCallBack)
|
||||
{
|
||||
dingtalkCallBack.setCreateTime(DateUtils.getNowDate());
|
||||
|
@ -77,7 +91,7 @@ public class DingtalkCallBackServiceImpl implements IDingtalkCallBackService
|
|||
dingtalkCallBackEvent.setEventName(t);
|
||||
String addressBook = sysDictDataServiceImpl.selectDictLabel("address_book", t);
|
||||
dingtalkCallBackEvent.setEventDesc(addressBook);
|
||||
dingtalkCallBackEvent.setId(i);
|
||||
dingtalkCallBackEvent.setCallBanckId((long)i);
|
||||
dingtalkCallBackEventMapper.insertDingtalkCallBackEvent(dingtalkCallBackEvent);
|
||||
});
|
||||
// 同步到dingding
|
||||
|
@ -96,6 +110,19 @@ public class DingtalkCallBackServiceImpl implements IDingtalkCallBackService
|
|||
public int updateDingtalkCallBack(DingtalkCallBack dingtalkCallBack)
|
||||
{
|
||||
dingtalkCallBack.setUpdateTime(DateUtils.getNowDate());
|
||||
dingtalkCallBackEventMapper.deleteDingtalkCallBackEventById(dingtalkCallBack.getId().intValue());
|
||||
DingtalkCallBackEvent dingtalkCallBackEvent=new DingtalkCallBackEvent();
|
||||
BeanUtils.copyProperties(dingtalkCallBack,dingtalkCallBackEvent);
|
||||
List<String> eventNameList = dingtalkCallBack.getEventNameList();
|
||||
eventNameList.forEach(t->{
|
||||
dingtalkCallBackEvent.setEventName(t);
|
||||
String addressBook = sysDictDataServiceImpl.selectDictLabel("address_book", t);
|
||||
dingtalkCallBackEvent.setEventDesc(addressBook);
|
||||
dingtalkCallBackEvent.setCallBanckId(dingtalkCallBack.getId());
|
||||
dingtalkCallBackEvent.setCreateTime(DateUtils.getNowDate());
|
||||
dingtalkCallBackEvent.setCreateBy(dingtalkCallBack.getUpdateBy());
|
||||
dingtalkCallBackEventMapper.insertDingtalkCallBackEvent(dingtalkCallBackEvent);
|
||||
});
|
||||
return dingtalkCallBackMapper.updateDingtalkCallBack(dingtalkCallBack);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
|
||||
<select id="selectDingtalkCallBackEventList" parameterType="DingtalkCallBackEvent" resultMap="DingtalkCallBackEventResult">
|
||||
<include refid="selectDingtalkCallBackEventVo"/>
|
||||
<where>
|
||||
where del_flag=0
|
||||
<if test="eventName != null and eventName != ''"> and event_name like concat('%', #{eventName}, '%')</if>
|
||||
<if test="callBanckId != null "> and call_banck_id = #{callBanckId}</if>
|
||||
<if test="eventDesc != null and eventDesc != ''"> and event_desc = #{eventDesc}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDingtalkCallBackEventById" parameterType="Integer" resultMap="DingtalkCallBackEventResult">
|
||||
|
|
Loading…
Reference in New Issue