百度 ip定位 获取省市 webAPI

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_37799190/article/details/79177953

首先创建应用,获取密钥,然后获取以下自己的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;
    }


展开阅读全文

没有更多推荐了,返回首页