|
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\Corp; |
|
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
|
|
|
public function __construct(ServiceContainer $app) |
|
25
|
|
|
{ |
|
26
|
|
|
parent::__construct($app, $app['suite_access_token']); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* 企业微信应用授权 url. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string $redirectUri |
|
33
|
|
|
* @param string $state |
|
34
|
|
|
* |
|
35
|
|
|
* @return string |
|
36
|
|
|
* |
|
37
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getPreAuthorizationUrl(string $redirectUri, string $state = '') |
|
40
|
|
|
{ |
|
41
|
|
|
$params = [ |
|
42
|
|
|
'suite_id' => $this->app['config']['suite_id'], |
|
43
|
|
|
'redirect_uri' => $redirectUri, |
|
44
|
|
|
'pre_auth_code' => $this->getPreAuthCode()['pre_auth_code'], |
|
45
|
|
|
'state' => $state || rand(), |
|
46
|
|
|
]; |
|
47
|
|
|
return 'https://open.work.weixin.qq.com/3rdapp/install?' . http_build_query($params); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* 获取预授权码. |
|
53
|
|
|
* |
|
54
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
55
|
|
|
* |
|
56
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getPreAuthCode() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->httpGet('cgi-bin/service/get_pre_auth_code'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* 设置授权配置. |
|
65
|
|
|
* |
|
66
|
|
|
* 该接口可对某次授权进行配置 |
|
67
|
|
|
* |
|
68
|
|
|
* @param array $data |
|
69
|
|
|
* |
|
70
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
71
|
|
|
* |
|
72
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
73
|
|
|
*/ |
|
74
|
|
|
public function setSession(array $data) |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->httpPostJson('cgi-bin/service/set_session_info', compact('data')); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* 获取企业永久授权码. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $authCode 临时授权码,会在授权成功时附加在redirect_uri中跳转回第三方服务商网站,或通过回调推送给服务商。长度为64至512个字节 |
|
83
|
|
|
* |
|
84
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
85
|
|
|
* |
|
86
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
87
|
|
|
*/ |
|
88
|
|
|
public function getPermanentByCode(string $authCode) |
|
89
|
|
|
{ |
|
90
|
|
|
$params = [ |
|
91
|
|
|
'auth_code' => $authCode, |
|
92
|
|
|
]; |
|
93
|
|
|
return $this->httpPostJson('cgi-bin/service/get_permanent_code', $params); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* 获取企业授权信息. |
|
98
|
|
|
* |
|
99
|
|
|
* @param string $authCorpId |
|
100
|
|
|
* @param string $permanentCode |
|
101
|
|
|
* |
|
102
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
103
|
|
|
* |
|
104
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getAuthorization(string $authCorpId, string $permanentCode) |
|
107
|
|
|
{ |
|
108
|
|
|
$params = [ |
|
109
|
|
|
'auth_corpid' => $authCorpId, |
|
110
|
|
|
'permanent_code' => $permanentCode, |
|
111
|
|
|
]; |
|
112
|
|
|
return $this->httpPostJson('cgi-bin/service/get_auth_info', $params); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* 获取应用的管理员列表. |
|
117
|
|
|
* |
|
118
|
|
|
* @param string $authCorpId |
|
119
|
|
|
* @param string $agentId |
|
120
|
|
|
* |
|
121
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
122
|
|
|
* |
|
123
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getManagers(string $authCorpId, string $agentId) |
|
126
|
|
|
{ |
|
127
|
|
|
$params = [ |
|
128
|
|
|
'auth_corpid' => $authCorpId, |
|
129
|
|
|
'agentid' => $agentId |
|
130
|
|
|
]; |
|
131
|
|
|
return $this->httpPostJson('cgi-bin/service/get_admin_lis', $params); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* 获取登录url. |
|
136
|
|
|
* |
|
137
|
|
|
* @param string $redirectUri |
|
138
|
|
|
* @param string $scope |
|
139
|
|
|
* @param string|null $state |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getOAuthRedirectUrl(string $redirectUri, string $scope = 'snsapi_userinfo', string $state = null) |
|
144
|
|
|
{ |
|
145
|
|
|
$params = [ |
|
146
|
|
|
'appid' => $this->app['config']['suite_id'], |
|
147
|
|
|
'redirect_uri' => $redirectUri, |
|
148
|
|
|
'response_type' => 'code', |
|
149
|
|
|
'scope' => $scope, |
|
150
|
|
|
'state' => $state || rand(), |
|
151
|
|
|
]; |
|
152
|
|
|
return 'https://open.weixin.qq.com/connect/oauth2/authorize?' . http_build_query($params) . '#wechat_redirect'; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* 第三方根据code获取企业成员信息. |
|
157
|
|
|
* |
|
158
|
|
|
* @param string $code |
|
159
|
|
|
* |
|
160
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
161
|
|
|
* |
|
162
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
163
|
|
|
*/ |
|
164
|
|
|
public function getUserByCode(string $code) |
|
165
|
|
|
{ |
|
166
|
|
|
$params = [ |
|
167
|
|
|
'code' => $code |
|
168
|
|
|
]; |
|
169
|
|
|
return $this->httpGet('cgi-bin/service/getuserinfo3rd', $params); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* 第三方使用user_ticket获取成员详情. |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $userTicket |
|
176
|
|
|
* |
|
177
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
178
|
|
|
* |
|
179
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
180
|
|
|
*/ |
|
181
|
|
|
public function getUserByTicket(string $userTicket) |
|
182
|
|
|
{ |
|
183
|
|
|
$params = [ |
|
184
|
|
|
'user_ticket' => $userTicket |
|
185
|
|
|
]; |
|
186
|
|
|
return $this->httpPostJson('cgi-bin/service/getuserdetail3rd', $params); |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|