Completed
Pull Request — master (#48)
by mingyoung
02:23
created

WeChatOpenPlatformProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getTokenUrl() 0 4 1
A getTokenFields() 0 10 1
1
<?php
2
3
/*
4
 * This file is part of the overtrue/socialite.
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 Overtrue\Socialite\Providers;
13
14
use Symfony\Component\HttpFoundation\Request;
15
16
/**
17
 * Class WeChatProvider.
18
 *
19
 * @link https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1419318590&token=&lang=zh_CN [WeChat - 公众开放平台代公众号 OAuth 文档]
20
 */
21
class WeChatOpenPlatformProvider extends WeChatProvider
22
{
23
    /**
24
     * Component AppId.
25
     *
26
     * @var string
27
     */
28
    protected $componentAppId;
29
30
    /**
31
     * Component Access Token.
32
     *
33
     * @var string
34
     */
35
    protected $componentAccessToken;
36
37
    /**
38
     * {@inheritdoc}.
39
     */
40
    protected $scopes = ['snsapi_base'];
41
42
    /**
43
     * Create a new provider instance.
44
     * (Overriding).
45
     *
46
     * @param \Symfony\Component\HttpFoundation\Request $request
47
     * @param string                                    $clientId
48
     * @param array                                     $componentCredits
49
     * @param string|null                               $redirectUrl
50
     */
51
    public function __construct(Request $request, $clientId, array $componentCredits, $redirectUrl = null)
52
    {
53
        parent::__construct($request, $clientId, null, $redirectUrl);
54
55
        list($componentAppId, $componentAccessToken) = $componentCredits;
56
57
        $this->componentAppId = $componentAppId;
58
        $this->componentAccessToken = $componentAccessToken;
59
    }
60
61
    /**
62
     * {@inheritdoc}.
63
     */
64
    protected function getTokenUrl()
65
    {
66
        return $this->baseUrl.'/oauth2/component/access_token';
67
    }
68
69
    /**
70
     * {@inheritdoc}.
71
     */
72
    protected function getTokenFields($code)
73
    {
74
        return [
75
            'appid' => $this->clientId,
76
            'component_appid' => $this->componentAppId,
77
            'component_access_token' => $this->componentAccessToken,
78
            'code' => $code,
79
            'grant_type' => 'authorization_code',
80
        ];
81
    }
82
}
83