|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/wechat. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace EasyWeChat\Work\User; |
|
13
|
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\BaseClient; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class Client. |
|
18
|
|
|
* |
|
19
|
|
|
* @author mingyoung <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Client extends BaseClient |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Create a user. |
|
25
|
|
|
* |
|
26
|
|
|
* @param array $data |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
29
|
|
|
*/ |
|
30
|
1 |
|
public function create(array $data) |
|
31
|
|
|
{ |
|
32
|
1 |
|
return $this->httpPostJson('cgi-bin/user/create', $data); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Update an exist user. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $id |
|
39
|
|
|
* @param array $data |
|
40
|
|
|
* |
|
41
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
42
|
|
|
*/ |
|
43
|
1 |
|
public function update(string $id, array $data) |
|
44
|
|
|
{ |
|
45
|
1 |
|
return $this->httpPostJson('cgi-bin/user/update', array_merge(['userid' => $id], $data)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Delete a user. |
|
50
|
|
|
* |
|
51
|
|
|
* @param string|array $userId |
|
52
|
|
|
* |
|
53
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function delete($userId) |
|
56
|
|
|
{ |
|
57
|
1 |
|
if (is_array($userId)) { |
|
58
|
1 |
|
return $this->batchDelete($userId); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
return $this->httpGet('cgi-bin/user/delete', ['userid' => $userId]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Batch delete users. |
|
66
|
|
|
* |
|
67
|
|
|
* @param array $userIds |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
70
|
|
|
*/ |
|
71
|
1 |
|
public function batchDelete(array $userIds) |
|
72
|
|
|
{ |
|
73
|
1 |
|
return $this->httpPostJson('cgi-bin/user/batchdelete', ['useridlist' => $userIds]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Get user. |
|
78
|
|
|
* |
|
79
|
|
|
* @param string $userId |
|
80
|
|
|
* |
|
81
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function get(string $userId) |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->httpGet('cgi-bin/user/get', ['userid' => $userId]); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get simple user list. |
|
90
|
|
|
* |
|
91
|
|
|
* @param int $departmentId |
|
92
|
|
|
* @param bool $fetchChild |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
95
|
|
|
*/ |
|
96
|
1 |
|
public function getDepartmentUsers(int $departmentId, bool $fetchChild = false) |
|
97
|
|
|
{ |
|
98
|
|
|
$params = [ |
|
99
|
1 |
|
'department_id' => $departmentId, |
|
100
|
1 |
|
'fetch_child' => (int) $fetchChild, |
|
101
|
|
|
]; |
|
102
|
|
|
|
|
103
|
1 |
|
return $this->httpGet('cgi-bin/user/simplelist', $params); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Get user list. |
|
108
|
|
|
* |
|
109
|
|
|
* @param int $departmentId |
|
110
|
|
|
* @param bool $fetchChild |
|
111
|
|
|
* |
|
112
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
113
|
|
|
*/ |
|
114
|
1 |
|
public function getDetailedDepartmentUsers(int $departmentId, bool $fetchChild = false) |
|
115
|
|
|
{ |
|
116
|
|
|
$params = [ |
|
117
|
1 |
|
'department_id' => $departmentId, |
|
118
|
1 |
|
'fetch_child' => (int) $fetchChild, |
|
119
|
|
|
]; |
|
120
|
|
|
|
|
121
|
1 |
|
return $this->httpGet('cgi-bin/user/list', $params); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Convert userId to openid. |
|
126
|
|
|
* |
|
127
|
|
|
* @param string $userId |
|
128
|
|
|
* @param int|null $agentId |
|
129
|
|
|
* |
|
130
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
131
|
|
|
*/ |
|
132
|
1 |
|
public function userIdToOpenid(string $userId, int $agentId = null) |
|
133
|
|
|
{ |
|
134
|
|
|
$params = [ |
|
135
|
1 |
|
'userid' => $userId, |
|
136
|
1 |
|
'agentid' => $agentId, |
|
137
|
|
|
]; |
|
138
|
|
|
|
|
139
|
1 |
|
return $this->httpPostJson('cgi-bin/user/convert_to_openid', $params); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Convert openid to userId. |
|
144
|
|
|
* |
|
145
|
|
|
* @param string $openid |
|
146
|
|
|
* |
|
147
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
148
|
|
|
*/ |
|
149
|
1 |
|
public function openidToUserId(string $openid) |
|
150
|
|
|
{ |
|
151
|
|
|
$params = [ |
|
152
|
1 |
|
'openid' => $openid, |
|
153
|
|
|
]; |
|
154
|
|
|
|
|
155
|
1 |
|
return $this->httpPostJson('cgi-bin/user/convert_to_userid', $params); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Convert mobile to userId. |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $mobile |
|
162
|
|
|
* |
|
163
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
164
|
|
|
* |
|
165
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
166
|
|
|
*/ |
|
167
|
1 |
|
public function mobileToUserId(string $mobile) |
|
168
|
|
|
{ |
|
169
|
|
|
$params = [ |
|
170
|
1 |
|
'mobile' => $mobile, |
|
171
|
|
|
]; |
|
172
|
|
|
|
|
173
|
1 |
|
return $this->httpPostJson('cgi-bin/user/getuserid', $params); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param string $userId |
|
178
|
|
|
* |
|
179
|
|
|
* @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string |
|
180
|
|
|
*/ |
|
181
|
1 |
|
public function accept(string $userId) |
|
182
|
|
|
{ |
|
183
|
|
|
$params = [ |
|
184
|
1 |
|
'userid' => $userId, |
|
185
|
|
|
]; |
|
186
|
|
|
|
|
187
|
1 |
|
return $this->httpGet('cgi-bin/user/authsucc', $params); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|