修复:私有频道改用数字 ID,解决中文用户名导致 Pusher 频道名非法
错误原因:Pusher 频道名只允许 [a-zA-Z0-9_\-=@,.],
中文用户名(如「超级舞魅」)用于 private-user.{username} 导致
PusherException: Invalid channel name。
修复方案(改用数字 ID):
- FriendAdded/FriendRemoved 构造加 toUserId 参数
- broadcastOn() 改为 PrivateChannel('user.' . $toUserId)
- FriendController 传入 $target->id / $targetUser->id
- channels.php 鉴权改为 'user.{id}',核对 $user->id 数字相等
- frame.blade.php chatContext 加 userId
- scripts.blade.php Echo.private 改用 userId 订阅
This commit is contained in:
+4
-4
@@ -27,8 +27,8 @@ Broadcast::channel('room.{roomId}', function ($user, $roomId) {
|
||||
];
|
||||
});
|
||||
|
||||
// 用户私有频道鉴权(好友通知:FriendAdded / FriendRemoved)
|
||||
// 只有用户名匹配的本人才能订阅
|
||||
Broadcast::channel('user.{username}', function ($user, string $username) {
|
||||
return $user->username === $username;
|
||||
// 用户私有频道鉴权(好友通知:FriendAdded / FriendRemoved / BannerNotification)
|
||||
// 使用数字 ID 命名频道,避免中文用户名导致 Pusher 频道名验证失败。
|
||||
Broadcast::channel('user.{id}', function ($user, int $id) {
|
||||
return (int) $user->id === $id;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user