消息推送
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user