工作通知
预期效果

接入流程简介
task_id
。task_id
,调用服务端API-获取工作通知消息的发送进度接口,获取发送进度。task_id
,调用服务端API-获取工作通知消息的发送结果接口,查看发送结果。task_id
,调用服务端API-更新工作通知状态栏接口,更新工作通知。task_id
,调用服务端API-撤回工作通知消息接口,撤回工作通知。步骤一:创建企业内部应用

步骤二:获取AppKey和AppSecret

步骤三:获取应用访问凭证accessToken
public void getAccessToken() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
OapiGettokenRequest req = new OapiGettokenRequest();
req.setAppkey("dingxxxxxxxxxhgn");
req.setAppsecret("9G_xxxxxxxxxxxxxxx1JDf0Qq3nexxxxxxxxGIO");
req.setHttpMethod("GET");
OapiGettokenResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
}
步骤四:调用服务端相关API

public void OAWorkNotice() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/asyncsend_v2");
OapiMessageCorpconversationAsyncsendV2Request request = new OapiMessageCorpconversationAsyncsendV2Request();
request.setAgentId(1185599675L);
request.setUseridList("manager7675");
request.setToAllUser(false);
OapiMessageCorpconversationAsyncsendV2Request.Msg msg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
OapiMessageCorpconversationAsyncsendV2Request.OA oa = new OapiMessageCorpconversationAsyncsendV2Request.OA();
OapiMessageCorpconversationAsyncsendV2Request.Head head = new OapiMessageCorpconversationAsyncsendV2Request.Head();
head.setBgcolor("FFFF6A00");
head.setText("测试");
OapiMessageCorpconversationAsyncsendV2Request.Body body = new OapiMessageCorpconversationAsyncsendV2Request.Body();
List<OapiMessageCorpconversationAsyncsendV2Request.Form> list = new ArrayList<>();
OapiMessageCorpconversationAsyncsendV2Request.Form form1 = new OapiMessageCorpconversationAsyncsendV2Request.Form();
form1.setKey("姓名:");
form1.setValue("小钉");
OapiMessageCorpconversationAsyncsendV2Request.Form form2 = new OapiMessageCorpconversationAsyncsendV2Request.Form();
form2.setKey("年龄:");
form2.setValue("21");
OapiMessageCorpconversationAsyncsendV2Request.Form form3 = new OapiMessageCorpconversationAsyncsendV2Request.Form();
form3.setKey("身高:");
form3.setValue("1.8米");
OapiMessageCorpconversationAsyncsendV2Request.Form form4 = new OapiMessageCorpconversationAsyncsendV2Request.Form();
form4.setKey("体重:");
form4.setValue("130斤");
OapiMessageCorpconversationAsyncsendV2Request.Form form5 = new OapiMessageCorpconversationAsyncsendV2Request.Form();
form5.setKey("学历:");
form5.setValue("本科");
OapiMessageCorpconversationAsyncsendV2Request.Form form6 = new OapiMessageCorpconversationAsyncsendV2Request.Form();
form6.setKey("爱好:");
form6.setValue("打球、听音乐");
OapiMessageCorpconversationAsyncsendV2Request.Rich rich = new OapiMessageCorpconversationAsyncsendV2Request.Rich();
rich.setNum("10.6");
rich.setUnit("元");
list.add(form1);
list.add(form2);
list.add(form3);
list.add(form4);
list.add(form5);
list.add(form6);
body.setForm(list);
body.setRich(rich);
body.setTitle("正文标题5");
body.setImage("@lADOADmaWMzazQKA");
body.setFileCount("3");
body.setAuthor("小钉");
OapiMessageCorpconversationAsyncsendV2Request.StatusBar statusBar = new OapiMessageCorpconversationAsyncsendV2Request.StatusBar();
statusBar.setStatusBg("0xFFFF6A00");
statusBar.setStatusValue("进行中");
oa.setMessageUrl("https://dingtalk.com");
oa.setHead(head);
oa.setBody(body);
oa.setStatusBar(statusBar);
msg.setOa(oa);
msg.setMsgtype("oa");
msg.setOa(oa);
request.setMsg(msg);
OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(request, "access_token");
System.out.println(rsp.getBody());
}
public void workNoticeSendProgress() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/getsendprogress");
OapiMessageCorpconversationGetsendprogressRequest req = new OapiMessageCorpconversationGetsendprogressRequest();
req.setAgentId(123L);
req.setTaskId(456L);
OapiMessageCorpconversationGetsendprogressResponse rsp = client.execute(req, "access_token");
System.out.println(rsp.getBody());
}
public void workNoticeSendResult() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult");
OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest();
req.setAgentId(123L);
req.setTaskId(456L);
OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, "access_token");
System.out.println(rsp.getBody());
}
public void recallWorkNotice() throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/message/corpconversation/recall");
OapiMessageCorpconversationRecallRequest req = new OapiMessageCorpconversationRecallRequest();
req.setAgentId(1000L);
req.setMsgTaskId(2000L);
OapiMessageCorpconversationRecallResponse rsp = client.execute(req, "access_token");
System.out.println(rsp.getBody());
}
修改于 2024-01-09 09:00:41