Skip to content

Commit 6f5c616

Browse files
authored
Update Server.php
1 parent fabdb9b commit 6f5c616

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Server.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ public function onMessage($connection, $data)
240240
if (!$data) {
241241
return;
242242
}
243+
if (!isset($data['event'])) {
244+
$connection->send($this->error(null, 'Empty event'));
245+
return;
246+
}
243247
$event = $data['event'];
244248
switch ($event) {
245249
case 'pusher:ping':
@@ -262,7 +266,7 @@ public function onMessage($connection, $data)
262266

263267
// {"event":"pusher:error","data":{"code":null,"message":"Received invalid JSON"}}
264268
if ($client_auth !== $auth) {
265-
return $connection->send($this->error(null, 'Received invalid JSON '.$auth));
269+
return $connection->send($this->error(null, 'Received invalid Auth '.$auth));
266270
}
267271
$user_data = json_decode($data['data']['channel_data'], true);
268272
if (!$user_data || !isset($user_data['user_id']) || !isset($user_data['user_info'])) {
@@ -277,9 +281,9 @@ public function onMessage($connection, $data)
277281
// {"event":"pusher:subscribe","data":{"auth":"b054014693241bcd9c26:10e3b628cb78e8bc4d1f44d47c9294551b446ae6ec10ef113d3d7e84e99763e6","channel_data":"{\"user_id\":100,\"user_info\":{\"name\":\"123\"}}","channel":"presence-channel"}}
278282
$client_auth = $data['data']['auth'];
279283
$auth = $connection->appKey.':'.hash_hmac('sha256', $connection->socketID.':'.$channel, $this->appInfo[$connection->appKey]['app_secret'], false);
280-
// {"event":"pusher:error","data":{"code":null,"message":"Received invalid JSON"}}
284+
// {"event":"pusher:error","data":{"code":null,"message":"Received invalid Auth"}}
281285
if ($client_auth !== $auth) {
282-
return $connection->send($this->error(null, 'Received invalid JSON '.$auth));
286+
return $connection->send($this->error(null, 'Received invalid Auth '.$auth));
283287
}
284288
$this->subscribePrivateChannel($connection, $channel);
285289
} else {
@@ -319,6 +323,10 @@ public function onMessage($connection, $data)
319323
if (strpos($event, 'pusher:') === 0) {
320324
return $connection->send($this->error(null, 'Unknown event'));
321325
}
326+
if (!isset($data['channel'])) {
327+
$connection->send($this->error(null, 'Empty channel'));
328+
return;
329+
}
322330
$channel = $data['channel'];
323331
// 客户端触发事件必须是private 或者 presence的channel
324332
$channel_type = $this->getChannelType($channel);

0 commit comments

Comments
 (0)