{ "code": 0, "data": { "ip": "115.60.198.75", "country": "中国", "area": "", "region": "河南", "city": "郑州", "county": "XX", "isp": "联通", "country_id": "CN", "area_id": "", "region_id": "410000", "city_id": "410100", "county_id": "xx", "isp_id": "100026" } }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/7/20 17:50 */ //---------------------------------- // 淘宝ip 调用类 //---------------------------------- class freeApi{ private $apiUrl = 'http://ip.taobao.com/service/getIpInfo.php?ip=115.60.198.75'; /** * 获取 淘宝ip 结果 * @return array */ public function getResult(){ return $this->freeApiCurl($this->apiUrl); } /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * @return string */ public function freeApiCurl($url,$params=false,$ispost=0){ $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params){ curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); if ($response === FALSE) { return false; } curl_close( $ch ); return $response; } }