对接微信公众号接口调整
This commit is contained in:
@@ -77,7 +77,7 @@ class Aiarticle extends Base
|
||||
**输出格式**
|
||||
中文格式[英文简写忽略首字母大写]
|
||||
格式内容
|
||||
```json{"covered": "【总字数<=100】", "overview": "【总字数>=1000】", "summary": "【总字数>=3500】", "title_chinese": "", "content": ""}'
|
||||
```json{"covered": "【总字数<=100】", "overview": "【总字数>=1000】", "summary": "【总字数>=350】", "title_chinese": "", "content": ""}'
|
||||
];
|
||||
|
||||
//文章图片icon地址
|
||||
@@ -220,8 +220,8 @@ class Aiarticle extends Base
|
||||
* @param model 接口模型
|
||||
* @param stream 是否流式输出 true是false否
|
||||
*/
|
||||
public function create(){
|
||||
|
||||
public function create(){
|
||||
//获取参数
|
||||
$aParam = $this->request->post();
|
||||
$iArticleId = empty($aParam['article_id']) ? '' : $aParam['article_id'];
|
||||
@@ -250,8 +250,7 @@ class Aiarticle extends Base
|
||||
if(empty($aJournal)){
|
||||
return json_encode(['status' => 3,'msg' => 'The journal to which the article belongs does not exist or has been closed']);
|
||||
}
|
||||
// Queue::later(10,'app\api\job\WechatMaterial@fire', ['article_id' => $iArticleId], 'uploadMaterial');
|
||||
// exit;
|
||||
|
||||
//查询AI内容是否生成
|
||||
$aAiArticle = json_decode($this->getAiArticle(['article_id' => $iArticleId]),true);
|
||||
$aAiArticleContent = empty($aAiArticle['data']) ? [] : $aAiArticle['data'];
|
||||
@@ -274,7 +273,24 @@ class Aiarticle extends Base
|
||||
}
|
||||
|
||||
//请求OPENAI
|
||||
return $this->createForOpenAi($aArticleContent,$aAiArticle);
|
||||
$aResult = json_decode($this->createForOpenAi($aArticleContent,$aAiArticle),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '生成失败' : $aResult['msg'];
|
||||
if($iStatus == 1){
|
||||
//四小时后推送上传素材并推送草稿箱
|
||||
$iDelaySeconds = 3;//4 * 3600; // 4小时的秒数
|
||||
Queue::later($iDelaySeconds,'app\api\job\WechatMaterial@fire', ['article_id' => $iArticleId], 'WechatMaterial');
|
||||
$sMsg = '文章AI内容生成成功';
|
||||
}else{
|
||||
$iStatus = 2;
|
||||
}
|
||||
|
||||
//插入日志记录
|
||||
$oMaterial = new Material;
|
||||
$aLogInfo = ['article_id' => $iArticleId,'type' => 5,'msg' =>$sMsg,'status' => $iStatus,'create_time' => time()];
|
||||
$result = json_decode($oMaterial->addWechatLog($aLogInfo),true);
|
||||
return json_encode($aResult);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -929,7 +945,7 @@ class Aiarticle extends Base
|
||||
//请求AI翻译
|
||||
$sContent = '';
|
||||
$aSearch['{#content#}'] = json_encode($aAuthor);
|
||||
// $aResult = json_decode($this->_createContentForOpenAI($aSearch,1),true);
|
||||
$aResult = json_decode($this->_createContentForOpenAI($aSearch,1),true);
|
||||
$aContent = empty($aResult['data']) ? [] : array_column($aResult['data'], null,'email');
|
||||
|
||||
foreach ($aAuthor as $key => $value) {
|
||||
@@ -1202,6 +1218,17 @@ class Aiarticle extends Base
|
||||
$oWechat = new Wechat;
|
||||
$aResult = json_decode($oWechat->addDraft($aParam),true);
|
||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
//插入操作日志
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '' : $aResult['msg'];
|
||||
if ($iStatus != 1) {
|
||||
$iStatus = 2;
|
||||
$sMsg = empty($sMsg) ? '草稿箱推送失败' : $sMsg;
|
||||
}
|
||||
//插入日志记录
|
||||
$oMaterial = new Material;
|
||||
$aLogInfo = ['article_id' => $iArticleId,'type' => 2,'msg' =>$sMsg,'status' => $iStatus,'create_time' => time()];
|
||||
$result = json_decode($oMaterial->addWechatLog($aLogInfo),true);
|
||||
if(empty($aData)){
|
||||
return json_encode($aResult);
|
||||
}
|
||||
@@ -1211,6 +1238,9 @@ class Aiarticle extends Base
|
||||
if($result === false){
|
||||
return json_encode(['status' => 5,'msg' => "Article data insertion failed"]);
|
||||
}
|
||||
|
||||
//写入发布队列
|
||||
// Queue::later(60,'app\api\job\WechatPublishDraft@fire', ['article_id' => $iArticleId], 'WechatPublishDraft');
|
||||
return json_encode(['status' => 1,'msg' => 'Upload draft box successfully','data' => []]);
|
||||
}
|
||||
|
||||
@@ -1357,18 +1387,33 @@ class Aiarticle extends Base
|
||||
//调用发布接口
|
||||
$oWechat = new Wechat;
|
||||
$aResult = json_decode($oWechat->publishDraft($aJournalInfo),true);
|
||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
if(empty($aData)){
|
||||
return json_encode($aResult);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
$sMsg = empty($aResult['msg']) ? '' : $aResult['msg'];
|
||||
if ($iStatus != 1) {
|
||||
$iStatus = 2;
|
||||
$sMsg = empty($sMsg) ? '发布失败' : $sMsg;
|
||||
}
|
||||
|
||||
//插入日志记录
|
||||
$oMaterial = new Material;
|
||||
$aLogInfo = ['article_id' => $iArticleId,'type' => 3,'msg' =>$sMsg,'status' => $iStatus,'create_time' => time()];
|
||||
$result = json_decode($oMaterial->addWechatLog($aLogInfo),true);
|
||||
if($iStatus != 1){
|
||||
return json_encode($aResult);
|
||||
}
|
||||
|
||||
//更新数据表
|
||||
//更新文章表publish_id
|
||||
$aData = empty($aResult['data']) ? [] : $aResult['data'];
|
||||
$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);
|
||||
if($result === false){
|
||||
return json_encode(['status' => 5,'msg' => "Failed to update the status of the published article"]);
|
||||
}
|
||||
|
||||
//发布成功查询状态
|
||||
$iDelaySeconds = 30;//4 * 3600; // 30秒数
|
||||
Queue::later($iDelaySeconds,'app\api\job\WechatQueryStatus@fire', ['article_id' => $iArticleId], 'WechatQueryStatus');
|
||||
return json_encode(['status' => 1,'msg' => 'Draft box article successfully published','data' => []]);
|
||||
}
|
||||
/**
|
||||
@@ -1494,6 +1539,13 @@ class Aiarticle extends Base
|
||||
return json_encode(['status' => 2, 'msg' => 'Please select an article']);
|
||||
}
|
||||
|
||||
//判断素材是否上传
|
||||
$oMaterial = new Material;
|
||||
$aLog = json_decode($oMaterial->getWechatLog(['article_id' => $iArticleId,'type' => 1,'status' =>1]),true);
|
||||
if(!empty($aLog['data'])){
|
||||
return json_encode(['status' => -1,'msg' => 'The material has been uploaded','data' => []]);
|
||||
}
|
||||
|
||||
//获取AI生成文章内容
|
||||
$aAiContent = json_decode($this->getAiArticle(['article_id' => $iArticleId,'is_select_author' => 1]),true);
|
||||
$aAiContent = empty($aAiContent['data']) ? [] : $aAiContent['data'];
|
||||
@@ -1568,30 +1620,24 @@ class Aiarticle extends Base
|
||||
}
|
||||
//上传微信公众号用到的素材
|
||||
$aUpload += ['article_id' => $iArticleId,'journal_id' => $aArticle['journal_id'],'wechat_app_id' => $sWechatAppId,'wechat_app_secret' => $sWechatAppSecret];
|
||||
$oMaterial = new Material;
|
||||
$aResult = json_decode($oMaterial->uploadMaterial($aUpload),true);
|
||||
$iStatus = empty($aResult['status']) ? 0 : $aResult['status'];
|
||||
if($iStatus != 1){
|
||||
return json_encode($aResult);
|
||||
$sMsg = empty($aResult['msg']) ? '' : $aResult['msg'];
|
||||
if ($iStatus != 1) {
|
||||
$iStatus = 2;
|
||||
$sMsg = empty($sMsg) ? '素材上传失败' : $sMsg;
|
||||
}
|
||||
Queue::later(60,'app\api\job\WechatDraft@fire', ['article_id' => $iArticleId], 'uploadDraft');
|
||||
}
|
||||
//插入日志记录
|
||||
$aLogInfo = ['article_id' => $iArticleId,'type' => 1,'msg' =>$sMsg,'status' => $iStatus,'create_time' => time()];
|
||||
$result = json_decode($oMaterial->addWechatLog($aLogInfo),true);
|
||||
|
||||
/**
|
||||
* 对接微信公众号日志
|
||||
*/
|
||||
public function addWechatLog($aParam = []){
|
||||
//获取参数
|
||||
$aParam = empty($aParam) ? $this->request->post() : $aParam;
|
||||
//必填参数验证
|
||||
if(empty($aParam['article_id']) || empty($aParam['type'])){
|
||||
return json_encode(['status' => 2, 'msg' => '非法操作']);
|
||||
//素材上传成功调用上传草稿箱的任务
|
||||
if($iStatus == 1){
|
||||
//1分钟后推送草稿箱
|
||||
$iDelaySeconds = 60;//4 * 3600; // 1分钟的秒数
|
||||
Queue::later($iDelaySeconds,'app\api\job\WechatDraft@fire', ['article_id' => $iArticleId], 'WechatDraft');
|
||||
}
|
||||
$result = Db::name('wechat_api_log')->insertGetId($aParam);
|
||||
if($result === false){
|
||||
return json_encode(['status' => 3, 'msg' => '数据插入失败'.Db::getLastSql()."\n数据内容:",'data' => $aParam]);
|
||||
}
|
||||
return json_encode(['status' => 1, 'msg' => '日志插入成功']);
|
||||
return json_encode(['status' => $iStatus,'msg' => $sMsg,'data' => $aLogInfo]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user