From 6d7f2a6e5cf692649fd31519cecfab4081cb7c29 Mon Sep 17 00:00:00 2001 From: tping Date: Mon, 2 Mar 2020 15:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E5=9B=BDip=20=20=E8=B4=9D=E5=A1=94?= =?UTF-8?q?=E7=89=88=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Sdk/Common/function.php | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/Application/Sdk/Common/function.php b/Application/Sdk/Common/function.php index 7a8f519a..4b39725a 100644 --- a/Application/Sdk/Common/function.php +++ b/Application/Sdk/Common/function.php @@ -315,20 +315,29 @@ function jsonOutput($status=0, $msg='', $data=[]) { */ function ip_is_country($ip, $country_id=['US'], $country=['美国']) { - $url = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; + $url = "http://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={$ip}&co=&resource_id=6006"; + $url2 = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip; $res = file_get_contents($url); - Log::write(serialize($res)); - if (!empty($res)) { + if (!$res) { // 走淘宝 + $res = file_get_contents($url2); + if (!empty($res)) { + $ipData = json_decode($res,true); + if ($ipData['code']==0 && in_array($ipData['data']['country_id'],$country_id)) { + return true; + } + + if ($ipData['code']==0 && in_array($ipData['data']['country'],$country)) { + return true; + } + + } + } else { $ipData = json_decode($res,true); - if ($ipData['code']==0 && in_array($ipData['data']['country_id'],$country_id)) { + if ($ipData['status']==0 && substr($ipData['location'], 0, strlen($country[0])-1) == $country[0]) { return true; } - - if ($ipData['code']==0 && in_array($ipData['data']['country'],$country)) { - return true; - } - } + return false; }