From 5a7d1565e54cb8f1a5f0828c56a08221da393b41 Mon Sep 17 00:00:00 2001 From: lkddi Date: Sun, 1 Mar 2026 01:54:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Achannels.php=20?= =?UTF-8?q?=E7=A7=BB=E9=99=A4=20int=20=E7=B1=BB=E5=9E=8B=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=EF=BC=8C=E6=94=B9=E7=94=A8=E5=BC=BA=E8=BD=AC=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E9=98=B2=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit int $id 类型提示在某些 PHP 版本下对字符串参数可能失败, 统一改为 (int) 强转比较,与 App.Models.User.{id} 写法一致。 --- resources/views/chat/partials/scripts.blade.php | 6 +++--- routes/channels.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/views/chat/partials/scripts.blade.php b/resources/views/chat/partials/scripts.blade.php index 33f34a2..bc70c0f 100644 --- a/resources/views/chat/partials/scripts.blade.php +++ b/resources/views/chat/partials/scripts.blade.php @@ -664,7 +664,7 @@ return; } const myName = window.chatContext.username; - const myId = window.chatContext.userId; + const myId = window.chatContext.userId; window.Echo.private(`user.${myId}`) .listen('.FriendAdded', (e) => { // 用居中大卡弹窗通知(有无互相好友显示不同文案和按钮) @@ -708,7 +708,7 @@ return; } const myName = window.chatContext.username; - const myId = window.chatContext.userId; + const myId = window.chatContext.userId; const roomId = window.chatContext.roomId; // 监听私有用户频道(单独推给某人,用数字 ID 避免中文名频道非法) @@ -1248,7 +1248,7 @@ contentInput.focus(); } else { window.chatDialog.alert('发送失败: ' + (data.message || JSON.stringify(data.errors)), '操作失败', - '#cc4444'); + '#cc4444'); } } catch (error) { window.chatDialog.alert('网络连接错误,消息发送失败!', '网络错误', '#cc4444'); diff --git a/routes/channels.php b/routes/channels.php index 2f4e8c7..4b154f9 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -29,6 +29,6 @@ Broadcast::channel('room.{roomId}', function ($user, $roomId) { // 用户私有频道鉴权(好友通知:FriendAdded / FriendRemoved / BannerNotification) // 使用数字 ID 命名频道,避免中文用户名导致 Pusher 频道名验证失败。 -Broadcast::channel('user.{id}', function ($user, int $id) { - return (int) $user->id === $id; +Broadcast::channel('user.{id}', function ($user, $id) { + return (int) $user->id === (int) $id; });