'); $text = preg_replace("/\<(blockquote|strong|pre|ol|ul|li|em|p|s|u).*?\>/is", "<$1>", $text); // 不用去除a标签,上面已经处理过了 $text = preg_replace("/\[:IMAGE:(.*?):(.*?):(.*?):(.*?):(.*?):\]/i", "", $text); $text = preg_replace("/\[:@:(.*?):(.*?):\]/i", "@$2", $text); $text = preg_replace("/\[:#:(.*?):(.*?):\]/i", "#$2", $text); return preg_replace("/^(
<\/p>)+|(
<\/p>)+$/i", "", $text); } /** * 发送消息 * @param int $dialog_id 会话ID(即 聊天室ID) * @param int $reply_id 回复ID * @param string $type 消息类型 * @param array $msg 发送的消息 * @param int $sender 发送的会员ID(默认自己,0为系统) * @param bool $push_self 是否推送给自己 * @return array */ public static function sendMsg($dialog_id, $reply_id, $type, $msg, $sender = 0, $push_self = false) { $link = 0; $mtype = $type; if ($type === 'text') { if (str_contains($msg['text'], ' $dialog_id, 'reply_id' => $reply_id, 'userid' => $sender ?: User::userid(), 'type' => $type, 'mtype' => $mtype, 'link' => $link, 'msg' => $msg, 'read' => 0, ]); if ($reply_id > 0) { self::whereId($reply_id)->increment('reply_num'); } AbstractModel::transaction(function () use ($dialogMsg) { $dialog = WebSocketDialog::find($dialogMsg->dialog_id); if (empty($dialog)) { throw new ApiException('获取会话失败'); } $dialog->last_at = Carbon::now(); $dialog->save(); $dialogMsg->send = 1; $dialogMsg->dialog_type = $dialog->type; $dialogMsg->key = $dialogMsg->generateMsgKey(); $dialogMsg->save(); }); // $task = new WebSocketDialogMsgTask($dialogMsg->id); if ($push_self) { $task->setIgnoreFd(null); } Task::deliver($task); // return Base::retSuccess('发送成功', $dialogMsg); } }