|
|
|
<?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;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|