hyperf-chat/app/Amqp/Producer/ChatMessageProducer.php

40 lines
888 B
PHP
Raw Normal View History

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;
2020-11-21 19:53:01 +08:00
public function __construct($sender, $receive, $source, $record_id)
2020-11-02 22:45:37 +08:00
{
2020-11-04 07:54:11 +08:00
$message = [
2020-11-07 22:57:10 +08:00
'uuid' => $this->uuid(),
2020-11-21 19:53:01 +08:00
'sender' => intval($sender), //发送者ID
'receive' => intval($receive), //接收者ID
'source' => intval($source), //接收者类型 1:好友;2:群组
'record_id' => intval($record_id)
2020-11-04 07:54:11 +08:00
];
2020-11-08 17:10:05 +08:00
$this->payload = $message;
2020-11-02 22:45:37 +08:00
}
2020-11-07 22:57:10 +08:00
/**
* 生成唯一ID
*
* @return string
*/
private function uuid()
{
2020-11-08 22:58:17 +08:00
return Str::random() . rand(100000, 999999) . uniqid();
2020-11-07 22:57:10 +08:00
}
2020-11-02 22:45:37 +08:00
}