-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathapi_contact.go
146 lines (129 loc) · 3.36 KB
/
api_contact.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
141
142
143
144
145
146
package godingtalk
import (
"fmt"
"net/url"
)
type User struct {
OAPIResponse
Userid string
Name string
Mobile string
Tel string
Remark string
Order int
IsAdmin bool
IsBoss bool
IsLeader bool
Active bool
Department []int
Position string
Email string
OrgEmail string
Avatar string
Extattr interface{}
}
type UserList struct {
OAPIResponse
HasMore bool
Userlist []User
}
type Department struct {
OAPIResponse
Id int
Name string
ParentId int
Order int
DeptPerimits string
UserPerimits string
OuterDept bool
OuterPermitDepts string
OuterPermitUsers string
OrgDeptOwner string
DeptManagerUseridList string
}
type DepartmentList struct {
OAPIResponse
Departments []Department `json:"department"`
}
// DepartmentList is 获取部门列表
func (c *DingTalkClient) DepartmentList() (DepartmentList, error) {
var data DepartmentList
err := c.httpRPC("department/list", nil, nil, &data)
return data, err
}
//DepartmentDetail is 获取部门详情
func (c *DingTalkClient) DepartmentDetail(id int) (Department, error) {
var data Department
params := url.Values{}
params.Add("id", fmt.Sprintf("%d", id))
err := c.httpRPC("department/get", params, nil, &data)
return data, err
}
//UserList is 获取部门成员
func (c *DingTalkClient) UserList(departmentID, offset, size int) (UserList, error) {
var data UserList
if size > 100 {
return data, fmt.Errorf("size 最大100")
}
params := url.Values{}
params.Add("department_id", fmt.Sprintf("%d", departmentID))
params.Add("offset", fmt.Sprintf("%d", offset))
params.Add("size", fmt.Sprintf("%d", size))
err := c.httpRPC("user/list", params, nil, &data)
return data, err
}
//CreateChat is
func (c *DingTalkClient) CreateChat(name string, owner string, useridlist []string) (string, error) {
var data struct {
OAPIResponse
Chatid string
}
request := map[string]interface{}{
"name": name,
"owner": owner,
"useridlist": useridlist,
}
err := c.httpRPC("chat/create", nil, request, &data)
return data.Chatid, err
}
//UserInfoByCode 校验免登录码并换取用户身份
func (c *DingTalkClient) UserInfoByCode(code string) (User, error) {
var data User
params := url.Values{}
params.Add("code", code)
err := c.httpRPC("user/getuserinfo", params, nil, &data)
return data, err
}
//UserInfoByUserId 获取用户详情
func (c *DingTalkClient) UserInfoByUserId(userid string) (User, error) {
var data User
params := url.Values{}
params.Add("userid", userid)
err := c.httpRPC("user/get", params, nil, &data)
return data, err
}
//UseridByUnionId 通过UnionId获取玩家Userid
func (c *DingTalkClient) UseridByUnionId(unionid string) (string, error) {
var data struct {
OAPIResponse
UserID string `json:"userid"`
}
params := url.Values{}
params.Add("unionid", unionid)
err := c.httpRPC("user/getUseridByUnionid", params, nil, &data)
if err != nil {
return "", err
}
return data.UserID, err
}
//UseridByMobile 通过手机号获取Userid
func (c *DingTalkClient) UseridByMobile(mobile string) (string, error) {
var data struct {
OAPIResponse
UserID string `json:"userid"`
}
params := url.Values{}
params.Add("mobile", mobile)
err := c.httpRPC("user/get_by_mobile", params, nil, &data)
return data.UserID, err
}