zoukankan      html  css  js  c++  java
  • ip 百度地图 php

    已知一个IP

    $ipname=api_hits($DT_IP);

    --------------

    //api
    function getAddressComponent($ak, $longitude, $latitude, $pois){

    $param = array(
    'ak' => $ak,
    'location' => implode(',', array($latitude, $longitude)),
    'pois' => $pois,
    'output' => 'json'
    );

    // 请求百度api
    $api = 'http://api.map.baidu.com/geocoder/v2/';
    $response = toCurl($api, $param);

    $result = array();

    if($response){
    $result = json_decode($response, true);
    }

    return $result;

    }

    function toCurl($url, $param=array()){

    $ch = curl_init();

    if(substr($url,0,5)=='https'){
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在
    }

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($param));

    $response = curl_exec($ch);

    if($error=curl_error($ch)){
    return false;
    }

    curl_close($ch);

    return $response;

    }
    function api_hits($ip){
    $ak = "AAAAAAAAAAAKKKKKKKKKKKK";
    $url="http://api.map.baidu.com/location/ip?ip=$ip&ak=AAAAAAAAKKKKKKKK&coor=bd09ll";
    // $url="http://api.map.baidu.com/location/ip?ip=27.184.129.10&ak=0ZcfSGCYyuvQNCbUXDPHBUIOes2rNEtW&coor=bd09ll";
    $myip=file_get_contents($url);
    $a=substr($myip, (stripos($myip, "x")+4));
    $b=preg_match_all('/d+/',$a,$arr);
    $arr=$arr['0'];

    $x=$arr['0'].".".$arr['1'];

    $y=$arr['2'].".".$arr['3'];

    $longitude = $x;
    $latitude = $y;
    $aa = getAddressComponent($ak,$longitude,$latitude,1);
    // var_dump($aa);
    $areaname = $aa['result']['addressComponent']['province'];
    // $areaname=substr($areaname, (stripos($areaname, "省")));
    // $areaname = stripos($areaname, "省");
    $areaname =mb_substr($areaname,0, -1);
    return $areaname;

    }

  • 相关阅读:
    Makefile学习笔记1
    Shell脚本学习笔记8——跳出循环
    Shell脚本学习笔记7——case...esac
    Shell脚本学习笔记6——循环语句
    Linux命令学习笔记3:touch命令
    Linux命令学习笔记2:ll命令
    Linux命令学习笔记1:ln命令
    Shell脚本学习笔记5——if条件语句
    Shell 脚本学习笔记4——Shell脚本中 '$' 符号的多种用法
    利用C++创建DLL并C#调用
  • 原文地址:https://www.cnblogs.com/vip-deng-vip/p/8125222.html
Copyright © 2011-2022 走看看