正在显示
5 个修改的文件
包含
166 行增加
和
9 行删除
| @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Ai; | @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Ai; | ||
| 5 | use App\Http\Controllers\Bside\BaseController; | 5 | use App\Http\Controllers\Bside\BaseController; |
| 6 | use App\Http\Logic\Bside\Ai\AiBlogLogic; | 6 | use App\Http\Logic\Bside\Ai\AiBlogLogic; |
| 7 | use App\Http\Requests\Bside\Ai\AiBlogRequest; | 7 | use App\Http\Requests\Bside\Ai\AiBlogRequest; |
| 8 | +use App\Services\AiBlogService; | ||
| 8 | 9 | ||
| 9 | class AiBlogController extends BaseController | 10 | class AiBlogController extends BaseController |
| 10 | { | 11 | { |
| @@ -20,4 +21,6 @@ class AiBlogController extends BaseController | @@ -20,4 +21,6 @@ class AiBlogController extends BaseController | ||
| 20 | $aiBlogLogic->blogSave(); | 21 | $aiBlogLogic->blogSave(); |
| 21 | $this->response('success'); | 22 | $this->response('success'); |
| 22 | } | 23 | } |
| 24 | + | ||
| 25 | + | ||
| 23 | } | 26 | } |
| @@ -662,7 +662,7 @@ class ProductController extends BaseController | @@ -662,7 +662,7 @@ class ProductController extends BaseController | ||
| 662 | 'product_id.required' => 'product_id不能为空', | 662 | 'product_id.required' => 'product_id不能为空', |
| 663 | ]); | 663 | ]); |
| 664 | $productInfo = $product->read(['id' => $this->param['product_id']]); | 664 | $productInfo = $product->read(['id' => $this->param['product_id']]); |
| 665 | - if (empty($productInfo)) { | 665 | + if ($productInfo == false) { |
| 666 | $this->fail('请选择有效产品信息!'); | 666 | $this->fail('请选择有效产品信息!'); |
| 667 | } | 667 | } |
| 668 | $productInfo = $this->handleParam($productInfo); | 668 | $productInfo = $this->handleParam($productInfo); |
| @@ -22,23 +22,22 @@ use App\Models\Manage\ManageHr; | @@ -22,23 +22,22 @@ use App\Models\Manage\ManageHr; | ||
| 22 | use App\Models\Project\CountAllProject as AllProject; | 22 | use App\Models\Project\CountAllProject as AllProject; |
| 23 | use App\Models\Project\Project; | 23 | use App\Models\Project\Project; |
| 24 | use App\Models\RouteMap\RouteMap; | 24 | use App\Models\RouteMap\RouteMap; |
| 25 | +use App\Services\AiBlogService; | ||
| 25 | use App\Services\ProjectServer; | 26 | use App\Services\ProjectServer; |
| 26 | use Illuminate\Support\Facades\DB; | 27 | use Illuminate\Support\Facades\DB; |
| 27 | 28 | ||
| 28 | class TestController extends BaseController | 29 | class TestController extends BaseController |
| 29 | { | 30 | { |
| 30 | /** | 31 | /** |
| 31 | - * @remark :非6.0拉取数据 | ||
| 32 | - * @name :NoSixProject | 32 | + * @remark :创建项目 |
| 33 | + * @name :createProject | ||
| 33 | * @author :lyh | 34 | * @author :lyh |
| 34 | * @method :post | 35 | * @method :post |
| 35 | - * @time :2024/11/11 14:51 | 36 | + * @time :2025/2/13 16:34 |
| 36 | */ | 37 | */ |
| 37 | public function ceshi(){ | 38 | public function ceshi(){ |
| 38 | - $pay = new PayStripeApi(); | ||
| 39 | - $data = $pay->createPaymentIntent(5000,'cny'); | ||
| 40 | - $this->response('success',Code::SUCCESS,$data); | 39 | + $aiBlogService = new AiBlogService(); |
| 40 | + $result = $aiBlogService->createProject('V6.0 - 演示项目','en','生产案例制作'); | ||
| 41 | + $this->response('success',Code::SUCCESS,$result); | ||
| 41 | } | 42 | } |
| 42 | - | ||
| 43 | - | ||
| 44 | } | 43 | } |
| @@ -43,6 +43,7 @@ use App\Models\User\ProjectMenu; | @@ -43,6 +43,7 @@ use App\Models\User\ProjectMenu; | ||
| 43 | use App\Models\User\ProjectRole; | 43 | use App\Models\User\ProjectRole; |
| 44 | use App\Models\User\User as UserModel; | 44 | use App\Models\User\User as UserModel; |
| 45 | use App\Models\WebSetting\WebLanguage; | 45 | use App\Models\WebSetting\WebLanguage; |
| 46 | +use App\Services\AiBlogService; | ||
| 46 | use App\Services\ProjectServer; | 47 | use App\Services\ProjectServer; |
| 47 | use App\Services\SyncService; | 48 | use App\Services\SyncService; |
| 48 | use App\Utils\LogUtils; | 49 | use App\Utils\LogUtils; |
| @@ -184,6 +185,38 @@ class ProjectLogic extends BaseLogic | @@ -184,6 +185,38 @@ class ProjectLogic extends BaseLogic | ||
| 184 | } | 185 | } |
| 185 | 186 | ||
| 186 | /** | 187 | /** |
| 188 | + * @remark :开启AI博客后 | ||
| 189 | + * @name :setAiBlog | ||
| 190 | + * @author :lyh | ||
| 191 | + * @method :post | ||
| 192 | + * @time :2025/2/13 16:02 | ||
| 193 | + */ | ||
| 194 | + public function setAiBlog($project_id){ | ||
| 195 | + if(empty($this->param['main_lang_id'])){ | ||
| 196 | + return true; | ||
| 197 | + } | ||
| 198 | + if($this->param['is_ai_blog'] == 0){ | ||
| 199 | + return true; | ||
| 200 | + } | ||
| 201 | + $projectModel = new Project(); | ||
| 202 | + $projectInfo = $projectModel->read(['id'=>$project_id],['is_ai_blog','main_lang_id']); | ||
| 203 | + //获取项目主语种 | ||
| 204 | + $languageModel = new WebLanguage(); | ||
| 205 | + $languageInfo = $languageModel->read(['id'=>$this->param['main_lang_id']],['short']); | ||
| 206 | + if($languageInfo == false){ | ||
| 207 | + return true; | ||
| 208 | + } | ||
| 209 | + if(($this->param['is_ai_blog'] == 1) && ($projectInfo['is_ai_blog'] == 0)){//第一次新增 | ||
| 210 | + $aiBlogService = new AiBlogService(); | ||
| 211 | + $result = $aiBlogService->createProject($this->param['title'],$languageInfo['short'],$projectInfo['company']); | ||
| 212 | + }else{ | ||
| 213 | + $aiBlogService = new AiBlogService(); | ||
| 214 | + $result = $aiBlogService->updatedProject($this->param['title'],$languageInfo['short']); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + /** | ||
| 187 | * @remark :选择服务器后双向绑定 | 220 | * @remark :选择服务器后双向绑定 |
| 188 | * @name :setServers | 221 | * @name :setServers |
| 189 | * @author :lyh | 222 | * @author :lyh |
app/Services/AiBlogService.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :AiBlogService.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2025/2/13 14:15 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Services; | ||
| 11 | + | ||
| 12 | +class AiBlogService | ||
| 13 | +{ | ||
| 14 | + public $url = 'https://ai-extend.ai.cc/'; | ||
| 15 | + | ||
| 16 | + public $mch_id = 1;//默认配置 | ||
| 17 | + public $sign = '';//签名 | ||
| 18 | + public $key = 'b3e4c722b821';//默认key | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * @remark :创建项目 | ||
| 23 | + * @name :createProject | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2025/2/13 14:28 | ||
| 27 | + */ | ||
| 28 | + public function createProject($project_name,$language = 'en',$profile){ | ||
| 29 | + $request_url = $this->url.'api/project/create'; | ||
| 30 | + $param = [ | ||
| 31 | + 'mch_id'=>$this->mch_id, | ||
| 32 | + 'title'=>$project_name, | ||
| 33 | + 'language'=>$language, | ||
| 34 | + 'profile'=>$profile | ||
| 35 | + ]; | ||
| 36 | + $this->sign = $this->generateSign($param,$this->key); | ||
| 37 | + $param['sign'] = $this->sign; | ||
| 38 | + $result = http_post($request_url,$param); | ||
| 39 | + return $result; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * @remark :更新项目 | ||
| 44 | + * @name :updatedProject | ||
| 45 | + * @author :lyh | ||
| 46 | + * @method :post | ||
| 47 | + * @time :2025/2/13 14:35 | ||
| 48 | + */ | ||
| 49 | + public function updatedProject($project_name,$language = 'en'){ | ||
| 50 | + $request_url = $this->url.'api/project/save'; | ||
| 51 | + $param = [ | ||
| 52 | + 'mch_id'=>$this->mch_id, | ||
| 53 | + 'sign'=>$this->sign, | ||
| 54 | + 'title'=>$project_name, | ||
| 55 | + 'language'=>$language | ||
| 56 | + ]; | ||
| 57 | + $result = http_post($request_url,$param); | ||
| 58 | + return $result; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * @remark :创建任务 | ||
| 63 | + * @name :createTask | ||
| 64 | + * @author :lyh | ||
| 65 | + * @method :post | ||
| 66 | + * @time :2025/2/13 14:39 | ||
| 67 | + * @param :type=(1作者2文章) keyword=关键词 subtype=blog url=回调url | ||
| 68 | + */ | ||
| 69 | + public function createTask($keyword,$type = 1,$subtype,$url,$template_id){ | ||
| 70 | + $request_url = $this->url.'api/task/create'; | ||
| 71 | + $param = [ | ||
| 72 | + 'mch_id'=>$this->mch_id, | ||
| 73 | + 'sign'=>$this->sign, | ||
| 74 | + 'keyword'=>$keyword, | ||
| 75 | + 'type'=>$type, | ||
| 76 | + 'subtype'=>$subtype, | ||
| 77 | + 'url'=>$url, | ||
| 78 | + 'template_id'=>$template_id | ||
| 79 | + ]; | ||
| 80 | + $result = http_post($request_url,$param); | ||
| 81 | + return $result; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * @remark :创建作者 | ||
| 86 | + * @name :createAuthor | ||
| 87 | + * @author :lyh | ||
| 88 | + * @method :post | ||
| 89 | + * @time :2025/2/13 14:43 | ||
| 90 | + */ | ||
| 91 | + public function createAuthor(){ | ||
| 92 | + $request_url = $this->url.'api/author/create'; | ||
| 93 | + $param = [ | ||
| 94 | + 'mch_id'=>$this->mch_id, | ||
| 95 | + 'sign'=>$this->sign, | ||
| 96 | + ]; | ||
| 97 | + $result = http_post($request_url,$param); | ||
| 98 | + return $result; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + /** | ||
| 102 | + * @remark :计算签名 | ||
| 103 | + * @name :generateSign | ||
| 104 | + * @author :lyh | ||
| 105 | + * @method :post | ||
| 106 | + * @time :2025/2/13 15:07 | ||
| 107 | + */ | ||
| 108 | + public function generateSign($params, $key) | ||
| 109 | + { | ||
| 110 | + // 去除数组中所有值为空的项 | ||
| 111 | + array_filter($params); | ||
| 112 | + // 按照key值的ASCII码从小到大排序 | ||
| 113 | + ksort($params); | ||
| 114 | + // 生成URL的查询字符串 | ||
| 115 | + $string = http_build_query($params); | ||
| 116 | + // 生成签名 | ||
| 117 | + $sign = md5($string . $key); | ||
| 118 | + // 转换成大写 | ||
| 119 | + $sign = strtoupper($sign); | ||
| 120 | + return $sign; | ||
| 121 | + } | ||
| 122 | +} |
-
请 注册 或 登录 后发表评论