-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathContactApi.go
49 lines (44 loc) · 1.44 KB
/
ContactApi.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
package feishuapi
import "github.com/sirupsen/logrus"
type UserInfo struct {
UnionId string
OpenId string
UserId string
Name string
DepartmentIds []interface{}
}
func (c AppClient) UserInfoById(UserId string, IdType UserIdType) *UserInfo {
query := make(map[string]any)
query["user_id_type"] = string(IdType)
data := c.Request("get", "open-apis/contact/v3/users/"+UserId, query, nil, nil)
if data == nil {
logrus.WithField("UserId", UserId).Warn("nil user info return")
return nil
}
user := data["user"].(map[string]interface{})
return &UserInfo{
UnionId: user["union_id"].(string),
OpenId: user["open_id"].(string),
UserId: user["user_id"].(string),
Name: user["name"].(string),
DepartmentIds: user["department_ids"].([]interface{}),
}
}
func (c AppClient) UserInfoByName(name string, userAccessToken string) *UserInfo {
headers := make(map[string]string)
headers["Authorization"] = userAccessToken
query := make(map[string]any)
query["query"] = name
data := c.Request("get", "open-apis/search/v1/user", query, headers, nil)
if data == nil {
logrus.WithField("name", name).Warn("nil user info return")
return nil
}
user := data["user"].(map[string]interface{})
return &UserInfo{
OpenId: user["open_id"].(string),
UserId: user["user_id"].(string),
Name: user["name"].(string),
DepartmentIds: user["department_ids"].([]interface{}),
}
}