获取ip地理环境的api

程序

    public function index()
    {
        $api_url = 'http://ip.taobao.com/service/getIpInfo.php';
        $ip      = '125.85.206.146';
        $get_url = $api_url . '?ip=' . $ip;
        $response = file_get_contents($get_url);
        // 或者
        // $ch = curl_init();
        // curl_setopt($ch, CURLOPT_URL, $get_url);
        // curl_setopt($ch, CURLOPT_REFERER, $get_url);
        // curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        // curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
        // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0');
        // $response = curl_exec($ch);
        // curl_close($ch);
        return json(json_decode($response));
    }

回馈内容

{
code: 0,
data: - {
	ip: "125.85.206.146",
	country: "中国",
	area: "",
	region: "重庆",
	city: "重庆",
	county: "XX",
	isp: "电信",
	country_id: "CN",
	area_id: "",
	region_id: "500000",
	city_id: "500100",
	county_id: "xx",
	isp_id: "100017"
	}
}