订阅私人频道的Pusher Auth值格式无效,格式为'key:signature'(Laravel)

时间:2019-11-18 22:25:35

标签: laravel laravel-5 pusher

推杆有效,但停止了。 .env设置是100%正确的。请告诉我该如何调试?另外,我尝试制作新的Puser应用

Pusher : State changed : connecting -> connected with new socket ID 126791.4368004
pusher.min.js:8 Pusher : Event sent : {"event":"pusher:subscribe","data":{"auth":":88536630b30af895eb4ac1fcab4af7fcac1fbce3883074b00aa47cfc873c9362","channel":"private-user.1971"}}
pusher.min.js:8 Pusher : Event recd : {"event":"pusher:error","data":{"code":null,"message":"Auth value for subscription to private-user.1971 is invalid: should be of format 'key:signature'"}}
pusher.min.js:8 Pusher : Error : {"type":"WebSocketError","error":{"type":"PusherError","data":{"code":null,"message":"Auth value for subscription to private-user.1971 is invalid: should be of format 'key:signature'"}}}
PUSHER_APP_ID=902144
PUSHER_APP_KEY=0dd4fc93384fc94b5d6b
PUSHER_APP_SECRET=*****************
var pusher = new Pusher('0dd4fc93384fc94b5d6b', {
    cluster: 'eu',
    forceTLS: true,
    auth: {
        headers: {
             'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content')
        }
    }
});
class PusherController extends Controller
{
    public $pusher;

    public function __construct ()
    {
        $this->middleware('auth');
        $this->pusher = new Pusher(env('PUSHER_APP_KEY'), env('PUSHER_APP_SECRET'), env('PUSHER_APP_ID'));
    }

    public function auth(Request $request)
    {
        if (Auth::check()) {
            return $this->pusher->socket_auth($request->get('channel_name'), $request->get('socket_id'));
        } else {
            return Response::make('Forbidden', 403);
        }
    }
}

Broadcasting.php:

'pusher' => [
            'driver' => 'pusher',
            'key' => env('PUSHER_APP_KEY'),
            'secret' => env('PUSHER_APP_SECRET'),
            'app_id' => env('PUSHER_APP_ID'),
            'options' => [
                'cluster' => 'eu',
                'useTLS' => true
            ],
        ],

一切正常,但在某些时候停止了。我很绝望:(

1 个答案:

答案 0 :(得分:0)

请勿在配置文件之外使用env(...)。参考您需要的文件和密钥使用config(...)。示例:config('broadcasting.pusher.key')

如果您缓存配置,则不会加载.env文件,这意味着env(...)会为所有内容返回null

听起来像您缓存了配置。您可以通过清除配置缓存来测试此理论:

php artisan config:clear

如果重新开始工作,那就是您的问题。

  

”如果在部署过程中执行config:cache命令,则应确保只从配置文件中调用env函数。配置被缓存后,{ {1}}文件将不会加载,对.env函数的所有调用都将返回env。”

Laravel 5.8 Docs - Configuration - Configuration Caching