-
Notifications
You must be signed in to change notification settings - Fork 10
/
api_user_caller.go
185 lines (173 loc) · 5.73 KB
/
api_user_caller.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package sdk
import (
"github.com/polaris-team/dingtalk-sdk-golang/http"
"github.com/polaris-team/dingtalk-sdk-golang/json"
"strconv"
)
//Desc: 获取用户详情
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetUserDetail(userId string, lang *string) (GetUserDetailResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"userid": userId,
}
if lang != nil {
params["lang"] = *lang
}
body, err := http.Get("https://oapi.dingtalk.com/user/get", params)
resp := GetUserDetailResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//Desc: 获取部门用户userid列表
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetDepMemberIds(deptId string) (GetDepMemberIdsResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"deptId": deptId,
}
body, err := http.Get("https://oapi.dingtalk.com/user/getDeptMember", params)
resp := GetDepMemberIdsResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
func (client *DingTalkClient) BaseGetDepMemberList(url string, deptId string, lang string, offset int64, size int64, order string) (GetDepMemberListResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"department_id": deptId,
}
if lang != "" {
params["lang"] = lang
}
if offset > -1 && size > 0 {
params["offset"] = strconv.FormatInt(offset, 10)
params["size"] = strconv.FormatInt(size, 10)
}
if order != "" {
params["order"] = order
}
body, err := http.Get(url, params)
resp := GetDepMemberListResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//Desc: 获取部门用户
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetDepMemberList(deptId string, lang string, offset int64, size int64, order string) (GetDepMemberListResp, error) {
return client.BaseGetDepMemberList("https://oapi.dingtalk.com/user/simplelist", deptId, lang, offset, size, order)
}
//Desc: 获取部门用户详情
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetDepMemberDetailList(deptId string, lang string, offset int64, size int64, order string) (GetDepMemberListResp, error) {
return client.BaseGetDepMemberList("https://oapi.dingtalk.com/user/listbypage", deptId, lang, offset, size, order)
}
//Desc: 获取管理员列表
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetAdminList() (GetAdminListResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
}
body, err := http.Get("https://oapi.dingtalk.com/user/get_admin", params)
resp := GetAdminListResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//Desc: 获取管理员通讯录权限范围
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetAdminScope(adminId string) (GetAdminScopeResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"userid": adminId,
}
body, err := http.Get("https://oapi.dingtalk.com/topapi/user/get_admin_scope", params)
resp := GetAdminScopeResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//Desc: 查询管理员是否具备管理某个应用的权限
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) CanAccessMicroApp(adminId string, appId string) (CanAccessMicroAppResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"userId": adminId,
"appId": appId,
}
body, err := http.Get("https://oapi.dingtalk.com/user/can_access_microapp", params)
resp := CanAccessMicroAppResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//Desc: 根据unionid获取userid
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetUserIdByUnionId(unionId string) (GetUserIdByUnionIdResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"unionid": unionId,
}
body, err := http.Get("https://oapi.dingtalk.com/user/getUseridByUnionid", params)
resp := GetUserIdByUnionIdResp{}
if err != nil {
return resp, err
}
json.FromJson(body, &resp)
return resp, err
}
//Desc: 获取企业员工人数
//Doc: https://open-doc.dingtalk.com/microapp/serverapi3/momrx5
func (client *DingTalkClient) GetOrgUserCount(onlyActive int) (GetOrgUserCountResp, error) {
params := map[string]string{
"access_token": client.AccessToken,
"onlyActive": strconv.Itoa(onlyActive),
}
body, err := http.Get("https://oapi.dingtalk.com/user/get_org_user_count", params)
resp := GetOrgUserCountResp{}
if err != nil {
return resp, err
}
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
}