You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB
PHTML

2 years ago
<?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;
}
}
}