RapIdApIService.php
3.0 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
<?php
/**
* @remark :
* @name :RapIdApIService.php
* @author :lyh
* @method :post
* @time :2025/3/25 11:36
*/
namespace App\Services;
use App\Helper\Country;
/**
* @remark :google关键字扩展
* @name :RapIdApIService
* @author :lyh
* @method :post
* @time :2025/3/25 11:38
*/
class RapIdApIService
{
public $url = "";
public $key = '3eba1ba999msh3a7c11101a7e298p19924bjsn5089487f7c37';
/**
* @remark :扩展关键词请求数据
* @name :requestUrl
* @author :lyh
* @method :post
* @time :2025/3/25 11:36
*/
public function requestUrl($keyword){
$this->url = 'https://google-keyword-insight1.p.rapidapi.com/globalkey';
$param = [
'keyword'=>$keyword,
'location'=>'US',
'lang'=>'en'
];
$query_string = str_replace('+', '%20', http_build_query($param));
$url = $this->url.'/?'.$query_string;
$data = $this->curlGoogleApi($url);
return $data;
}
/**
* @remark :备用数据
* @name :keywordResearch
* @author :lyh
* @method :post
* @time :2025/4/10 10:23
*/
public function keywordResearch($keyword){
$this->url = 'https://seo-keyword-research.p.rapidapi.com/keynew.php';
$param = ["keyword" => $keyword, 'country' => 'us'];
$query_string = str_replace('+', '%20', http_build_query($param));
$url = $this->url.'/?'.$query_string;
return $this->curlGoogleApi($url);
}
/**
* @remark :请求
* @name :curlGoogleApi
* @author :lyh
* @method :post
* @time :2025/3/27 16:59
*/
public function curlGoogleApi($url){
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"x-rapidapi-host: google-keyword-insight1.p.rapidapi.com",
"x-rapidapi-key: $this->key"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return false;
} else {
return json_decode($response,true);
}
}
/**
* @remark :google搜索
* @name :googleSearch
* @author :lyh
* @method :post
* @time :2025/3/27 11:18
* @param :date,query,page,device,country/时间、聚合、前页、设备、国家
*/
public function googleSearch($domain,$search){
$this->url = 'https://www.cmer.site/api/google/search';
$url = $this->url.'?domain='.$domain.'&q='.$search;
$data = http_get($url);
if(!isset($data['status']) || $data['status'] != 200){
return [];
}
$data = $data['data'] ?? [];
return $data;
}
}