这里用的file_put_contents,你也可以用别的,直接怼代码:

//拼接传递的参数
$getData = array(
'query' => '127.0.0.1',
'resource_id' => '6006',
'oe' => 'UTF-8',
'format' => 'json'
);
$getData = http_build_query($getData);
$opts = array(
'http'=>array(
'method'=>"POST",
'header'=>"Content-type:application/x-www-form-urlencoded\r\n" .
"Content-length:". strlen($getData) ."\r\n",
"content"=>$getData,
)
);
//获取Ip所属位置
$context = stream_context_create($opts);
$fp = file_get_contents('http://opendata.baidu.com/api.php', false, $context);
var_dump(json_decode($fp, true));

返回的数据样式为:

array (4) { ["status"]=> string(1) "0" ["t"]=> string(0) "" ["set_cache_time"]=> string(0) "" ["data"]=> array(1) { [0]=> array (15) { ["location"]=> string(31) "北京市北京市 不告诉你" ["titlecont"]=> string(14) "IP地址查询" ["origip"]=> string(14) "123.206.79.176" ["origipquery"]=> string(14) "123.206.79.176" ["showlamp"]=> string(1) "1" ["showLikeShare"]=> int(1) ["shareImage"]=> int(1) ["ExtendedLocation"]=> string(0) "" ["OriginQuery"]=> string(14) "123.206.79.176" ["tplt"]=> string(2) "ip" ["resourceid"]=> string(4) "6006" ["fetchkey"]=> string(14) "123.206.79.176" ["appinfo"]=> string(0) "" ["role_id"]=> int(0) ["disp_type"]=> int(0) } } } 

php根据IP获取所在省份-百度api接口的更多相关文章

  1. (分享)根据IP获取地理位置(百度API)

    说明: 本程序调用的百度地图接口 http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip#h. 使用C#语言+VS2015 IDE开发 效 ...

  2. php根据IP获取所在省份-淘宝api接口

    这里用的file_put_contents,你也可以用别的,直接怼代码: //拼接传递的参数$ip = '175.12.53.12' $opts = array( 'http'=>array( ...

  3. C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市

    百度天气 接口地址:http://api.map.baidu.com/telematics/v3/weather?location=上海&output=json&ak=hXWAgbsC ...

  4. ip获取所在城市名称等信息接口,及函数

    函数: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ...

  5. 根据IP获取所在的国家城市

    根据IP获取所在的国家城市 新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:htt ...

  6. PHP根据ip获取地理位置(通过高德地图接口)

    PHP根据ip获取地理位置(通过高德地图接口)<pre>//restapi.amap.com/v3/ip?key=2004f145cf3a39a72e9ca70ca4b2a1dc& ...

  7. php根据IP获取经纬度信息--百度地图篇

    一.前言 之前一篇写过 php根据IP获取IP所在城市  ,但是还想再精确一点,获取这个IP所在的经纬度信息,该怎么办呢? 百度地图为我提供了一种解决方案(当然还有其他的解决方案). 先总的来数一下, ...

  8. html5获取经纬度,百度api获取街区名,并使用JS保存进cookie

    引用js<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak= ...

  9. 根据IP获得城市信息(百度API的运用)

    /**      * 根据IP获取城市      * @param string $ip ip地址      * @return array      * http://api.map.baidu.c ...

随机推荐

  1. ExtJS浏览器对象模型BOM——命名空间和用户代理对象、Cookie

    BOM(浏览器对象模型(BrowserObjectModel)),允许访问和操控浏览器窗口.研发者通过使用BOM,可移动窗口.更改状态栏文本.执行其它不与页面内容发生直接联系的操作. 本文将从ExtJ ...

  2. Maven项目编译时报错缺少tools.jar

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default ...

  3. Tomcat源码(一):整体架构

    由于tomcat的组件较多,处理流程比较复杂 ,这里是 由浅到深来解释tomcat的整体架构 1.首先应该大致了解下tomcat的 /conf/server.xml  配置文件:在tomcat启动的时 ...

  4. 带你玩转Visual Studio——带你高效开发

    VassistX的简单介绍与下载安装 简单介绍 VassistX的全称是Visual Assist X,是whole tomato开发的一个非常好用的插件,可用于VC6.0及Visual Studio ...

  5. WebGL 一

    WebGL绘制窗口 <html><head><title>OpenGL Test</title> </head><body>&l ...

  6. 17、xtrabackup 常用备份功能与选项

    并行备份 > innobackupex -p123123 --parallel=8 /backup 节流备份 > innobackupex -p123123 --throttle=200  ...

  7. 洛谷P5265 【模板】多项式反三角函数

    题面 传送门 题解 我数学好像学得太差了 据说根据反三角函数求导公式 \[{d\over dx}\arcsin x={1\over \sqrt{1-x^2}}\] \[{d\over dx}\arct ...

  8. LINQ -2015-04-27

    LINQ--language-integrated-query 1.它和sql语言区别呢? SQL语言常用在ralational-database中,而LINQ对内存数据,数据库,xml文件等多种形式 ...

  9. 怎么使用Vue-cli3开发像iview、element那样的组件可下载直接使用

    https://www.cnblogs.com/wisewrong/archive/2018/12/28/10186611.html 参考这个就行. 而我这篇文章主要是对里面的相关步骤作一些简单的说明 ...

  10. centos的基本命令02

    16:查看系统运行的进程 ps -ef 17:查看系统已开放的端口 netstat -tunlp 18:管道命令 ps -ef | grep tom # 查看系统中与tom相关的进程 19:grep过 ...