我尝试使用我的应用程序测试推送器,连接设置成功,但推送器无法侦听我的应用程序事件。
我正在使用拉拉维尔 7
广播.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => 'ap2',
'encrypted' => true,
'useTLS' => true,
// 'curl_options' => [
// CURLOPT_SSL_VERIFYHOST => 0,
// CURLOPT_SSL_VERIFYPEER => 0,
// ],
],
],
.env 文件
APP_URL=http://localhost
DB_HOST=localhost
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=XXXXX
PUSHER_APP_KEY=XXXXX
PUSHER_APP_SECRET=XXXXX
PUSHER_APP_CLUSTER=ap2
事件类
class LikeEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $id;
public $type;
public function __construct($id,$type)
{
$this->id = $id;
$this->type = $type;
}
public function broadcastOn()
{
//return new PrivateChannel('likeChannel'); //I try both
return new Channel('likeChannel');
}
public function broadcastAs()
{
return 'LikeEvent';
}
}
频道.php
Broadcast::channel('likeChannel', function () {
return true;
});
我尝试通过以下方式调用控制器中的事件
broadcast(new LikeEvent($reply->id,1))->toOthers();
//broadcast(new LikeEvent($reply->id,1));
//broadcast(new TestEvent("hello pusher"));
//event(new LikeEvent($reply->id,1));
它总是抛出广播异常
"message": "",
"exception": "Illuminate\Broadcasting\BroadcastException",
"file": "C:\wamp64\www\rtforum.test\vendor\laravel\framework\src\Illuminate\Broadcasting\Broadcasters\PusherBroadcaster.php",
"line": 121,
我通过使加密错误来解决我的问题
'options' => [
'cluster' => 'ap2',
'encrypted' => false,
]