Completed
Pull Request — master (#1277)
by
unknown
03:17
created

Client::getRegisterCode()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 16
nop 4
dl 0
loc 13
rs 9.5222
c 0
b 0
f 0
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
    /**
26
     * Client constructor.
27
     *
28
     *
29
     * @param ServiceContainer $app
30
     */
31
    public function __construct(ServiceContainer $app)
32
    {
33
        parent::__construct($app, $app['provider_access_token']);
34
    }
35
36
    /**
37
     * 单点登录 - 获取登录的地址.
38
     *
39
     * @param string $redirect_uri
40
     * @param string $usertype
41
     * @param string $state
42
     *
43
     * @return string
44
     */
45
    public function getLoginUrl(string $redirect_uri, string $usertype = 'admin', string $state = '')
46
    {
47
        $params = [
48
            'appid'        => $this->app['config']['corp_id'],
49
            'redirect_uri' => $redirect_uri,
50
            'usertype'     => $usertype,
51
            'state'        => $state || rand()
52
        ];
53
        return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?' . http_build_query($params);
54
    }
55
56
    /**
57
     * 单点登录 - 获取登录用户信息.
58
     *
59
     * @param string $auth_code
60
     *
61
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
62
     *
63
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
64
     */
65
    public function getLoginInfo(string $auth_code)
66
    {
67
        $params = [
68
            'auth_code' => $auth_code
69
        ];
70
        return $this->httpPostJson('cgi-bin/service/get_login_info', $params);
71
    }
72
73
74
    /**
75
     * 获取注册定制化URL.
76
     *
77
     * @param $register_code
78
     *
79
     * @return string
80
     */
81
    public function getRegisterUri($register_code)
82
    {
83
        $params = ['register_code' => $register_code];
84
        return 'https://open.work.weixin.qq.com/3rdservice/wework/register?' . http_build_query($params);
85
    }
86
87
88
    /**
89
     * 获取注册码.
90
     *
91
     * @param string $corp_name
92
     * @param string $admin_name
93
     * @param string $admin_mobile
94
     * @param string $state
95
     *
96
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
97
     *
98
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
99
     */
100
    public function getRegisterCode(
101
        string $corp_name = '',
102
        string $admin_name = '',
103
        string $admin_mobile = '',
104
        string $state = ''
105
    ) {
106
        $params = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 42 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
        $params['template_id'] = $this->app['config']['template_id'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 27 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($corp_name) && $params['corp_name'] = $corp_name;
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...
109
        !empty($admin_name) && $params['admin_name'] = $admin_name;
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...
110
        !empty($admin_mobile) && $params['admin_mobile'] = $admin_mobile;
111
        !empty($state) && $params['state'] = $state;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 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...
112
        return $this->httpPostJson('cgi-bin/service/get_register_code', $params);
113
    }
114
115
    /**
116
     * 查询注册状态.
117
     *
118
     * Desc:该API用于查询企业注册状态,企业注册成功返回注册信息.
119
     *
120
     * @param string $register_code
121
     *
122
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
123
     *
124
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
125
     */
126
    public function getRegisterInfo(string $register_code)
127
    {
128
        $params = [
129
            'register_code' => $register_code
130
        ];
131
        return $this->httpPostJson('cgi-bin/service/get_register_info', $params);
132
    }
133
134
    /**
135
     * 设置授权应用可见范围.
136
     *
137
     * Desc:调用该接口前提是开启通讯录迁移,收到授权成功通知后可调用。
138
     *      企业注册初始化安装应用后,应用默认可见范围为根部门。
139
     *      如需修改应用可见范围,服务商可以调用该接口设置授权应用的可见范围。
140
     *      该接口只能使用注册完成回调事件或者查询注册状态返回的access_token。
141
     *      调用设置通讯录同步完成后或者access_token超过30分钟失效(即解除通讯录锁定状态)则不能继续调用该接口。
142
     *
143
     * @param string $access_token
144
     * @param string $agentid
145
     * @param array  $allow_user
146
     * @param array  $allow_party
147
     * @param array  $allow_tag
148
     *
149
     * @return array|\EasyWeChat\Kernel\Support\Collection|object|\Psr\Http\Message\ResponseInterface|string
150
     *
151
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
152
     */
153
    public function setAgentScope(
154
        string $access_token,
155
        string $agentid,
156
        array $allow_user = [],
157
        array $allow_party = [],
158
        array $allow_tag = []
159
    ) {
160
        $this->middlewares = ['access_token' => $access_token];
161
        $params = [
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
162
            "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...
163
            "allow_user"  => $allow_user,
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...
164
            "allow_party" => $allow_party,
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...
165
            "allow_tag"   => $allow_tag
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...
166
        ];
167
        return $this->httpGet('cgi-bin/agent/set_scope', $params);
168
    }
169
170
    /**
171
     * 设置通讯录同步完成.
172
     *
173
     * Desc:该API用于设置通讯录同步完成,解除通讯录锁定状态,同时使通讯录迁移access_token失效。
174
     *
175
     * @param $access_token
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 $access_token)
182
    {
183
        $this->middlewares = ['access_token' => $access_token];
184
        return $this->httpGet('cgi-bin/sync/contact_sync_success');
185
    }
186
187
}