作者 lyh

gx

... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Ai;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Ai\AiBlogLogic;
use App\Http\Requests\Bside\Ai\AiBlogRequest;
use App\Services\AiBlogService;
class AiBlogController extends BaseController
{
... ... @@ -20,4 +21,6 @@ class AiBlogController extends BaseController
$aiBlogLogic->blogSave();
$this->response('success');
}
}
... ...
... ... @@ -662,7 +662,7 @@ class ProductController extends BaseController
'product_id.required' => 'product_id不能为空',
]);
$productInfo = $product->read(['id' => $this->param['product_id']]);
if (empty($productInfo)) {
if ($productInfo == false) {
$this->fail('请选择有效产品信息!');
}
$productInfo = $this->handleParam($productInfo);
... ...
... ... @@ -22,23 +22,22 @@ use App\Models\Manage\ManageHr;
use App\Models\Project\CountAllProject as AllProject;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class TestController extends BaseController
{
/**
* @remark :非6.0拉取数据
* @name :NoSixProject
* @remark :创建项目
* @name :createProject
* @author :lyh
* @method :post
* @time :2024/11/11 14:51
* @time :2025/2/13 16:34
*/
public function ceshi(){
$pay = new PayStripeApi();
$data = $pay->createPaymentIntent(5000,'cny');
$this->response('success',Code::SUCCESS,$data);
$aiBlogService = new AiBlogService();
$result = $aiBlogService->createProject('V6.0 - 演示项目','en','生产案例制作');
$this->response('success',Code::SUCCESS,$result);
}
}
... ...
... ... @@ -43,6 +43,7 @@ use App\Models\User\ProjectMenu;
use App\Models\User\ProjectRole;
use App\Models\User\User as UserModel;
use App\Models\WebSetting\WebLanguage;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use App\Services\SyncService;
use App\Utils\LogUtils;
... ... @@ -184,6 +185,38 @@ class ProjectLogic extends BaseLogic
}
/**
* @remark :开启AI博客后
* @name :setAiBlog
* @author :lyh
* @method :post
* @time :2025/2/13 16:02
*/
public function setAiBlog($project_id){
if(empty($this->param['main_lang_id'])){
return true;
}
if($this->param['is_ai_blog'] == 0){
return true;
}
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$project_id],['is_ai_blog','main_lang_id']);
//获取项目主语种
$languageModel = new WebLanguage();
$languageInfo = $languageModel->read(['id'=>$this->param['main_lang_id']],['short']);
if($languageInfo == false){
return true;
}
if(($this->param['is_ai_blog'] == 1) && ($projectInfo['is_ai_blog'] == 0)){//第一次新增
$aiBlogService = new AiBlogService();
$result = $aiBlogService->createProject($this->param['title'],$languageInfo['short'],$projectInfo['company']);
}else{
$aiBlogService = new AiBlogService();
$result = $aiBlogService->updatedProject($this->param['title'],$languageInfo['short']);
}
}
/**
* @remark :选择服务器后双向绑定
* @name :setServers
* @author :lyh
... ...
<?php
/**
* @remark :
* @name :AiBlogService.php
* @author :lyh
* @method :post
* @time :2025/2/13 14:15
*/
namespace App\Services;
class AiBlogService
{
public $url = 'https://ai-extend.ai.cc/';
public $mch_id = 1;//默认配置
public $sign = '';//签名
public $key = 'b3e4c722b821';//默认key
/**
* @remark :创建项目
* @name :createProject
* @author :lyh
* @method :post
* @time :2025/2/13 14:28
*/
public function createProject($project_name,$language = 'en',$profile){
$request_url = $this->url.'api/project/create';
$param = [
'mch_id'=>$this->mch_id,
'title'=>$project_name,
'language'=>$language,
'profile'=>$profile
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,$param);
return $result;
}
/**
* @remark :更新项目
* @name :updatedProject
* @author :lyh
* @method :post
* @time :2025/2/13 14:35
*/
public function updatedProject($project_name,$language = 'en'){
$request_url = $this->url.'api/project/save';
$param = [
'mch_id'=>$this->mch_id,
'sign'=>$this->sign,
'title'=>$project_name,
'language'=>$language
];
$result = http_post($request_url,$param);
return $result;
}
/**
* @remark :创建任务
* @name :createTask
* @author :lyh
* @method :post
* @time :2025/2/13 14:39
* @param :type=(1作者2文章) keyword=关键词 subtype=blog url=回调url
*/
public function createTask($keyword,$type = 1,$subtype,$url,$template_id){
$request_url = $this->url.'api/task/create';
$param = [
'mch_id'=>$this->mch_id,
'sign'=>$this->sign,
'keyword'=>$keyword,
'type'=>$type,
'subtype'=>$subtype,
'url'=>$url,
'template_id'=>$template_id
];
$result = http_post($request_url,$param);
return $result;
}
/**
* @remark :创建作者
* @name :createAuthor
* @author :lyh
* @method :post
* @time :2025/2/13 14:43
*/
public function createAuthor(){
$request_url = $this->url.'api/author/create';
$param = [
'mch_id'=>$this->mch_id,
'sign'=>$this->sign,
];
$result = http_post($request_url,$param);
return $result;
}
/**
* @remark :计算签名
* @name :generateSign
* @author :lyh
* @method :post
* @time :2025/2/13 15:07
*/
public function generateSign($params, $key)
{
// 去除数组中所有值为空的项
array_filter($params);
// 按照key值的ASCII码从小到大排序
ksort($params);
// 生成URL的查询字符串
$string = http_build_query($params);
// 生成签名
$sign = md5($string . $key);
// 转换成大写
$sign = strtoupper($sign);
return $sign;
}
}
... ...