|
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\OpenWork\Provider; |
|
13
|
|
|
|
|
14
|
|
|
use EasyWeChat\Kernel\BaseClient; |
|
15
|
|
|
use EasyWeChat\Kernel\ServiceContainer; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Client. |
|
19
|
|
|
* |
|
20
|
|
|
* @author xiaomin <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class Client extends BaseClient |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Client constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* |
|
28
|
|
|
* @param ServiceContainer $app |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(ServiceContainer $app) |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct($app, $app['provider_access_token']); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* 单点登录 - 获取登录的地址. |
|
37
|
|
|
* |
|
38
|
|
|
* @param string $redirectUri |
|
39
|
|
|
* @param string $userType |
|
40
|
|
|
* @param string $state |
|
41
|
|
|
* |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getLoginUrl(string $redirectUri = '', string $userType = 'admin', string $state = '') |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
$redirectUri || $redirectUri = $this->app->config['redirect_uri_single']; |
|
48
|
|
|
$state || $state = rand(); |
|
|
|
|
|
|
49
|
|
|
$params = [ |
|
|
|
|
|
|
50
|
|
|
'appid' => $this->app['config']['corp_id'], |
|
51
|
|
|
'redirect_uri' => $redirectUri, |
|
52
|
|
|
'usertype' => $userType, |
|
53
|
|
|
'state' => $state |
|
54
|
|
|
]; |
|
55
|
|
|
|
|
56
|
|
|
return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?' . http_build_query($params); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* 单点登录 - 获取登录用户信息. |
|
61
|
|
|
* |
|
62
|
|
|
* @param string $authCode |
|
63
|
|
|
* |
|
64
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
65
|
|
|
* |
|
66
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getLoginInfo(string $authCode) |
|
69
|
|
|
{ |
|
70
|
|
|
$params = [ |
|
71
|
|
|
'auth_code' => $authCode |
|
72
|
|
|
]; |
|
73
|
|
|
return $this->httpPostJson('cgi-bin/service/get_login_info', $params); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* 获取注册定制化URL. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $registerCode |
|
81
|
|
|
* |
|
82
|
|
|
* @return string |
|
83
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getRegisterUri(string $registerCode = '') |
|
86
|
|
|
{ |
|
87
|
|
|
$registerCode || $registerCode = $this->getRegisterCode()['register_code']; |
|
88
|
|
|
$params = ['register_code' => $registerCode]; |
|
|
|
|
|
|
89
|
|
|
return 'https://open.work.weixin.qq.com/3rdservice/wework/register?' . http_build_query($params); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* 获取注册码. |
|
95
|
|
|
* |
|
96
|
|
|
* @param string $corpName |
|
97
|
|
|
* @param string $adminName |
|
98
|
|
|
* @param string $adminMobile |
|
99
|
|
|
* @param string $state |
|
100
|
|
|
* |
|
101
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
102
|
|
|
* |
|
103
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getRegisterCode( |
|
106
|
|
|
string $corpName = '', |
|
107
|
|
|
string $adminName = '', |
|
108
|
|
|
string $adminMobile = '', |
|
109
|
|
|
string $state = '' |
|
110
|
|
|
) |
|
111
|
|
|
{ |
|
112
|
|
|
$params = []; |
|
|
|
|
|
|
113
|
|
|
$params['template_id'] = $this->app['config']['reg_template_id']; |
|
|
|
|
|
|
114
|
|
|
!empty($corpName) && $params['corp_name'] = $corpName; |
|
|
|
|
|
|
115
|
|
|
!empty($adminName) && $params['admin_name'] = $adminName; |
|
|
|
|
|
|
116
|
|
|
!empty($adminMobile) && $params['admin_mobile'] = $adminMobile; |
|
117
|
|
|
!empty($state) && $params['state'] = $state; |
|
|
|
|
|
|
118
|
|
|
return $this->httpPostJson('cgi-bin/service/get_register_code', $params); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* 查询注册状态. |
|
123
|
|
|
* |
|
124
|
|
|
* Desc:该API用于查询企业注册状态,企业注册成功返回注册信息. |
|
125
|
|
|
* |
|
126
|
|
|
* @param string $registerCode |
|
127
|
|
|
* |
|
128
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
129
|
|
|
* |
|
130
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getRegisterInfo(string $registerCode) |
|
133
|
|
|
{ |
|
134
|
|
|
$params = [ |
|
135
|
|
|
'register_code' => $registerCode |
|
136
|
|
|
]; |
|
137
|
|
|
return $this->httpPostJson('cgi-bin/service/get_register_info', $params); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* 设置授权应用可见范围. |
|
142
|
|
|
* |
|
143
|
|
|
* Desc:调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。 |
|
144
|
|
|
* 企业注册初始化安装应用后,应用默认可见范围为根部门。 |
|
145
|
|
|
* 如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。 |
|
146
|
|
|
* 该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。 |
|
147
|
|
|
* 调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。 |
|
148
|
|
|
* |
|
149
|
|
|
* @param string $accessToken |
|
150
|
|
|
* @param string $agentId |
|
151
|
|
|
* @param array $allowUser |
|
152
|
|
|
* @param array $allowParty |
|
153
|
|
|
* @param array $allowTag |
|
154
|
|
|
* |
|
155
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
156
|
|
|
* |
|
157
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
158
|
|
|
*/ |
|
159
|
|
|
|
|
160
|
|
|
public function setAgentScope( |
|
161
|
|
|
string $accessToken, |
|
162
|
|
|
string $agentId, |
|
163
|
|
|
array $allowUser = [], |
|
164
|
|
|
array $allowParty = [], |
|
165
|
|
|
array $allowTag = [] |
|
166
|
|
|
) |
|
167
|
|
|
{ |
|
168
|
|
|
$params = [ |
|
169
|
|
|
"agentid" => $agentId, |
|
|
|
|
|
|
170
|
|
|
"allow_user" => $allowUser, |
|
|
|
|
|
|
171
|
|
|
"allow_party" => $allowParty, |
|
|
|
|
|
|
172
|
|
|
"allow_tag" => $allowTag, |
|
|
|
|
|
|
173
|
|
|
"access_token" => $accessToken |
|
|
|
|
|
|
174
|
|
|
]; |
|
175
|
|
|
return $this->httpGet('cgi-bin/agent/set_scope', $params); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
/** |
|
179
|
|
|
* 设置通讯录同步完成. |
|
180
|
|
|
* |
|
181
|
|
|
* Desc:该API用于设置通讯录同步完成,解除通讯录锁定状态,同时使通讯录迁移access_token失效。 |
|
182
|
|
|
* |
|
183
|
|
|
* @param $accessToken |
|
184
|
|
|
* |
|
185
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
186
|
|
|
* |
|
187
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
188
|
|
|
*/ |
|
189
|
|
|
public function contactSyncSuccess(string $accessToken) |
|
190
|
|
|
{ |
|
191
|
|
|
$params = ['access_token' => $accessToken]; |
|
192
|
|
|
return $this->httpGet('cgi-bin/sync/contact_sync_success', $params); |
|
193
|
|
|
} |
|
194
|
|
|
} |
|
195
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.