一、钉钉参数获取
本文主要介绍如何实现这一功能,对钉钉其他使用不做过度解读。
首先进入钉钉的开发者后台,需要创建一个企业内部应用,在右侧可以看见一个CorpId 这是我们需要的。
然后点击这个企业内部应用进入,可以看到AgentId、AppKey、AppSecret 这三个参数
以上就拿到了需要的四个参数。
二、流程图
在抄送环节我们使用SendTask【发送任务】。发送任务用于发送消息。在Camunda中,这是通过调用Java代码来完成的。
填写相关参数,也就是告诉它使用java的哪个类去处理
三、功能实现
首先在配置文件中敲上相关参数
pom中新增依赖
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>2.0.0</version>
</dependency>
直接上这个委托类的代码
@Component
public class SendMessageTaskDelegate implements JavaDelegate {
@Value("${ding.talk.agentId}")
private Long agentId;
@Value("${ding.talk.appKey}")
private String appKey;
@Value("${ding.talk.appSecret}")
private String appSecret;
@Value("${ding.talk.corpId}")
private String corpId;
@Override
public void execute(DelegateExecution delegateExecution) throws Exception {
//获取token appkey+appsecret通过下面接口就能获取到token
DingTalkClient client = new DefaultDingTalkClient(DingUrlConstant.URL_GET_TOKKEN);
OapiGettokenRequest tokenRequest = new OapiGettokenRequest();
tokenRequest.setAppkey(appKey);
tokenRequest.setAppsecret(appSecret);
tokenRequest.setHttpMethod("GET");
OapiGettokenResponse response = client.execute(tokenRequest);
System.out.println(response.getBody());
//获取到token
String accessToken = response.getAccessToken();
//发送消息接口
DefaultDingTalkClient clientOne = new DefaultDingTalkClient(DingUrlConstant.MESSAGE_ASYNCSEND);
OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
request.setAgentId(agentId);//微应用ID
request.setToAllUser(false);//是否发给所有人 false否 ,否的情况下要获取接受者id 可以是多个和接收者部门id
request.setUseridList("manager1374");//接收者ID
request.setHttpMethod("GET");
OapiMessageCorpconversationAsyncsendV2Request.Msg message = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
message.setOa(new OapiMessageCorpconversationAsyncsendV2Request.OA());
message.getOa().setHead(new OapiMessageCorpconversationAsyncsendV2Request.Head());
message.getOa().getHead().setText("head");
message.getOa().setBody(new OapiMessageCorpconversationAsyncsendV2Request.Body());
message.getOa().getBody().setContent("您在业务系统有待审批任务");
message.setMsgtype("oa");
request.setMsg(message);
OapiMessageCorpconversationAsyncsendV2Response rsp = clientOne.execute(request, accessToken);
System.out.println(rsp.getBody());
}
}
大体意思就是获取到token,然后给指定的人发消息,通过delegateExecution 也是可以拿到很多流程实例相关的参数的。这样就可以处理更多的业务需求,具体的大家自己试一试。
钉钉接口常量类DingUrlConstant也贴出来一下
/**
* 钉钉网关gettoken地址
*/
public static final String URL_GET_TOKKEN = "https://oapi.dingtalk.com/gettoken";
/**
*获取用户在企业内userId的接口URL
*/
public static final String URL_GET_USER_INFO = "https://oapi.dingtalk.com/user/getuserinfo";
/**
*获取用户姓名的接口url
*/
public static final String URL_USER_GET = "https://oapi.dingtalk.com/user/get";
/**
* 发起审批实例的接口url
*/
public static final String URL_PROCESSINSTANCE_START = "https://oapi.dingtalk.com/topapi/processinstance/create";
/**
* 获取审批实例的接口url
*/
public static final String URL_PROCESSINSTANCE_GET = "https://oapi.dingtalk.com/topapi/processinstance/get";
/**
* 发送企业通知消息的接口url
*/
public static final String MESSAGE_ASYNCSEND = "https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2";
/**
* 删除企业回调接口url
*/
public static final String DELETE_CALLBACK = "https://oapi.dingtalk.com/call_back/delete_call_back";
/**
* 注册企业回调接口url
*/
public static final String REGISTER_CALLBACK = "https://oapi.dingtalk.com/call_back/register_call_back";
四、测试
部署流程定义后发起流程实例
期望效果:发起人提交后抄送给钉钉指定人员