【问题标题】:Laravel Broadcast Notification error : Client can not be authenticated, got HTTP status 404Laravel 广播通知错误:客户端无法通过身份验证,获得 HTTP 状态 404
【发布时间】:2018-11-21 11:48:41
【问题描述】:

我正在尝试构建一个实时通知系统。 我使用了 Laravel-Notifications 和 laravel-echo-server。 当我在终端 laravel-echo-server start 中使用 start 命令收听通知时,私人频道出现错误:

⚠ [下午 4:36:43] - H12aWYBsF5UdR5NYAAAH 无法通过 private-App.Domain.User.User.1 的身份验证

客户端无法通过身份验证,得到 HTTP 状态 404

代码

//频道.php

Broadcast::channel('App.Domain.User.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;});

//通知文件代码(ListingApproved.php)

class ListingApproved extends Notification implements ShouldQueue {
use Queueable;

private $listing;

/**
 * Create a new notification instance.
 *
 * @return void
 */
public function __construct(Listing $listing)
{
    $this->listing = $listing;
}

/**
 * Get the notification's delivery channels.
 *
 * @param  mixed  $notifiable
 * @return array
 */
public function via($notifiable)
{
    return ['database', 'broadcast'];
}

public function toArray($notifiable)
{
    return $this->listing->id;
}
public function toBroadcast($notifiable)
{
    return new BroadcastMessage([
        'invoice_id' => $this->listing->id
    ]);
}}

//监听通知的前端脚本

Echo.private('App.Domain.User.User.' + '{{ auth()->user()->id }}')
        .listen(".Illuminate\\Notifications\\Events\\BroadcastNotificationCreated", (notification) => {
            console.log('yes');
            console.log(notification.type);
        });

【问题讨论】:

    标签: php laravel laravel-echo laravel-broadcast


    【解决方案1】:

    可能与你的 echo server auth host 配置有关,

    您可以使用 laravel echo server 和 redis 检查例如 laravel 实时应用程序,

    Real time application example with Laravel / Redis / Socket.IO / Laravel-Echo

    我希望这会有所帮助

    【讨论】:

    • 例如我分享了这个链接。您是否使用共享示例检查了您的conf?您的身份验证主机链接有问题,示例包含此用法,为此请检查 https://github.com/durmus-aydogdu/real-time-application/blob/master/resources/assets/js/UserEvents.jshttps://github.com/durmus-aydogdu/real-time-application/blob/master/laravel-echo-server.json.example 和自述文件
    猜你喜欢
    • 2018-11-24
    • 2019-01-25
    • 2018-02-19
    • 2020-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    相关资源
    最近更新 更多