接口调整
This commit is contained in:
@@ -94,6 +94,8 @@ class Aiarticle extends Base
|
|||||||
'wechat_app_secret' => 'd5e6002b8b48de46f64dc9a02312f944'
|
'wechat_app_secret' => 'd5e6002b8b48de46f64dc9a02312f944'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//生成AI文章状态
|
||||||
|
protected $sGenerateStatusName = 'generate_status_article_id';
|
||||||
public function __construct(\think\Request $request = null) {
|
public function __construct(\think\Request $request = null) {
|
||||||
|
|
||||||
$this->proxy = '';
|
$this->proxy = '';
|
||||||
@@ -289,6 +291,8 @@ class Aiarticle extends Base
|
|||||||
$aSearch['{#title_chinese#}'] = $this->basic_html_filter($aArticle['title']);
|
$aSearch['{#title_chinese#}'] = $this->basic_html_filter($aArticle['title']);
|
||||||
$aSearch['{#journal_content#}'] = $this->basic_html_filter($aJournal['journal_content'] ?? '');
|
$aSearch['{#journal_content#}'] = $this->basic_html_filter($aJournal['journal_content'] ?? '');
|
||||||
$aSearch['{#journal_content#}'] = trim(trim($aSearch['{#journal_content#}'],'.'),'。');
|
$aSearch['{#journal_content#}'] = trim(trim($aSearch['{#journal_content#}'],'.'),'。');
|
||||||
|
|
||||||
|
//写入Redis 标识已经开始请求OPENAI处理
|
||||||
$aResult = $this->_createContentForOpenAI($aSearch,2);
|
$aResult = $this->_createContentForOpenAI($aSearch,2);
|
||||||
$aResult = json_decode($aResult,true);
|
$aResult = json_decode($aResult,true);
|
||||||
if($aResult['status'] != 1){
|
if($aResult['status'] != 1){
|
||||||
@@ -411,19 +415,6 @@ class Aiarticle extends Base
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//查询是否上传到微信草稿箱
|
|
||||||
if(!empty($iArticleId)){
|
|
||||||
$aWhere = ['article_id' => $iArticleId,'is_delete' => 2];
|
|
||||||
if(!empty($aParam['template_id'])){
|
|
||||||
$aWhere['template_id'] = $aParam['template_id'];
|
|
||||||
}
|
|
||||||
if(!empty($aParam['wechat_id'])){
|
|
||||||
$aWhere['wechat_id'] = $aParam['wechat_id'];
|
|
||||||
}
|
|
||||||
$aDraft = Db::name('ai_wechat_article')->field('template_id,wechat_id')->where($aWhere)->select();
|
|
||||||
$aAiArticle['upload_draft'] = $aDraft;
|
|
||||||
}
|
|
||||||
|
|
||||||
return json_encode(['status' => 1,'msg' => 'success','data' => ['ai_article' => $aAiArticle,'ai_article_author' => $aAiAuthor]]);
|
return json_encode(['status' => 1,'msg' => 'success','data' => ['ai_article' => $aAiArticle,'ai_article_author' => $aAiAuthor]]);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -710,52 +701,46 @@ class Aiarticle extends Base
|
|||||||
// //上传素材到微信
|
// //上传素材到微信
|
||||||
if($iIsSync == 1){
|
if($iIsSync == 1){
|
||||||
|
|
||||||
//文章图片上传
|
//查询参数组装
|
||||||
$sWechatAppId = empty($aParam['wechat_app_id']) ? '' : $aParam['wechat_app_id'];
|
$aQueryParam = ['article_id' => $iArticleId,'journal_id' => $aArticle['journal_id']];
|
||||||
$sWechatAppSecret = empty($aParam['wechat_app_secret']) ? '' : $aParam['wechat_app_secret'];
|
//组装作者数据
|
||||||
$aUpload = ['article_id' => $iArticleId,'icon' => $sArticleIcon,'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
|
||||||
$aArticleResult = json_decode($oMaterial->addArticleMaterial($aUpload),true);
|
|
||||||
$aArticleData = empty($aArticleResult['data']) ? [] : $aArticleResult['data'];
|
|
||||||
$aAiArticle['article_icon'] = empty($aArticleData['media_url']) ? $sArticleIcon : $aArticleData['media_url'];
|
|
||||||
|
|
||||||
//期刊图片上传
|
|
||||||
$aUpload = ['journal_id' => $aAiArticle['journal_id'],'icon' => $sJournalIcon,'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
|
||||||
$aJournalResult = json_decode($oMaterial->addJournalMaterial($aUpload),true);
|
|
||||||
$aJournalData = empty($aJournalResult['data']) ? [] : $aJournalResult['data'];
|
|
||||||
$aAiArticle['journal_icon'] = empty($aJournalData['media_url']) ? $sJournalIcon : $aJournalData['media_url'];
|
|
||||||
|
|
||||||
//期刊二维码图片上传
|
|
||||||
$aUpload = ['journal_id' => $aAiArticle['journal_id'],'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
|
||||||
$aJournalQrCodeResult = json_decode($oMaterial->updateJournalQrcode($aUpload),true);
|
|
||||||
$aJournalQrCodeData = empty($aJournalQrCodeResult['data']) ? [] : $aJournalQrCodeResult['data'];
|
|
||||||
$aAiArticle['journal_qrcode'] = empty($aJournalQrCodeData['media_url']) ? $sJournalIcon : $aJournalQrCodeData['media_url'];
|
|
||||||
|
|
||||||
//文章二维码图片上传
|
|
||||||
$aUpload = ['article_id' => $iArticleId,'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
|
||||||
$aArticleQrCodeResult = json_decode($oMaterial->updateArticleQrcode($aUpload),true);
|
|
||||||
$aArticleQrCodeData = empty($aArticleQrCodeResult['data']) ? [] : $aArticleQrCodeResult['data'];
|
|
||||||
$aAiArticle['article_qrcode'] = empty($aArticleQrCodeData['media_url']) ? $sArticleIcon : $aArticleQrCodeData['media_url'];
|
|
||||||
|
|
||||||
//作者图片上传
|
|
||||||
if(!empty($aAuthor)){
|
if(!empty($aAuthor)){
|
||||||
$aAuthor = $this->_dealAuthor($aAuthor);
|
$aAuthor = $this->_dealAuthor($aAuthor);
|
||||||
|
$aUpload['author_info'] = $aAuthor;
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取素材信息
|
||||||
|
$oMaterial = new Material;
|
||||||
|
$aReturnDataResult = json_decode($oMaterial->getMaterial($aQueryParam),true);
|
||||||
|
$aReturnData = empty($aReturnDataResult['data']) ? [] : $aReturnDataResult['data'];
|
||||||
|
//文章图片
|
||||||
|
$aDataInfo = empty($aReturnData['ai_article_material']) ? [] : $aReturnData['ai_article_material'];
|
||||||
|
$aAiArticle['article_icon'] = empty($aDataInfo['media_url']) ? $sArticleIcon : $aDataInfo['media_url'];
|
||||||
|
//文章二维码图片
|
||||||
|
$aDataInfo = empty($aReturnData['ai_article_qrcode']) ? [] : $aReturnData['ai_article_qrcode'];
|
||||||
|
$aAiArticle['article_qrcode'] = empty($aDataInfo['media_url']) ? $sArticleIcon : $aDataInfo['media_url'];
|
||||||
|
//期刊图片
|
||||||
|
$aDataInfo = empty($aReturnData['ai_journal_material']) ? [] : $aReturnData['ai_journal_material'];
|
||||||
|
$aAiArticle['journal_icon'] = empty($aDataInfo['media_url']) ? $sJournalIcon : $aDataInfo['media_url'];
|
||||||
|
//期刊二维码图片
|
||||||
|
$aDataInfo = empty($aReturnData['ai_journal_qrcode']) ? [] : $aReturnData['ai_journal_qrcode'];
|
||||||
|
$aAiArticle['journal_qrcode'] = empty($aDataInfo['media_url']) ? $sJournalIcon : $aDataInfo['media_url'];
|
||||||
|
//期刊编辑二维码
|
||||||
|
$aDataInfo = empty($aReturnData['ai_journal_editor_material']) ? [] : $aReturnData['ai_journal_editor_material'];
|
||||||
|
$aAiArticle['editor_qrcode'] = empty($aDataInfo['media_url']) ? $sEditorQrcode : $aDataInfo['media_url'];
|
||||||
|
//作者图片上传
|
||||||
|
$aDataInfo = empty($aReturnData['ai_author_material']) ? [] : $aReturnData['ai_author_material'];
|
||||||
|
if(!empty($aDataInfo) && $aAuthor){
|
||||||
|
$aDataInfo = array_column($aDataInfo, null,'email');
|
||||||
foreach ($aAuthor as $key => $value) {
|
foreach ($aAuthor as $key => $value) {
|
||||||
if(empty($value['icon'])){
|
$aAuthorData = empty($aDataInfo[$value['email']]) ? [] : $aDataInfo[$value['email']];
|
||||||
|
if(empty($aUser)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//文章二维码图片上传
|
|
||||||
$aUpload = ['email' => $value['email'],'icon' => $value['icon'],'user_id' => $value['user_id'],'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
|
||||||
$aAuthorResult = json_decode($oMaterial->updateArticleAuthor($aUpload),true);
|
|
||||||
$aAuthorData = empty($aAuthorResult['data']) ? [] : $aAuthorResult['data'];
|
|
||||||
$aAuthor[$key]['icon'] = empty($aAuthorData['media_url']) ? $value['icon'] : $aAuthorData['media_url'];
|
$aAuthor[$key]['icon'] = empty($aAuthorData['media_url']) ? $value['icon'] : $aAuthorData['media_url'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//上传期刊编辑二维码
|
|
||||||
$aUpload = ['editor_qrcode' => $aJournal['editor_qrcode']??'','journal_id' => $aAiArticle['journal_id'],'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
|
||||||
$aJournalEditorQrCodeResult = json_decode($oMaterial->updateJournalEditorQrcode($aUpload),true);
|
|
||||||
$aJournalEditorQrCodeData = empty($aJournalEditorQrCodeResult['data']) ? [] : $aJournalEditorQrCodeResult['data'];
|
|
||||||
$aAiArticle['editor_qrcode'] = empty($aJournalEditorQrCodeData['media_url']) ? $sEditorQrcode : $aJournalEditorQrCodeData['media_url'];
|
|
||||||
}else{
|
}else{
|
||||||
|
|
||||||
//处理文章图片地址数据
|
//处理文章图片地址数据
|
||||||
@@ -813,7 +798,9 @@ class Aiarticle extends Base
|
|||||||
$aAuthorInfo = json_decode($this->dealTemplateAuthor($aAuthor,$iTemplateId),true);
|
$aAuthorInfo = json_decode($this->dealTemplateAuthor($aAuthor,$iTemplateId),true);
|
||||||
$aAuthorInfo = empty($aAuthorInfo['data']) ? [] : $aAuthorInfo['data'];
|
$aAuthorInfo = empty($aAuthorInfo['data']) ? [] : $aAuthorInfo['data'];
|
||||||
$aSearch['{###author_summary###}'] = empty($aAuthorInfo['author_info']) ? '' : $aAuthorInfo['author_info'];
|
$aSearch['{###author_summary###}'] = empty($aAuthorInfo['author_info']) ? '' : $aAuthorInfo['author_info'];
|
||||||
|
|
||||||
|
$aSearch['{###author_string###}'] = empty($aAuthorInfo['author_string']) ? '' : ',通讯作者为'.$aAuthorInfo['author_string'];
|
||||||
|
|
||||||
//处理往期推荐数据
|
//处理往期推荐数据
|
||||||
$aPreviousRecommend = json_decode($this->dealTemplatePreviousRecommend($aArticle,$iTemplateId),true);
|
$aPreviousRecommend = json_decode($this->dealTemplatePreviousRecommend($aArticle,$iTemplateId),true);
|
||||||
$aSearch['{###previous_recommend_summary###}'] = empty($aPreviousRecommend['data']) ? '' : $aPreviousRecommend['data'];
|
$aSearch['{###previous_recommend_summary###}'] = empty($aPreviousRecommend['data']) ? '' : $aPreviousRecommend['data'];
|
||||||
@@ -874,8 +861,6 @@ class Aiarticle extends Base
|
|||||||
return json_encode(['status' => 2,'msg' => 'Corresponding author or template does not exist']);
|
return json_encode(['status' => 2,'msg' => 'Corresponding author or template does not exist']);
|
||||||
}
|
}
|
||||||
|
|
||||||
//处理作者
|
|
||||||
// $aAuthor = $this->_dealAuthor($aAuthor);
|
|
||||||
//获取通讯作者模版
|
//获取通讯作者模版
|
||||||
$sAuthorTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/author.html';
|
$sAuthorTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/author.html';
|
||||||
if (!file_exists($sAuthorTemplatePath)) {
|
if (!file_exists($sAuthorTemplatePath)) {
|
||||||
@@ -955,7 +940,7 @@ class Aiarticle extends Base
|
|||||||
|
|
||||||
//通讯作者字符串处理
|
//通讯作者字符串处理
|
||||||
$sAuthorInfo = trim($sAuthorInfo,',');
|
$sAuthorInfo = trim($sAuthorInfo,',');
|
||||||
return json_encode(['status' => 1,'msg' => 'success','data' => ['author_info' => $sAuthorTemplate,'author' => trim($sAuthorInfo,';')]]);
|
return json_encode(['status' => 1,'msg' => 'success','data' => ['author_info' => $sAuthorTemplate,'author_string' => trim($sAuthorInfo,';')]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1089,8 +1074,6 @@ class Aiarticle extends Base
|
|||||||
$iArticleId = empty($aParam['article_id'] ) ? '' : $aParam['article_id'];
|
$iArticleId = empty($aParam['article_id'] ) ? '' : $aParam['article_id'];
|
||||||
//模版ID
|
//模版ID
|
||||||
$iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id'];
|
$iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id'];
|
||||||
// //推送公众号Id
|
|
||||||
// $sWechatId = empty($aParam['wechat_id']) ? '' : $aParam['wechat_id'];
|
|
||||||
|
|
||||||
//必填参数验证
|
//必填参数验证
|
||||||
if(empty($iArticleId)){
|
if(empty($iArticleId)){
|
||||||
@@ -1099,9 +1082,6 @@ class Aiarticle extends Base
|
|||||||
if(empty($iTemplateId)){
|
if(empty($iTemplateId)){
|
||||||
return json_encode(['status' => 2, 'msg' => 'Please select a template']);
|
return json_encode(['status' => 2, 'msg' => 'Please select a template']);
|
||||||
}
|
}
|
||||||
// if(empty($sWechatId)){
|
|
||||||
// return json_encode(['status' => 2, 'msg' => 'Please select the WeChat official account to push']);
|
|
||||||
// }
|
|
||||||
//判断文章类型
|
//判断文章类型
|
||||||
$article_type = empty($aParam['article_type']) ? 'news' : $aParam['article_type'];
|
$article_type = empty($aParam['article_type']) ? 'news' : $aParam['article_type'];
|
||||||
if(!in_array($article_type, ['news','newspic'])){
|
if(!in_array($article_type, ['news','newspic'])){
|
||||||
@@ -1219,18 +1199,64 @@ class Aiarticle extends Base
|
|||||||
return json_encode(['status' => 2,'msg' => 'Please select the article to be generated']);
|
return json_encode(['status' => 2,'msg' => 'Please select the article to be generated']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//返回数据定义
|
||||||
|
$aResult = ['generate_status' => 3,'draft_status' => 2,'publish_status' => -1];
|
||||||
|
|
||||||
//查询AI生成的文章内容
|
//查询AI生成的文章内容
|
||||||
$aWhere = ['is_delete' => 2];
|
$aWhere = ['is_delete' => 2];
|
||||||
if(!empty($iArticleId)){
|
if(!empty($iArticleId)){
|
||||||
$aWhere['article_id'] = $iArticleId;
|
$aWhere['article_id'] = $iArticleId;
|
||||||
}
|
}
|
||||||
$aAiArticle = Db::name('ai_article')->field('is_generate')->where($aWhere)->find();
|
$aAiArticle = Db::name('ai_article')->field('is_generate')->where($aWhere)->find();
|
||||||
|
|
||||||
// 生成状态
|
// 生成状态
|
||||||
$aMsg = [1 => 'The data has been generated, please proceed with the next steps',2 => 'AI content generation in progress',3 => 'AI content not generated'];
|
$aMsg = [1 => 'The data has been generated, please proceed with the next steps',2 => 'AI content generation in progress',3 => 'AI content not generated',4 => 'The article has been pushed to the draft box',6 => 'The article has been pushed to the draft box'];
|
||||||
$iStatus = empty($aAiArticle['is_generate']) ? 3 : $aAiArticle['is_generate'];
|
$iStatus = empty($aAiArticle['is_generate']) ? 3 : $aAiArticle['is_generate'];
|
||||||
$sMsg = empty($aMsg[$iStatus]) ? 'illegal request' : $aMsg[$iStatus];
|
$sMsg = empty($aMsg[$iStatus]) ? 'illegal request' : $aMsg[$iStatus];
|
||||||
return json_encode(['status' => 1,'msg' => $sMsg,'data' => ['is_generate' => $iStatus]]);
|
$aResult['generate_status'] = $iStatus;
|
||||||
|
|
||||||
|
if(!empty($aAiArticle)){
|
||||||
|
|
||||||
|
$aMsg = [1 => 'The article has been pushed to the draft box',2 => 'Not pushed to the draft box',3 => 'Material upload in progress',4 => 'Material upload completed'];
|
||||||
|
//获取Redis内容,判断是否上传素材成功
|
||||||
|
$oMaterial = new Material;
|
||||||
|
$sUploadInfo = $oMaterial->getStepForRedis($iArticleId);
|
||||||
|
$sErrorInfo = '';
|
||||||
|
if(!empty($sUploadInfo) && $sUploadInfo != 'finish'){
|
||||||
|
$iStatus = 3;//素材上传中
|
||||||
|
$sErrorInfo = $oMaterial->getErrorForRedis($iArticleId);
|
||||||
|
if(!empty($sErrorInfo)){
|
||||||
|
$iStatus = 5;
|
||||||
|
return json_encode(['status' => 5,'msg' => $sErrorInfo]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if(!empty($sUploadInfo) && $sUploadInfo == 'finish'){
|
||||||
|
$iStatus = 4;//素材上传完成
|
||||||
|
}
|
||||||
|
//判断是否推送到草稿箱
|
||||||
|
if(empty($sUploadInfo) || $iStatus == 4){
|
||||||
|
if(!empty($aParam['template_id'])){
|
||||||
|
$aWhere['template_id'] = $aParam['template_id'];
|
||||||
|
}
|
||||||
|
$aDraft = Db::name('ai_wechat_article')->field('is_publish,publish_status,article_id,template_id,wechat_id')->where($aWhere)->find();
|
||||||
|
$iStatus = empty($aDraft) ? 2 : 1;
|
||||||
|
}
|
||||||
|
$aResult['draft_status'] = $iStatus;
|
||||||
|
|
||||||
|
if(!empty($aDraft)){
|
||||||
|
$aMsg = [0 => 'Article successfully published', 1 => 'Article is being published',2 => 'Original article creation failed', 3 => 'Article conventional failure', 4 => 'WeChat official account platform review failed', 5 => 'After success, the user deletes all articles', 6 => 'After success, the system will ban all articles','-1' => 'Draft box article not published'];
|
||||||
|
|
||||||
|
//查询微信接口获取发布状态
|
||||||
|
if($aDraft['publish_status'] == 1){
|
||||||
|
$aReturnData = json_decode($this->queryStatus($aDraft),true);
|
||||||
|
$aData = empty($aReturnData['data']['data']) ? [] : $aReturnData['data']['data'];
|
||||||
|
}
|
||||||
|
$iStatus = empty($aData['publish_status']) ? $aDraft['publish_status'] : $aData['publish_status'];
|
||||||
|
$aResult['publish_status'] = $iStatus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$sMsg = empty($aMsg[$iStatus]) ? 'illegal request' : $aMsg[$iStatus];
|
||||||
|
return json_encode(['status' => 1,'msg' => $sMsg,'data' => $aResult]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1267,7 +1293,7 @@ class Aiarticle extends Base
|
|||||||
// return json_encode(['status' => 2, 'msg' => 'Please select the WeChat official account to push']);
|
// return json_encode(['status' => 2, 'msg' => 'Please select the WeChat official account to push']);
|
||||||
// }
|
// }
|
||||||
//查询是否上传到草稿箱
|
//查询是否上传到草稿箱
|
||||||
$aWhere = ['article_id' => $iArticleId,'template_id' => $iTemplateId,'wechat_id' => $sWechatId];
|
$aWhere = ['article_id' => $iArticleId,'template_id' => $iTemplateId];
|
||||||
$aWechatArticle = Db::name('ai_wechat_article')->field('id,is_publish,media_id,publish_status,wechat_id')->where($aWhere)->find();
|
$aWechatArticle = Db::name('ai_wechat_article')->field('id,is_publish,media_id,publish_status,wechat_id')->where($aWhere)->find();
|
||||||
$sMediaId = empty($aWechatArticle['media_id']) ? '' : $aWechatArticle['media_id'];
|
$sMediaId = empty($aWechatArticle['media_id']) ? '' : $aWechatArticle['media_id'];
|
||||||
if(empty($sMediaId)){
|
if(empty($sMediaId)){
|
||||||
@@ -1299,7 +1325,6 @@ class Aiarticle extends Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
//更新数据表
|
//更新数据表
|
||||||
$aData['publish_id'] = '100000001';
|
|
||||||
//更新文章表publish_id
|
//更新文章表publish_id
|
||||||
$aUpdate = ['update_time' => time(),'is_publish' => 1,'publish_id' => $aData['publish_id'],'publish_status' => 1];
|
$aUpdate = ['update_time' => time(),'is_publish' => 1,'publish_id' => $aData['publish_id'],'publish_status' => 1];
|
||||||
$result = Db::name('ai_wechat_article')->where('id',$iId)->limit(1)->update($aUpdate);
|
$result = Db::name('ai_wechat_article')->where('id',$iId)->limit(1)->update($aUpdate);
|
||||||
@@ -1313,10 +1338,10 @@ class Aiarticle extends Base
|
|||||||
* @param $sToken Token
|
* @param $sToken Token
|
||||||
* @param article_id array 文章ID
|
* @param article_id array 文章ID
|
||||||
*/
|
*/
|
||||||
public function queryStatus(){
|
public function queryStatus($aParam = []){
|
||||||
|
|
||||||
//获取参数
|
//获取参数
|
||||||
$aParam = $this->request->post();
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
//查询条件
|
//查询条件
|
||||||
$aWhere = ['is_publish' => 1,'publish_id' => ['<>',''],'publish_status' => 1,'is_delete' => 2];
|
$aWhere = ['is_publish' => 1,'publish_id' => ['<>',''],'publish_status' => 1,'is_delete' => 2];
|
||||||
@@ -1346,13 +1371,13 @@ class Aiarticle extends Base
|
|||||||
$aWhere = ['issn' => ['in',$aIssn]];
|
$aWhere = ['issn' => ['in',$aIssn]];
|
||||||
$aJournalInfo = Db::name('journal')->field('issn,wechat_app_id,wechat_app_secret')->where($aWhere)->select();
|
$aJournalInfo = Db::name('journal')->field('issn,wechat_app_id,wechat_app_secret')->where($aWhere)->select();
|
||||||
if(!empty($aJournalInfo)){
|
if(!empty($aJournalInfo)){
|
||||||
// return json_encode(['status' => 4, 'msg' => 'WeChat official account interface docking account is not configured, please confirm']);
|
|
||||||
$aJournalInfo = array_column($aJournalInfo, null,'issn');
|
$aJournalInfo = array_column($aJournalInfo, null,'issn');
|
||||||
}
|
}
|
||||||
|
|
||||||
//循环处理
|
//循环处理
|
||||||
$oWechat = new Wechat;
|
$oWechat = new Wechat;
|
||||||
$aInsert = $aUpdate = [];
|
$aInsert = [];
|
||||||
|
Db::startTrans();
|
||||||
foreach ($aWechatArticle as $key => $value) {
|
foreach ($aWechatArticle as $key => $value) {
|
||||||
if(empty($value['wechat_id']) || empty($value['publish_id'])){
|
if(empty($value['wechat_id']) || empty($value['publish_id'])){
|
||||||
continue;
|
continue;
|
||||||
@@ -1365,51 +1390,147 @@ class Aiarticle extends Base
|
|||||||
$aAccount['publish_id'] = $value['publish_id'];
|
$aAccount['publish_id'] = $value['publish_id'];
|
||||||
$aResult = json_decode($oWechat->queryStatus($aAccount),true);
|
$aResult = json_decode($oWechat->queryStatus($aAccount),true);
|
||||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||||
|
|
||||||
if(empty($aData)){
|
if(empty($aData)){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//日志记录
|
//日志记录
|
||||||
$aData = $this->dealStatusData($aData);
|
$aData = $this->dealStatusData($aData);
|
||||||
$aInsert[] = $aData;
|
$aLog = empty($aData['log']) ? [] : $aData['log'];
|
||||||
|
if(!empty($aLog)){
|
||||||
|
$aInsert[] = $aData['log'];
|
||||||
|
}
|
||||||
//更新状态
|
//更新状态
|
||||||
$aUpdate[$aData['publish_status']][] = $value['id'];
|
$aDetail = empty($aData['article_detail']) ? [] : $aData['article_detail'];
|
||||||
|
$iStatus = isset($aLog['publish_status']) ? $aLog['publish_status'] : $value['publish_status'];
|
||||||
|
//微信文章链接
|
||||||
|
$sUrl = empty($aDetail[0]['article_url']) ? '' : $aDetail[0]['article_url'];
|
||||||
|
$updateResult = Db::name('ai_wechat_article')->where('id',$value['id'])->limit(1)->update(['publish_status' => $iStatus,'wechat_article_url' => $sUrl,'update_time' => time()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Db::startTrans();
|
|
||||||
//插入日志表
|
//插入日志表
|
||||||
if(!empty($aInsert)){
|
if(!empty($aInsert)){
|
||||||
$result = Db::name('wechat_article_publish_log')->insertAll($aInsert);
|
$insertResult = Db::name('wechat_article_publish_log')->insertAll($aInsert);
|
||||||
}
|
|
||||||
//更新文章表的发布状态
|
|
||||||
if(!empty($aUpdate)){
|
|
||||||
foreach ($aUpdate as $key => $value) {
|
|
||||||
if(empty($value)){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$result = Db::name('ai_wechat_article')->whereIn('id',$value)->limit(count($value))->update(['publish_status' => $key,'update_time' => time()]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return json_encode(['status' => 1,'msg' => 'success']);
|
return json_encode(['status' => 1,'msg' => 'success']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发布日志数据处理
|
||||||
|
* @param $sToken Token
|
||||||
|
* @param article_id array 文章ID
|
||||||
|
*/
|
||||||
private function dealStatusData($aParam = []){
|
private function dealStatusData($aParam = []){
|
||||||
|
|
||||||
//log日志需要参数
|
//log日志需要参数
|
||||||
$aField = ['publish_id','publish_status' ,'article_id' ,'article_detail' ,'fail_idx' ,'create_time'];
|
$aField = ['publish_id' => '','publish_status' => '' ,'article_id' => '' ,'article_detail' => '' ,'fail_idx' => ''];
|
||||||
$aResult = [];
|
|
||||||
foreach ($aField as $value) {
|
$aDetail = [];
|
||||||
if($value == 'create_time'){
|
foreach ($aParam as $key => $value) {
|
||||||
$aResult[$value] = time();
|
if($key == 'article_detail'){
|
||||||
continue;
|
$aDetail = empty($value) ? [] : $value;
|
||||||
}
|
$aDetail = empty($aDetail['item']) ? [] : $aDetail['item'];
|
||||||
$aResult[$value] = empty($aParam[$value]) ? ' ' : $aParam[$value];
|
|
||||||
if(is_array($aResult[$value])){
|
|
||||||
$aResult[$value] = json_encode($aResult[$value]);
|
|
||||||
}
|
}
|
||||||
|
$aField[$key] = empty($value) ? '' : $value;
|
||||||
|
$aField[$key] = is_array($aField[$key]) ? json_encode($aField[$key]) : $aField[$key];
|
||||||
}
|
}
|
||||||
return $aResult;
|
$aField['create_time'] = time();
|
||||||
|
return ['article_detail' => $aDetail,'log' => $aField];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传素材
|
||||||
|
* @param $sToken Token
|
||||||
|
* @param article_id array 文章ID
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function uploadMaterial($aParam = []){
|
||||||
|
|
||||||
|
//获取参数
|
||||||
|
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||||
|
|
||||||
|
//文章ID
|
||||||
|
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||||
|
//模版ID
|
||||||
|
$iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id'];
|
||||||
|
|
||||||
|
//必填参数验证
|
||||||
|
if(empty($iArticleId)){
|
||||||
|
return json_encode(['status' => 2, 'msg' => 'Please select an article']);
|
||||||
|
}
|
||||||
|
if(empty($iTemplateId)){
|
||||||
|
return json_encode(['status' => 2, 'msg' => 'Please select a template']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//获取AI生成文章内容
|
||||||
|
$aAiContent = json_decode($this->getAiArticle(['article_id' => $iArticleId,'is_select_author' => 1]),true);
|
||||||
|
$aAiContent = empty($aAiContent['data']) ? [] : $aAiContent['data'];
|
||||||
|
$aAiArticle = empty($aAiContent['ai_article']) ? [] : $aAiContent['ai_article'];
|
||||||
|
//判断是否生成AI内容
|
||||||
|
if(empty($aAiArticle)){
|
||||||
|
return json_encode(['status' => 3, 'msg' => 'The article content of WeChat official account has not been generated']);
|
||||||
|
}
|
||||||
|
//模版ID
|
||||||
|
$iTemplateId = empty($iTemplateId) ? $aAiArticle['template_id'] : $iTemplateId;
|
||||||
|
|
||||||
|
//获取文章内容
|
||||||
|
$aResult = json_decode($this->getArticle($iArticleId),true);
|
||||||
|
//获取数据
|
||||||
|
$aArticleContent = empty($aResult['data']) ? [] : $aResult['data'];
|
||||||
|
if(empty($aArticleContent)){
|
||||||
|
return json_encode($aResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
//文章数据
|
||||||
|
$aArticle = empty($aArticleContent['article']) ? [] : $aArticleContent['article'];
|
||||||
|
if(empty($aArticle)){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Article data is empty']);
|
||||||
|
}
|
||||||
|
//期刊数据
|
||||||
|
$aJournal = empty($aArticleContent['journal']) ? [] : $aArticleContent['journal'];
|
||||||
|
if(empty($aJournal)){
|
||||||
|
return json_encode(['status' => 4,'msg' => 'Journal data is empty']);
|
||||||
|
}
|
||||||
|
|
||||||
|
//通讯作者
|
||||||
|
$aAuthor = empty($aArticleContent['author']) ? [] : $aArticleContent['author'];
|
||||||
|
|
||||||
|
//文章图片
|
||||||
|
$sArticleIcon = trim($this->sJournalUsx,'/').$this->sArticleIcon.$aArticle['article_icon'];
|
||||||
|
//期刊图片
|
||||||
|
$sJournalIcon = trim($this->sJournalUsx,'/').$this->sJournalIcon.$aJournal['journal_icon'];
|
||||||
|
|
||||||
|
//期刊编辑二维码
|
||||||
|
$editor_qrcode = empty($aJournal['editor_qrcode']) ? '' : $aJournal['editor_qrcode'];
|
||||||
|
$sEditorQrcode = trim($this->sSubmissionUrl,'/').$this->sJournalEditorQrcode.$editor_qrcode;
|
||||||
|
|
||||||
|
//获取期刊二维码
|
||||||
|
$oMaterial = new Material;
|
||||||
|
$aJournalQrCode = $oMaterial->createJournalQrCode($aJournal);
|
||||||
|
$sJournalCode = empty($aJournalQrCode['qrcode_url']) ? '' : $this->sSubmissionUrl.'public/qrcode/'.$aJournalQrCode['qrcode_url'];
|
||||||
|
$aAiArticle['journal_qrcode'] = $sJournalCode;
|
||||||
|
|
||||||
|
//文章二维码
|
||||||
|
$aArticleQrCode = $oMaterial->createArticleQrCode($aArticle);
|
||||||
|
$sArticleCode = empty($aArticleQrCode['qrcode_url']) ? '' : $this->sSubmissionUrl.'public/qrcode/'.$aArticleQrCode['qrcode_url'];
|
||||||
|
$aAiArticle['article_qrcode'] = $sArticleCode;
|
||||||
|
|
||||||
|
// //上传素材到微信
|
||||||
|
//组装文章数据
|
||||||
|
$aWechatConfig = $this->aWechatConfig;
|
||||||
|
$sWechatAppId = empty($aJournal['wechat_app_id']) ? $aWechatConfig['wechat_app_id'] : $aJournal['wechat_app_id'];
|
||||||
|
$sWechatAppSecret = empty($aJournal['wechat_app_secret']) ? $aWechatConfig['wechat_app_secret'] : $aJournal['wechat_app_secret'];
|
||||||
|
$aUpload['article_info'] = ['icon' => $sArticleIcon];
|
||||||
|
|
||||||
|
//组装期刊数据
|
||||||
|
$aUpload['journal_info'] = ['icon' => $sJournalIcon,'editor_qrcode' => $editor_qrcode];
|
||||||
|
|
||||||
|
//组装作者数据
|
||||||
|
if(!empty($aAuthor)){
|
||||||
|
$aUpload['author_info'] = $this->_dealAuthor($aAuthor);
|
||||||
|
}
|
||||||
|
//上传微信公众号用到的素材
|
||||||
|
$aUpload += ['article_id' => $iArticleId,'journal_id' => $aArticle['journal_id'],'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
||||||
|
$oMaterial = new Material;
|
||||||
|
return $oMaterial->uploadMaterial($aUpload);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user