Completed
Push — master ( b9b2bf...873ba2 )
by mingyoung
01:32
created

AccessToken   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCredentials() 0 8 1
A getEndpoint() 0 6 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\OpenPlatform\Authorizer\Auth;
13
14
use EasyWeChat\Kernel\AccessToken as BaseAccessToken;
15
use EasyWeChat\OpenPlatform\Application;
16
use Pimple\Container;
17
18
/**
19
 * Class AccessToken.
20
 *
21
 * @author mingyoung <[email protected]>
22
 */
23
class AccessToken extends BaseAccessToken
24
{
25
    /**
26
     * @var string
27
     */
28
    protected $requestMethod = 'POST';
29
30
    /**
31
     * @var string
32
     */
33
    protected $queryName = 'access_token';
34
35
    /**
36
     * {@inheritdoc}.
37
     */
38
    protected $tokenKey = 'authorizer_access_token';
39
40
    /**
41
     * @var \EasyWeChat\OpenPlatform\Application
42
     */
43
    protected $component;
44
45
    /**
46
     * AuthorizerAccessToken constructor.
47
     *
48
     * @param \Pimple\Container                    $app
49
     * @param \EasyWeChat\OpenPlatform\Application $component
50
     */
51
    public function __construct(Container $app, Application $component)
52
    {
53
        parent::__construct($app);
54
55
        $this->component = $component;
56
    }
57
58
    /**
59
     * {@inheritdoc}.
60
     */
61
    protected function getCredentials(): array
62
    {
63
        return [
64
            'component_appid' => $this->component['config']['app_id'],
65
            'authorizer_appid' => $this->app['config']['app_id'],
66
            'authorizer_refresh_token' => $this->app['config']['refresh_token'],
67
        ];
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getEndpoint(): string
74
    {
75
        return 'cgi-bin/component/api_authorizer_token?'.http_build_query([
76
            'component_access_token' => $this->component['access_token']->getToken()['component_access_token'],
77
        ]);
78
    }
79
}
80