diff --git a/sdk/api_auth_caller_test.go b/sdk/api_auth_caller_test.go index 715f344..c317d74 100644 --- a/sdk/api_auth_caller_test.go +++ b/sdk/api_auth_caller_test.go @@ -11,7 +11,7 @@ import ( func CreateCorp() *Corp { os.Setenv("SUITE_KEY", "suiteocpiljyoalvbhrbi") os.Setenv("SUITE_SECRET", "d1XKtyVpocDrOVJrDqPfqysmLGX7pinWS7iA8l5T7OWPd8aWZWNRfXEJrHoyb5Ng") - return NewCorp("xxx", "dingf877c5d6d03a678aa1320dcb25e91351") + return NewCorp("xxx", "ding696a8496a96bcf58a1320dcb25e91351") } //Create Client just for test diff --git a/sdk/api_dept_caller.go b/sdk/api_dept_caller.go index cfc5c32..76e636e 100644 --- a/sdk/api_dept_caller.go +++ b/sdk/api_dept_caller.go @@ -24,16 +24,21 @@ func (client *DingTalkClient) GetSubDept(id string) (GetSubdeptResp, error) { //获取部门列表 //https://open-doc.dingtalk.com/microapp/serverapi3/fuqv8x#-1 -func (client *DingTalkClient) GetDeptList(lang *string, fetchChild *bool, id string) (GetDeptListResp, error) { +func (client *DingTalkClient) GetDeptList(lang *string, fetchChild bool, id string) (GetDeptListResp, error) { params := map[string]string{ "access_token": client.AccessToken, - "id": id, + } + if id != "" { + params["id"] = id } if lang != nil { params["lang"] = *lang } - if *fetchChild != false { + + if fetchChild { params["fetch_child"] = "true" + } else { + params["fetch_child"] = "false" } body, err := http.Get("https://oapi.dingtalk.com/department/list", params) diff --git a/sdk/api_dept_caller_test.go b/sdk/api_dept_caller_test.go index 4d7973e..2e503f1 100644 --- a/sdk/api_dept_caller_test.go +++ b/sdk/api_dept_caller_test.go @@ -13,7 +13,7 @@ func TestGetSubDept(t *testing.T) { func TestGetDeptList(t *testing.T) { fetchChild := false - resp, err := CreateClient().GetDeptList(nil, &fetchChild, "1") + resp, err := CreateClient().GetDeptList(nil, fetchChild, "1") t.Log(json.ToJson(resp)) t.Log(err) } diff --git a/sdk/api_user_caller.go b/sdk/api_user_caller.go index d313d30..78a9c74 100644 --- a/sdk/api_user_caller.go +++ b/sdk/api_user_caller.go @@ -156,3 +156,30 @@ func (client *DingTalkClient) GetOrgUserCount(onlyActive int) (GetOrgUserCountRe json.FromJson(body, &resp) return resp, err } + +func (client *DingTalkClient) GetDeptUserListV2(deptId int64, cursor int64, size int, orderField string, containAccessLimit *bool, language string) (GetDeptUserListV2Resp, error) { + params := map[string]string{ + "access_token": client.AccessToken, + } + reqBody := map[string]interface{}{} + reqBody["dept_id"] = deptId + reqBody["cursor"] = cursor + reqBody["size"] = size + if orderField != "" { + reqBody["order_field"] = orderField + } + if containAccessLimit != nil { + reqBody["contain_access_limit"] = *containAccessLimit + } + if language != "" { + reqBody["language"] = language + } + reqBodyJson, _ := json.ToJson(reqBody) + body, err := http.Post("https://oapi.dingtalk.com/topapi/v2/user/list", params, reqBodyJson) + resp := GetDeptUserListV2Resp{} + if err != nil { + return resp, err + } + _ = json.FromJson(body, &resp) + return resp, err +} diff --git a/sdk/api_user_caller_test.go b/sdk/api_user_caller_test.go index 639cb53..f40b3ef 100644 --- a/sdk/api_user_caller_test.go +++ b/sdk/api_user_caller_test.go @@ -61,3 +61,8 @@ func TestDingTalkClient_GetOrgUserCount(t *testing.T) { resp, _ = CreateClient().GetOrgUserCount(1) t.Log(json.ToJson(resp)) } + +func TestDingTalkClient_GetDeptUserListV2(t *testing.T) { + resp, _ := CreateClient().GetDeptUserListV2(1, 0, 10, "", nil, "") + t.Log(json.ToJson(resp)) +} diff --git a/sdk/api_user_models.go b/sdk/api_user_models.go index 67916c2..3aadb9f 100644 --- a/sdk/api_user_models.go +++ b/sdk/api_user_models.go @@ -84,3 +84,43 @@ type UserDetailRole struct { Name string `json:"name"` GroupName string `json:"groupName"` } + +type GetDeptUserListV2Resp struct { + BaseResp + + Result GetDeptUserListV2RespResult `json:"result"` +} + +type GetDeptUserListV2RespResult struct { + HasMore bool `json:"has_more"` + NextCursor int64 `json:"nextCursor"` + List []UserDetailInfoV2 `json:"list"` +} + +type UserDetailInfoV2 struct { + UserID string `json:"userid"` + UnionID string `json:"unionid"` + Name string `json:"name"` + Avatar string `json:"avatar"` + StateCode string `json:"state_code"` + Mobile string `json:"mobile"` + HideMobile bool `json:"hide_mobile"` + Telephone string `json:"telephone"` + JobNumber string `json:"job_number"` + Title string `json:"title"` + Email string `json:"email"` + OrgEmail string `json:"org_email"` + WorkPlace string `json:"work_place"` + Remark string `json:"remark"` + DeptIdList []int64 `json:"dept_id_list"` + DeptOrder int64 `json:"dept_order"` + Extension string `json:"extension"` + HiredDate int64 `json:"hired_date"` + Active bool `json:"active"` + Admin bool `json:"admin"` + Boss bool `json:"boss"` + Leader bool `json:"leader"` + ExclusiveAccount bool `json:"exclusive_account"` + LoginId string `json:"login_id"` + ExclusiveAccountType string `json:"exclusive_account_type"` +} diff --git a/sdk/sdk.go b/sdk/sdk.go index c9788b3..f490c9a 100644 --- a/sdk/sdk.go +++ b/sdk/sdk.go @@ -25,6 +25,7 @@ type Corp struct { } type DingTalkClient struct { + AccessKey string AccessToken string AgentId int64 }