百度 ip定位 获取省市 webAPI

首先创建应用,获取密钥,然后获取以下自己的ip

 function  ding(){
        $url='http://api.map.baidu.com/location/ip?ip=124.133.254.59&ak=abDsBedrGw46lo1CyQuwZs9magjV5gSf&coor=';
         $res=curl_get($url);
          $user_json = json_decode($res,true); //数据转换
 
     var_dump($user_json);//位置
    }
   
    function curl_get($url) {
        $ch = curl_init();
        $timeout = 300;
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        $res = curl_exec($ch);

        if (curl_errno($ch)) {
            echo 'Curl error: ' . curl_error($ch);
        }

        curl_close($ch);
        return $res;
    }


你可能感兴趣的:(百度 ip定位 获取省市 webAPI)