修复钉钉注册回调异常

This commit is contained in:
qimingjin 2021-06-22 22:40:04 +08:00
parent 7395f1983e
commit 7f5770edea
9 changed files with 64 additions and 22 deletions

View File

@ -78,7 +78,7 @@ public class CallBackController {
String eventType = callBackContent.getString(EVENT_TYPE); String eventType = callBackContent.getString(EVENT_TYPE);
DingTalkListenerType type = DingTalkListenerType.getType(eventType); DingTalkListenerType type = DingTalkListenerType.getType(eventType);
if(StringUtils.isEmpty(type)){ if(StringUtils.isEmpty(type)){
return Constants.CALL_BACK_FAIL_RETURN; return dingTalkEncryptor.getEncryptedMap(Constants.CALL_BACK_SUCCESS_RETURN, timestamp, nonce);
} }
//测试回调URL事件直接返回加密后的success即可 //测试回调URL事件直接返回加密后的success即可
if(eventType.equals(DingTalkListenerType.CALL_BACK_CHECK_URL.getInfo())){ if(eventType.equals(DingTalkListenerType.CALL_BACK_CHECK_URL.getInfo())){

View File

@ -3,10 +3,13 @@ package com.snow.web.controller.system;
import java.util.List; import java.util.List;
import com.dingtalk.api.response.OapiCallBackGetCallBackFailedResultResponse; import com.dingtalk.api.response.OapiCallBackGetCallBackFailedResultResponse;
import com.snow.common.enums.DingTalkListenerType;
import com.snow.dingtalk.service.impl.CallBackServiceImpl; import com.snow.dingtalk.service.impl.CallBackServiceImpl;
import com.snow.framework.util.ShiroUtils; import com.snow.framework.util.ShiroUtils;
import com.snow.system.event.SyncEvent;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap; import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@ -23,6 +26,8 @@ import com.snow.common.core.domain.AjaxResult;
import com.snow.common.utils.poi.ExcelUtil; import com.snow.common.utils.poi.ExcelUtil;
import com.snow.common.core.page.TableDataInfo; import com.snow.common.core.page.TableDataInfo;
import javax.annotation.Resource;
/** /**
* 回调事件Controller * 回调事件Controller
* *
@ -38,6 +43,9 @@ public class DingtalkCallBackController extends BaseController
@Autowired @Autowired
private IDingtalkCallBackService dingtalkCallBackService; private IDingtalkCallBackService dingtalkCallBackService;
@Resource
private ApplicationContext applicationContext;
@RequiresPermissions("system:back:view") @RequiresPermissions("system:back:view")
@GetMapping() @GetMapping()
public String back() public String back()
@ -91,9 +99,23 @@ public class DingtalkCallBackController extends BaseController
public AjaxResult addSave(DingtalkCallBack dingtalkCallBack) public AjaxResult addSave(DingtalkCallBack dingtalkCallBack)
{ {
dingtalkCallBack.setCreateBy(ShiroUtils.getLoginName()); dingtalkCallBack.setCreateBy(ShiroUtils.getLoginName());
dingtalkCallBack.setIsSyncDingTalk(false);
return toAjax(dingtalkCallBackService.insertDingtalkCallBack(dingtalkCallBack)); return toAjax(dingtalkCallBackService.insertDingtalkCallBack(dingtalkCallBack));
} }
@RequiresPermissions("system:back:register")
@Log(title = "注册", businessType = BusinessType.INSERT)
@GetMapping("/register")
@ResponseBody
public AjaxResult register(Long id)
{
DingtalkCallBack dingtalkCallBack = dingtalkCallBackService.selectDingtalkCallBackById(id);
// 同步到dingding
SyncEvent syncEvent = new SyncEvent(dingtalkCallBack, DingTalkListenerType.CALL_BACK_REGISTER);
applicationContext.publishEvent(syncEvent);
return AjaxResult.success();
}
/** /**
* 修改回调事件 * 修改回调事件
*/ */

View File

@ -6,9 +6,9 @@ spring:
druid: druid:
# 主库数据源 # 主库数据源
master: master:
url: jdbc:mysql://localhost:3306/snow?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 url: jdbc:mysql://rm-bp1j1554xv1qs04295o.mysql.rds.aliyuncs.com:3306/snow-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
username: root username: cloud_root
password: root password: Jin!152377
# 从库数据源 # 从库数据源
slave: slave:
# 从数据源开关/默认关闭 # 从数据源开关/默认关闭

View File

@ -31,15 +31,9 @@
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label">app_key</label> <label class="col-sm-3 control-label">corpId</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="appKey" class="form-control" type="text"> <input name="corpId" class="form-control" type="text">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">app_secret</label>
<div class="col-sm-8">
<input name="appSecret" class="form-control" type="text">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@ -24,9 +24,9 @@
</div> </div>
<div class="btn-group-sm" id="toolbar" role="group"> <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> 添加 <i class="fa fa-plus"></i> 添加
</a>--> </a>
<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:back:edit"> <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:back:edit">
<i class="fa fa-edit"></i> 修改 <i class="fa fa-edit"></i> 修改
</a> </a>
@ -46,6 +46,7 @@
<script th:inline="javascript"> <script th:inline="javascript">
var editFlag = [[${@permission.hasPermi('system:back:edit')}]]; var editFlag = [[${@permission.hasPermi('system:back:edit')}]];
var removeFlag = [[${@permission.hasPermi('system:back:remove')}]]; var removeFlag = [[${@permission.hasPermi('system:back:remove')}]];
var registerFlag = [[${@permission.hasPermi(' system:back:register')}]];
var detailFlag = [[${@permission.hasPermi('system:back:detail')}]]; var detailFlag = [[${@permission.hasPermi('system:back:detail')}]];
var prefix = ctx + "system/back"; var prefix = ctx + "system/back";
@ -80,7 +81,9 @@
align: 'center', align: 'center',
formatter: function(value, row, index) { formatter: function(value, row, index) {
var actions = []; var actions = [];
actions.push('<a class="btn btn-primary btn-xs '+ registerFlag + '" href="javascript:void(0)" onclick="registerCallBack(\'' + row.id + '\')"><i class="fa fa-registered"></i>注册</a> ');
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-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-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
return actions.join(''); return actions.join('');
} }
@ -88,6 +91,27 @@
}; };
$.table.init(options); $.table.init(options);
}); });
function registerCallBack(id) {
$.ajax({
type: "GET",
url: "/system/back/register?id="+id,
cache: false,
contentType: false,
processData: false,
dataType: 'json',
success: function(result) {
if (result.code == web_status.SUCCESS) {
$.modal.alertSuccess(result.msg);
} else {
$.modal.alertError(result.msg);
}
},
error: function(error) {
$.modal.alertWarning("注册失败。");
}
});
}
</script> </script>
</body> </body>
</html> </html>

View File

@ -37,7 +37,7 @@ public class CallBackService implements ISyncDingTalkInfo {
callBackServiceImpl.updateCallBack((DingtalkCallBack) syncEvent.getSource()); callBackServiceImpl.updateCallBack((DingtalkCallBack) syncEvent.getSource());
} }
else if(code.equals(DingTalkListenerType.CALL_BACK_DELETE.getCode())){ else if(code.equals(DingTalkListenerType.CALL_BACK_DELETE.getCode())){
callBackServiceImpl.deleteCallBack((DingtalkCallBack) syncEvent.getSource()); callBackServiceImpl.deleteCallBack();
} }

View File

@ -25,9 +25,9 @@ public interface CallBackService {
/** /**
* 删除事件 * 删除事件
* @param dingtalkCallBack *
*/ */
void deleteCallBack(DingtalkCallBack dingtalkCallBack); void deleteCallBack();
/** /**
* 获取回调失败结果 * 获取回调失败结果

View File

@ -75,7 +75,7 @@ public class CallBackServiceImpl extends BaseService implements CallBackService
@Override @Override
@SyncLog(dingTalkListenerType = DingTalkListenerType.CALL_BACK_DELETE,dingTalkUrl=BaseConstantUrl.DELETE_CALL_BACK,dingTalkSyncType=DingTalkSyncType.AUTOMATIC) @SyncLog(dingTalkListenerType = DingTalkListenerType.CALL_BACK_DELETE,dingTalkUrl=BaseConstantUrl.DELETE_CALL_BACK,dingTalkSyncType=DingTalkSyncType.AUTOMATIC)
public void deleteCallBack(DingtalkCallBack dingtalkCallBack) { public void deleteCallBack() {
DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DELETE_CALL_BACK); DingTalkClient client = new DefaultDingTalkClient(BaseConstantUrl.DELETE_CALL_BACK);
OapiCallBackDeleteCallBackRequest request = new OapiCallBackDeleteCallBackRequest(); OapiCallBackDeleteCallBackRequest request = new OapiCallBackDeleteCallBackRequest();
request.setHttpMethod("GET"); request.setHttpMethod("GET");

View File

@ -95,12 +95,14 @@ public class DingtalkCallBackServiceImpl implements IDingtalkCallBackService
dingtalkCallBackEvent.setEventName(t); dingtalkCallBackEvent.setEventName(t);
String addressBook = sysDictDataServiceImpl.selectDictLabel(Constants.ADDRESS_BOOK, t); String addressBook = sysDictDataServiceImpl.selectDictLabel(Constants.ADDRESS_BOOK, t);
dingtalkCallBackEvent.setEventDesc(addressBook); dingtalkCallBackEvent.setEventDesc(addressBook);
dingtalkCallBackEvent.setCallBanckId((long)i); dingtalkCallBackEvent.setCallBanckId(dingtalkCallBack.getId());
dingtalkCallBackEventMapper.insertDingtalkCallBackEvent(dingtalkCallBackEvent); dingtalkCallBackEventMapper.insertDingtalkCallBackEvent(dingtalkCallBackEvent);
}); });
// 同步到dingding if(dingtalkCallBack.getIsSyncDingTalk()){
SyncEvent syncEvent = new SyncEvent(dingtalkCallBack, DingTalkListenerType.CALL_BACK_REGISTER); // 同步到dingding
applicationContext.publishEvent(syncEvent); SyncEvent syncEvent = new SyncEvent(dingtalkCallBack, DingTalkListenerType.CALL_BACK_REGISTER);
applicationContext.publishEvent(syncEvent);
}
return 1; return 1;
} }