Laravel Pusher Presence Channel Auth 错误

Laravel Pusher Presence Channel Auth error

我正在尝试建立一个状态通道。但是返回的授权字符串不正确。

后台代码如下:

class pusherController extends Controller
{

    protected $pusher;

    public function __construct(PusherManager $pusher)
    {
        $this->pusher = $pusher;
    }

    public function pusherPinyinAuth(Request $request)
    {
        if($request->user()) {
            $user = $request->user();
            $auth= $this->pusher->presence_auth($request->input('channel_name'),$request->input('socket_id'), $user->id, array('h'=>'user_info'));
            return response($auth);
        }
    }
}

错误信息

Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth value for subscription to presence-5 is invalid: should be of format 'key:signature'"}}}

我猜这个错误是由在授权字符串之前添加的附加':'引起的。但是我手动删除它仍然报告相同的错误。这是我的字符串输出:

{auth: ":8dacf362f8fe62bae42c33dfe5511d3d1c42144685d5843a6a6a8014490ed0f6",…}

我正在使用 https://github.com/vinkla/pusher

的推桥

我想试试官方的 pusher-php-server,但是安装 composer 后,我不知道如何在我的代码中使用它。我想知道https://github.com/pusher/pusher-http-php是否有同样的问题

对我来说,这是由于推送密钥、密钥和 app_id 值在生产中未正确设置造成的。

我也遇到同样的错误

Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth value for subscription to presence-5 is invalid: should be of format 'key:signature'"}}}

我能够通过返回包含 channel.php 文件

中的用户详细信息的数组来解决此问题

参见下面的代码示例:channel.php

Broadcast::channel('request_channel', function ($user) {
    return  ['id' => $user->id, 'name' => $user->name];
});