[英]Pusher Private Channel Auth info required to subscribe to private-asdf
嘗試使用 Pusher 訂閱私人頻道。 但是每次它嘗試訂閱時,我都會收到以下錯誤。 這沒有任何意義,因為它顯然返回了身份驗證信息。
Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth info required to subscribe to private-sadfsadf"}}}
通常它會返回狀態為200
的 auth json(如下)。
"{\"auth\":\"0b1ce844906bd4d82cb4:21571e5667bf99f17bbf67ae0411594560748fde30b9edeca653653158f8a1f5\"}"
推送器 PHP (縮短)
$pusher = new Pusher($app_key, $app_secret, $app_id);
$auth = $pusher->socket_auth($postvars['channel_name'], $postvars['socked_id']);
if ($auth)
return $response->withJSON($auth);
else
return $response->withStatus(403);
推桿 JS
var pusher = new Pusher('0b1ce844906bd4d82cb4', {
cluster: 'us2',
encrypted: true,
authEndpoint: '{{site.uri.public}}/chat/auth/{{game.id}}',
authTransport: 'ajax',
auth: {
params: {
'csrf_name': '{{site.csrf.name}}',
'csrf_value': '{{site.csrf.value}}'
},
headers: {
'{{site.csrf.name}}': '{{site.csrf.value}}'
}
}
});
我遇到了這個錯誤,這是由於將 BROADCAST_DRIVER 設置為 redis 而不是 pusher 引起的。
這是因為我的端點/pusher/auth
返回了 JSON 格式的簽名。
所以,我只是改變了這個:
return $response
對此:
return json_decode($response)
注意:PUSHER 簽名使用hash_hmac
生成哈希:您可以將entryPoint
返回與
$sig = hash_hmac('sha256',$socket, $channelNam);
var_dump($sig);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.