接口调整
This commit is contained in:
@@ -1087,11 +1087,22 @@ class Aiarticle extends Base
|
|||||||
}
|
}
|
||||||
//查询文章是否存在
|
//查询文章是否存在
|
||||||
$aWhere = ['article_id' => $iArticleId,'is_delete' => 2];
|
$aWhere = ['article_id' => $iArticleId,'is_delete' => 2];
|
||||||
$aAiArticle = Db::name('ai_article')->field('title_chinese as title,author,journal_id')->where($aWhere)->find();
|
$aAiArticle = Db::name('ai_article')->field('title_chinese as title,author,journal_id,digest')->where($aWhere)->find();
|
||||||
if(empty($aAiArticle)){
|
if(empty($aAiArticle)){
|
||||||
return json_encode(['status' => 3, 'msg' => 'The article does not exist']);
|
return json_encode(['status' => 3, 'msg' => 'The article does not exist']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//数据处理
|
||||||
|
$sTitle = empty($aAiArticle['title']) ? '' : $aAiArticle['title'];
|
||||||
|
$sTitle = mb_convert_encoding($sTitle, 'UTF-8', 'auto');
|
||||||
|
// 截断处理
|
||||||
|
$aAiArticle['title'] = $this->truncateByBytes($sTitle, 64);
|
||||||
|
|
||||||
|
$sDigest = empty($aAiArticle['digest']) ? '' : $aAiArticle['digest'];
|
||||||
|
// 编码转换
|
||||||
|
$sDigest = mb_convert_encoding($sDigest, 'UTF-8', 'auto');
|
||||||
|
$aAiArticle['digest'] = $this->truncateByBytes($sDigest, 120);
|
||||||
|
|
||||||
//查询该模版是否推送到微信公众号
|
//查询该模版是否推送到微信公众号
|
||||||
$aWhere['template_id'] = $iTemplateId;
|
$aWhere['template_id'] = $iTemplateId;
|
||||||
$aWhere['wechat_id'] = $sWechatId;
|
$aWhere['wechat_id'] = $sWechatId;
|
||||||
@@ -1132,6 +1143,26 @@ class Aiarticle extends Base
|
|||||||
return $aResult;
|
return $aResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function truncateByBytes($str, $maxBytes) {
|
||||||
|
$len = 0;
|
||||||
|
$result = '';
|
||||||
|
$i = 0;
|
||||||
|
|
||||||
|
while ($i < mb_strlen($str, 'UTF-8')) {
|
||||||
|
$char = mb_substr($str, $i, 1, 'UTF-8');
|
||||||
|
$charBytes = strlen($char); // UTF-8 下实际字节数
|
||||||
|
|
||||||
|
if ($len + $charBytes > $maxBytes) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result .= $char;
|
||||||
|
$len += $charBytes;
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取Ai生成文章状态
|
* 获取Ai生成文章状态
|
||||||
|
|||||||
Reference in New Issue
Block a user