我刚开始使用pusher,因为我在使用redis和socket.io时遇到了问题。为此,我遵循了documentation of Laravel,在pusher上创建了一个帐户,并将密钥插入文件.env中。
BROADCAST_DRIVER=pusher
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=database
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
PUSHER_APP_ID=XXXXX
PUSHER_APP_KEY=XXXXXXXXXXXXX
PUSHER_APP_SECRET=XXXXXXXXXXXXXX
PUSHER_APP_CLUSTER=eu
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
然后我创建了一个实现应播接口的事件
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class IncrementAddingOrderCounter implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $length;
public $value;
/**
* Create a new event instance.
*
* @param $length
* @param $value
*/
public function __construct($length, $value)
{
$this->length = $length;
$this->value = $value;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new Channel('add.order');
}
public function broadcastAs()
{
return 'increment.order';
}
}
然后我用
发出事件event(new IncrementAddingOrderCounter(count($parsedData), $size));
但是事件执行失败
[2018-07-26 04:21:26] local.ERROR: Invalid signature: you should have sent HmacSHA256Hex("POST\n/apps/xxxxxx/events\nauth_key=xxxxxxxxxx&auth_timestamp=xxxxxxxx&auth_version=1.0&body_md5=xxxxxxxxxxxx", your_secret_key), but you sent "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
{"exception":"[object] (Illuminate\\Broadcasting\\BroadcastException(code: 0): Invalid signature: you should have sent HmacSHA256Hex(\"POST\
/apps/567300/events\
auth_key=xxxxxxxxxx&auth_timestamp=xxxxxxx&auth_version=1.0&body_md5=xxxxxxxxxxxx\", your_secret_key), but you sent \"xxxxxxxxxxxxxxx\"
at /home/oza/lab/php/Client1_GestionCommerce/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php:116)
[stacktrace]
有人对此有解决方案吗,因为我在互联网上搜索,却找不到任何东西
答案 0 :(得分:2)
如果您发送的签名错误,通常意味着它们的密钥/秘密/应用程序ID /集群未正确配置。你能仔细检查一下吗?您还可能在帖子中发布了一个敏感密钥-我建议将其隐藏起来并生成一个新的id / key / secret组合(可以在Pusher仪表板中完成!)。