GetUinAndPsessionidRequest::parseResponse()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the slince/smartqq package.
4
 *
5
 * (c) Slince <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Slince\SmartQQ\Request;
12
13
use GuzzleHttp\Psr7\Response;
14
use Slince\SmartQQ\Exception\RuntimeException;
15
16
class GetUinAndPsessionidRequest extends Request
17
{
18
    protected $uri = 'http://d1.web2.qq.com/channel/login2';
19
20
    protected $referer = 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2';
21
22
    protected $method = RequestInterface::REQUEST_METHOD_POST;
23
24
    public function __construct(array $data)
25
    {
26
        $this->setParameter('r', json_encode($data));
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public static function parseResponse(Response $response)
33
    {
34
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
35
        if (!isset($jsonData['result']['uin'])) {
36
            throw new RuntimeException('Can not find argument [uin] and [psessionid]');
37
        }
38
39
        return [$jsonData['result']['uin'], $jsonData['result']['psessionid']];
40
    }
41
}
42