AiBlogService.php
7.3 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?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 $route = '';//回调地址
public $task_id = '';//任务id
public $author_id = '';//作者id
/**
* @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 = 2,$subtype = 'Blog',$anchor = []){
$request_url = $this->url.'api/task/create';
$param = [
'keyword'=>$keyword,
'type'=>$type,
'subtype'=>$subtype,
];
$param['anchor'] = json_encode($anchor,true);
$param['url'] = $this->route;
$param['mch_id'] = $this->mch_id;
$param['template_id'] = 1;
$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,
];
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :获取作者信息
* @name :getAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 10:57
*/
public function getAuthor(){
$request_url = $this->url.'api/author/list';
$param = [
'mch_id'=>$this->mch_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 :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;
}
/**
* @remark :获取文章详情
* @name :getDetail
* @author :lyh
* @method :post
* @time :2025/2/14 11:23
*/
public function getDetail(){
$request_url = $this->url.'api/result/detail';
$param = [
'mch_id'=>$this->mch_id,
'task_id'=>$this->task_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 :getAuthorDetail
* @author :lyh
* @method :post
* @time :2025/2/21 11:55
*/
public function getAuthorDetail(){
$request_url = $this->url.'api/author/detail';
$param = [
'mch_id'=>$this->mch_id,
'author_id'=>$this->author_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 :updateDetail
* @author :lyh
* @method :post
* @time :2025/2/21 14:38
* @param :title , thumb , route , task_id
*/
public function updateDetail($param){
$request_url = $this->url.'api/result/save';
$param['mch_id'] = $this->mch_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 :getAiBlogList
* @author :lyh
* @method :post
* @time :2025/2/21 15:51
*/
public function getAiBlogList($page,$page_size){
$request_url = $this->url.'api/result/list';
$param['mch_id'] = $this->mch_id;
$param['page'] = $page;
$param['page_size'] = $page_size;
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
/**
* @remark :修改作者信息
* @name :updateAuthorInfo
* @author :lyh
* @method :post
* @time :2025/2/21 16:00
* @param :author_id ,title , picture, description
*/
public function updateAuthorInfo($param){
$request_url = $this->url.'api/author/update';
$param['mch_id'] = $this->mch_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 :updateAuthorInfo
* @author :lyh
* @method :post
* @time :2025/3/4 16:22
* @param :task_id
*/
public function delDetail($task_id){
$param['task_id'] = $task_id;
$request_url = $this->url.'api/result/delete';
$param['mch_id'] = $this->mch_id;
$this->sign = $this->generateSign($param,$this->key);
$param['sign'] = $this->sign;
$result = http_post($request_url,json_encode($param,true));
return $result;
}
}