Completed
Pull Request — master (#1275)
by
unknown
03:05
created

Client   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getRegisterUri() 0 4 1
A getLoginUrl() 0 9 2
A getRegisterCode() 0 9 5
A getLoginInfo() 0 6 1
A setAgentScope() 0 10 1
A contactSyncSuccess() 0 4 1
A __construct() 0 3 1
A getRegisterInfo() 0 6 1
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();
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...
78
        $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...
79
        !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...
80
        !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...
81
        !empty($admin_mobile) && $params['admin_mobile'] = $admin_mobile;
82
        !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...
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 = [])
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 140 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
117
    {
118
        $this->middlewares = ['access_token' => $access_token];
119
        $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...
120
            "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...
121
            "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...
122
            "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...
123
            "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...
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
}