增加消息推送
This commit is contained in:
@@ -53,6 +53,16 @@ class WsEvents
|
||||
}
|
||||
}
|
||||
|
||||
protected function eventToMethod(string $event): string
|
||||
{
|
||||
$parts = explode('.', $event);
|
||||
$method = array_shift($parts);
|
||||
foreach ($parts as $part) {
|
||||
$method .= ucfirst($part);
|
||||
}
|
||||
return $method;
|
||||
}
|
||||
|
||||
|
||||
// ================= 系统事件 =================
|
||||
/**
|
||||
@@ -112,6 +122,14 @@ class WsEvents
|
||||
'system.auth',
|
||||
['uid' => $user->uid]
|
||||
));
|
||||
|
||||
// 初始化推送
|
||||
$wdata = [
|
||||
'is_first' => true,
|
||||
'event' => 'approval.todo.counts',
|
||||
'user_id' => $user->uid
|
||||
];
|
||||
\Webman\RedisQueue\Redis::send('ws-msg', $wdata);
|
||||
} catch (\Throwable $th) {
|
||||
flg('[x] [TOKEN认证] TOKEN认证失败:'.$th->getMessage(), false);
|
||||
Gateway::sendToClient($client_id, WsResponse::error(
|
||||
@@ -235,22 +253,20 @@ class WsEvents
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息通知
|
||||
*/
|
||||
public function pushWsNotice(array $wsData, int $userId)
|
||||
{
|
||||
Gateway::sendToUid($userId, WsResponse::success('notify.receive', $wsData));
|
||||
}
|
||||
|
||||
// ================= 辅助方法 =================
|
||||
protected function eventToMethod(string $event): string
|
||||
/*
|
||||
approval.todo.counts 审批待办数量
|
||||
|
||||
*/
|
||||
|
||||
// ================= 主动推送 =================
|
||||
|
||||
public function pushWebsocket(string $event, int|string $uid, array $data)
|
||||
{
|
||||
$parts = explode('.', $event);
|
||||
$method = array_shift($parts);
|
||||
foreach ($parts as $part) {
|
||||
$method .= ucfirst($part);
|
||||
}
|
||||
return $method;
|
||||
return match (gettype($uid)) {
|
||||
'integer' => Gateway::sendToUid($uid, WsResponse::success($event, $data)),
|
||||
'string' => Gateway::sendToClient($uid, WsResponse::success($event, $data)),
|
||||
default => throw new \InvalidArgumentException('UID must be integer or string'),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user