Java對接釘釘考勤記錄的完整步驟
一. 基礎(chǔ)配置
首先需要創(chuàng)建一個
應(yīng)用
進入應(yīng)用中點擊
憑證與基礎(chǔ)信息獲取Client ID (原 AppKey)和Client Secret (原 AppSecret)
修改
權(quán)限管理中 權(quán)限范圍為全部員工, 不然獲取不到數(shù)據(jù)
二. 依賴導(dǎo)入及說明
<!--
說明: 下面的兩個釘釘依賴目前來說都需要, 因為新版并沒有完全覆蓋舊版中的功能
(官方說明: 現(xiàn)狀:舊版服務(wù)端API和新版服務(wù)端API開放的產(chǎn)品能力不同,即新版服務(wù)端API未包含全部的服務(wù)端API的產(chǎn)品能力,請根據(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包手動的安裝到本地或者服務(wù)器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
調(diào)試地址:
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
調(diào)試地址:
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
調(diào)試地址:
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
調(diào)試地址:
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
調(diào)試地址:
https://open-dev.dingtalk.com/apiExplorer?spm=ding_open_doc.document.0.0.35c53ca7OHAOZj#/?devType=org&api=dingtalk.oapi.v2.user.get
6. 獲取打卡結(jié)果
接口地址:
https://open.dingtalk.com/document/orgapp/open-attendance-clock-in-data
調(diào)試地址:
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
調(diào)試地址:
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
調(diào)試地址:
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
調(diào)試地址:
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();
//事件產(chǎn)生時間
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();
}
}
總結(jié)
到此這篇關(guān)于Java對接釘釘考勤記錄的文章就介紹到這了,更多相關(guān)Java對接釘釘考勤記錄內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java API方式調(diào)用Kafka各種協(xié)議的方法
本篇文章主要介紹了Java API方式調(diào)用Kafka各種協(xié)議的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09
深入理解happens-before和as-if-serial語義
本文大部分整理自《Java并發(fā)編程的藝術(shù)》,溫故而知新,加深對基礎(chǔ)的理解程度。下面可以和小編來一起學(xué)習(xí)下2019-05-05
解決遇到Cannot resolve ch.qos.logback:logback-classic:
當(dāng)使用Maven配置項目依賴時,可能會遇到無法解析特定版本的錯誤,例如,logback-classic版本1.2.3可能無法在配置的倉庫中找到,解決方法包括檢查倉庫是否包含所需版本,或更新到其他可用版本,可通過Maven官網(wǎng)搜索并找到適用的版本,替換依賴配置中的版本信息2024-09-09





