正在显示
3 个修改的文件
包含
25 行增加
和
8 行删除
| @@ -1588,4 +1588,27 @@ if (!function_exists('httpGetSsl')) { | @@ -1588,4 +1588,27 @@ if (!function_exists('httpGetSsl')) { | ||
| 1588 | $result = json_decode($res, true); | 1588 | $result = json_decode($res, true); |
| 1589 | return is_array($result) ? $result : $res; | 1589 | return is_array($result) ? $result : $res; |
| 1590 | } | 1590 | } |
| 1591 | + | ||
| 1592 | + /** | ||
| 1593 | + * @remark :截取自付出啊 | ||
| 1594 | + * @name :truncate_words | ||
| 1595 | + * @author :lyh | ||
| 1596 | + * @method :post | ||
| 1597 | + * @time :2025/9/22 14:46 | ||
| 1598 | + */ | ||
| 1599 | + function truncate_text($text, $limit = 300) { | ||
| 1600 | + // 长度小于限制直接返回 | ||
| 1601 | + if (mb_strlen($text, 'UTF-8') <= $limit) { | ||
| 1602 | + return $text; | ||
| 1603 | + } | ||
| 1604 | + // 先取前 $limit 个字符 | ||
| 1605 | + $truncated = mb_substr($text, 0, $limit, 'UTF-8'); | ||
| 1606 | + // 如果这一段包含空格(说明有英文单词),尽量在最后一个空格处截断 | ||
| 1607 | + $lastSpace = mb_strrpos($truncated, ' ', 0, 'UTF-8'); | ||
| 1608 | + if ($lastSpace !== false) { | ||
| 1609 | + // 在最后一个空格处截断,避免英文单词被截断 | ||
| 1610 | + $truncated = mb_substr($truncated, 0, $lastSpace, 'UTF-8'); | ||
| 1611 | + } | ||
| 1612 | + return $truncated; | ||
| 1613 | + } | ||
| 1591 | } | 1614 | } |
| @@ -229,13 +229,11 @@ class AiBlogController extends BaseController | @@ -229,13 +229,11 @@ class AiBlogController extends BaseController | ||
| 229 | 'image'=>['required'], | 229 | 'image'=>['required'], |
| 230 | 'author_id'=>['required'], | 230 | 'author_id'=>['required'], |
| 231 | 'text'=>['required'], | 231 | 'text'=>['required'], |
| 232 | - 'description'=>['required'], | ||
| 233 | ],[ | 232 | ],[ |
| 234 | 'new_title.required' => '标题不能为空', | 233 | 'new_title.required' => '标题不能为空', |
| 235 | 'image.required' => '缩略图不能为空', | 234 | 'image.required' => '缩略图不能为空', |
| 236 | 'author_id.required' => '作者id不能为空', | 235 | 'author_id.required' => '作者id不能为空', |
| 237 | - 'text.required' => '作者id不能为空', | ||
| 238 | - 'description.required' => '短描述不能为空', | 236 | + 'text.required' => '内容不能为空', |
| 239 | ]); | 237 | ]); |
| 240 | $data = $aiBlogLogic->customSaveBlog($this->param); | 238 | $data = $aiBlogLogic->customSaveBlog($this->param); |
| 241 | $this->response('success',Code::SUCCESS,$data); | 239 | $this->response('success',Code::SUCCESS,$data); |
| @@ -197,11 +197,7 @@ class AiBlogLogic extends BaseLogic | @@ -197,11 +197,7 @@ class AiBlogLogic extends BaseLogic | ||
| 197 | $param['seo_keyword'] = $text1; | 197 | $param['seo_keyword'] = $text1; |
| 198 | } | 198 | } |
| 199 | if(!isset($param['description']) || empty($param['description'])){ | 199 | if(!isset($param['description']) || empty($param['description'])){ |
| 200 | - $ai = "According to the keyword {$param['title']}, write a seo meta description show to purchaser within 100 characters"; | ||
| 201 | - $text2 = Gpt::instance()->openai_chat_qqs($ai); | ||
| 202 | - $text2 = Common::deal_keywords($text2); | ||
| 203 | - $text2 = Common::deal_str($text2); | ||
| 204 | - $param['description'] = $text2; | 200 | + $param['description'] = truncate_text($param['text']); |
| 205 | } | 201 | } |
| 206 | $param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']); | 202 | $param['route'] = RouteMap::setRoute($param['route'], RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']); |
| 207 | $this->model->edit($param,['id'=>$param['id']]); | 203 | $this->model->edit($param,['id'=>$param['id']]); |
-
请 注册 或 登录 后发表评论