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\Exception\Code103ResponseException; |
16
|
|
|
use Slince\SmartQQ\Message\Request\Message; |
17
|
|
|
|
18
|
|
|
class SendMessageRequest extends Request |
19
|
|
|
{ |
20
|
|
|
protected $method = RequestInterface::REQUEST_METHOD_POST; |
21
|
|
|
|
22
|
|
|
protected $referer = 'http://d1.web2.qq.com/cfproxy.html?v=20151105001&callback=1'; |
23
|
|
|
|
24
|
|
|
public function makeMessageParameter(Message $message, Credential $credential) |
25
|
|
|
{ |
26
|
|
|
return [ |
27
|
|
|
'content' => (string) $message->getContent(), |
28
|
|
|
'face' => $message->getFace(), |
29
|
|
|
'clientid' => $credential->getClientId(), |
30
|
|
|
'msg_id' => $message->getMsgId(), |
31
|
|
|
'psessionid' => $credential->getPSessionId(), |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param Response $response |
37
|
|
|
* |
38
|
|
|
* @throws Code103ResponseException |
39
|
|
|
* |
40
|
|
|
* @return bool |
41
|
|
|
*/ |
42
|
|
|
public static function parseResponse(Response $response) |
43
|
|
|
{ |
44
|
|
|
$jsonData = \GuzzleHttp\json_decode($response->getBody(), true); |
45
|
|
|
if ( |
46
|
|
|
(isset($jsonData['errCode']) && 0 === $jsonData['errCode']) |
47
|
|
|
|| (isset($jsonData['retcode']) && 0 === $jsonData['retcode']) |
48
|
|
|
) { |
49
|
|
|
return true; |
50
|
|
|
} |
51
|
|
|
if (isset($jsonData['retcode']) && 103 === $jsonData['retcode']) { |
52
|
|
|
throw new Code103ResponseException($response); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return false; |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|