2020-11-02 22:45:37 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Amqp\Producer;
|
|
|
|
|
|
|
|
use Hyperf\Amqp\Message\ProducerMessage;
|
|
|
|
use Hyperf\Amqp\Message\Type;
|
2020-11-07 22:57:10 +08:00
|
|
|
use Hyperf\Utils\Str;
|
2020-11-02 22:45:37 +08:00
|
|
|
|
2020-11-04 11:57:16 +08:00
|
|
|
class ChatMessageProducer extends ProducerMessage
|
2020-11-02 22:45:37 +08:00
|
|
|
{
|
|
|
|
public $exchange = 'im.message.fanout';
|
|
|
|
|
|
|
|
public $type = Type::FANOUT;
|
|
|
|
|
|
|
|
public function __construct($data)
|
|
|
|
{
|
2020-11-04 07:54:11 +08:00
|
|
|
$message = [
|
2020-11-07 22:57:10 +08:00
|
|
|
'uuid' => $this->uuid(),
|
|
|
|
'method' => '', //
|
|
|
|
'sender' => '', //发送者ID
|
|
|
|
'receive' => '', //接收者ID
|
|
|
|
'receiveType' => '', //接收者类型 1:好友;2:群组
|
|
|
|
'message' => []
|
2020-11-04 07:54:11 +08:00
|
|
|
];
|
|
|
|
|
2020-11-02 22:45:37 +08:00
|
|
|
$this->payload = $data;
|
|
|
|
}
|
2020-11-07 22:57:10 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 生成唯一ID
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function uuid()
|
|
|
|
{
|
|
|
|
return Str::random() . rand(100000, 999999);
|
|
|
|
}
|
2020-11-02 22:45:37 +08:00
|
|
|
}
|