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; }