消息推送

This commit is contained in:
mzl
2025-08-20 19:14:27 +08:00
parent 9f96b8d625
commit 58dc6729d9
5 changed files with 130 additions and 5 deletions
+23
View File
@@ -222,6 +222,29 @@ class WsEvents
));
}
/**
* 推送消息通知
*/
public function pushNotice(int $msgId, string $title, string $content, array $recipient)
{
$payload = WsResponse::success('notify.push', [
'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);
}
}
// ================= 辅助方法 =================
protected function eventToMethod(string $event): string
{