AiBlogService.php
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?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
public $webhook = 'https://develop.globalso.com/api/ai_webhook';//回调地址
/**
* @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,json_encode($param,true));
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,
'title'=>$project_name,
'language'=>$language
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
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 = 'Blog',$template_id = 1){
$request_url = $this->url.'api/task/create';
$param = [
'mch_id'=>$this->mch_id,
'keyword'=>$keyword,
'type'=>$type,
'subtype'=>$subtype,
'url'=>$this->webhook,
'template_id'=>$template_id
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
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;
}
}