~~~
//获取IP地址
$ip = $this->request->ip();
//通过IP地址获取城市
$result = file_get_contents('http://api.map.baidu.com/location/ip?ak=kC9QTUMKc5G672aVFkFQ8aQmRvEiCU0f&ip=' . $ip . '&coor=bd09ll');
//json数据转化成数组
$result = json_decode($result, true);
$city_title = $result['content']['address_detail']['city'];
~~~
结果如下图:
~~~
array(3) {
["address"] => string(34) "CN|四川|成都|None|CHINANET|0|0"
["content"] => array(3) {
["address"] => string(18) "四川省成都市"
["address_detail"] => array(6) {
["city"] => string(9) "成都市"
["city_code"] => int(75)
["district"] => string(0) ""
["province"] => string(9) "四川省"
["street"] => string(0) ""
["street_number"] => string(0) ""
}
["point"] => array(2) {
["x"] => string(12) "104.06792346"
["y"] => string(11) "30.67994285"
}
}
["status"] => int(0)
}
~~~
- ThinkPHP
- MySql
- 事务
- 漏洞修复
- jQuery
- select搜索下拉框,多选,全选等
- 移动端富文本编辑器
- 复制内容
- ajax请求
- PHP
- 基本语法
- 关于屏蔽“未定义数组下标:0”错误的问题
- PHP文件操作
- 使用PhpOffice 在PHP7.3中导出数据报错问题
- curl
- PHP生成PPT
- Redis
- 如何在PHP中安装Redis扩展
- Redis队列,秒杀,抢购
- 压力测试(ab)
- apache ab压力测试
- 微信
- 微信支付
- 微信分享
- 授权登录
- 微信公众号服务器
- 自动回复
- 微信发起支付html页面
- composer
- 安装
- 二维码的生成
- Excel导入导出
- 数据采集
- 采集列表
- 采集内容详情
- 图片采集
- Linux
- 常用命令
- 解压压缩
- 服务器
- 服务器运行缓慢的原因
- IIS 隐藏index.php
- 端口检测
- Nginx
- 数据库
- Oracle数据库
- MySql
- 新增MySql
- Field字段
- Tp验证码加载不出来,解决办法
- API接口
- Google API
- 织梦CMS支付接口
- SMTP发送邮箱问题
- Could not connect to SMTP host
- 阿里云API接口
- 支付宝新版配置
- 腾讯API接口
- 安装方法
- 百度地图API
- 通过ip地址获取当前城市
- 常用笔记
- yarn