调通回调事件

This commit is contained in:
459816669@qq.com 2020-11-14 21:04:56 +08:00
parent 0126366f95
commit 65bc8105e6
9 changed files with 79 additions and 286 deletions

View File

@ -4,11 +4,15 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dingtalk.oapi.lib.aes.DingTalkEncryptor;
import com.snow.dingtalk.common.EventNameEnum;
import com.snow.system.domain.DingtalkCallBack;
import com.snow.system.service.impl.DingtalkCallBackServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.util.Collections;
import java.util.List;
/**
* @author qimingjin
@ -16,9 +20,13 @@ import org.springframework.web.bind.annotation.RestController;
* @Description:
* @date 2020/11/3 17:11
*/
@RestController("/dingTalk")
@RestController
@Slf4j
public class DingTalkCallBack {
@RequestMapping("/dingTalk")
public class DingTalkCallBackController {
@Autowired
private DingtalkCallBackServiceImpl dingtalkCallBackService;
/**
* 钉钉回调
@ -35,10 +43,18 @@ public class DingTalkCallBack {
@RequestParam(value = "nonce") String nonce,
@RequestBody(required = false) JSONObject body
) {
DingtalkCallBack dingtalkCallBack=new DingtalkCallBack();
dingtalkCallBack.setFlag(true);
List<DingtalkCallBack> dingtalkCallBacks = dingtalkCallBackService.selectDingtalkCallBackList(dingtalkCallBack);
if(!CollectionUtils.isEmpty(dingtalkCallBacks)){
dingtalkCallBack=dingtalkCallBacks.get(0);
}else {
return "fail";
}
String params = "signature:" + signature + " timestamp:" + timestamp + " nonce:" + nonce + " body:" + body;
try {
log.info("begin callback:" + params);
DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor("","","");
DingTalkEncryptor dingTalkEncryptor = new DingTalkEncryptor(dingtalkCallBack.getToken(),dingtalkCallBack.getAesKey(),dingtalkCallBack.getCorpId());
// 从post请求的body中获取回调信息的加密数据进行解密处理
String encrypt = body.getString("encrypt");

View File

@ -37,8 +37,6 @@ public class DingtalkCallBackController extends BaseController
@Autowired
private IDingtalkCallBackService dingtalkCallBackService;
@Autowired
private CallBackServiceImpl callBackServiceImpl;
@RequiresPermissions("system:back:view")
@GetMapping()
@ -132,12 +130,5 @@ public class DingtalkCallBackController extends BaseController
return toAjax(dingtalkCallBackService.deleteDingtalkCallBackByIds(ids));
}
@RequiresPermissions("system:back:detail")
@GetMapping("/detail/{id}")
public String detail(@PathVariable("id") Long operId, ModelMap mmap)
{
List<OapiCallBackGetCallBackFailedResultResponse.Failed> callBackFailedResult = callBackServiceImpl.getCallBackFailedResult();
mmap.put("operLog", callBackFailedResult);
return prefix + "/detail";
}
}

View File

@ -24,7 +24,7 @@
</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 class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:back:edit">
@ -66,18 +66,10 @@
title: 'ID',
visible: false
},
/* {
field: 'token',
title: 'token'
},
{
field: 'aesKey',
title: '数据加密密钥'
},*/
{
field: 'callBackName',
title: '回调名称'
},
field: 'callBackName',
title: '回调名称'
},
{
field: 'url',
title: '回调url'
@ -89,8 +81,7 @@
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>获取失败结果</a>');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
return actions.join('');
}
}]

View File

@ -1,74 +0,0 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
<th:block th:include="include :: header('操作日志详细')" />
<th:block th:include="include :: jsonview-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
<form class="form-horizontal m-t" id="signupForm">
<div class="form-group">
<label class="col-sm-2 control-label">操作模块:</label>
<div class="form-control-static" th:text="${operLog.title} + ' / ' + ${@dict.getLabel('sys_oper_type',operLog.businessType)}">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">登录信息:</label>
<div class="form-control-static" th:text="${operLog.operName} + ' / ' + ${operLog.deptName} + ' / ' + ${operLog.operIp}+ ' / ' + ${operLog.operLocation}">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求地址:</label>
<div class="form-control-static" th:text="${operLog.operUrl}">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求方式:</label>
<div class="form-control-static" th:text="${operLog.requestMethod}">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">操作方法:</label>
<div class="form-control-static" th:text="${operLog.method}">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求参数:</label>
<div class="form-control-static"><pre id="operParam"></pre></div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">返回参数:</label>
<div class="form-control-static"><pre id="jsonResult"></pre></div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">状态:</label>
<div class="form-control-static" th:class="${operLog.status == 0 ? 'label label-primary' : 'label label-danger'}" th:text="${operLog.status == 0 ? '正常' : '异常'}">
</div>
</div>
<div class="form-group" th:style="'display:' + ${operLog.status == 0 ? 'none' : 'block'}">
<label class="col-sm-2 control-label">异常信息:</label>
<div class="form-control-static" th:text="${operLog.errorMsg}">
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: jsonview-js" />
<script th:inline="javascript">
$(function() {
var operParam = [[${operLog.operParam}]];
if ($.common.isNotEmpty(operParam) && operParam.length < 2000) {
$("#operParam").JSONView(operParam);
} else {
$("#operParam").text(operParam);
}
var jsonResult = [[${operLog.jsonResult}]];
if ($.common.isNotEmpty(jsonResult) && jsonResult.length < 2000) {
$("#jsonResult").JSONView(jsonResult);
} else {
$("#jsonResult").text(jsonResult);
}
});
</script>
</body>
</html>

View File

@ -9,7 +9,7 @@
<form class="form-horizontal m-t" id="signupForm">
<div class="form-group">
<label class="col-sm-2 control-label">操作模块:</label>
<div class="form-control-static" th:text="${operLog.title} + ' / ' + ${@dict.getLabel('sys_oper_type',operLog.businessType)}">
<div class="form-control-static" th:text="${@dict.getLabel('dingtalk_module_type',operLog.moduleType)}+'/'+${operLog.title} + ' / ' + ${@dict.getLabel('sys_oper_type',operLog.businessType)}">
</div>
</div>
<div class="form-group">
@ -33,13 +33,25 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求参数:</label>
<label class="col-sm-2 control-label">请求参数:</label>
<div class="form-control-static"><pre id="operParam"></pre></div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">请求钉钉参数:</label>
<div class="form-control-static"><pre id="operDingtalkParam"></pre></div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">返回参数:</label>
<div class="form-control-static"><pre id="jsonResult"></pre></div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">同步类型:</label>
<div class="radio-box" th:each="dict : ${@dict.getType('dingtalk_sync_type')}">
<input type="radio" th:id="${dict.dictCode}" name="operatorType" th:value="${dict.dictValue}" th:field="${operLog.operatorType}" disabled>
<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">状态:</label>
<div class="form-control-static" th:class="${operLog.status == 0 ? 'label label-primary' : 'label label-danger'}" th:text="${operLog.status == 0 ? '正常' : '异常'}">
@ -57,11 +69,19 @@
<script th:inline="javascript">
$(function() {
var operParam = [[${operLog.operSourceParam}]];
var operDingtalkParam= [[${operLog.operDingtalkParam}]];
if ($.common.isNotEmpty(operParam) && operParam.length < 2000) {
$("#operParam").JSONView(operParam);
} else {
$("#operParam").text(operParam);
}
var operDingtalkParam = [[${operLog.operDingtalkParam}]];
if ($.common.isNotEmpty(operDingtalkParam) && operDingtalkParam.length < 2000) {
$("#operDingtalkParam").JSONView(operDingtalkParam);
} else {
$("#operDingtalkParam").text(operDingtalkParam);
}
var jsonResult = [[${operLog.jsonResult}]];
if ($.common.isNotEmpty(jsonResult) && jsonResult.length < 2000) {
$("#jsonResult").JSONView(jsonResult);

View File

@ -28,46 +28,11 @@
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</li>
<li>
<label>方法名称:</label>
<input type="text" name="method"/>
</li>
<li>
<label>请求方式:</label>
<input type="text" name="requestMethod"/>
</li>
<li>
<label>操作类别:</label>
<select name="operatorType">
<select name="businessType" th:with="type=${@dict.getType('dingtalk_sync_type')}">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
</select>
</li>
<li>
<label>操作人员:</label>
<input type="text" name="operName"/>
</li>
<li>
<label>部门名称:</label>
<input type="text" name="deptName"/>
</li>
<li>
<label>请求URL</label>
<input type="text" name="operUrl"/>
</li>
<li>
<label>主机地址:</label>
<input type="text" name="operIp"/>
</li>
<li>
<label>操作地点:</label>
<input type="text" name="operLocation"/>
</li>
<li>
<label>操作状态:</label>
<select name="status">
<option value="">所有</option>
<option value="-1">代码生成请选择字典属性</option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
</select>
</li>
<li class="select-time">
@ -86,12 +51,6 @@
</div>
<div class="btn-group-sm" id="toolbar" role="group">
<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:log:add">
<i class="fa fa-plus"></i> 添加
</a>
<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:log:edit">
<i class="fa fa-edit"></i> 修改
</a>
<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:log:remove">
<i class="fa fa-remove"></i> 删除
</a>
@ -107,6 +66,7 @@
<th:block th:include="include :: footer" />
<script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('system:log:edit')}]];
var detailFlag=[[${@permission.hasPermi('system:log:detail')}]];
var removeFlag = [[${@permission.hasPermi('system:log:remove')}]];
var moduleTypeDatas = [[${@dict.getType('dingtalk_module_type')}]];
var businessTypeDatas = [[${@dict.getType('dingtalk_oper_type')}]];
@ -150,10 +110,6 @@
return $.table.selectDictLabel(businessTypeDatas, value);
}
},
/* {
field: 'method',
title: '方法名称'
},*/
{
field: 'requestMethod',
title: '请求方式'
@ -173,10 +129,6 @@
field: 'deptName',
title: '部门名称'
},
/* {
field: 'operUrl',
title: '请求URL'
},*/
{
field: 'operIp',
title: '主机地址'
@ -185,18 +137,7 @@
field: 'operLocation',
title: '操作地点'
},
/* {
field: 'operSourceParam',
title: '请求原参数'
},
{
field: 'operDingtalkParam',
title: '请求钉钉参数'
},
{
field: 'jsonResult',
title: '返回参数'
},*/
{
field: 'status',
title: '操作状态',
@ -209,10 +150,6 @@
}
}
},
/* {
field: 'errorMsg',
title: '错误消息'
},*/
{
field: 'operTime',
title: '操作时间'
@ -222,8 +159,13 @@
align: 'center',
formatter: function(value, row, index) {
var actions = [];
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.logId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.logId + '\')"><i class="fa fa-remove"></i>删除</a>');
if(row.status==1){
actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.logId + '\')"><i class="fa fa-edit"></i>手工同步</a> ');
}
actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.logId + '\')"><i class="fa fa-remove"></i>删除</a> ');
actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.logId + '\')"><i class="fa fa-search"></i>详细</a>');
return actions.join('');
}

View File

@ -280,10 +280,12 @@ public class ShiroConfig
filterChainDefinitionMap.put("/js/**", "anon");
filterChainDefinitionMap.put("/ruoyi/**", "anon");
filterChainDefinitionMap.put("/captcha/captchaImage**", "anon");
filterChainDefinitionMap.put("/dingTalk/dingTalkCallBack", "anon");
// 退出 logout地址shiro去清除session
filterChainDefinitionMap.put("/logout", "logout");
// 不需要拦截的访问
filterChainDefinitionMap.put("/login", "anon,captchaValidate");
// 注册相关
filterChainDefinitionMap.put("/register", "anon,captchaValidate");
// 系统权限列表

View File

@ -2,6 +2,7 @@ package com.snow.system.domain;
import com.snow.common.annotation.Excel;
import com.snow.common.core.domain.BaseEntity;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -13,6 +14,7 @@ import java.util.List;
* @author qimingjin
* @date 2020-11-02
*/
@Data
public class DingtalkCallBack extends BaseEntity
{
private static final long serialVersionUID = 1L;
@ -32,11 +34,11 @@ public class DingtalkCallBack extends BaseEntity
@Excel(name = "接收事件回调的url必须是公网可以访问的url地址")
private String url;
/** app_key */
private String appKey;
/**企业内部应用 */
private String corpId;
/** app_secret */
private String appSecret;
/** 第三方企业应用 */
private String suiteKey;
/** 删除表示 */
private Integer delFlag;
@ -52,102 +54,5 @@ public class DingtalkCallBack extends BaseEntity
private Boolean flag=false;
public void setId(Long id)
{
this.id = id;
}
public Long getId()
{
return id;
}
public void setToken(String token)
{
this.token = token;
}
public String getToken()
{
return token;
}
public void setAesKey(String aesKey)
{
this.aesKey = aesKey;
}
public String getAesKey()
{
return aesKey;
}
public void setUrl(String url)
{
this.url = url;
}
public String getUrl()
{
return url;
}
public void setAppKey(String appKey)
{
this.appKey = appKey;
}
public String getAppKey()
{
return appKey;
}
public void setAppSecret(String appSecret)
{
this.appSecret = appSecret;
}
public String getAppSecret()
{
return appSecret;
}
public void setDelFlag(Integer delFlag)
{
this.delFlag = delFlag;
}
public Integer getDelFlag()
{
return delFlag;
}
public void setCallBackName(String callBackName)
{
this.callBackName = callBackName;
}
public String getCallBackName()
{
return callBackName;
}
public List<String> getEventNameList() {
return eventNameList;
}
public void setEventNameList(List<String> eventNameList) {
this.eventNameList = eventNameList;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("id", getId())
.append("token", getToken())
.append("aesKey", getAesKey())
.append("url", getUrl())
.append("appKey", getAppKey())
.append("appSecret", getAppSecret())
.append("delFlag", getDelFlag())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("callBackName", getCallBackName())
.toString();
}
}

View File

@ -9,8 +9,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="token" column="token" />
<result property="aesKey" column="aes_key" />
<result property="url" column="url" />
<result property="appKey" column="app_key" />
<result property="appSecret" column="app_secret" />
<result property="corpId" column="corp_id" />
<result property="suiteKey" column="suite_key" />
<result property="delFlag" column="del_flag" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
@ -20,7 +20,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectDingtalkCallBackVo">
select id, token, aes_key, url, app_key, app_secret, del_flag, create_by, create_time, update_by, update_time, call_back_name from dingtalk_call_back
select id, token, aes_key, url, corp_id, suite_key, del_flag, create_by, create_time, update_by, update_time, call_back_name from dingtalk_call_back
</sql>
<select id="selectDingtalkCallBackList" parameterType="DingtalkCallBack" resultMap="DingtalkCallBackResult">
@ -41,8 +41,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="token != null">token,</if>
<if test="aesKey != null">aes_key,</if>
<if test="url != null">url,</if>
<if test="appKey != null">app_key,</if>
<if test="appSecret != null">app_secret,</if>
<if test="corpId != null">corp_id,</if>
<if test="suiteKey != null">suite_key,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
@ -54,8 +54,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="token != null">#{token},</if>
<if test="aesKey != null">#{aesKey},</if>
<if test="url != null">#{url},</if>
<if test="appKey != null">#{appKey},</if>
<if test="appSecret != null">#{appSecret},</if>
<if test="corpId != null">#{corpId},</if>
<if test="suiteKey != null">#{suiteKey},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
@ -71,8 +71,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="token != null">token = #{token},</if>
<if test="aesKey != null">aes_key = #{aesKey},</if>
<if test="url != null">url = #{url},</if>
<if test="appKey != null">app_key = #{appKey},</if>
<if test="appSecret != null">app_secret = #{appSecret},</if>
<if test="corpId != null">corp_id = #{corpId},</if>
<if test="suiteKey != null">suite_key = #{suiteKey},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>