Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -94,6 +94,8 @@ class Aiarticle extends Base
|
||||
'wechat_app_secret' => 'd5e6002b8b48de46f64dc9a02312f944'
|
||||
];
|
||||
|
||||
//生成AI文章状态
|
||||
protected $sGenerateStatusName = 'generate_status_article_id';
|
||||
public function __construct(\think\Request $request = null) {
|
||||
|
||||
$this->proxy = '';
|
||||
@@ -289,6 +291,8 @@ class Aiarticle extends Base
|
||||
$aSearch['{#title_chinese#}'] = $this->basic_html_filter($aArticle['title']);
|
||||
$aSearch['{#journal_content#}'] = $this->basic_html_filter($aJournal['journal_content'] ?? '');
|
||||
$aSearch['{#journal_content#}'] = trim(trim($aSearch['{#journal_content#}'],'.'),'。');
|
||||
|
||||
//写入Redis 标识已经开始请求OPENAI处理
|
||||
$aResult = $this->_createContentForOpenAI($aSearch,2);
|
||||
$aResult = json_decode($aResult,true);
|
||||
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]]);
|
||||
}
|
||||
/**
|
||||
@@ -710,52 +701,46 @@ class Aiarticle extends Base
|
||||
// //上传素材到微信
|
||||
if($iIsSync == 1){
|
||||
|
||||
//文章图片上传
|
||||
$sWechatAppId = empty($aParam['wechat_app_id']) ? '' : $aParam['wechat_app_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'];
|
||||
|
||||
//作者图片上传
|
||||
//查询参数组装
|
||||
$aQueryParam = ['article_id' => $iArticleId,'journal_id' => $aArticle['journal_id']];
|
||||
//组装作者数据
|
||||
if(!empty($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) {
|
||||
if(empty($value['icon'])){
|
||||
$aAuthorData = empty($aDataInfo[$value['email']]) ? [] : $aDataInfo[$value['email']];
|
||||
if(empty($aUser)){
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
//上传期刊编辑二维码
|
||||
$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{
|
||||
|
||||
//处理文章图片地址数据
|
||||
@@ -813,7 +798,9 @@ class Aiarticle extends Base
|
||||
$aAuthorInfo = json_decode($this->dealTemplateAuthor($aAuthor,$iTemplateId),true);
|
||||
$aAuthorInfo = empty($aAuthorInfo['data']) ? [] : $aAuthorInfo['data'];
|
||||
$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);
|
||||
$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']);
|
||||
}
|
||||
|
||||
//处理作者
|
||||
// $aAuthor = $this->_dealAuthor($aAuthor);
|
||||
//获取通讯作者模版
|
||||
$sAuthorTemplatePath = ROOT_PATH."public/wechatTemplate/template_".$iTemplateId.'/author.html';
|
||||
if (!file_exists($sAuthorTemplatePath)) {
|
||||
@@ -955,7 +940,7 @@ class Aiarticle extends Base
|
||||
|
||||
//通讯作者字符串处理
|
||||
$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'];
|
||||
//模版ID
|
||||
$iTemplateId = empty($aParam['template_id']) ? '' : $aParam['template_id'];
|
||||
// //推送公众号Id
|
||||
// $sWechatId = empty($aParam['wechat_id']) ? '' : $aParam['wechat_id'];
|
||||
|
||||
//必填参数验证
|
||||
if(empty($iArticleId)){
|
||||
@@ -1099,9 +1082,6 @@ class Aiarticle extends Base
|
||||
if(empty($iTemplateId)){
|
||||
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'];
|
||||
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']);
|
||||
}
|
||||
|
||||
//返回数据定义
|
||||
$aResult = ['generate_status' => 3,'draft_status' => 2,'publish_status' => -1];
|
||||
|
||||
//查询AI生成的文章内容
|
||||
$aWhere = ['is_delete' => 2];
|
||||
if(!empty($iArticleId)){
|
||||
$aWhere['article_id'] = $iArticleId;
|
||||
}
|
||||
$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'];
|
||||
$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']);
|
||||
// }
|
||||
//查询是否上传到草稿箱
|
||||
$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();
|
||||
$sMediaId = empty($aWechatArticle['media_id']) ? '' : $aWechatArticle['media_id'];
|
||||
if(empty($sMediaId)){
|
||||
@@ -1299,7 +1325,6 @@ class Aiarticle extends Base
|
||||
}
|
||||
|
||||
//更新数据表
|
||||
$aData['publish_id'] = '100000001';
|
||||
//更新文章表publish_id
|
||||
$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);
|
||||
@@ -1313,10 +1338,10 @@ class Aiarticle extends Base
|
||||
* @param $sToken Token
|
||||
* @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];
|
||||
@@ -1346,13 +1371,13 @@ class Aiarticle extends Base
|
||||
$aWhere = ['issn' => ['in',$aIssn]];
|
||||
$aJournalInfo = Db::name('journal')->field('issn,wechat_app_id,wechat_app_secret')->where($aWhere)->select();
|
||||
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');
|
||||
}
|
||||
|
||||
//循环处理
|
||||
$oWechat = new Wechat;
|
||||
$aInsert = $aUpdate = [];
|
||||
$aInsert = [];
|
||||
Db::startTrans();
|
||||
foreach ($aWechatArticle as $key => $value) {
|
||||
if(empty($value['wechat_id']) || empty($value['publish_id'])){
|
||||
continue;
|
||||
@@ -1365,51 +1390,147 @@ class Aiarticle extends Base
|
||||
$aAccount['publish_id'] = $value['publish_id'];
|
||||
$aResult = json_decode($oWechat->queryStatus($aAccount),true);
|
||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
|
||||
if(empty($aData)){
|
||||
continue;
|
||||
}
|
||||
//日志记录
|
||||
$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)){
|
||||
$result = 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()]);
|
||||
}
|
||||
$insertResult = Db::name('wechat_article_publish_log')->insertAll($aInsert);
|
||||
}
|
||||
Db::commit();
|
||||
return json_encode(['status' => 1,'msg' => 'success']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发布日志数据处理
|
||||
* @param $sToken Token
|
||||
* @param article_id array 文章ID
|
||||
*/
|
||||
private function dealStatusData($aParam = []){
|
||||
|
||||
//log日志需要参数
|
||||
$aField = ['publish_id','publish_status' ,'article_id' ,'article_detail' ,'fail_idx' ,'create_time'];
|
||||
$aResult = [];
|
||||
foreach ($aField as $value) {
|
||||
if($value == 'create_time'){
|
||||
$aResult[$value] = time();
|
||||
continue;
|
||||
}
|
||||
$aResult[$value] = empty($aParam[$value]) ? ' ' : $aParam[$value];
|
||||
if(is_array($aResult[$value])){
|
||||
$aResult[$value] = json_encode($aResult[$value]);
|
||||
$aField = ['publish_id' => '','publish_status' => '' ,'article_id' => '' ,'article_detail' => '' ,'fail_idx' => ''];
|
||||
|
||||
$aDetail = [];
|
||||
foreach ($aParam as $key => $value) {
|
||||
if($key == 'article_detail'){
|
||||
$aDetail = empty($value) ? [] : $value;
|
||||
$aDetail = empty($aDetail['item']) ? [] : $aDetail['item'];
|
||||
}
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace app\api\controller;
|
||||
use app\api\controller\Base;
|
||||
use think\Validate;
|
||||
use app\api\controller\User as usercontroller;
|
||||
|
||||
use think\Db;
|
||||
/**
|
||||
* @title 期刊相关
|
||||
* @description 期刊相关
|
||||
@@ -157,7 +157,36 @@ class Journal extends Base {
|
||||
$url = "http://journalapi.tmrjournals.com/public/index.php/master/Journal/getJournalStageArticlesForSubmission";
|
||||
$program['issn'] = $journal_info['issn'];
|
||||
$res = object_to_array(json_decode(myPost($url,$program)));
|
||||
$list = $res['data']['list'];
|
||||
|
||||
$list = empty($res['data']['list']) ? [] : $res['data']['list'];
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 start
|
||||
if(!empty($list)){
|
||||
$aArticleId = array_column($list, 'article_id');
|
||||
$aWechatArticle = $this->getWechatInfo($aArticleId);
|
||||
$aAiArticle = empty($aWechatArticle['ai_article']) ? [] : $aWechatArticle['ai_article'];
|
||||
$aAiWechatArticle = empty($aWechatArticle['ai_wechat_article']) ? [] : $aWechatArticle['ai_wechat_article'];
|
||||
foreach ($list as $key => $val) {
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 start
|
||||
$list[$key]['ai_wechat_status'] = 2; //1 Ai内容已生成 2ai内容未生成
|
||||
if(in_array($val['article_id'],$aAiArticle)){
|
||||
$list[$key]['ai_wechat_status'] = 1;
|
||||
//是否推送到微信
|
||||
$aDraft = empty($aAiWechatArticle[$val['article_id']]) ? [] : $aAiWechatArticle[$val['article_id']];
|
||||
$list[$key]['ai_wechat_status'] = empty($aDraft) ? 3 : 4; //3 未生成草稿 4 已生成草稿未发布 10 发布成功 11 发布中 >11发布失败
|
||||
if(!empty($aDraft)){
|
||||
foreach ($aDraft as $kk => $value) {
|
||||
if($kk == '-1'){
|
||||
$list[$key]['ai_wechat_status'] = 4;
|
||||
}else{
|
||||
$list[$key]['ai_wechat_status'] = '1'.$kk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 end
|
||||
}
|
||||
}
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 end
|
||||
|
||||
$re['list'] = $list;
|
||||
return jsonSuccess($re);
|
||||
@@ -401,4 +430,31 @@ class Journal extends Base {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信公众号相关数量
|
||||
*/
|
||||
public function getWechatInfo($aArticleId){
|
||||
|
||||
if(empty($aArticleId)){
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取文章生成记录
|
||||
$aWhere = ['article_id' => ['in',$aArticleId],'is_delete' => 2];
|
||||
$aAiArticle = Db::name('ai_article')->where($aWhere)->column('article_id');
|
||||
if(!empty($aAiArticle)){
|
||||
//获取推送到草稿箱否
|
||||
$aWhere['article_id'] = ['in',$aAiArticle];
|
||||
$ai_wechat_article = Db::name('ai_wechat_article')->field('article_id,template_id,wechat_id,is_publish,publish_status')->where($aWhere)->select();
|
||||
if(!empty($ai_wechat_article)){
|
||||
foreach ($ai_wechat_article as $key => $value) {
|
||||
$aWechatArticle[$value['article_id']][$value['publish_status']][] = $value['template_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($ai_wechat_article);
|
||||
//返回数据
|
||||
return ['ai_article' => $aAiArticle,'ai_wechat_article' => empty($aWechatArticle) ? [] : $aWechatArticle];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -470,6 +470,33 @@ class Monitor extends Base
|
||||
$program = [];
|
||||
$program['issn'] = $data['issn'];
|
||||
$res = object_to_array(json_decode(myPost($url,$program)));
|
||||
//新增邮件发送数量 chengxiaoling 20250520 start
|
||||
$aData = empty($res['data']) ? [] : $res['data'];
|
||||
if(!empty($aData['list'])){
|
||||
$aArticleCiteId = array_column($aData['list'], 'article_cite_id');
|
||||
//查询邮件发送数量
|
||||
$aWhere = ['article_cite_id' => ['in',$aArticleCiteId]];
|
||||
$aEmail = Db::name('email_article_cite')->field('article_cite_id,count(article_cite_id) as num,is_success')->where($aWhere)->group('article_cite_id,is_success')->select();
|
||||
if(!empty($aEmail)){
|
||||
$aEmailLog = [];
|
||||
foreach ($aEmail as $key => $value) {
|
||||
$aEmailLog[$value['article_cite_id']][$value['is_success']] = $value['num'];
|
||||
}
|
||||
}
|
||||
//数据处理
|
||||
foreach ($aData['list'] as $key => $value) {
|
||||
$aEmail = ['email_success' => 0,'email_fail' => 0];
|
||||
//邮件发送数量
|
||||
$aEmailInfo = empty($aEmailLog[$value['article_cite_id']]) ? [] : $aEmailLog[$value['article_cite_id']];
|
||||
if(!empty($aEmailInfo)){
|
||||
$aEmail['email_success'] = empty($aEmailInfo[1]) ? $aEmail['email_success'] : $aEmailInfo[1];
|
||||
$aEmail['email_fail'] = empty($aEmailInfo[2]) ? $aEmail['email_fail'] : $aEmailInfo[2];
|
||||
}
|
||||
$aData['list'][$key] += $aEmail;
|
||||
}
|
||||
$res['data'] = $aData;
|
||||
}
|
||||
//新增邮件发送数量 chengxiaoling 20250520 end
|
||||
return jsonSuccess($res['data']);
|
||||
}
|
||||
|
||||
@@ -485,7 +512,6 @@ class Monitor extends Base
|
||||
$program = [];
|
||||
$program['issn'] = $data['issn'];
|
||||
$res = object_to_array(json_decode(myPost($url,$program)));
|
||||
|
||||
//新增邮件发送数量 chengxiaoling 20250520 start
|
||||
$aData = empty($res['data']) ? [] : $res['data'];
|
||||
if(!empty($aData['list'])){
|
||||
@@ -510,7 +536,7 @@ class Monitor extends Base
|
||||
}
|
||||
$aData['list'][$key] += $aEmail;
|
||||
}
|
||||
$res['data']['list'] = $aData;
|
||||
$res['data'] = $aData;
|
||||
}
|
||||
//新增邮件发送数量 chengxiaoling 20250520 end
|
||||
return jsonSuccess($res['data']);
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace app\api\controller;
|
||||
|
||||
use app\api\controller\Base;
|
||||
use think\Validate;
|
||||
|
||||
use think\Db;
|
||||
/**
|
||||
* @title 公共管理相关
|
||||
* @description 公共管理相关
|
||||
@@ -37,6 +37,17 @@ class Publish extends Base
|
||||
|
||||
$stages = $res['data']['stages'];
|
||||
foreach ($stages as $k =>$v){
|
||||
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 start
|
||||
if(empty($v['articles'])){
|
||||
continue;
|
||||
}
|
||||
$aArticleId = array_column($v['articles'], 'article_id');
|
||||
$aWechatArticle = $this->getWechatInfo($aArticleId);
|
||||
$aAiArticle = empty($aWechatArticle['ai_article']) ? [] : $aWechatArticle['ai_article'];
|
||||
$aAiWechatArticle = empty($aWechatArticle['ai_wechat_article']) ? [] : $aWechatArticle['ai_wechat_article'];
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 end
|
||||
|
||||
foreach ($v['articles'] as $key =>$val){
|
||||
$a = explode('/',$val['doi']);
|
||||
if(!isset($a[1])){
|
||||
@@ -49,6 +60,25 @@ class Publish extends Base
|
||||
}
|
||||
$stages[$k]['articles'][$key]['tg_article_id'] = $pro_info['article_id'];
|
||||
$stages[$k]['articles'][$key]['p_article_id'] = $pro_info['p_article_id'];
|
||||
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 start
|
||||
$stages[$k]['articles'][$key]['ai_wechat_status'] = 2; //1 Ai内容已生成 2ai内容未生成
|
||||
if(in_array($val['article_id'],$aAiArticle)){
|
||||
$stages[$k]['articles'][$key]['ai_wechat_status'] = 1;
|
||||
//是否推送到微信
|
||||
$aDraft = empty($aAiWechatArticle[$val['article_id']]) ? [] : $aAiWechatArticle[$val['article_id']];
|
||||
$stages[$k]['articles'][$key]['ai_wechat_status'] = empty($aDraft) ? 3 : 4; //3 未生成草稿 4 已生成草稿未发布 10 发布成功 11 发布中 >11发布失败
|
||||
if(!empty($aDraft)){
|
||||
foreach ($aDraft as $kk => $value) {
|
||||
if($kk == '-1'){
|
||||
$stages[$k]['articles'][$key]['ai_wechat_status'] = 4;
|
||||
}else{
|
||||
$stages[$k]['articles'][$key]['ai_wechat_status'] = '1'.$kk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//获取微信公众号文章状态 chengxiaoling 20250522 end
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,7 +296,14 @@ class Publish extends Base
|
||||
$res = object_to_array(json_decode(myPost($url, $pra)));
|
||||
|
||||
$articles = $res['data']["articleList"];
|
||||
|
||||
//AI内容是否生成 chengxiaoling 20250522 start
|
||||
if(!empty($articles)){
|
||||
$aArticleId = array_column($articles, 'article_id');
|
||||
$aWechatArticle = $this->getWechatInfo($aArticleId);
|
||||
$aAiArticle = empty($aWechatArticle['ai_article']) ? [] : $aWechatArticle['ai_article'];
|
||||
$aAiWechatArticle = empty($aWechatArticle['ai_wechat_article']) ? [] : $aWechatArticle['ai_wechat_article'];
|
||||
}
|
||||
//AI内容是否生成 chengxiaoling 20250522 end
|
||||
foreach ($articles as $k => $v){
|
||||
$a = explode('/',$v['doi']);
|
||||
if(!isset($a[1])){
|
||||
@@ -284,6 +321,25 @@ class Publish extends Base
|
||||
$articles[$k]['p_article_id'] = $pro_info['p_article_id'];
|
||||
$articles[$k]['tg_article_id'] = $pro_info['article_id'];
|
||||
$articles[$k]['refers'] = [];//$this->production_article_refer_obj->where("p_article_id",$pro_info['p_article_id'])->where('state',0)->order("index")->select();
|
||||
|
||||
//AI内容是否生成 chengxiaoling 20250522 start
|
||||
$articles[$k]['ai_wechat_status'] = 2;
|
||||
if(in_array($v['article_id'],$aAiArticle)){
|
||||
$articles[$k]['ai_wechat_status'] = 1;
|
||||
//是否推送到微信
|
||||
$aDraft = empty($aAiWechatArticle[$v['article_id']]) ? [] : $aAiWechatArticle[$v['article_id']];
|
||||
$articles[$k]['ai_wechat_status'] = empty($aDraft) ? 3 : 4; //3 未生成草稿 4 已生成草稿
|
||||
if(!empty($aDraft)){
|
||||
foreach ($aDraft as $kk=> $value) {
|
||||
if($kk == '-1'){
|
||||
$articles[$k]['ai_wechat_status'] = 4;
|
||||
}else{
|
||||
$articles[$k]['ai_wechat_status'] = '1'.$kk;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//AI内容是否生成 chengxiaoling 20250522 end
|
||||
}
|
||||
|
||||
$re['count'] = $res['data']["count"];
|
||||
@@ -663,5 +719,31 @@ class Publish extends Base
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信公众号相关数量
|
||||
*/
|
||||
public function getWechatInfo($aArticleId){
|
||||
|
||||
if(empty($aArticleId)){
|
||||
return [];
|
||||
}
|
||||
|
||||
//获取文章生成记录
|
||||
$aWhere = ['article_id' => ['in',$aArticleId],'is_delete' => 2];
|
||||
$aAiArticle = Db::name('ai_article')->where($aWhere)->column('article_id');
|
||||
if(!empty($aAiArticle)){
|
||||
//获取推送到草稿箱否
|
||||
$aWhere['article_id'] = ['in',$aAiArticle];
|
||||
$ai_wechat_article = Db::name('ai_wechat_article')->field('article_id,template_id,wechat_id,is_publish,publish_status')->where($aWhere)->select();
|
||||
if(!empty($ai_wechat_article)){
|
||||
foreach ($ai_wechat_article as $key => $value) {
|
||||
$aWechatArticle[$value['article_id']][$value['publish_status']][] = $value['template_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($ai_wechat_article);
|
||||
//返回数据
|
||||
return ['ai_article' => $aAiArticle,'ai_wechat_article' => empty($aWechatArticle) ? [] : $aWechatArticle];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ namespace app\common;
|
||||
use think\Db;
|
||||
use app\common\QrCodeImage;
|
||||
use app\common\Wechat;
|
||||
use think\Cache;
|
||||
class Material
|
||||
{
|
||||
|
||||
@@ -23,6 +24,12 @@ class Material
|
||||
//默认头像
|
||||
protected $sDefaultUserIcon = '/static/img/userImg.f3d9bc3b.jpg';
|
||||
|
||||
protected $sMaterialStepName = 'upload_step_name_';
|
||||
protected $sMaterialError = 'upload_error_';
|
||||
|
||||
protected $sAppID; //= 'wx03cb871b66e34e10';
|
||||
protected $sAppSecret; //= 'f59ccaf00383dcfab489292c4697620a';
|
||||
|
||||
public function __construct(\think\Request $request = null) {
|
||||
|
||||
}
|
||||
@@ -161,7 +168,7 @@ class Material
|
||||
* @param sType select 查询|add 新增
|
||||
* @param $sPath 图片地址
|
||||
*/
|
||||
public function addArticleMaterial($aParam = []){
|
||||
private function addArticleMaterial($aParam = []){
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||
@@ -219,7 +226,7 @@ class Material
|
||||
/**
|
||||
* 添加期刊素材
|
||||
*/
|
||||
public function addJournalMaterial($aParam = []){
|
||||
private function addJournalMaterial($aParam = []){
|
||||
|
||||
//期刊ID
|
||||
$iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id'];
|
||||
@@ -275,7 +282,7 @@ class Material
|
||||
/**
|
||||
* 更新期刊二维码关联微信公众号素材
|
||||
*/
|
||||
public function updateJournalQrcode($aParam = []){
|
||||
private function updateJournalQrcode($aParam = []){
|
||||
|
||||
//期刊ID
|
||||
$iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id'];
|
||||
@@ -312,13 +319,14 @@ class Material
|
||||
if($response === false){
|
||||
return json_encode(['status' => 3,'msg' => 'fail']);
|
||||
}
|
||||
|
||||
return json_encode(['status' => 1,'msg' => 'success','data' => $aUpdate]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文章二维码关联微信公众号素材
|
||||
*/
|
||||
public function updateArticleQrcode($aParam = []){
|
||||
private function updateArticleQrcode($aParam = []){
|
||||
|
||||
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||
if(empty($iArticleId)){
|
||||
@@ -361,7 +369,7 @@ class Material
|
||||
/**
|
||||
* 更新通讯作者关联微信公众号素材
|
||||
*/
|
||||
public function updateArticleAuthor($aParam = []){
|
||||
private function updateArticleAuthor($aParam = []){
|
||||
|
||||
$sEmail = empty($aParam['email']) ? '' : $aParam['email'];
|
||||
//文章图片
|
||||
@@ -406,13 +414,14 @@ class Material
|
||||
}
|
||||
$sSql = $sStartSql.trim($sSql,',').$sEndSql;
|
||||
$result = Db::execute($sSql);
|
||||
|
||||
return json_encode(['status' => 1,'msg' => 'success','data' => $aInsert]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新通讯作者关联微信公众号素材
|
||||
*/
|
||||
public function updateJournalEditorQrcode($aParam = []){
|
||||
private function updateJournalEditorQrcode($aParam = []){
|
||||
|
||||
$iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id'];
|
||||
//文章图片
|
||||
@@ -455,6 +464,237 @@ class Material
|
||||
}
|
||||
$sSql = $sStartSql.trim($sSql,',').$sEndSql;
|
||||
$result = Db::execute($sSql);
|
||||
|
||||
return json_encode(['status' => 1,'msg' => 'success','data' => $aInsert]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入Reids 防止两小时内重复上传
|
||||
*/
|
||||
public function setStepForRedis($iArticleId = 0,$sStepName = 'addArticleMaterial'){
|
||||
//写入redis 避免重复请求
|
||||
$sStepNameForRedis = $this->getStepForRedis($iArticleId);
|
||||
if(empty($sStepNameForRedis) || (!empty($sStepNameForRedis) && $sStepNameForRedis != 'finish')){
|
||||
$sRedisKey = $this->sMaterialStepName.'upload_article_id_'.$iArticleId;
|
||||
return Cache::set($sRedisKey, $sStepName, 600); // 有效期600秒
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Reids 防止两小时内重复上传
|
||||
*/
|
||||
public function getStepForRedis($iArticleId = 0){
|
||||
$sRedisKey = $this->sMaterialStepName.'upload_article_id_'.$iArticleId;
|
||||
return Cache::get($sRedisKey); // 有效期600秒
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入Reids 防止两小时内重复上传
|
||||
*/
|
||||
public function setErrorForRedis($iArticleId = 0,$sStepName = 'addArticleMaterial'){
|
||||
$sRedisKey = $this->sMaterialError.$iArticleId;
|
||||
return Cache::set($sRedisKey, $sStepName, 600); // 有效期600秒
|
||||
}
|
||||
|
||||
/**
|
||||
* 写入Reids 防止两小时内重复上传
|
||||
*/
|
||||
public function getErrorForRedis($iArticleId = 0){
|
||||
$sRedisKey = $this->sMaterialError.$iArticleId;
|
||||
return Cache::set($sRedisKey, $sStepName, 600); // 有效期600秒
|
||||
}
|
||||
/**
|
||||
* 上传素材
|
||||
*/
|
||||
|
||||
public function uploadMaterial($aParam = []){
|
||||
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? $this->input->post() : $aParam;
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||
|
||||
//必填验证
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(['status' => 2,'msg' => 'article_id is empty']);
|
||||
}
|
||||
//期刊ID
|
||||
$iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id'];
|
||||
if(empty($iJournalId)){
|
||||
return json_encode(['status' => 2,'msg' => 'journal_id is empty']);
|
||||
}
|
||||
|
||||
// 获取微信公众号APPID和APPKEY
|
||||
if(empty($aParam['wechat_app_id']) || empty($aParam['wechat_app_secret'])){
|
||||
return json_encode(['status' => 2,'msg' => 'Please configure the AppID and AppSecret']);
|
||||
}
|
||||
|
||||
//获取缓存标识
|
||||
$sStepName = $this->getStepForRedis($iArticleId);
|
||||
if(!empty($sStepName) && $sStepName == 'finish'){
|
||||
return json_encode(['status' => 1,'msg' => 'The relevant materials for the article have been uploaded. Please try again in ten minutes']);
|
||||
}
|
||||
if(empty($sStepName)){
|
||||
//写入标识
|
||||
$this->setStepForRedis($iArticleId);
|
||||
$sStepName = 'addArticleMaterial';
|
||||
}
|
||||
|
||||
|
||||
//微信公众号密钥
|
||||
$aWechatParam = ['wechat_app_id' => $aParam['wechat_app_id'],'wechat_app_secret' => $aParam['wechat_app_secret']];
|
||||
|
||||
//获取文章参数
|
||||
$aArticle = empty($aParam['article_info']) ? [] : $aParam['article_info'];
|
||||
|
||||
//上传文章素材参数组装
|
||||
$aArticleParam = ['article_id' => $iArticleId,'icon' => empty($aArticle['icon']) ? '' : $aArticle['icon']];
|
||||
$aArticleParam += $aWechatParam;
|
||||
|
||||
//上传文章图片素材
|
||||
if(!empty($aArticleParam['icon']) && $sStepName == 'addArticleMaterial'){
|
||||
$aUploadResult = json_decode($this->addArticleMaterial($aArticleParam),true);
|
||||
$aParam['article_info'] = empty($aUploadResult['data']) ? [] : $aUploadResult['data'];
|
||||
if(empty($aParam['article_info'])){
|
||||
$sMsg = empty($aUploadResult['msg']) ? 'Article material upload failed' : $aUploadResult['msg'];
|
||||
$this->setErrorForRedis($iArticleId,$sMsg);
|
||||
return json_encode(['status' => 2,'msg' => $sMsg]);
|
||||
}
|
||||
}
|
||||
//写入Redis下一个执行方法
|
||||
$sStepName = 'updateArticleQrcode';
|
||||
$this->setStepForRedis($iArticleId,$sStepName);
|
||||
//文章二维码图片上传
|
||||
if($sStepName == 'updateArticleQrcode'){
|
||||
$aUploadResult = json_decode($this->updateArticleQrcode($aArticleParam),true);
|
||||
$aParam['article_qrcode_info'] = empty($aUploadResult['data']) ? [] : $aUploadResult['data'];
|
||||
if(empty($aParam['article_qrcode_info'])){
|
||||
$sMsg = empty($aUploadResult['msg']) ? 'Article QR code image upload failed' : $aUploadResult['msg'];
|
||||
$this->setErrorForRedis($iArticleId,$sMsg);
|
||||
return json_encode(['status' => 2,'msg' => $sMsg]);
|
||||
}
|
||||
}
|
||||
//写入Redis下一个执行方法
|
||||
$sStepName = 'addJournalMaterial';
|
||||
$this->setStepForRedis($iArticleId, $sStepName);
|
||||
//获取期刊信息
|
||||
$aJournal = empty($aParam['journal_info']) ? [] : $aParam['journal_info'];
|
||||
//上传期刊素材相关参数组装
|
||||
$aJournalParam = ['journal_id' => $iJournalId,'icon' => empty($aJournal['icon']) ? '' : $aJournal['icon'],'editor_qrcode' => empty($aJournal['editor_qrcode']) ? '' : $aJournal['editor_qrcode']];
|
||||
$aJournalParam += $aWechatParam;
|
||||
//上传期刊图片
|
||||
if(!empty($aJournalParam['icon']) && $sStepName == 'addJournalMaterial'){
|
||||
$aUploadResult = json_decode($this->addJournalMaterial($aJournalParam),true);
|
||||
$aParam['journal_info'] = empty($aUploadResult['data']) ? [] : $aUploadResult['data'];
|
||||
if(empty($aParam['journal_info'])){
|
||||
|
||||
$sMsg = empty($aUploadResult['msg']) ? 'Journal material image upload failed' : $aUploadResult['msg'];
|
||||
$this->setErrorForRedis($iArticleId,$sMsg);
|
||||
return json_encode(['status' => 2,'msg' => $sMsg]);
|
||||
}
|
||||
}
|
||||
//写入Redis下一个执行方法
|
||||
$sStepName = 'updateJournalQrcode';
|
||||
$this->setStepForRedis($iArticleId,$sStepName);
|
||||
//上传期刊二维码
|
||||
if($sStepName == 'updateJournalQrcode'){
|
||||
$aUploadResult = json_decode($this->updateJournalQrcode($aJournalParam),true);
|
||||
$aParam['journal_qrcode_info'] = empty($aUploadResult['data']) ? [] : $aUploadResult['data'];
|
||||
if(empty($aParam['journal_qrcode_info'])){
|
||||
$sMsg = empty($aUploadResult['msg']) ? 'Journal QR code image upload failed' : $aUploadResult['msg'];
|
||||
$this->setErrorForRedis($iArticleId,$sMsg);
|
||||
return json_encode(['status' => 2,'msg' => $sMsg]);
|
||||
}
|
||||
}
|
||||
//写入Redis下一个执行方法
|
||||
$sStepName = 'updateJournalEditorQrcode';
|
||||
$this->setStepForRedis($iArticleId,$sStepName);
|
||||
//期刊编辑二维码
|
||||
if(!empty($aJournalParam['editor_qrcode']) && $sStepName == 'updateJournalEditorQrcode'){
|
||||
$aUploadResult = json_decode($this->updateJournalEditorQrcode($aJournalParam),true);
|
||||
$aParam['editor_qrcode_info'] = empty($aUploadResult['data']) ? [] : $aUploadResult['data'];
|
||||
if(empty($aParam['editor_qrcode_info'])){
|
||||
$sMsg = empty($aUploadResult['msg']) ? "Journal editor's QR code image upload failed" : $aUploadResult['msg'];
|
||||
$this->setErrorForRedis($iArticleId,$sMsg);
|
||||
return json_encode(['status' => 2,'msg' => $sMsg]);
|
||||
}
|
||||
}
|
||||
//写入下一个执行方法
|
||||
$sStepName = 'updateArticleAuthor';
|
||||
$this->setStepForRedis($iArticleId,$sStepName);
|
||||
//作者
|
||||
$aAuthor = empty($aParam['author_info']) ? [] : $aParam['author_info'];
|
||||
if(!empty($aAuthor) && $sStepName == 'updateArticleAuthor'){
|
||||
$sError = '';
|
||||
foreach ($aAuthor as $key => $value) {
|
||||
if(empty($value['icon'])){
|
||||
continue;
|
||||
}
|
||||
//文章二维码图片上传
|
||||
$aUpload = ['email' => $value['email'],'icon' => $value['icon'],'user_id' => $value['user_id']];
|
||||
$aUpload += $aWechatParam;
|
||||
$aAuthorResult = json_decode($this->updateArticleAuthor($aUpload),true);
|
||||
$aAuthorData = empty($aAuthorResult['data']) ? [] : $aAuthorResult['data'];
|
||||
if(empty($aAuthorData)){
|
||||
$sError .= empty($aAuthorResult['msg']) ? "The corresponding author's avatar upload failed:".$value['email'].';' : $aAuthorResult['msg']."-".$value['email'].';';
|
||||
}
|
||||
$aAuthor[$key]['icon'] = empty($aAuthorData['media_url']) ? $value['icon'] : $aAuthorData['media_url'];
|
||||
}
|
||||
$aParam['author_info'] = $aAuthor;
|
||||
}
|
||||
if(!empty($sError)){
|
||||
$this->setErrorForRedis($iArticleId,$sError);
|
||||
return json_encode(['status' => 2,'msg' => $sError]);
|
||||
}
|
||||
//写入redis 上传执行完成
|
||||
$this->setStepForRedis($iArticleId,'finish');
|
||||
//返回参数
|
||||
return json_encode(['status' => 1,'msg' => 'Upload successful','data' => $aParam]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取素材
|
||||
*/
|
||||
|
||||
public function getMaterial($aParam = []){
|
||||
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? $this->input->post() : $aParam;
|
||||
|
||||
//文章ID
|
||||
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||
|
||||
//必填验证
|
||||
if(empty($iArticleId)){
|
||||
return json_encode(['status' => 2,'msg' => 'article_id is empty']);
|
||||
}
|
||||
//期刊ID
|
||||
$iJournalId = empty($aParam['journal_id']) ? '' : $aParam['journal_id'];
|
||||
if(empty($iJournalId)){
|
||||
return json_encode(['status' => 2,'msg' => 'journal_id is empty']);
|
||||
}
|
||||
|
||||
//返回数据定义空数组
|
||||
$aData = [];
|
||||
//文章图片素材
|
||||
$aWhere = ['article_id' => $iArticleId,'is_delete' => 2];
|
||||
$aData['ai_article_material'] = Db::name('ai_article_material')->field('media_id,media_url')->where($aWhere)->find();
|
||||
//文章二维码素材
|
||||
$aData['ai_article_qrcode'] = Db::name('ai_article_qrcode')->field('media_id,media_url')->where($aWhere)->find();
|
||||
//期刊素材
|
||||
$aJournalWhere = ['journal_id' => $iJournalId,'is_delete' => 2];
|
||||
$aData['ai_journal_material'] = Db::name('ai_journal_material')->field('media_id,media_url')->where($aJournalWhere)->find();
|
||||
//期刊二维码
|
||||
$aData['ai_journal_qrcode'] = Db::name('ai_journal_qrcode')->field('media_id,media_url')->where($aJournalWhere)->find();
|
||||
//期刊编辑
|
||||
$aData['ai_journal_editor_material'] = Db::name('ai_journal_editor_material')->field('media_id,media_url')->where($aJournalWhere)->find();
|
||||
//文章作者
|
||||
if(!empty($aParam['author_info'])){
|
||||
$aEmail = array_column($aParam['author_info'], 'email');
|
||||
$aWhere = ['email' => ['in',$aEmail],'is_delete' => 2];
|
||||
$aData['ai_author_material'] = Db::name('ai_author_material')->field('user_id,email,media_id,media_url')->where($aWhere)->find();
|
||||
}
|
||||
return json_encode(['status' => 1,'msg' => 'Successfully obtained data','data' => $aData]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ class Wechat
|
||||
return FALSE;
|
||||
}
|
||||
$result = json_decode($result, true);
|
||||
|
||||
if (!empty($result['access_token'])) {
|
||||
$sToken = $result['access_token'];
|
||||
Cache::set($this->sWechatAccessToken.'_'.$this->sAppID, $sToken, 7000); // 有效期7200秒
|
||||
@@ -305,19 +304,18 @@ class Wechat
|
||||
return json_encode($aInfo);
|
||||
}
|
||||
|
||||
// //CURL请求
|
||||
// $sUrl = "https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token={$sToken}";
|
||||
// //参数组装
|
||||
// $sJsonData = json_encode([
|
||||
// 'media_id' => $sMediaId
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// //发送CURL请求
|
||||
// $aCurlResult = $this->curlWechatApi($sUrl,$sJsonData);
|
||||
// if($aCurlResult['status'] != 1){
|
||||
// return $aCurlResult;
|
||||
// }
|
||||
// $response = empty($aCurlResult['data']) ? [] : $aCurlResult['data'];
|
||||
$response['publish_id'] = '100000001';
|
||||
//CURL请求
|
||||
$sUrl = "https://api.weixin.qq.com/cgi-bin/freepublish/submit?access_token={$sToken}";
|
||||
//参数组装
|
||||
$sJsonData = json_encode([
|
||||
'media_id' => $sMediaId
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
//发送CURL请求
|
||||
$aCurlResult = $this->curlWechatApi($sUrl,$sJsonData);
|
||||
if($aCurlResult['status'] != 1){
|
||||
return $aCurlResult;
|
||||
}
|
||||
$response = empty($aCurlResult['data']) ? [] : $aCurlResult['data'];
|
||||
//判断是否推送成功
|
||||
if(empty($response['publish_id'])){
|
||||
return json_encode(['status' => 9,'msg' => "The publish_id of the published draft was not obtained"]);
|
||||
@@ -345,25 +343,24 @@ $response['publish_id'] = '100000001';
|
||||
return json_encode(['status' => 2,'msg' => 'Please configure the AppID and AppSecret']);
|
||||
}
|
||||
|
||||
// //获取Token
|
||||
// $sToken = $this->getAccessToken();
|
||||
// if (empty($sToken)) {
|
||||
// return json_encode(['status' => 3, 'msg' => 'Failed to obtain access_token']);
|
||||
// }
|
||||
//获取Token
|
||||
$sToken = $this->getAccessToken();
|
||||
if (empty($sToken)) {
|
||||
return json_encode(['status' => 3, 'msg' => 'Failed to obtain access_token']);
|
||||
}
|
||||
|
||||
// //CURL请求
|
||||
// $sUrl = "https://api.weixin.qq.com/cgi-bin/freepublish/get?access_token={$sToken}";
|
||||
// //参数组装
|
||||
// $sJsonData = json_encode([
|
||||
// 'publish_id' => $sPublishId
|
||||
// ], JSON_UNESCAPED_UNICODE);
|
||||
// //发送CURL请求
|
||||
// $aCurlResult = $this->curlWechatApi($sUrl,$sJsonData);
|
||||
// $response = empty($aCurlResult['data']) ? [] : $aCurlResult['data'];
|
||||
// if(empty($response)){
|
||||
// return json_encode(['status' => 4,'msg' => 'Query failed']);
|
||||
// }
|
||||
$response = ['publish_id' => '1000001','publish_status' => 2,'article_id'=> '','article_detail','fail_idx' => [1,2]];
|
||||
//CURL请求
|
||||
$sUrl = "https://api.weixin.qq.com/cgi-bin/freepublish/get?access_token={$sToken}";
|
||||
//参数组装
|
||||
$sJsonData = json_encode([
|
||||
'publish_id' => $sPublishId
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
//发送CURL请求
|
||||
$aCurlResult = $this->curlWechatApi($sUrl,$sJsonData);
|
||||
$response = empty($aCurlResult['data']) ? [] : $aCurlResult['data'];
|
||||
if(empty($response)){
|
||||
return json_encode(['status' => 4,'msg' => 'Query failed']);
|
||||
}
|
||||
return json_encode(['status' => 1,'msg' => 'query was successful','data' => $response]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user