These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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; |
||
12 | |||
13 | use GuzzleHttp\Cookie\CookieJar; |
||
14 | use GuzzleHttp\Cookie\SetCookie; |
||
15 | |||
16 | class Credential |
||
17 | { |
||
18 | /** |
||
19 | * 鉴权参数ptwebqq,存储在cookie中. |
||
20 | * |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $ptWebQQ; |
||
24 | |||
25 | /** |
||
26 | * 鉴权参数vfwebqq. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $vfWebQQ; |
||
31 | |||
32 | /** |
||
33 | * 鉴权参数pSessionId. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $pSessionId; |
||
38 | |||
39 | /** |
||
40 | * 客户端id. |
||
41 | * |
||
42 | * @var int |
||
43 | */ |
||
44 | protected $clientId; |
||
45 | |||
46 | /** |
||
47 | * 当前登录的用户编号(o+QQ号). |
||
48 | * |
||
49 | * @var string |
||
50 | */ |
||
51 | protected $uin; |
||
52 | |||
53 | /** |
||
54 | * cookie信息,由于client发起请求需要使用cookie信息故cookie也需要一同处理. |
||
55 | * |
||
56 | * @var CookieJar |
||
57 | */ |
||
58 | protected $cookies; |
||
59 | |||
60 | public function __construct($ptWebQQ, $vfWebQQ, $pSessionId, $uin, $clientId, CookieJar $cookies) |
||
61 | { |
||
62 | $this->ptWebQQ = $ptWebQQ; |
||
63 | $this->vfWebQQ = $vfWebQQ; |
||
64 | $this->pSessionId = $pSessionId; |
||
65 | $this->uin = $uin; |
||
66 | $this->clientId = $clientId; |
||
67 | $this->cookies = $cookies; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | public function getPtWebQQ() |
||
74 | { |
||
75 | return $this->ptWebQQ; |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * @param string $ptWebQQ |
||
80 | */ |
||
81 | public function setPtWebQQ($ptWebQQ) |
||
82 | { |
||
83 | $this->ptWebQQ = $ptWebQQ; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * @return string |
||
88 | */ |
||
89 | public function getVfWebQQ() |
||
90 | { |
||
91 | return $this->vfWebQQ; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * @param string $vfWebQQ |
||
96 | */ |
||
97 | public function setVfWebQQ($vfWebQQ) |
||
98 | { |
||
99 | $this->vfWebQQ = $vfWebQQ; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getPSessionId() |
||
106 | { |
||
107 | return $this->pSessionId; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @return CookieJar |
||
112 | */ |
||
113 | public function getCookies() |
||
114 | { |
||
115 | return $this->cookies; |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * @param CookieJar $cookies |
||
120 | */ |
||
121 | public function setCookies($cookies) |
||
122 | { |
||
123 | $this->cookies = $cookies; |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @param string $pSessionId |
||
128 | */ |
||
129 | public function setPSessionId($pSessionId) |
||
130 | { |
||
131 | $this->pSessionId = $pSessionId; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @return int |
||
136 | */ |
||
137 | public function getClientId() |
||
138 | { |
||
139 | return $this->clientId; |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * @param int $clientId |
||
144 | */ |
||
145 | public function setClientId($clientId) |
||
146 | { |
||
147 | $this->clientId = $clientId; |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getUin() |
||
154 | { |
||
155 | return $this->uin; |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @param string $uin |
||
160 | */ |
||
161 | public function setUin($uin) |
||
162 | { |
||
163 | $this->uin = $uin; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @return array |
||
168 | */ |
||
169 | public function toArray() |
||
170 | { |
||
171 | return [ |
||
172 | 'ptWebQQ' => $this->ptWebQQ, |
||
173 | 'vfWebQQ' => $this->vfWebQQ, |
||
174 | 'pSessionId' => $this->pSessionId, |
||
175 | 'uin' => $this->uin, |
||
176 | 'clientId' => $this->clientId, |
||
177 | 'cookies' => $this->cookies->toArray(), |
||
178 | ]; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * Create from a array data. |
||
183 | * |
||
184 | * @param array $data |
||
185 | * |
||
186 | * @return static |
||
187 | */ |
||
188 | public static function fromArray(array $data) |
||
189 | { |
||
190 | $cookieJar = null; |
||
191 | if (isset($data['cookies'])) { |
||
192 | $cookieJar = new CookieJar(); |
||
193 | foreach ($data['cookies'] as $cookie) { |
||
194 | $cookieJar->setCookie(new SetCookie($cookie)); |
||
195 | } |
||
196 | } |
||
197 | |||
198 | return new static($data['ptWebQQ'], $data['vfWebQQ'], |
||
199 | $data['pSessionId'], $data['uin'], $data['clientId'], |
||
200 | $cookieJar |
||
0 ignored issues
–
show
|
|||
201 | ); |
||
202 | } |
||
203 | } |
||
204 |
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: