'); $text = preg_replace("/\
", $text);
$text = preg_replace("/\[:IMAGE:(.*?):(.*?):(.*?):(.*?):(.*?):\]/i", "", $text);
$text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "@$2", $text);
return preg_replace("/\[:#:(.*?):(.*?):\]/i", "#$2", $text);
}
/**
* 发送消息
* @param int $dialog_id 会话ID(即 聊天室ID)
* @param string $type 消息类型
* @param array $msg 发送的消息
* @param int $sender 发送的会员ID(默认自己,0为系统)
* @return array
*/
public static function sendMsg($dialog_id, $type, $msg, $sender = 0)
{
$dialogMsg = self::createInstance([
'userid' => $sender ?: User::userid(),
'type' => $type,
'msg' => $msg,
'read' => 0,
]);
AbstractModel::transaction(function () use ($dialog_id, $msg, $dialogMsg) {
$dialog = WebSocketDialog::find($dialog_id);
if (empty($dialog)) {
throw new ApiException('获取会话失败');
}
$dialog->last_at = Carbon::now();
$dialog->save();
$dialogMsg->send = 1;
$dialogMsg->dialog_id = $dialog->id;
$dialogMsg->save();
});
Task::deliver(new WebSocketDialogMsgTask($dialogMsg->id));
return Base::retSuccess('发送成功', $dialogMsg);
}
}