Java對接釘釘考勤記錄的完整步驟
一. 基礎配置
首先需要創(chuàng)建一個
應用
進入應用中點擊
憑證與基礎信息獲取Client ID (原 AppKey)和Client Secret (原 AppSecret)
修改
權限管理中 權限范圍為全部員工, 不然獲取不到數(shù)據(jù)
二. 依賴導入及說明
<!--
說明: 下面的兩個釘釘依賴目前來說都需要, 因為新版并沒有完全覆蓋舊版中的功能
(官方說明: 現(xiàn)狀:舊版服務端API和新版服務端API開放的產品能力不同,即新版服務端API未包含全部的服務端API的產品能力,請根據(jù)實際需求,選擇需要的API接入)
資料鏈接: https://open.dingtalk.com/document/orgapp/differences-between-server-apis-and-new-server-apis?spm=ding_open_doc.document.0.0.200e2b49DAUrx4
-->
<!-- 釘釘新版SDK模塊 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dingtalk</artifactId>
<version>2.2.33</version>
</dependency>
<!-- 釘釘舊版SDK模塊 -->
<!--
對于老版本依賴包目前來說還沒有辦法從中央倉庫拉取(中央倉庫版本過舊), 只能通過jar包手動的安裝到本地或者服務器maven倉庫中
詳情請見: https://open.dingtalk.com/document/isvapp/download-the-server-side-sdk-2
下載鏈接: https://open-dev.dingtalk.com/download/openSDK/java?spm=ding_open_doc.document.0.0.2ce83ca70MjetW
-->
<dependency>
<groupId>com.taobao.sdk</groupId>
<artifactId>taobao-sdk-java-auto</artifactId>
<version>2025.07.17</version>
</dependency>
<!-- 釘釘Stream模塊 用于推送和訂閱消息 -->
<dependency>
<groupId>com.dingtalk.open</groupId>
<artifactId>app-stream-client</artifactId>
<version>1.3.6</version>
</dependency>
三. 獲取用戶考勤情況
下面提供了兩種實現(xiàn)方案. 每日統(tǒng)計 和 考勤統(tǒng)計
每日統(tǒng)計: 需要每天上下班的數(shù)據(jù)
考勤統(tǒng)計: 需要本月的指定員工指定時間范圍的考勤統(tǒng)計
注: 對于考勤統(tǒng)計中需要的用戶信息可以參考每日統(tǒng)計
對于已有 用戶名稱只需要獲取userId的情況可以嘗試通過下方接口獲取
0. 搜索用戶userId (通過用戶姓名獲取用戶ID)
接口地址:
https://open.dingtalk.com/document/orgapp/address-book-search-user-id
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=contact_1.0%23SearchUser
示例: 搜索姓名為
午后的員工
經(jīng)測試該接口模糊匹配存在問題, 建議通過fullMatchField = 1精確
每日統(tǒng)計
1. 獲取部門列表
接口地址:
https://open.dingtalk.com/document/orgapp/obtain-the-department-list-v2
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.7408441ceuCNWZ#/?devType=org&api=dingtalk.oapi.v2.department.listsub
2. 獲取部門的子部門列表
接口地址:
https://open.dingtalk.com/document/orgapp/obtain-a-sub-department-id-list-v2
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.7408441ceuCNWZ#/?devType=org&api=dingtalk.oapi.v2.department.listsubid
3. 獲取部門用戶userid列表
接口地址:
https://open.dingtalk.com/document/orgapp/query-the-list-of-department-userids
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.7408441ceuCNWZ#/?devType=org&api=dingtalk.oapi.user.listid
4. 根據(jù)系統(tǒng)中的用戶ID查詢用戶信息
接口地址:
https://open.dingtalk.com/document/orgapp/query-user-details
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=dingtalk.oapi.v2.user.get
6. 獲取打卡結果
接口地址:
https://open.dingtalk.com/document/orgapp/open-attendance-clock-in-data
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=dingtalk.oapi.attendance.list
7. 獲取打卡詳情
接口地址:
https://open.dingtalk.com/document/orgapp/attendance-clock-in-record-is-open
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=dingtalk.oapi.attendance.listRecord

考勤統(tǒng)計(可指定時間范圍)
1. 獲取考勤報表列定義(用于在獲取考勤報表列值制定獲取的數(shù)據(jù)項)
接口地址:
https://open.dingtalk.com/document/orgapp/queries-the-enterprise-attendance-report-column
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=dingtalk.oapi.attendance.getattcolumns
2. 獲取考勤報表列值
接口地址:
https://open.dingtalk.com/document/orgapp/queries-the-column-value-of-the-attendance-report
調試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=dingtalk.oapi.attendance.getcolumnval

測試用例
/**
* @author : Cookie
* date : 2025/8/8
*/
public class DingDingAPITest {
private final String appKey = "dingxw1111111kgdb";
private final String appSecret = "2hN-XXSu7BwpLUSRbvGdeNvEMrfKHjy_1111111111111ThLwYqHFLrL";
/**
* 通過appKey和appSecret獲取access_token
*/
@Test
public void getAccessTokenTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
OapiGettokenRequest req = new OapiGettokenRequest();
req.setAppkey(appKey);
req.setAppsecret(appSecret);
req.setHttpMethod("GET");
OapiGettokenResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 獲取部門列表
*/
@Test
public void getDepartmentListTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
OapiV2DepartmentListsubResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 獲取部門的子部門列表
*/
@Test
public void getMessageTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
req.setDeptId(664446160L);
OapiV2DepartmentListsubidResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 獲取部門用戶userid列表
*/
@Test
public void userIdList() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listid");
OapiUserListidRequest req = new OapiUserListidRequest();
req.setDeptId(664286346L);
OapiUserListidResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 根據(jù)系統(tǒng)中的用戶ID查詢用戶信息
*/
@Test
public void getUserInfoTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
OapiV2UserGetRequest req = new OapiV2UserGetRequest();
req.setUserid("1912096523433372683");
OapiV2UserGetResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 獲取企業(yè)考勤報表列
*/
@Test
public void getAttendanceColumnsTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getattcolumns");
OapiAttendanceGetattcolumnsRequest req = new OapiAttendanceGetattcolumnsRequest();
OapiAttendanceGetattcolumnsResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 獲取考勤報表列定義
*/
@Test
public void getAttendanceRecordColumnsTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getattcolumns");
OapiAttendanceGetattcolumnsRequest req = new OapiAttendanceGetattcolumnsRequest();
OapiAttendanceGetattcolumnsResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 指定用戶考勤查詢
*/
@Test
public void getAttendanceRecordTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
req.setUserid("022762312345635565");
req.setColumnIdList("281432955,281432956,281432958,281432961");
req.setFromDate(StringUtils.parseDateTime("2025-07-01 08:00:00"));
req.setToDate(StringUtils.parseDateTime("2025-07-31 20:00:00"));
OapiAttendanceGetcolumnvalResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 獲取打卡詳情
*/
@Test
public void getCheckinRecordTest() {
try {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/attendance/listRecord");
OapiAttendanceListRecordRequest req = new OapiAttendanceListRecordRequest();
req.setUserIds(Arrays.asList("4952111165934", "0227623222235565", "0225373333171716"));
req.setCheckDateFrom("2025-08-14 08:00:00");
req.setCheckDateTo("2025-08-20 08:00:00");
OapiAttendanceListRecordResponse rsp = client.execute(req, "6d5bd176e2fd3e111111149ae4d104");
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
/**
* 釘釘Stream模塊測試
*/
public static void main(String[] args) throws Exception {
OpenDingTalkStreamClientBuilder
.custom()
.credential(new AuthClientCredential("dingxw1111111kgdb", "2hN-XXSu7BwpLUSRbvGdeNvEMrfKHjy_1111111111111ThLwYqHFLrL"))
//注冊事件監(jiān)聽
.registerAllEventListener(new GenericEventListener() {
public EventAckStatus onEvent(GenericOpenDingTalkEvent event) {
try {
//事件唯一Id
String eventId = event.getEventId();
//事件類型
String eventType = event.getEventType();
//事件產生時間
Long bornTime = event.getEventBornTime();
//獲取事件體
JSONObject bizData = event.getData();
//處理事件
// process(bizData);
System.out.println(bizData);
//消費成功
return EventAckStatus.SUCCESS;
} catch (Exception e) {
//消費失敗
return EventAckStatus.LATER;
}
}
})
.build().start();
}
}
總結
到此這篇關于Java對接釘釘考勤記錄的文章就介紹到這了,更多相關Java對接釘釘考勤記錄內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- docker-compose搭建prometheus+grafana+釘釘告警
- zabbix?6.0?使用?JavaScript?發(fā)出釘釘告警的方法
- SpringBoot-Admin實現(xiàn)微服務監(jiān)控+健康檢查+釘釘告警
- Zabbix 配置釘釘告警功能的實現(xiàn)代碼
- Python腳本構建輕量級監(jiān)控告警體系(郵件/釘釘/企業(yè)微信)
- SpringBoot AOP實現(xiàn)釘釘+企業(yè)微信雙渠道異常告警
- C#調用釘釘API發(fā)送通知的實現(xiàn)示例
- Python實現(xiàn)釘釘自動化完整指南
- 基于Python實現(xiàn)開發(fā)釘釘通知機器人
- Golang接入釘釘通知的示例代碼
- Python腳本如何實現(xiàn)監(jiān)控服務器日志異常并通過釘釘推送告警?
相關文章
Java實現(xiàn)經(jīng)典游戲黃金礦工的示例代碼
《黃金礦工》游戲是一個經(jīng)典的抓金子小游戲,它可以鍛煉人的反應能力。本文將用Java實現(xiàn)這一經(jīng)典的游戲,感興趣的小伙伴可以了解一下2022-02-02
Jasypt的StandardPBEByteEncryptor使用源碼解析
這篇文章主要介紹了Jasypt的StandardPBEByteEncryptor使用源碼解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-09-09
Spring AOP之@Around,@AfterReturning使用、切不進去的解決方案
這篇文章主要介紹了Spring AOP之@Around,@AfterReturning使用、切不進去的解決方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-05-05





