AccessToken::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 6
rs 10
ccs 5
cts 5
cp 1
crap 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\Work\Auth;
13
14
use EasyWeChat\Kernel\AccessToken as BaseAccessToken;
15
use EasyWeChat\OpenWork\Application;
16
use Pimple\Container;
17
18
/**
19
 * AccessToken.
20
 *
21
 * @author xiaomin <[email protected]>
22
 */
23
class AccessToken extends BaseAccessToken
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $requestMethod = 'POST';
29
30
    /**
31
     * @var string 授权方企业ID
32
     */
33
    protected $authCorpid;
34
35
    /**
36
     * @var string 授权方企业永久授权码,通过get_permanent_code获取
37
     */
38
    protected $permanentCode;
39
40
    protected $component;
41
42
    /**
43
     * AccessToken constructor.
44
     *
45
     * @param Container   $app
46
     * @param string      $authCorpId
47
     * @param string      $permanentCode
48
     * @param Application $component
49
     */
50 3
    public function __construct(Container $app, string $authCorpId, string $permanentCode, Application $component)
51
    {
52 3
        $this->authCorpid = $authCorpId;
53 3
        $this->permanentCode = $permanentCode;
54 3
        $this->component = $component;
55 3
        parent::__construct($app);
56 3
    }
57
58
    /**
59
     * Credential for get token.
60
     *
61
     * @return array
62
     */
63 1
    protected function getCredentials(): array
64
    {
65
        return [
66 1
            'auth_corpid' => $this->authCorpid,
67 1
            'permanent_code' => $this->permanentCode,
68
        ];
69
    }
70
71
    /**
72
     * @return string
73
     */
74 1
    public function getEndpoint(): string
75
    {
76 1
        return 'cgi-bin/service/get_corp_token?'.http_build_query([
77 1
                'suite_access_token' => $this->component['suite_access_token']->getToken()['suite_access_token'],
78
            ]);
79
    }
80
}
81