GoogleKeywordInsightService.php
1.5 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
<?php
/**
* @remark :
* @name :GoogleKeywordInsightService.php
* @author :lyh
* @method :post
* @time :2025/3/25 11:36
*/
namespace App\Services;
/**
* @remark :google关键字扩展
* @name :GoogleKeywordInsightService
* @author :lyh
* @method :post
* @time :2025/3/25 11:38
*/
class GoogleKeywordInsightService
{
public $url = "";
/**
* @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';
$url = $this->url.'/?keyword='.$keyword.'&lang=en';
$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: d246239565mshc29088b58ff484dp17c0bdjsn2d28d03622c7"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return "cURL Error #:" . $err;
} else {
return json_decode($response,true);
}
}
}