php根据IP获取所在省份-百度api接口
这里用的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接口的更多相关文章
- (分享)根据IP获取地理位置(百度API)
说明: 本程序调用的百度地图接口 http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip#h. 使用C#语言+VS2015 IDE开发 效 ...
- php根据IP获取所在省份-淘宝api接口
这里用的file_put_contents,你也可以用别的,直接怼代码: //拼接传递的参数$ip = '175.12.53.12' $opts = array( 'http'=>array( ...
- C# 解析百度天气数据,Rss解析百度新闻以及根据IP获取所在城市
百度天气 接口地址:http://api.map.baidu.com/telematics/v3/weather?location=上海&output=json&ak=hXWAgbsC ...
- 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 ...
- 根据IP获取所在的国家城市
根据IP获取所在的国家城市 新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 新浪多地域测试方法:htt ...
- PHP根据ip获取地理位置(通过高德地图接口)
PHP根据ip获取地理位置(通过高德地图接口)<pre>//restapi.amap.com/v3/ip?key=2004f145cf3a39a72e9ca70ca4b2a1dc& ...
- php根据IP获取经纬度信息--百度地图篇
一.前言 之前一篇写过 php根据IP获取IP所在城市 ,但是还想再精确一点,获取这个IP所在的经纬度信息,该怎么办呢? 百度地图为我提供了一种解决方案(当然还有其他的解决方案). 先总的来数一下, ...
- html5获取经纬度,百度api获取街区名,并使用JS保存进cookie
引用js<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak= ...
- 根据IP获得城市信息(百度API的运用)
/** * 根据IP获取城市 * @param string $ip ip地址 * @return array * http://api.map.baidu.c ...
随机推荐
- windows 多个人同时远程同一台电脑
windows 多个人同时远程同一台电脑 第一步:(内外远程) 参考内网多个人同时远程一台电脑: http://www.cnblogs.com/zlp520/p/7688984.html 第二步:( ...
- php面试题汇集2
1.实现中文字符串截取无乱码方法 开启mbstring扩展,然后自定义函数: <?php header('content-Type:text/html:charset=utf-8'); func ...
- Python 中当前位置以及目录文件遍历操作
Python 中当前位置以及目录文件遍历操作 当前位置 print(os.path.dirname(__file__)) 其中 dirname 会选择目录(文件夹),"__file__&qu ...
- java处理excel-xlsx格式大文件的解决方案
1.第一次读取7M左右的ecxel文件,使用poi 库实现,参考了下面的博文. http://www.cnblogs.com/chenfool/p/3632642.html 使用上面的方法在 下面Wo ...
- python cookbook
一 .数据结构 python collections包中 deque :固定长度队列,(例如固定长度的cache什么的) defaultdict:如果每个键值不存在,默认返回值 orderdict:有 ...
- 976 AlvinZH想回家(背包DP大作战T)
976 AlvinZH想回家 思路 如果在第i小时有一些飞机延误,那么一架飞机的c值越大,这一小时产生的损失也越大.而使这一小时产生的损失尽可能的小并不会导致接下来时间产生的损失增大.因此应当每一小时 ...
- SQL SERVER中的二种获得自增长ID的方法
新方法 insert into TblClass output inserted.tClassId values('Hi~班','英语班') 老方法 insert into 表名 () values ...
- sql92和sql99
sql1992sql分类 1.笛卡尔积 (表乘表) 2.等值连接 表的连接条件使用“=” 3.非等值连接 表的连接条件使用“>.>=. <.<=.!=.any等” 4.自连接 ...
- Codeforces Round #545 (Div. 2) 题解
题目链接 A. Sushi for Two 题意 在一个 01 序列中找出长为偶数的连续的一段使得它前一半和后一半内部分别相同,而前一半和后一半不同. \(2\le n\le 100\ 000\) 题 ...
- 2018牛客多校2 - J farm 随机乱搞/二进制分组
题意:给定n*m的格子,每个格子有不同的种类,q次操作,每次操作使[x1,y1]到[x2,y2]的格子除了k类型的以外都删除,最后单次询问所有格子被删了几个 官方题解提到了两种有意思的做法,随机和二进 ...