我有一个具有订阅私人频道的代码,当我尝试订阅时,我有下一条消息:
Pusher :无法从您的get应用程序中获得信息: 404
场景:
Javascript(Sencha touch)和PHP(Laravel)
订阅在javascript中:
Pusher.channel_auth_endpoint = "/pusher.php";
var APP_KEY = '4324523452435234523';
var pusher = new Pusher(APP_KEY);
var channel = pusher.subscribe('private-l2');
channel.bind('pusher:subscription_succeeded', function() {
alert("ahora siiii");
});
// for debugging purposes. Not required.
Pusher.log = function(msg) {
if(window.console && window.console.log) {
window.console.log("PUSHER LOG: "+msg);
}
}和pusher.php / LARAVEL
$this->app_id = '66981';
$this->app_key = '4324523452435234523';
$this->app_secret = 'f34632459911e2670dcf';
$pusher = new Pusher($this->app_key, $this->app_secret, $this->app_id);
$auth = $pusher->socket_auth(Input::get('channel_name'), Input::get('socket_id'));
echo $auth;其结果是错误:
Pusher : State changed : connecting -> connected
Pusher : Couldn't get auth info from your webapp : 404 发布于 2016-08-09 09:24:07
您应该为Pusher身份验证Route::post('pusher/auth', 'ApiController@pusherAuth');设置一个路由。
在这种方法中,首先应该禁用php调试器(如果使用它),对用户进行身份验证,如果身份验证检查,则返回响应。
我会在下面粘贴我的控制器代码。
public function pusherAuth()
{
\Debugbar::disable();
$user = auth()->user();
if ($user) {
$pusher = new \Pusher(config('broadcasting.connections.pusher.key'), config('broadcasting.connections.pusher.secret'), config('broadcasting.connections.pusher.app_id'));
echo $pusher->socket_auth(request()->input('channel_name'), request()->input('socket_id'));
return;
}else {
header('', true, 403);
echo "Forbidden";
return;
}
}我的JS代码:
var pusher = new Pusher(project.pusherKey, {
cluster: 'eu',
encrypted: true,
authEndpoint: apiUrl(['pusher', 'auth']), // just a helper method to create a link
auth: {
headers: {
'X-CSRF-Token': project.token // CSRF token
}
}
});
var channelName = 'private-notifications-' + project.userId; // channel for the user id
var channel = pusher.subscribe(channelName);
channel.bind('new_notification', function (data)
{
app.addNotification(data); // send the notification in the JS app
});我希望这能帮到你。
干杯!
发布于 2014-06-24 17:53:02
私人推送通道要求客户端进行身份验证以进行访问。有关配置客户端以进行身份验证和设置身份验证端点的详细信息,请参阅配置客户端以进行身份验证。
发布于 2017-05-19 14:19:41
变化
Pusher.channel_auth_endpoint = "/pusher.php";适用于:
Pusher.channel_auth_endpoint = "/public/broadcasting/auth";https://stackoverflow.com/questions/23868766
复制相似问题