Completed
Push — master ( 1ae43c...a59297 )
by Carlos
03:01
created

Sns::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 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 11
ccs 0
cts 10
cp 0
crap 2
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
/**
13
 * User.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\Sns;
28
29
use EasyWeChat\MiniProgram\Core\AbstractMiniProgram;
30
31
class Sns extends AbstractMiniProgram
32
{
33
    /**
34
     * Api.
35
     */
36
    const JSCODE_TO_SESSION = 'https://api.weixin.qq.com/sns/jscode2session';
37
38
    /**
39
     * JsCode 2 session key.
40
     *
41
     * @param string $jsCode
42
     *
43
     * @return \EasyWeChat\Support\Collection
44
     */
45
    public function getSessionKey($jsCode)
46
    {
47
        $params = [
48
            'appid' => $this->config['app_id'],
49
            'secret' => $this->config['secret'],
50
            'js_code' => $jsCode,
51
            'grant_type' => 'authorization_code',
52
        ];
53
54
        return $this->parseJSON('GET', [self::JSCODE_TO_SESSION, $params]);
55
    }
56
}
57