调整消息推送

This commit is contained in:
mzl
2025-08-22 16:27:50 +08:00
parent 5dc515f712
commit 8b91924d1a
5 changed files with 158 additions and 88 deletions
+12 -27
View File
@@ -74,16 +74,16 @@ class WsEvents
}
// 连接是否满足条件
if ($payload['server']['HTTP_ORIGIN'] != 'https://wstool.js.org') {
flg('[x] [TOKEN认证] HTTP_ORIGIN不满足条件', false);
Gateway::sendToClient($client_id, WsResponse::error(
'system.auth',
1001,
'[x] [TOKEN认证] HTTP_ORIGIN不满足条件'
));
Gateway::closeClient($client_id);
return;
}
// if ($payload['server']['HTTP_ORIGIN'] != 'https://wstool.js.org') {
// flg('[x] [TOKEN认证] HTTP_ORIGIN不满足条件', false);
// Gateway::sendToClient($client_id, WsResponse::error(
// 'system.auth',
// 1001,
// '[x] [TOKEN认证] HTTP_ORIGIN不满足条件'
// ));
// Gateway::closeClient($client_id);
// return;
// }
// 签名检查
if (!isset($payload['get']['token'])) {
@@ -226,24 +226,9 @@ class WsEvents
/**
* 推送消息通知
*/
public function pushNotice(int $msgId, string $title, string $content, array $recipient)
public function pushWsNotice(array $wsData, int $userId)
{
$payload = WsResponse::success('notify.receive', [
'msg_id' => $msgId,
'title' => $title,
'content' => $content,
'created_at' => time()
]);
if (count($recipient) > 0) {
// 推送给指定用户
foreach ($recipient as $uid) {
Gateway::sendToUid($uid, $payload);
}
} else {
// 推送给全体在线用户
Gateway::sendToAll($payload);
}
Gateway::sendToUid($userId, WsResponse::success('notify.receive', $wsData));
}
// ================= 辅助方法 =================