Completed
Push — master ( 2addb1...4d5931 )
by Carlos
08:01 queued 02:29
created

Client::getPreAuthCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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