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\Credential; |
15
|
|
|
use Slince\SmartQQ\Entity\Recent; |
16
|
|
|
use Slince\SmartQQ\EntityCollection; |
17
|
|
|
use Slince\SmartQQ\EntityFactory; |
18
|
|
|
use Slince\SmartQQ\Exception\ResponseException; |
19
|
|
|
|
20
|
|
|
class GetRecentListRequest extends Request |
21
|
|
|
{ |
22
|
|
|
protected $uri = 'http://d1.web2.qq.com/channel/get_recent_list2'; |
23
|
|
|
|
24
|
|
|
protected $referer = 'http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2'; |
25
|
|
|
|
26
|
|
|
protected $method = RequestInterface::REQUEST_METHOD_POST; |
27
|
|
|
|
28
|
|
|
public function __construct(Credential $credential) |
29
|
|
|
{ |
30
|
|
|
$this->setParameter('r', \GuzzleHttp\json_encode([ |
31
|
|
|
'vfwebqq' => $credential->getVfWebQQ(), |
32
|
|
|
'clientid' => $credential->getClientId(), |
33
|
|
|
'psessionid' => $credential->getPSessionId(), |
34
|
|
|
])); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* 解析响应数据. |
39
|
|
|
* |
40
|
|
|
* @param Response $response |
41
|
|
|
* |
42
|
|
|
* @return EntityCollection |
43
|
|
|
*/ |
44
|
|
|
public static function parseResponse(Response $response) |
45
|
|
|
{ |
46
|
|
|
$jsonData = \GuzzleHttp\json_decode($response->getBody(), true); |
47
|
|
|
if ($jsonData && 0 == $jsonData['retcode']) { |
48
|
|
|
$recentList = []; |
49
|
|
|
foreach ($jsonData['result'] as $recent) { |
50
|
|
|
$recentList[] = EntityFactory::createEntity(Recent::class, [ |
51
|
|
|
'type' => $recent['type'], |
52
|
|
|
'uin' => $recent['uin'], |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return new EntityCollection($recentList); |
57
|
|
|
} |
58
|
|
|
throw new ResponseException($jsonData['retcode'], $response); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|