forked from whyiyhw/go-workwx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_info.go
61 lines (55 loc) · 1.35 KB
/
user_info.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
package workwx
// GetUser 读取成员
func (c *WorkwxApp) GetUser(userid string) (*UserInfo, error) {
resp, err := c.execUserGet(reqUserGet{
UserID: userid,
})
if err != nil {
return nil, err
}
obj, err := resp.intoUserInfo()
if err != nil {
return nil, err
}
// TODO: return bare T instead of &T?
return &obj, nil
}
// ListUsersByDeptID 获取部门成员详情
func (c *WorkwxApp) ListUsersByDeptID(deptID int64, fetchChild bool) ([]*UserInfo, error) {
resp, err := c.execUserList(reqUserList{
DeptID: deptID,
FetchChild: fetchChild,
})
if err != nil {
return nil, err
}
users := make([]*UserInfo, len(resp.Users))
for index, user := range resp.Users {
userInfo, err := user.intoUserInfo()
if err != nil {
return nil, err
}
users[index] = &userInfo
}
return users, nil
}
// GetUserIDByMobile 通过手机号获取 userid
func (c *WorkwxApp) GetUserIDByMobile(mobile string) (string, error) {
resp, err := c.execUserIDByMobile(reqUserIDByMobile{
Mobile: mobile,
})
if err != nil {
return "", err
}
return resp.UserID, nil
}
// GetUserInfoByCode 获取访问用户身份,根据code获取成员信息
func (c *WorkwxApp) GetUserInfoByCode(code string) (*UserIdentityInfo, error) {
resp, err := c.execUserInfoGet(reqUserInfoGet{
Code: code,
})
if err != nil {
return nil, err
}
return &resp.UserIdentityInfo, nil
}