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

MiniProgram::getSessionKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
rs 9.4285
ccs 0
cts 10
cp 0
crap 2
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