From 1c7bc19ae2c209205f3ddd441b2ba88e66401e29 Mon Sep 17 00:00:00 2001 From: chengxl Date: Tue, 3 Jun 2025 09:25:19 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=8C=96=E9=98=9F=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/job/ArticleAiCreateContent.php | 61 ++++++++++++++++++ application/api/job/WechatDraftPublish.php | 62 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 application/api/job/ArticleAiCreateContent.php create mode 100644 application/api/job/WechatDraftPublish.php diff --git a/application/api/job/ArticleAiCreateContent.php b/application/api/job/ArticleAiCreateContent.php new file mode 100644 index 0000000..23b2a01 --- /dev/null +++ b/application/api/job/ArticleAiCreateContent.php @@ -0,0 +1,61 @@ +getRawBody())){ + $aJob = json_decode($job->getRawBody(), true); + $aParam = [ + 'job_id' => empty($aJob['id']) ? '' : $aJob['id'], + 'job_class' => get_class($this), + 'status' => 0, + 'create_time' => time(), + 'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE) + ]; + $iLogId = $oQueueJob->addLog($aParam); + // 步骤1:上传素材(图片) + $iArticleId = empty($data['article_id']) ? 0 : $data['article_id']; + if (!empty($iArticleId)) { + //上传素材 + $oAiarticle = new Aiarticle; + $aResult = json_decode($oAiarticle->create($data),true); + $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; + $sMsg = empty($aResult['msg']) ? '文章AI内容声场失败' : $aResult['msg']; + } + } + $job->delete(); + + //更新任务状态 + $aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + // // 记录日志 + // \think\Log::info("ArticleAiCreateContent延迟任务执行成功: ".json_encode($data)); + } catch (\Exception $e) { + + //实例化 + $oQueueJob = new QueueJob; + //更新任务状态 + $sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage(); + $aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + $job->delete(); + // // 记录错误日志 + // \think\Log::error("ArticleAiCreateContent延迟任务失败: ".$e->getMessage()); + }finally { + gc_collect_cycles(); // 强制垃圾回收 + } + } + +} \ No newline at end of file diff --git a/application/api/job/WechatDraftPublish.php b/application/api/job/WechatDraftPublish.php new file mode 100644 index 0000000..54d9924 --- /dev/null +++ b/application/api/job/WechatDraftPublish.php @@ -0,0 +1,62 @@ +getRawBody())){ + $aJob = json_decode($job->getRawBody(), true); + $aParam = [ + 'job_id' => empty($aJob['id']) ? '' : $aJob['id'], + 'job_class' => get_class($this), + 'status' => 0, + 'create_time' => time(), + 'params' => json_encode($aJob, JSON_UNESCAPED_UNICODE) + ]; + $iLogId = $oQueueJob->addLog($aParam); + // 步骤1:上传素材(图片) + $iArticleId = empty($data['article_id']) ? 0 : $data['article_id']; + if (!empty($iArticleId)) { + //上传素材 + $oAiarticle = new Aiarticle; + $aResult = json_decode($oAiarticle->publishDraft($data),true); + $iStatus = empty($aResult['status']) ? 0 : $aResult['status']; + $sMsg = empty($aResult['msg']) ? '草稿箱发布失败' : $aResult['msg']; + } + } + $job->delete(); + + //更新任务状态 + $aParam = ['log_id' => $iLogId,'status' => 1,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + // // 记录日志 + // \think\Log::info("WechatDraft-延迟任务执行成功: ".json_encode($data)); + } catch (\Exception $e) { + + //实例化 + $oQueueJob = new QueueJob; + //更新任务状态 + $sMsg = empty($e->getMessage()) ? '任务出错' : $e->getMessage(); + $aParam = ['log_id' => $iLogId,'status' => 2,'update_time' => time(),'error' => $sMsg]; + $oQueueJob->updateLog($aParam); + $job->delete(); + // // 记录错误日志 + // \think\Log::error("WechatDraft-延迟任务失败: ".$e->getMessage()); + }finally { + gc_collect_cycles(); // 强制垃圾回收 + } + } + +} \ No newline at end of file