Completed
Push — master ( de9fa0...af8f3e )
by mingyoung
02:09
created

Client::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 9.4285
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\OpenPlatform\Authorizer\MiniProgram\Auth;
13
14
use EasyWeChat\Kernel\BaseClient;
15
use EasyWeChat\Kernel\ServiceContainer;
16
use EasyWeChat\OpenPlatform\Application;
17
18
/**
19
 * Class Client.
20
 *
21
 * @author mingyoung <[email protected]>
22
 */
23
class Client extends BaseClient
24
{
25
    /**
26
     * @var \EasyWeChat\OpenPlatform\Application
27
     */
28
    protected $component;
29
30
    /**
31
     * Client constructor.
32
     *
33
     * @param \EasyWeChat\Kernel\ServiceContainer  $app
34
     * @param \EasyWeChat\OpenPlatform\Application $component
35
     */
36
    public function __construct(ServiceContainer $app, Application $component)
37
    {
38
        parent::__construct($app);
39
40
        $this->component = $component;
41
    }
42
43
    /**
44
     * Get session info by code.
45
     *
46
     * @param string $code
47
     *
48
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
49
     */
50
    public function session(string $code)
51
    {
52
        $params = [
53
            'appid' => $this->app['config']['app_id'],
54
            'js_code' => $code,
55
            'grant_type' => 'authorization_code',
56
            'component_appid' => $this->component['config']['app_id'],
57
            'component_access_token' => $this->component['access_token']->getToken()['component_access_token'],
58
        ];
59
60
        return $this->httpGet('sns/component/jscode2session', $params);
61
    }
62
}
63