From f5d1a86b4819472a759d0e792d908d8041b2bd57 Mon Sep 17 00:00:00 2001 From: wanghongjun <1445693971@qq.com> Date: Thu, 10 Jul 2025 14:05:11 +0800 Subject: [PATCH] =?UTF-8?q?=E9=99=90=E5=88=B6=E6=9C=8B=E5=8F=8B=E5=9C=88?= =?UTF-8?q?=E6=96=87=E5=AD=97=E9=95=BF=E5=BA=A6=EF=BC=8C=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=EF=BC=8C=E8=BF=9E=E6=8E=A5+=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/enterprise/controller/Posts.php | 33 +++++++++++++++++++++++++++++ app/lang/en_us.php | 1 + app/lang/zh_cn.php | 1 + 3 files changed, 35 insertions(+) diff --git a/app/enterprise/controller/Posts.php b/app/enterprise/controller/Posts.php index 82cb319..c445796 100644 --- a/app/enterprise/controller/Posts.php +++ b/app/enterprise/controller/Posts.php @@ -270,6 +270,11 @@ class Posts extends BaseController $type = ''; if (!empty($content)) { $type = '1'; + $detectionRes = $this->detectionProcessingText($content); + if (isset($detectionRes['error'])) { + return error($detectionRes['error']); + } + $content = $detectionRes['content']; } if (!empty($imgArr)) { if (is_array($imgArr) && count($imgArr) > 9) { @@ -395,6 +400,28 @@ class Posts extends BaseController return $data; } + // 检查文本输入内容 + protected function detectionProcessingText($content, $type = 1) + { + // 限制文字内容长度 + $text = strip_tags($content); + $textLen = mb_strlen($text); + $length = 2048; + $error = lang('posts.msgContentLimit') . $textLen; + if ($type == 2) { + $length = 500; + $error = lang('im.msgContentLimit') . $textLen; + } else { + $content = preg_link($content); + } + if ($textLen > $length) { + return ['error' => $error]; + } + // 接入聊天内容检测服务 + event('GreenText',['content'=>$content,'service'=>"chat_detection"]); + return ['content' => $content]; + } + // 获取上传草稿帖子数据 public function getLastPosts() { @@ -504,6 +531,12 @@ class Posts extends BaseController return error(lang('system.fail')); } + $detectionRes = $this->detectionProcessingText($content, 2); + if (isset($detectionRes['error'])) { + return error($detectionRes['error']); + } + $content = $detectionRes['content']; + $pid = $this->request->param('pid', 0); $reply_user_id = 0; if (!empty($pid)) { diff --git a/app/lang/en_us.php b/app/lang/en_us.php index f5b90c2..7151950 100644 --- a/app/lang/en_us.php +++ b/app/lang/en_us.php @@ -170,5 +170,6 @@ return [ 'img_max_length' => 'Up to 9 images can be uploaded', 'comment_del' => 'This comment has been deleted', 'postsDel' => 'This content has been deleted', + 'msgContentLimit' => 'The length of the content you entered is too long', ] ]; \ No newline at end of file diff --git a/app/lang/zh_cn.php b/app/lang/zh_cn.php index d34a6e6..bd921af 100644 --- a/app/lang/zh_cn.php +++ b/app/lang/zh_cn.php @@ -169,5 +169,6 @@ return [ 'img_max_length' => '图片最多上传9张', 'comment_del' => '此条评论已被删除', 'postsDel' => '该内容已被删除', + 'msgContentLimit' => '你输入的内容长度太长了!', ] ]; \ No newline at end of file