QuanqiusouApi.php
10.2 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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<?php
namespace App\Helper;
use App\Models\RankData\RankDataLog;
use App\Utils\HttpUtils;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
/**
* Class QuanqiusouApi
* @package App\Helper
* @author zbj
* @date 2023/5/11
*/
class QuanqiusouApi
{
//接口地址
protected $url = 'http://api.quanqiusou.cn';
/**
* 所有站点收录页面数
* @author zbj
* @date 2023/5/11
*/
public function getSiteRes()
{
// $key = 'quanqiusou_api_site_res_' . date('Y-m-d');
// $res = Cache::get($key);
// if (!$res) {
$api_url = $this->url . '/google-rank/echo_site_res.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
// Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
return false;
}
// }
return $res;
}
/**
* 指定站点收录页面数
* @param $api_no
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getSiteResPer($api_no, $is_ext = 0, $copy_domain = ''){
// $key = 'quanqiusou_api_site_res_per_' . $api_no . '_' . date('Y-m-d');
// $res = Cache::get($key);
// if (!$res) {
$api_url = $this->url . '/google-rank/echo_site_res_per.php';
try {
$param = ['apino' => $api_no];
$is_ext && $param['is_ext'] = $is_ext;
$copy_domain && $param['domain'] = $copy_domain;
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
// Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取站点收录页面数', [], $e);
return false;
}
// }
return $res;
}
/**
* 复制站点
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getSiteNumList(){
$api_url = $this->url . '/google-rank/ext_sitenum_list.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取复制站点收录页面数', [], $e);
return [];
}
return array_column($res, 'url');
}
/**
* 获取谷歌排名数据
* @param $project_id
* @param $api_no
* @param string $lang
* @param int $day
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRank($project_id, $api_no, string $lang = '', int $day = 7, $force = true)
{
$key = "quanqiusou_api_rank_{$api_no}_{$lang}_{$day}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res || $force) {
if ($lang) {
$api_no = $api_no . '_' . $lang;
}
$today = date('Y-m-d');
$startDay = date('Y-m-d', strtotime('-'.$day.' day'));
$endDay = date('Y-m-d', strtotime('-1 day'));
//8918_kr_2024-02-19_2024-02-25.json 8918_2024-02-19_2024-02-25.json
$api_url = "https://quanqiusou.cn/google-rank/data_json/{$today}/{$api_no}_{$startDay}_{$endDay}.json";
try {
//$res = HttpUtils::get($api_url, []);
$client = new Client();
$res = $client->request('GET', $api_url, [
'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号
// 其他请求选项
])->getBody()->getContents();
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取谷歌排名数据失败', [$api_no], $e);
return false;
}
}
return $res;
}
/**
* 获取每周谷歌排名数据
* fixme https://quanqiusou.cn/extend_api/api/data/2024-09-02.json
* @return array|false|mixed
* @author zbj
* @date 2023/5/11
*/
public function getGoogleRankWeek()
{
$key = "quanqiusou_api_week_data_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/google-rank/echo_week_data.php';
try {
$res = HttpUtils::get($api_url, []);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
Log::channel('rank_data')->error('获取每周谷歌排名数据失败' . $e->getMessage());
return false;
}
}
return $res;
}
/**
* 获取历史排名统计数据
* @param $api_no
* @param string $lang
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getHistoryCount($api_no, $lang = '')
{
// $key = "quanqiusou_api_history_count_{$api_no}_{$lang}_" . date('Y-m-d');
// $res = Cache::get($key);
// if (!$res) {
$api_url = $this->url . '/google-rank/history_count.php';
$param = [
'apino' => $api_no,
];
if ($lang) {
$param['lang'] = $lang;
}
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
// Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取历史排名统计数据失败', [], $e);
return false;
}
// }
return $res;
}
/**
* 获取小语种项目
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getLangList()
{
$key = "quanqiusou_api_lang_list_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/api/index/langlist';
$param = [
'key' => '289c1fc81c89d79c04ed4fd72822948e',
];
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取小语种项目数据失败', [], $e);
return false;
}
}
return $res;
}
/**
* 获取项目小语种信息
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/5/15
*/
public function getLangRankData($api_no)
{
$key = "quanqiusou_get_language_rank_data_{$api_no}_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/api/index/get_language_rank_data';
$param = [
'apino' => $api_no,
];
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取项目小语种数据失败', [], $e);
return false;
}
}
return $res;
}
/**
* 项目api_no对应关系
* @return array|false|int|mixed|null
* @author zbj
* @date 2023/10/16
*/
public function getWebApiNo(){
$key = "quanqiusou_web_api_no_" . date('Y-m-d');
$res = Cache::get($key);
if (!$res) {
$api_url = $this->url . '/api/index/weblist';
$param = [
'key' => '289c1fc81c89d79c04ed4fd72822948e',
];
try {
$res = HttpUtils::get($api_url, $param);
if($res){
$res = Arr::s2a($res);
Cache::put($key, $res, 2 * 3600);
}
} catch (\Exception | GuzzleException $e) {
errorLog('获取项目API_NO数据失败', [], $e);
return false;
}
}
return $res;
}
/**
* 获取代理信息
* @param $domain
* @return array|mixed
* @author zbj
* @date 2024/10/26
*/
public function getV5Agent($domain){
$token = md5($domain.'qqs');
try {
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://quanqiusou.cn/extend_api/api/get_agent_by_domain.php?'.http_build_query(['token' => $token, 'domain' => $domain]), [
'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号
])->getBody()->getContents();
return Arr::s2a($res);
} catch (\Exception | GuzzleException $e) {
errorLog('获取代理失败', [$domain], $e);
return [];
}
}
/**
* 获取代理信息
* @param $domain
* @return array|mixed
* @author zbj
* @date 2024/10/26
*/
public function getV5RemainDay($domain){
$token = md5($domain.'qqs');
try {
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', 'https://quanqiusou.cn/extend_api/api/get_remain_day_by_domain.php?'.http_build_query(['token' => $token]), [
'proxy' => env('CURL_PROXY'), // 代理服务器地址和端口号
])->getBody()->getContents();
return Arr::s2a($res);
} catch (\Exception | GuzzleException $e) {
errorLog('获取代理失败', [$domain], $e);
return [];
}
}
}