moshaorui 11 цаг өмнө
parent
commit
6534bcb358

+ 1 - 1
app/Distributor/Controllers/SmmPostController.php

@@ -204,7 +204,7 @@ class SmmPostController extends AdminDistController
                 return Admin::json()->error(admin_trans_label('fill_post_message'));
             }
             $messageCount = mb_strlen($post['message'], 'UTF-8');
-            if ($messageCount > 2000) {
+            if ($messageCount > 500) {
                 return Admin::json()->error(admin_trans_label('post_message_limit'));
             }
             if ($this->checkStoragePath($image_video_url) === false) {

+ 29 - 0
app/Services/Smm/TwitterService.php

@@ -324,6 +324,9 @@ class TwitterService implements SmmPlatformInterface
      */
     public function uploadAndPost($filePaths, $tweetText) {
         try {
+
+            $tweetText = $this->truncateText($tweetText, 138);// 截断推文
+
             $media_ids = [];
             foreach ($filePaths as $filePath) {
                 $file_info = pathinfo($filePath);
@@ -450,4 +453,30 @@ class TwitterService implements SmmPlatformInterface
             ];
         }
     }
+
+
+    /**
+     * 安全截断多字节文本(支持中文、日文等)
+     * @param string $text 原始文本
+     * @param int $maxLength 最大长度(默认280)
+     * @param string $ellipsis 截断后缀(默认...)
+     * @return string 处理后的文本
+     */
+    function truncateText(string $text, int $maxLength = 140, string $ellipsis = ''): string {
+        // 检测文本长度
+        $textLength = mb_strlen($text, 'UTF-8');
+
+        if ($textLength <= $maxLength) {
+            return $text;
+        }
+
+        // 计算后缀长度
+        $ellipsisLength = mb_strlen($ellipsis, 'UTF-8');
+
+        // 确保后缀不会导致总长度超过限制
+        $truncateLength = $maxLength - $ellipsisLength;
+
+        // 安全截取并添加后缀
+        return mb_substr($text, 0, $truncateLength, 'UTF-8') . $ellipsis;
+    }
 }

+ 2 - 2
lang/en/global.php

@@ -255,8 +255,8 @@ return [
         'youtube_category' => 'Youtube Category',
         'input_yutube_fields' => 'Please enter a YouTube title and category',
         'yutube_title_limit' => 'The maximum length of the YouTube title is 70 characters',
-        'post_message_limit' => 'The maximum length of the post message is 2000 characters',
-        'post_message_help' => 'Normal Twitter accounts can only enter 280 characters, if you exceed the limit, sending will fail and you need to upgrade your account.',
+        'post_message_limit' => 'The maximum length of the post message is 500 characters',
+        'post_message_help' => 'Tweets are limited to 140 characters and will be automatically intercepted if the limit is exceeded.',
     ],
     'options' => [
         //

+ 2 - 2
lang/zh_CN/global.php

@@ -266,8 +266,8 @@ return [
         'youtube_category'      => 'Youtube 分类',
         'input_yutube_fields'  => '请输入Youtube标题和分类',
         'yutube_title_limit'   => 'Youtube标题长度不能超过70个字符',
-        'post_message_limit'    => '帖子内容长度不能超过2000个字符',
-        'post_message_help' => '推特普通账号仅可输入 280 字符,超限将发送失败,需升级账号。',
+        'post_message_limit'    => '帖子内容长度不能超过50个字符',
+        'post_message_help' => '推特仅可输入 140 字符,超限系统将自动截取。',
     ],
     'options' => [
         //