@@ -5,17 +5,61 @@ import (
5
5
"fmt"
6
6
"net/http"
7
7
"net/url"
8
+ "strconv"
9
+ "strings"
8
10
)
9
11
10
12
// API地址
11
13
const (
12
14
USER_SIMPLELIST_URL = DINGTALK_API_URL + "/user/simplelist"
15
+ USER_GET_URL = DINGTALK_API_URL + "/user/get"
13
16
)
14
17
18
+ type UserRole struct {
19
+ Id int
20
+ Name string
21
+ GroupName string
22
+ }
23
+
15
24
// 用户
16
25
type User struct {
17
- Userid string
18
- Name string
26
+ Unionid string
27
+ Remark string
28
+ Userid string
29
+ IsLeaderInDepts string
30
+ IsBoss bool
31
+ HiredDate int
32
+ IsSenior bool
33
+ Tel string
34
+ Department []int
35
+ WorkPlace string
36
+ Email string
37
+ OrderInDepts string
38
+ Mobile string
39
+ Errmsg string
40
+ Active bool
41
+ Avatar string
42
+ IsAdmin bool
43
+ IsHide bool
44
+ Jobnumber string
45
+ Name string
46
+ Extattr interface {}
47
+ StateCode string
48
+ Position string
49
+ Roles []UserRole
50
+ }
51
+
52
+ func (u * User ) DeptLeaderInfo () map [int ]bool {
53
+ fragments := strings .Split (u .IsLeaderInDepts [1 :len (u .IsLeaderInDepts )- 1 ], "," )
54
+
55
+ info := make (map [int ]bool )
56
+ for _ , fragment := range fragments {
57
+ kv := strings .Split (fragment , ":" )
58
+ id , _ := strconv .Atoi (kv [0 ])
59
+ info [id ] = kv [1 ] == "true"
60
+ }
61
+ json .Unmarshal ([]byte (u .IsLeaderInDepts ), & info )
62
+ return info
19
63
}
20
64
21
65
// 获取部门列表API的返回数据
@@ -50,3 +94,35 @@ func GetUsers(deptId int) ([]User, error) {
50
94
51
95
return info .UserList , nil
52
96
}
97
+
98
+ // 获取用户详情的API的返回数据
99
+ type UserGetResponse struct {
100
+ CommonResponse
101
+ User
102
+ }
103
+
104
+ // 获取指定用户详情
105
+ func GetUser (userId string ) (User , error ) {
106
+ param := url.Values {
107
+ "access_token" : {accessToken },
108
+ "userid" : {userId },
109
+ }
110
+
111
+ resp , err := http .Get (USER_GET_URL + "?" + param .Encode ())
112
+ if err != nil {
113
+ return User {}, err
114
+ }
115
+ defer resp .Body .Close ()
116
+
117
+ var info UserGetResponse
118
+ err = json .NewDecoder (resp .Body ).Decode (& info )
119
+ if err != nil {
120
+ return User {}, err
121
+ }
122
+
123
+ if err := info .CommonResponse .Error (); err != nil {
124
+ return User {}, err
125
+ }
126
+
127
+ return info .User , nil
128
+ }
0 commit comments