Completed
Push — master ( 6971e7...8d77a8 )
by Carlos
06:30 queued 02:09
created

MiniProgram   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 46
rs 10
ccs 0
cts 15
cp 0
wmc 2
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSessionKey() 0 11 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
/**
13
 * MiniProgram.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @copyright 2016
22
 *
23
 * @see      https://github.com/overtrue
24
 * @see      http://overtrue.me
25
 */
26
27
namespace EasyWeChat\MiniProgram;
28
29
use EasyWeChat\Core\AbstractAPI;
30
31
/**
32
 * Class MiniProgram.
33
 */
34
class MiniProgram extends AbstractAPI
35
{
36
    /**
37
     * Api.
38
     */
39
    const JSCODE_TO_SESSION = 'https://api.weixin.qq.com/sns/jscode2session';
40
41
    /**
42
     * Mini program config.
43
     *
44
     * @var array
45
     */
46
    protected $config;
47
48
    /**
49
     * MiniProgram constructor.
50
     *
51
     * @param \EasyWeChat\MiniProgram\AccessToken $accessToken
52
     * @param array                               $config
53
     */
54
    public function __construct($accessToken, $config)
55
    {
56
        parent::__construct($accessToken);
57
58
        $this->config = $config;
59
    }
60
61
    /**
62
     * JsCode 2 session key.
63
     *
64
     * @param string $jsCode
65
     *
66
     * @return \EasyWeChat\Support\Collection
67
     */
68
    public function getSessionKey($jsCode)
69
    {
70
        $params = [
71
            'appid' => $this->config['app_id'],
72
            'secret' => $this->config['secret'],
73
            'js_code' => $jsCode,
74
            'grant_type' => 'authorization_code',
75
        ];
76
77
        return $this->parseJSON('GET', [self::JSCODE_TO_SESSION, $params]);
78
    }
79
}
80