|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the slince/smartqq package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Slince <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Slince\SmartQQ; |
|
13
|
|
|
|
|
14
|
|
|
use GuzzleHttp\Cookie\CookieJar; |
|
15
|
|
|
use GuzzleHttp\Cookie\SetCookie; |
|
16
|
|
|
|
|
17
|
|
|
class Credential |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* 鉴权参数ptwebqq,存储在cookie中. |
|
21
|
|
|
* |
|
22
|
|
|
* @var string |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $ptWebQQ; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* 鉴权参数vfwebqq. |
|
28
|
|
|
* |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $vfWebQQ; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* 鉴权参数pSessionId. |
|
35
|
|
|
* |
|
36
|
|
|
* @var string |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $pSessionId; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* 客户端id. |
|
42
|
|
|
* |
|
43
|
|
|
* @var int |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $clientId; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* 当前登录的用户编号(o+QQ号). |
|
49
|
|
|
* |
|
50
|
|
|
* @var string |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $uin; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* cookie信息,由于client发起请求需要使用cookie信息故cookie也需要一同处理. |
|
56
|
|
|
* |
|
57
|
|
|
* @var CookieJar |
|
58
|
|
|
*/ |
|
59
|
|
|
protected $cookies; |
|
60
|
|
|
|
|
61
|
|
|
public function __construct($ptWebQQ, $vfWebQQ, $pSessionId, $uin, $clientId, CookieJar $cookies) |
|
62
|
|
|
{ |
|
63
|
|
|
$this->ptWebQQ = $ptWebQQ; |
|
64
|
|
|
$this->vfWebQQ = $vfWebQQ; |
|
65
|
|
|
$this->pSessionId = $pSessionId; |
|
66
|
|
|
$this->uin = $uin; |
|
67
|
|
|
$this->clientId = $clientId; |
|
68
|
|
|
$this->cookies = $cookies; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
|
|
public function getPtWebQQ() |
|
75
|
|
|
{ |
|
76
|
|
|
return $this->ptWebQQ; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param string $ptWebQQ |
|
81
|
|
|
*/ |
|
82
|
|
|
public function setPtWebQQ($ptWebQQ) |
|
83
|
|
|
{ |
|
84
|
|
|
$this->ptWebQQ = $ptWebQQ; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return string |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getVfWebQQ() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->vfWebQQ; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param string $vfWebQQ |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setVfWebQQ($vfWebQQ) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->vfWebQQ = $vfWebQQ; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public function getPSessionId() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->pSessionId; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @return CookieJar |
|
113
|
|
|
*/ |
|
114
|
|
|
public function getCookies() |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->cookies; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param CookieJar $cookies |
|
121
|
|
|
*/ |
|
122
|
|
|
public function setCookies($cookies) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->cookies = $cookies; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @param string $pSessionId |
|
129
|
|
|
*/ |
|
130
|
|
|
public function setPSessionId($pSessionId) |
|
131
|
|
|
{ |
|
132
|
|
|
$this->pSessionId = $pSessionId; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return int |
|
137
|
|
|
*/ |
|
138
|
|
|
public function getClientId() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->clientId; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @param int $clientId |
|
145
|
|
|
*/ |
|
146
|
|
|
public function setClientId($clientId) |
|
147
|
|
|
{ |
|
148
|
|
|
$this->clientId = $clientId; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return string |
|
153
|
|
|
*/ |
|
154
|
|
|
public function getUin() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->uin; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @param string $uin |
|
161
|
|
|
*/ |
|
162
|
|
|
public function setUin($uin) |
|
163
|
|
|
{ |
|
164
|
|
|
$this->uin = $uin; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return array |
|
169
|
|
|
*/ |
|
170
|
|
|
public function toArray() |
|
171
|
|
|
{ |
|
172
|
|
|
return [ |
|
173
|
|
|
'ptWebQQ' => $this->ptWebQQ, |
|
174
|
|
|
'vfWebQQ' => $this->vfWebQQ, |
|
175
|
|
|
'pSessionId' => $this->pSessionId, |
|
176
|
|
|
'uin' => $this->uin, |
|
177
|
|
|
'clientId' => $this->clientId, |
|
178
|
|
|
'cookies' => $this->cookies->toArray(), |
|
179
|
|
|
]; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/** |
|
183
|
|
|
* Create from a array data. |
|
184
|
|
|
* |
|
185
|
|
|
* @param array $data |
|
186
|
|
|
* |
|
187
|
|
|
* @return static |
|
188
|
|
|
*/ |
|
189
|
|
|
public static function fromArray(array $data) |
|
190
|
|
|
{ |
|
191
|
|
|
$cookieJar = null; |
|
192
|
|
|
if (isset($data['cookies'])) { |
|
193
|
|
|
$cookieJar = new CookieJar(); |
|
194
|
|
|
foreach ($data['cookies'] as $cookie) { |
|
195
|
|
|
$cookieJar->setCookie(new SetCookie($cookie)); |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
|
199
|
|
|
return new static($data['ptWebQQ'], $data['vfWebQQ'], |
|
200
|
|
|
$data['pSessionId'], $data['uin'], $data['clientId'], |
|
201
|
|
|
$cookieJar |
|
|
|
|
|
|
202
|
|
|
); |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: