74 lines
1.7 KiB
PHP
74 lines
1.7 KiB
PHP
<?php
|
||
|
||
namespace app\common\library\live\message;
|
||
|
||
/**
|
||
* 直播消息值对象
|
||
* 描述一条待发送的消息,封装消息各字段,便于在业务层与服务商层之间传递
|
||
*/
|
||
class Message
|
||
{
|
||
/**
|
||
* @var string 群组ID(奥点云 topic / 阿里云 GroupId)
|
||
*/
|
||
public $groupId;
|
||
|
||
/**
|
||
* @var string 发送者ID(阿里云必填)
|
||
*/
|
||
public $senderId;
|
||
|
||
/**
|
||
* @var string 发送者扩展信息
|
||
*/
|
||
public $senderMeta;
|
||
|
||
/**
|
||
* @var string 消息体(JSON 字符串)
|
||
*/
|
||
public $body;
|
||
|
||
/**
|
||
* @var int 消息类型
|
||
*/
|
||
public $msgType;
|
||
|
||
/**
|
||
* @var string 消息唯一标识(用于撤回)
|
||
*/
|
||
public $msgTid;
|
||
|
||
/**
|
||
* 构造函数
|
||
* @param array $data 初始化数据,支持键:group_id/sender_id/sender_meta/body/msg_type/msg_tid
|
||
*/
|
||
public function __construct(array $data = [])
|
||
{
|
||
$this->groupId = $data['group_id'] ?? '';
|
||
$this->senderId = $data['sender_id'] ?? '';
|
||
$this->senderMeta = $data['sender_meta'] ?? '';
|
||
$this->body = $data['body'] ?? '';
|
||
$this->msgType = isset($data['msg_type']) ? (int)$data['msg_type'] : 10001;
|
||
$this->msgTid = $data['msg_tid'] ?? '';
|
||
}
|
||
|
||
/**
|
||
* 消息业务类型到阿里云 MsgType 的映射
|
||
* text -> 10001
|
||
* image -> 10002
|
||
* gift -> 10003
|
||
* 其他 -> 10099
|
||
* @param string $type 业务消息类型
|
||
* @return int
|
||
*/
|
||
public static function mapMsgType($type)
|
||
{
|
||
$map = [
|
||
'text' => 10001,
|
||
'image' => 10002,
|
||
'gift' => 10003,
|
||
];
|
||
return isset($map[$type]) ? $map[$type] : 10099;
|
||
}
|
||
}
|