异常:Illuminate \ Broadcasting \ BroadcastException PusherBroadcaster.php 中没有消息:119

Jas*_*yer 3 php pusher laravel-5

拉拉维尔 5.8

我对整个推送功能很陌生,我一直在遵循本教程并尝试它,

使用 Laravel 和 Pusher Channels 创建 Web 通知

我已经一步一步地进行了操作,当我到达通过访问测试网址手动测试事件的步骤时,我收到以下异常:

照亮\广播\广播异常 无消息

C:\wamp\www\ares\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php

这是代码:

    $response = $this->pusher->trigger(
        $this->formatChannels($channels), $event, $payload, $socket, true
    );

    if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
        || $response === true) {
        return;
    }

    throw new BroadcastException( // <-- Exception at this line
        is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
    );
}

/**
 * Get the Pusher SDK instance.
 *
 * @return \Pusher\Pusher
 */
public function getPusher()
{
    return $this->pusher;
}
}
Run Code Online (Sandbox Code Playgroud)

我看过其他一些堆栈溢出文章,其中讨论了更改encrypted: trueencrypted: false,但这似乎没有影响任何事情。

EGB*_*yuk 5

我 4 天前开始使用 Laravel,在实现实时聊天应用程序时遇到了同样的问题。经过多天的搜索,我发现这可能会根据您运行的 Laravel 版本而有所不同。如果是 5.8,您可以通过在文件 config/broadcasting.php 的 Pusher.options 数组中添加以下代码来解决此问题:

'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ],
Run Code Online (Sandbox Code Playgroud)

添加此后,config/broadcasting.php 中的推送器数组应如下所示。

'pusher' => [
        'driver' => 'pusher',
        'key' => env('PUSHER_APP_KEY'),
        'secret' => env('PUSHER_APP_SECRET'),
        'app_id' => env('PUSHER_APP_ID'),
        'options' => [
            'cluster' => env('PUSHER_APP_CLUSTER'),
            'encrypted' => true,
            'curl_options' => [
                CURLOPT_SSL_VERIFYHOST => 0,
                CURLOPT_SSL_VERIFYPEER => 0,
            ],
        ],
    ],
Run Code Online (Sandbox Code Playgroud)

然后您可以运行php artisan config:cache(在某些情况下可能没有必要)并最终运行php artisan serve。您可以在推送者网站中查阅您的应用程序并查看发送消息后收到的事件。希望能帮助到你!!