新增钉钉2.0接口
This commit is contained in:
parent
57ca8ae41f
commit
8ca13edc9b
|
@ -6,7 +6,7 @@ spring:
|
|||
druid:
|
||||
# 主库数据源
|
||||
master:
|
||||
url: jdbc:mysql://localhost:3306/snow-dev?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://localhost:3306/snow?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: root
|
||||
# 从库数据源
|
||||
|
|
|
@ -38,5 +38,10 @@
|
|||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.10</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dingtalk</artifactId>
|
||||
<version>1.1.10</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -2,6 +2,12 @@ package com.snow.dingtalk.common;
|
|||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import com.aliyun.dingtalkoauth2_1_0.Client;
|
||||
import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest;
|
||||
import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.Common;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.request.OapiGettokenRequest;
|
||||
import com.dingtalk.api.response.OapiGettokenResponse;
|
||||
|
@ -26,6 +32,8 @@ public class BaseService {
|
|||
|
||||
public static final String TOKEN="dingtalk_token";
|
||||
|
||||
public static final String TOKENV2="dingtalk_token_V2";
|
||||
|
||||
private SysConfigServiceImpl sysConfigService=SpringUtils.getBean("sysConfigServiceImpl");
|
||||
|
||||
private SysOperLogServiceImpl iSysOperLogService=SpringUtils.getBean("sysOperLogServiceImpl");
|
||||
|
@ -65,6 +73,38 @@ public class BaseService {
|
|||
|
||||
}
|
||||
|
||||
public String getDingTalkTokenV2(){
|
||||
//创建缓存,缓存默认是7100S
|
||||
TimedCache<String, String> timedCache = CacheUtil.newTimedCache(7100);
|
||||
if(StringUtils.isEmpty(timedCache.get(TOKENV2))) {
|
||||
Config config = new Config();
|
||||
config.protocol = "https";
|
||||
config.regionId = "central";
|
||||
try {
|
||||
Client client = new Client(config);
|
||||
GetAccessTokenRequest getAccessTokenRequest = new GetAccessTokenRequest()
|
||||
.setAppKey(sysConfigService.selectConfigByKey(Constants.ENTERPRICE_APP_KEY))
|
||||
.setAppSecret(sysConfigService.selectConfigByKey(Constants.ENTERPRICE_APP_SECRET));
|
||||
try {
|
||||
GetAccessTokenResponse accessToken = client.getAccessToken(getAccessTokenRequest);
|
||||
timedCache.put(TOKENV2,accessToken.getBody().getAccessToken());
|
||||
return accessToken.getBody().getAccessToken();
|
||||
} catch (Exception exception) {
|
||||
TeaException err = new TeaException(exception.getMessage(), exception);
|
||||
if (!Common.empty(err.code) && !Common.empty(err.message)) {
|
||||
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
||||
syncDingTalkErrorOperLog(BaseConstantUrl.GET_TOKEN_URL,err.getMessage(),"getDingTalkToken()", com.alibaba.fastjson.JSON.toJSONString(getAccessTokenRequest));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}else {
|
||||
return timedCache.get(TOKEN);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录钉钉异常信息
|
||||
* @param url
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package com.snow.dingtalk.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyun.dingtalktodo_1_0.Client;
|
||||
import com.aliyun.dingtalktodo_1_0.models.CreateTodoTaskHeaders;
|
||||
import com.aliyun.dingtalktodo_1_0.models.CreateTodoTaskRequest;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMessageCorpconversationAsyncsendV2Request;
|
||||
|
@ -34,6 +40,9 @@ import org.apache.commons.lang3.StringUtils;
|
|||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
/**
|
||||
* @author qimingjin
|
||||
* @Title: 待办事项
|
||||
|
@ -74,6 +83,45 @@ public class WorkRecodeServiceImpl extends BaseService implements WorkRecodeServ
|
|||
|
||||
}
|
||||
|
||||
|
||||
public void createV2() throws Exception {
|
||||
Config config = new Config();
|
||||
config.protocol = "https";
|
||||
config.regionId = "central";
|
||||
Client client = new com.aliyun.dingtalktodo_1_0.Client(config);
|
||||
CreateTodoTaskHeaders createTodoTaskHeaders = new CreateTodoTaskHeaders();
|
||||
createTodoTaskHeaders.xAcsDingtalkAccessToken = getDingTalkTokenV2();
|
||||
CreateTodoTaskRequest.CreateTodoTaskRequestDetailUrl detailUrl = new CreateTodoTaskRequest.CreateTodoTaskRequestDetailUrl()
|
||||
.setAppUrl("dingtalk://dingtalkclient/action/open_mini_app?miniAppId={0}&ddMode=push&page=pages%2ftask-detail%2ftask-detail%3ftaskId%3d{1}")
|
||||
.setPcUrl("https://todo.dingtalk.com/ding-portal/detail/task/{0}");
|
||||
CreateTodoTaskRequest createTodoTaskRequest = new CreateTodoTaskRequest()
|
||||
.setSourceId("isv_dingtalkTodo1")
|
||||
.setSubject("接入钉钉待办")
|
||||
.setCreatorId("PUoiinWIpa2yH2ymhiiGiP6g")
|
||||
.setDescription("应用可以调用该接口发起一个钉钉待办任务,该待办事项会出现在钉钉客户端“待办”页面,需要注意的是,通过开放接口发起的待办,目前仅支持直接跳转ISV应用详情页(ISV在调该接口时需传入自身应用详情页链接)。")
|
||||
.setDueTime(1617675000000L)
|
||||
.setExecutorIds(Arrays.asList(
|
||||
"PUoiinWIpa2yH2ymhiiGiP6g"
|
||||
))
|
||||
.setParticipantIds(Arrays.asList(
|
||||
"PUoiinWIpa2yH2ymhiiGiP6g"
|
||||
))
|
||||
.setDetailUrl(detailUrl);
|
||||
try {
|
||||
client.createTodoTaskWithOptions("PUoiinWIpa2yH2ymhiiGiP6g", createTodoTaskRequest, createTodoTaskHeaders, new RuntimeOptions());
|
||||
} catch (TeaException err) {
|
||||
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
||||
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
||||
}
|
||||
|
||||
} catch (Exception _err) {
|
||||
TeaException err = new TeaException(_err.getMessage(), _err);
|
||||
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
|
||||
// err 中含有 code 和 message 属性,可帮助开发定位问题
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 根据用户ID获取待办
|
||||
* @param workrecordGetbyuseridRequest
|
||||
|
|
Loading…
Reference in New Issue