Passed
Pull Request — master (#1278)
by
unknown
03:33
created

Client   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 163
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
dl 0
loc 163
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegisterCode() 0 13 5
A getRegisterInfo() 0 6 1
A setAgentScope() 0 15 1
A contactSyncSuccess() 0 4 1
A getRegisterUri() 0 4 1
A getLoginUrl() 0 9 2
A getLoginInfo() 0 6 1
A __construct() 0 3 1
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
        $params = [
47
            'appid'        => $this->app['config']['corp_id'],
48
            'redirect_uri' => $redirectUri,
49
            'usertype'     => $userType,
50
            'state'        => $state || rand()
51
        ];
52
        return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?' . http_build_query($params);
53
    }
54
55
    /**
56
     * 单点登录 - 获取登录用户信息.
57
     *
58
     * @param string $authCode
59
     *
60
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
61
     *
62
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
63
     */
64
    public function getLoginInfo(string $authCode)
65
    {
66
        $params = [
67
            'auth_code' => $authCode
68
        ];
69
        return $this->httpPostJson('cgi-bin/service/get_login_info', $params);
70
    }
71
72
73
    /**
74
     * 获取注册定制化URL.
75
     *
76
     * @param $registerCode
77
     *
78
     * @return string
79
     */
80
    public function getRegisterUri($registerCode)
81
    {
82
        $params = ['register_code' => $registerCode];
83
        return 'https://open.work.weixin.qq.com/3rdservice/wework/register?' . http_build_query($params);
84
    }
85
86
87
    /**
88
     * 获取注册码.
89
     *
90
     * @param string $corpName
91
     * @param string $adminName
92
     * @param string $adminMobile
93
     * @param string $state
94
     *
95
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
96
     *
97
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
98
     */
99
    public function getRegisterCode(
100
        string $corpName = '',
101
        string $adminName = '',
102
        string $adminMobile = '',
103
        string $state = ''
104
    ) {
105
        $params = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 41 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
106
        $params['template_id'] = $this->app['config']['template_id'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 26 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
107
        !empty($corpName) && $params['corp_name'] = $corpName;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
108
        !empty($adminName) && $params['admin_name'] = $adminName;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
109
        !empty($adminMobile) && $params['admin_mobile'] = $adminMobile;
110
        !empty($state) && $params['state'] = $state;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

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

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
111
        return $this->httpPostJson('cgi-bin/service/get_register_code', $params);
112
    }
113
114
    /**
115
     * 查询注册状态.
116
     *
117
     * Desc:该API用于查询企业注册状态,企业注册成功返回注册信息.
118
     *
119
     * @param string $registerCode
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 getRegisterInfo(string $registerCode)
126
    {
127
        $params = [
128
            'register_code' => $registerCode
129
        ];
130
        return $this->httpPostJson('cgi-bin/service/get_register_info', $params);
131
    }
132
133
    /**
134
     * 设置授权应用可见范围.
135
     *
136
     * Desc:调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。
137
     *      企业注册初始化安装应用后,应用默认可见范围为根部门。
138
     *      如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。
139
     *      该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。
140
     *      调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。
141
     *
142
     * @param string $accessToken
143
     * @param string $agentId
144
     * @param array  $allowUser
145
     * @param array  $allowParty
146
     * @param array  $allowTag
147
     *
148
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
149
     *
150
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
151
     */
152
153
    public function setAgentScope(
154
        string $accessToken,
155
        string $agentId,
156
        array $allowUser = [],
157
        array $allowParty = [],
158
        array $allowTag = []
159
    ) {
160
        $params = [
161
            "agentid"     => $agentId,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal agentid does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
162
            "allow_user"  => $allowUser,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal allow_user does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
163
            "allow_party" => $allowParty,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal allow_party does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
164
            "allow_tag"   => $allowTag,
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal allow_tag does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
165
            "access_token" => $accessToken
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal access_token does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
166
        ];
167
        return $this->httpGet('cgi-bin/agent/set_scope', $params);
168
    }
169
170
    /**
171
     * 设置通讯录同步完成.
172
     *
173
     * Desc:该API用于设置通讯录同步完成,解除通讯录锁定状态,同时使通讯录迁移access_token失效。
174
     *
175
     * @param $accessToken
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 contactSyncSuccess(string $accessToken)
182
    {
183
        $params = ['access_token' => $accessToken];
184
        return $this->httpGet('cgi-bin/sync/contact_sync_success',$params);
185
    }
186
}
187