-
Notifications
You must be signed in to change notification settings - Fork 170
/
user_info.go
140 lines (128 loc) · 3.48 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
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
package workwx
// UserDetail 成员详细信息的公共字段
type UserDetail struct {
UserID string `json:"userid"`
Name string `json:"name,omitempty"`
DeptIDs []int64 `json:"department"`
DeptOrder []uint32 `json:"order"`
Position string `json:"position"`
Mobile string `json:"mobile,omitempty"`
Gender string `json:"gender,omitempty"`
Email string `json:"email,omitempty"`
IsLeaderInDept []int `json:"is_leader_in_dept"`
AvatarURL string `json:"avatar"`
Telephone string `json:"telephone"`
IsEnabled int `json:"enable"`
Alias string `json:"alias"`
Status int `json:"status"`
QRCodeURL string `json:"qr_code"`
// TODO: extattr external_profile external_position
}
// 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
}
// UpdateUser 更新成员
func (c *WorkwxApp) UpdateUser(userDetail *UserDetail) error {
_, err := c.execUserUpdate(reqUserUpdate{
UserDetail: userDetail,
})
if err != nil {
return err
}
return 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
}
// ConvertUserIDToOpenID userid转openid
func (c *WorkwxApp) ConvertUserIDToOpenID(userID string) (string, error) {
resp, err := c.execConvertUserIDToOpenID(reqConvertUserIDToOpenID{
UserID: userID,
})
if err != nil {
return "", err
}
return resp.OpenID, nil
}
// ConvertOpenIDToUserID openid转userid
func (c *WorkwxApp) ConvertOpenIDToUserID(openID string) (string, error) {
resp, err := c.execConvertOpenIDToUserID(reqConvertOpenIDToUserID{
OpenID: openID,
})
if err != nil {
return "", err
}
return resp.UserID, nil
}
// GetUserJoinQrcode 获取加入企业二维码
func (c *WorkwxApp) GetUserJoinQrcode(sizeType SizeType) (string, error) {
resp, err := c.execUserJoinQrcode(reqUserJoinQrcode{
SizeType: sizeType,
})
if err != nil {
return "", err
}
return resp.JoinQrcode, 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
}
// GetUserIDByEmail 通过邮箱获取 userid
func (c *WorkwxApp) GetUserIDByEmail(email string, emailType EmailType) (string, error) {
if emailType == 0 {
emailType = EmailTypeCorporate
}
resp, err := c.execUserIDByEmail(reqUserIDByEmail{
Email: email,
EmailType: emailType,
})
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
}