GetQQRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A parseResponse() 0 8 3
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 Slince\SmartQQ\Credential;
14
use Slince\SmartQQ\Entity\Friend;
15
use GuzzleHttp\Psr7\Response;
16
use Slince\SmartQQ\Exception\ResponseException;
17
18
class GetQQRequest extends Request
19
{
20
    protected $uri = 'http://s.web2.qq.com/api/get_friend_uin2?tuin={uin}&type=1&vfwebqq={vfwebqq}&t=0.1';
21
22
    protected $referer = 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2';
23
24
    public function __construct(Friend $friend, Credential $credential)
25
    {
26
        $this->setTokens([
27
            'uin' => $friend->getUin(),
28
            'vfwebqq' => $credential->getVfWebQQ(),
29
        ]);
30
    }
31
32
    /**
33
     * 解析响应数据.
34
     *
35
     * @param Response $response
36
     *
37
     * @return int
38
     */
39
    public static function parseResponse(Response $response)
40
    {
41
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
42
        if ($jsonData && 0 == $jsonData['retcode']) {
43
            return $jsonData['result']['account'];
44
        }
45
        throw new ResponseException($jsonData['retcode'], $response);
46
    }
47
}
48