Skip to content

Commit

Permalink
新增获取部门用户V2接口
Browse files Browse the repository at this point in the history
  • Loading branch information
ainilili committed Jul 9, 2021
1 parent 652d2b7 commit 674f415
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sdk/api_auth_caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions sdk/api_dept_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sdk/api_dept_caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
27 changes: 27 additions & 0 deletions sdk/api_user_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions sdk/api_user_caller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
40 changes: 40 additions & 0 deletions sdk/api_user_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
1 change: 1 addition & 0 deletions sdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Corp struct {
}

type DingTalkClient struct {
AccessKey string
AccessToken string
AgentId int64
}
Expand Down

0 comments on commit 674f415

Please sign in to comment.