修改ip地区查询接口

master
ELF 4 years ago
parent d0c7618556
commit 78dc0dc277

@ -4,6 +4,7 @@ namespace Base\Service;
use Base\Tool\TaskClient;
use Think\Log;
use Base\Tool\Redis;
use Base\Tool\IPTool;
/**
*
@ -216,14 +217,16 @@ class UserService
protected function isIpWarning($user, $clientIp)
{
$newResult = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$clientIp);
$oldResult = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$user['login_ip']);
$newResult = json_decode($newResult, true);
$oldResult = json_decode($oldResult, true);
if($newResult['data']['city'] != $oldResult['data']['city']) {
return true;
$newResult = IPTool::getIpInfo($clientIp);
$oldResult = IPTool::getIpInfo($user['login_ip']);
if (
$newResult['data']['country_id'] == $oldResult['data']['country_id'] &&
$newResult['data']['region_id'] == $oldResult['data']['region_id'] &&
$newResult['data']['city_id'] == $oldResult['data']['city_id']
) {
return false;
}
return false;
return true;
}
/**

@ -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…
Cancel
Save