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
|
1 |
|
public function __construct(ServiceContainer $app) |
31
|
|
|
{ |
32
|
1 |
|
parent::__construct($app, $app['provider_access_token']); |
33
|
1 |
|
} |
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
|
|
|
$redirectUri || $redirectUri = $this->app->config['redirect_uri_single']; |
47
|
|
|
$state || $state = rand(); |
|
|
|
|
48
|
|
|
$params = [ |
|
|
|
|
49
|
|
|
'appid' => $this->app['config']['corp_id'], |
50
|
|
|
'redirect_uri' => $redirectUri, |
51
|
|
|
'usertype' => $userType, |
52
|
|
|
'state' => $state, |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?'.http_build_query($params); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* 单点登录 - 获取登录用户信息. |
60
|
|
|
* |
61
|
|
|
* @param string $authCode |
62
|
|
|
* |
63
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
64
|
|
|
* |
65
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
66
|
|
|
*/ |
67
|
|
|
public function getLoginInfo(string $authCode) |
68
|
|
|
{ |
69
|
|
|
$params = [ |
70
|
|
|
'auth_code' => $authCode, |
71
|
|
|
]; |
72
|
|
|
|
73
|
|
|
return $this->httpPostJson('cgi-bin/service/get_login_info', $params); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* 获取注册定制化URL. |
78
|
|
|
* |
79
|
|
|
* @param string $registerCode |
80
|
|
|
* |
81
|
|
|
* @return string |
82
|
|
|
* |
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
|
|
|
|
90
|
|
|
return 'https://open.work.weixin.qq.com/3rdservice/wework/register?'.http_build_query($params); |
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
|
|
|
$params = []; |
|
|
|
|
112
|
|
|
$params['template_id'] = $this->app['config']['reg_template_id']; |
|
|
|
|
113
|
|
|
!empty($corpName) && $params['corp_name'] = $corpName; |
|
|
|
|
114
|
|
|
!empty($adminName) && $params['admin_name'] = $adminName; |
|
|
|
|
115
|
|
|
!empty($adminMobile) && $params['admin_mobile'] = $adminMobile; |
116
|
|
|
!empty($state) && $params['state'] = $state; |
|
|
|
|
117
|
|
|
|
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
|
|
|
|
138
|
|
|
return $this->httpPostJson('cgi-bin/service/get_register_info', $params); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* 设置授权应用可见范围. |
143
|
|
|
* |
144
|
|
|
* Desc:调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。 |
145
|
|
|
* 企业注册初始化安装应用后,应用默认可见范围为根部门。 |
146
|
|
|
* 如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。 |
147
|
|
|
* 该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。 |
148
|
|
|
* 调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。 |
149
|
|
|
* |
150
|
|
|
* @param string $accessToken |
151
|
|
|
* @param string $agentId |
152
|
|
|
* @param array $allowUser |
153
|
|
|
* @param array $allowParty |
154
|
|
|
* @param array $allowTag |
155
|
|
|
* |
156
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
157
|
|
|
* |
158
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
159
|
|
|
*/ |
160
|
|
|
public function setAgentScope( |
161
|
|
|
string $accessToken, |
162
|
|
|
string $agentId, |
163
|
|
|
array $allowUser = [], |
164
|
|
|
array $allowParty = [], |
165
|
|
|
array $allowTag = [] |
166
|
|
|
) { |
167
|
|
|
$params = [ |
168
|
|
|
'agentid' => $agentId, |
169
|
|
|
'allow_user' => $allowUser, |
170
|
|
|
'allow_party' => $allowParty, |
171
|
|
|
'allow_tag' => $allowTag, |
172
|
|
|
'access_token' => $accessToken, |
173
|
|
|
]; |
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
|
|
|
|
193
|
|
|
return $this->httpGet('cgi-bin/sync/contact_sync_success', $params); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
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.