|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EasyWeChat\OpenWork\Provider; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use EasyWeChat\Kernel\BaseClient; |
|
7
|
|
|
use EasyWeChat\Kernel\ServiceContainer; |
|
8
|
|
|
|
|
9
|
|
|
class Client extends BaseClient |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Client constructor. |
|
14
|
|
|
* @param ServiceContainer $app |
|
15
|
|
|
*/ |
|
16
|
|
|
public function __construct(ServiceContainer $app) |
|
17
|
|
|
{ |
|
18
|
|
|
parent::__construct($app, $app['provider_access_token']); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* 单点登录 - 获取登录的地址 |
|
23
|
|
|
* @param string $redirect_uri |
|
24
|
|
|
* @param string $usertype |
|
25
|
|
|
* @param string $state |
|
26
|
|
|
* @return string |
|
27
|
|
|
*/ |
|
28
|
|
|
public function getLoginUrl(string $redirect_uri, string $usertype = 'admin', string $state = '') |
|
29
|
|
|
{ |
|
30
|
|
|
$params = [ |
|
31
|
|
|
'appid' => $this->app['config']['corp_id'], |
|
32
|
|
|
'redirect_uri' => $redirect_uri, |
|
33
|
|
|
'usertype' => $usertype, |
|
34
|
|
|
'state' => $state || rand() |
|
35
|
|
|
]; |
|
36
|
|
|
return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?' . http_build_query($params); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* 单点登录 - 获取登录用户信息 |
|
41
|
|
|
* @param string $auth_code |
|
42
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
43
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function getLoginInfo(string $auth_code) |
|
46
|
|
|
{ |
|
47
|
|
|
$params = [ |
|
48
|
|
|
'auth_code' => $auth_code |
|
49
|
|
|
]; |
|
50
|
|
|
return $this->httpPostJson('cgi-bin/service/get_login_info', $params); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* 获取注册定制化URL |
|
56
|
|
|
* @param $register_code |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getRegisterUri($register_code) |
|
60
|
|
|
{ |
|
61
|
|
|
$params = ['register_code' => $register_code]; |
|
62
|
|
|
return 'https://open.work.weixin.qq.com/3rdservice/wework/register?' . http_build_query($params); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* 获取注册码 |
|
68
|
|
|
* @param string $corp_name |
|
69
|
|
|
* @param string $admin_name |
|
70
|
|
|
* @param string $admin_mobile |
|
71
|
|
|
* @param string $state |
|
72
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
73
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getRegisterCode(string $corp_name = '', string $admin_name = '', string $admin_mobile = '', string $state = '') |
|
76
|
|
|
{ |
|
77
|
|
|
$params = array(); |
|
|
|
|
|
|
78
|
|
|
$params['template_id'] = $this->app['config']['template_id']; |
|
|
|
|
|
|
79
|
|
|
!empty($corp_name) && $params['corp_name'] = $corp_name; |
|
|
|
|
|
|
80
|
|
|
!empty($admin_name) && $params['admin_name'] = $admin_name; |
|
|
|
|
|
|
81
|
|
|
!empty($admin_mobile) && $params['admin_mobile'] = $admin_mobile; |
|
82
|
|
|
!empty($state) && $params['state'] = $state; |
|
|
|
|
|
|
83
|
|
|
return $this->httpPostJson('cgi-bin/service/get_register_code', $params); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* 查询注册状态 |
|
88
|
|
|
* Desc:该API用于查询企业注册状态,企业注册成功返回注册信息。 |
|
89
|
|
|
* @param string $register_code |
|
90
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
91
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
92
|
|
|
*/ |
|
93
|
|
|
public function getRegisterInfo(string $register_code) |
|
94
|
|
|
{ |
|
95
|
|
|
$params = [ |
|
96
|
|
|
'register_code' => $register_code |
|
97
|
|
|
]; |
|
98
|
|
|
return $this->httpPostJson('cgi-bin/service/get_register_info', $params); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* 设置授权应用可见范围 |
|
103
|
|
|
* Desc:调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。 |
|
104
|
|
|
* 企业注册初始化安装应用后,应用默认可见范围为根部门。 |
|
105
|
|
|
* 如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。 |
|
106
|
|
|
* 该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。 |
|
107
|
|
|
* 调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。 |
|
108
|
|
|
* @param string $access_token |
|
109
|
|
|
* @param string $agentid |
|
110
|
|
|
* @param array $allow_user |
|
111
|
|
|
* @param array $allow_party |
|
112
|
|
|
* @param array $allow_tag |
|
113
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
114
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
115
|
|
|
*/ |
|
116
|
|
|
public function setAgentScope(string $access_token, string $agentid, array $allow_user = [], array $allow_party = [], array $allow_tag = []) |
|
|
|
|
|
|
117
|
|
|
{ |
|
118
|
|
|
$this->middlewares = ['access_token' => $access_token]; |
|
119
|
|
|
$params = [ |
|
|
|
|
|
|
120
|
|
|
"agentid" => $agentid, |
|
|
|
|
|
|
121
|
|
|
"allow_user" => $allow_user, |
|
|
|
|
|
|
122
|
|
|
"allow_party" => $allow_party, |
|
|
|
|
|
|
123
|
|
|
"allow_tag" => $allow_tag |
|
|
|
|
|
|
124
|
|
|
]; |
|
125
|
|
|
return $this->httpGet('cgi-bin/agent/set_scope', $params); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* 设置通讯录同步完成 |
|
130
|
|
|
* Desc:该API用于设置通讯录同步完成,解除通讯录锁定状态,同时使通讯录迁移access_token失效。 |
|
131
|
|
|
* @param $access_token |
|
132
|
|
|
* @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string |
|
133
|
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException |
|
134
|
|
|
*/ |
|
135
|
|
|
public function contactSyncSuccess(string $access_token) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->middlewares = ['access_token' => $access_token]; |
|
138
|
|
|
return $this->httpGet('cgi-bin/sync/contact_sync_success'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
|
|
142
|
|
|
} |
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.