Client.php
6.9 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<?php
/*
* This file is part of the overtrue/wechat.
*
* (c) overtrue <i@overtrue.me>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace EasyWeChat\OpenWork\Provider;
use EasyWeChat\Kernel\BaseClient;
use EasyWeChat\Kernel\ServiceContainer;
/**
* Client.
*
* @author xiaomin <keacefull@gmail.com>
*/
class Client extends BaseClient
{
/**
* Client constructor.
*/
public function __construct(ServiceContainer $app)
{
parent::__construct($app, $app['provider_access_token']);
}
/**
* 单点登录 - 获取登录的地址.
*
* @return string
*/
public function getLoginUrl(string $redirectUri = '', string $userType = 'admin', string $state = '')
{
$redirectUri || $redirectUri = $this->app->config['redirect_uri_single'];
$state || $state = rand();
$params = [
'appid' => $this->app['config']['corp_id'],
'redirect_uri' => $redirectUri,
'usertype' => $userType,
'state' => $state,
];
return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?'.http_build_query($params);
}
/**
* 单点登录 - 获取登录用户信息.
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getLoginInfo(string $authCode)
{
$params = [
'auth_code' => $authCode,
];
return $this->httpPostJson('cgi-bin/service/get_login_info', $params);
}
/**
* 获取注册定制化URL.
*
* @return string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
*/
public function getRegisterUri(string $registerCode = '')
{
if (!$registerCode) {
/** @var array $response */
$response = $this->detectAndCastResponseToType($this->getRegisterCode(), 'array');
$registerCode = $response['register_code'];
}
$params = ['register_code' => $registerCode];
return 'https://open.work.weixin.qq.com/3rdservice/wework/register?'.http_build_query($params);
}
/**
* 获取注册码.
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getRegisterCode(
string $corpName = '',
string $adminName = '',
string $adminMobile = '',
string $state = ''
) {
$params = [];
$params['template_id'] = $this->app['config']['reg_template_id'];
!empty($corpName) && $params['corp_name'] = $corpName;
!empty($adminName) && $params['admin_name'] = $adminName;
!empty($adminMobile) && $params['admin_mobile'] = $adminMobile;
!empty($state) && $params['state'] = $state;
return $this->httpPostJson('cgi-bin/service/get_register_code', $params);
}
/**
* 查询注册状态.
*
* Desc:该API用于查询企业注册状态,企业注册成功返回注册信息.
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getRegisterInfo(string $registerCode)
{
$params = [
'register_code' => $registerCode,
];
return $this->httpPostJson('cgi-bin/service/get_register_info', $params);
}
/**
* 设置授权应用可见范围.
*
* Desc:调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。
* 企业注册初始化安装应用后,应用默认可见范围为根部门。
* 如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。
* 该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。
* 调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
*/
public function setAgentScope(
string $accessToken,
string $agentId,
array $allowUser = [],
array $allowParty = [],
array $allowTag = []
) {
$params = [
'agentid' => $agentId,
'allow_user' => $allowUser,
'allow_party' => $allowParty,
'allow_tag' => $allowTag,
'access_token' => $accessToken,
];
return $this->httpGet('cgi-bin/agent/set_scope', $params);
}
/**
* 设置通讯录同步完成.
*
* Desc:该API用于设置通讯录同步完成,解除通讯录锁定状态,同时使通讯录迁移access_token失效。
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
*
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
*/
public function contactSyncSuccess(string $accessToken)
{
$params = ['access_token' => $accessToken];
return $this->httpGet('cgi-bin/sync/contact_sync_success', $params);
}
/**
* 通讯录单个搜索
*
* @param string $queryWord
* @param $agentId
* @param int $offset
* @param int $limit
* @param int $queryType
* @param null $fullMatchField
*
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function searchContact(
string $queryWord,
$agentId,
int $offset = 0,
int $limit = 50,
int $queryType = 0,
$fullMatchField = null
) {
$params = [];
$params['auth_corpid'] = $this->app['config']['corp_id'];
$params['query_word'] = $queryWord;
$params['query_type'] = $queryType;
$params['agentid'] = $agentId;
$params['offset'] = $offset;
$params['limit'] = $limit;
!empty($fullMatchField) && $params['full_match_field'] = $fullMatchField;
return $this->httpPostJson('cgi-bin/service/contact/search', $params);
}
}