-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser.go
103 lines (86 loc) · 2.96 KB
/
user.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
package dingtalk
import (
"net/http"
)
// 根据userid获取用户详情 https://developers.dingtalk.com/document/app/query-user-details
func (c *Client) GetUserInfo(params *GetUserInfoParams) (*GetUserInfoRes, *http.Response, error) {
req, err := c.NewRequest(http.MethodPost, "/topapi/v2/user/get", nil, params)
if err != nil {
return nil, nil, err
}
var data *GetUserInfoRes
resp, err := c.Do(req, &data)
if err != nil {
return nil, resp, err
}
return data, resp, nil
}
// 获取部门用户详情 https://developers.dingtalk.com/document/app/queries-the-complete-information-of-a-department-user
func (c *Client) GetUserInfoWithDepartment(params *GetUserInfoWithDepartmentParams) (*GetUserInfoWithDepartmentRes, *http.Response, error) {
req, err := c.NewRequest(http.MethodPost, "/topapi/v2/user/list", nil, params)
if err != nil {
return nil, nil, err
}
var data *GetUserInfoWithDepartmentRes
resp, err := c.Do(req, &data)
if err != nil {
return nil, resp, err
}
return data, resp, err
}
// 获取部门用户userid列表 https://developers.dingtalk.com/document/app/query-the-list-of-department-userids
func (c *Client) GetUserIdWithDepartment(params *GetUserIdWithDepartmentParams) (*GetUserIdWithDepartmentRes, *http.Response, error) {
req, err := c.NewRequest(http.MethodPost, "/topapi/user/listid", nil, params)
if err != nil {
return nil, nil, err
}
var data *GetUserIdWithDepartmentRes
resp, err := c.Do(req, &data)
if err != nil {
return nil, resp, err
}
return data, resp, err
}
// 根据unionid获取userid https://open.dingtalk.com/document/orgapp-server/query-a-user-by-the-union-id
func (c *Client) GetUserIdByUnionid(unionid string) (data *GetUseridByUnionidRes, resp *http.Response, err error) {
body := struct {
Unionid string `json:"unionid"`
}{unionid}
req, err := c.NewRequest(http.MethodPost, "/topapi/user/getbyunionid", nil, body)
if err != nil {
return nil, nil, err
}
resp, err = c.Do(req, &data)
if err != nil {
return nil, resp, err
}
return
}
// 根据免登码获取用户信息 https://open.dingtalk.com/document/orgapp-server/query-a-user-by-the-union-id
func (c *Client) GetUserInfoByCode(code string) (data *GetUserinfoByCodeRes, resp *http.Response, err error) {
body := struct {
Code string `json:"code"`
}{code}
req, err := c.NewRequest(http.MethodPost, "/topapi/v2/user/getuserinfo", nil, body)
if err != nil {
return nil, nil, err
}
resp, err = c.Do(req, &data)
if err != nil {
return nil, resp, err
}
return
}
// 根据手机号获取用户id https://open.dingtalk.com/document/orgapp/query-users-by-phone-number
func (c *Client) GetUserInfoByMobile(params *GetUserinfoByMobileParams) (*GetUserinfoByMobileRes, *http.Response, error) {
req, err := c.NewRequest(http.MethodPost, "/topapi/v2/user/getbymobile", nil, params)
if err != nil {
return nil, nil, err
}
var data *GetUserinfoByMobileRes
resp, err := c.Do(req, &data)
if err != nil {
return nil, resp, err
}
return data, resp, nil
}