commit
3b071f30d9
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Base\Tool;
|
||||
|
||||
class IPTool
|
||||
{
|
||||
public static function getIpInfo($ip)
|
||||
{
|
||||
$host = 'https://api01.aliyun.venuscn.com';
|
||||
$path = '/ip';
|
||||
$method = 'GET';
|
||||
$appcode = '244181f0846541a19e24df409736d3b9';
|
||||
$headers = [];
|
||||
array_push($headers, 'Authorization:APPCODE ' . $appcode);
|
||||
$querys = 'ip=' . $ip;
|
||||
$bodys = '';
|
||||
$url = $host . $path . '?' . $querys;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($curl, CURLOPT_FAILONERROR, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
// curl_setopt($curl, CURLOPT_HEADER, true);
|
||||
if (1 == strpos('$'.$host, 'https://')) {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
}
|
||||
$response = curl_exec($curl);
|
||||
if (!$response) {
|
||||
return null;
|
||||
}
|
||||
$result = json_decode($response, true);
|
||||
if ($result['ret'] == 200) {
|
||||
return $result['data'];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue