• 技术文章 >php教程 >php手册

    php使用百度天气接口示例

    2016-06-13 09:37:18原创415
    注意地区要转码的
    百度ak申请地址:http://lbsyun.baidu.com/apiconsole/key

    复制代码 代码如下:


    $city="嘉兴";
    $content = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=%E5%98%89%E5%85%B4&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ");
    print_r(json_decode($content));

    复制代码 代码如下:


    {
    error: 0,
    status: "success",
    date: "2014-04-18",
    results: [
    {
    currentCity: "嘉兴",
    weather_data: [
    {
    date: "今天(周三)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "多云",
    wind: "微风",
    temperature: "23℃"
    },
    {
    date: "明天(周四)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/leizhenyu.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/zhongyu.png",
    weather: "雷阵雨转中雨",
    wind: "微风",
    temperature: "29~22℃"
    },
    {
    date: "后天(周五)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/yin.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "阴转多云",
    wind: "微风",
    temperature: "31~23℃"
    },
    {
    date: "大后天(周六)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "多云",
    wind: "微风",
    temperature: "31~24℃"
    }
    ]
    },
    {
    currentCity: "合肥市",
    weather_data: [
    {
    date: "今天(周三)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "多云",
    wind: "东风3-4级",
    temperature: "27℃"
    },
    {
    date: "明天(周四)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "多云",
    wind: "东北风3-4级",
    temperature: "35~27℃"
    },
    {
    date: "后天(周五)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "多云",
    wind: "南风",
    temperature: "35~27℃"
    },
    {
    date: "大后天(周六)",
    dayPictureUrl: "http://api.map.baidu.com/images/weather/day/duoyun.png",
    nightPictureUrl: "http://api.map.baidu.com/images/weather/night/duoyun.png",
    weather: "多云",
    wind: "东风",
    temperature: "34~27℃"
    }
    ]
    }
    ]
    }

    声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
    专题推荐:php 百度天气
    上一篇:CodeIgniter框架提示Disallowed Key Characters的解决办法 下一篇:通过PHP.ini关闭php错误信息回显的方法
    千万级数据并发解决方案

    相关文章推荐

    • Yii中创建自己的Widget实例,yiiwidget实例• php使用cookie实现记住用户名和密码实现代码,phpcookie• javascript+php实现根据用户时区显示当地时间的方法,javascript当地• 基于GD2图形库的PHP生成图片缩略图类代码分享• php批量添加数据与批量更新数据的实现方法,php添加数据
    1/1

    PHP中文网