釘釘開(kāi)放平臺(tái)文檔地址
https://open.dingtalk.com/document/
服務(wù)端SDK下載地址
https://open.dingtalk.com/document/resourcedownload/download-server-sdk
就拿java的服務(wù)端SDK來(lái)說(shuō)分為兩個(gè)大的版本:老版本SDK和新版本SDK.
釘釘相關(guān)依賴的官方maven倉(cāng)庫(kù)地址
https://s01.oss.sonatype.org/?spm=ding_open_doc.document.0.0.4564722fJDmwRj#nexus-search;quick~dingtalk
1.自定義機(jī)器人接入
這種方式只需要在釘釘中拉一個(gè)群,人員超過(guò)三個(gè)人即可拉一個(gè)聊天的群,然后設(shè)置智能群助手,添加機(jī)器人:
機(jī)器人設(shè)置:
webHook地址就是下面的url地址(不包含sign和timestamp): https://oapi.dingtalk.com/robot/send?access_token=xxxxxx
加簽的key就是下面代碼中的的secret的值
1.1接口文檔
https://open.dingtalk.com/document/group/custom-robot-access
1.2引入pom依賴
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>alibaba-dingtalk-service-sdk</artifactId>
<version>2.0.0</version>
</dependency>
1.3代碼編寫
// 簽名
private String getSign(String secret, Long timestamp) {
try {
String stringToSign = timestamp + "\n" + secret;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8");
log.info("【發(fā)送釘釘群消息】獲取到簽名sign = {}", sign);
return sign;
} catch (Exception e) {
log.error("【發(fā)送釘釘群消息】計(jì)算簽名異常,errMsg = {}", e);
return null;
}
}
//接口調(diào)用code
Long timestamp = System.currentTimeMillis();
String secret = "xxxxxx";
String sign = this.getSign(secret, timestamp);
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/robot/send?access_token=xxxxxx"+"&sign="+sign+"×tamp="+timestamp);
OapiRobotSendRequest request = new OapiRobotSendRequest();
request.setMsgtype("text");
OapiRobotSendRequest.Text text = new OapiRobotSendRequest.Text();
text.setContent("測(cè)試文本消息");
request.setText(text);
OapiRobotSendResponse rsp = client.execute(request);
當(dāng)前自定義機(jī)器人支持以下消息類型,請(qǐng)根據(jù)自己的使用場(chǎng)景選擇合適的類型,詳情參見(jiàn)消息類型及數(shù)據(jù)格式。
-
文本 (text)
-
鏈接 (link)
-
markdown(markdown)
-
ActionCard
-
FeedCard
2.企業(yè)機(jī)器人向內(nèi)部群發(fā)消息
2.1如何調(diào)用機(jī)器人API
https://open.dingtalk.com/document/group/call-robot-api-operations
2.2接口文檔
https://open.dingtalk.com/document/group/the-robot-sends-a-group-message
企業(yè)機(jī)器人向內(nèi)部群發(fā)送消息是屬于新版本skd的酷應(yīng)用的接口
2.3酷應(yīng)用是什么?
https://open.dingtalk.com/document/org/cool-application-introduction
簡(jiǎn)單來(lái)說(shuō):酷應(yīng)用 = 場(chǎng)景 + 組件 + 場(chǎng)景的邏輯做成事兒為主
2.4酷應(yīng)用官方訓(xùn)練營(yíng)
https://h5.dingtalk.com/live/video_lesson.htm?feedId=e8a07af9-339a-47ca-84cd-15e8939789b9&mcnId=6580122020211712477&feedProperty=1#/
2.5酷應(yīng)用分類
2.6API在線調(diào)試工具
API Explorer是一款可視化的API在線調(diào)試工具,集成了API總覽、快速檢索、開(kāi)發(fā)文檔、可視化調(diào)試、同步動(dòng)態(tài)生成可執(zhí)行SDK Demo代碼,功能豐富、簡(jiǎn)單易用。
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.3361722f69ljpO#/?devType=org&api=robot_1.0%23OrgGroupSend文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-494333.html
2.7引入POM依賴
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dingtalk</artifactId>
<version>1.4.44</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-openapi</artifactId>
<version>0.2.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-util</artifactId>
<version>0.2.14</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>openapiutil</artifactId>
<version>0.1.14</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>endpoint-util</artifactId>
<version>0.0.7</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea</artifactId>
<version>1.1.14</version>
</dependency>
2.8接口代碼示例
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
com.aliyun.dingtalkrobot_1_0.Client client = new com.aliyun.dingtalkrobot_1_0.Client(config);
OrgGroupSendHeaders orgGroupSendHeaders = new OrgGroupSendHeaders();
orgGroupSendHeaders.xAcsDingtalkAccessToken = "xxxxxxxxxxxxxxx";
OrgGroupSendRequest orgGroupSendRequest = new OrgGroupSendRequest()
.setMsgParam("{\"content\":\"今天吃肘子\"}")
.setMsgKey("sampleText")
.setOpenConversationId("cid6KeBBLoveMJOGXoYKF5x7EeiodoA==")
.setRobotCode("dingue4kfzdxbynxxxxxx")
.setCoolAppCode("COOLAPP-1-101A83B831A5212Cxxxxxxxxxxx");
try {
client.orgGroupSendWithOptions(orgGroupSendRequest, orgGroupSendHeaders, new RuntimeOptions());
} catch (TeaException err) {
if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
// err 中含有 code 和 message 屬性,可幫助開(kāi)發(fā)定位問(wèn)題
}
} 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 屬性,可幫助開(kāi)發(fā)定位問(wèn)題
}
}
這種方式由于我不是超級(jí)管理員沒(méi)有開(kāi)放平臺(tái)的權(quán)限,所以這個(gè)只是一個(gè)思路,具體的實(shí)踐還得自己去摸索了哈、文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-494333.html
到了這里,關(guān)于釘釘機(jī)器人推送消息的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!