zoukankan      html  css  js  c++  java
  • 中国天气网天气api接口 天气预报调用方法 2019

    说明(只是为了保存干货)

    百度了很久没有找到免费的天气 API , 不是收费就是接口打不开了,

    最后终于找到了天气api ( https://www.tianqiapi.com/ ) 号称无需注册,没有调用次数、频率和IP限制,

    最重要的是天气数据和中国天气网一致, 城市编号也是用的天气网的, 这样就方便多了

    体验了一下, 确实如此, 大家可以点击一下链接看看, 直接输出天气预报json数据, 而且还是一周的, 字段很全

    curl "https://www.tianqiapi.com/api/?version=v1"
     使用方法

    接口调用确实很简单, 看一下我的PHP例子, 一个curl或者get请求就可以得到数据

        $obj = file_get_contents('https://www.tianqiapi.com/api/?version=v1');
        $data = json_decode($obj, true);
        print_r($data);

    接口参数说明
    参数               类型             必填                 备注
    version          String            是           接口标识, v1:七天 v6: 实时1天
    cityid             String            否           城市ID
    city                String            否           城市名称 如: 青岛, 微山
    ip                  String            否           IP所在城市天气, 默认返回当前IP地区天气
    callback        String            否           返回jsonp格式, 如: jQuery.Callbacks

     可以根据城市编号/ 城市名称 / IP地址获取天气数据

    version值为 v1 时, 返回一周天气数据, version值为 v2 时, 返回一周天气数据
    看一下返回json结果

        {
            "cityid":"101110101",
            "update_time":"2019-04-29 11:30:00",
            "city":"西安",
            "cityEn":"xian",
            "country":"中国",
            "countryEn":"China",
            "data":[
                {
                    "day":"29日(今天)",
                    "date":"2019-04-29",
                    "week":"星期一",
                    "wea":"晴转多云",
                    "wea_img":"yun",
                    "air":39,
                    "humidity":99,
                    "air_level":"优",
                    "air_tips":"空气很好,可以外出活动,呼吸新鲜空气,拥抱大自然!",
                    "alarm":{
                        "alarm_type":"大雾",
                        "alarm_level":"黄色",
                        "alarm_content":"西安市气象台2019年04月29日00时40分发布大雾黄色预警信号:由于空气湿度大,风速小,预计周至县、鄠邑区、长安区、蓝田县、临潼区、高陵区、阎良区、雁塔区、碑林区、莲湖区、新城区、未央区、灞桥区、西咸新区12小时内可能出现能见度小于500米的雾,请注意防范!防御指南:1.有关部门和单位按照职责做好防雾准备工作;2.机场、高速公路等单位加强交通管理,保障安全;3.驾驶人员注意雾的变化,小心驾驶;4.户外活动注意安全。
        (预警信息来源:国家预警信息发布中心)"
                    },
                    "tem1":"25℃",
                    "tem2":"9℃",
                    "tem":"24℃",
                    "win":[
                        "西风",
                        "西南风"
                    ],
                    "win_speed":"<3级",
                    "hours":[
                        {
                            "day":"29日08时",
                            "wea":"多云",
                            "tem":"12℃",
                            "win":"西风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"29日11时",
                            "wea":"晴",
                            "tem":"22℃",
                            "win":"西风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"29日14时",
                            "wea":"晴",
                            "tem":"24℃",
                            "win":"西风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"29日17时",
                            "wea":"晴",
                            "tem":"25℃",
                            "win":"西风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"29日20时",
                            "wea":"晴",
                            "tem":"17℃",
                            "win":"西风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"29日23时",
                            "wea":"多云",
                            "tem":"12℃",
                            "win":"西南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日02时",
                            "wea":"多云",
                            "tem":"11℃",
                            "win":"西南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日05时",
                            "wea":"多云",
                            "tem":"9℃",
                            "win":"西南风",
                            "win_speed":"<3级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"强",
                            "desc":"涂擦SPF大于15、PA+防晒护肤品。"
                        },
                        {
                            "title":"减肥指数",
                            "level":null,
                            "desc":"夏天悄然到,肉已无处藏。天气较舒适,快去运动吧。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"较易波动",
                            "desc":"血糖较易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"舒适",
                            "desc":"建议穿长袖衬衫单裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"较适宜",
                            "desc":"无雨且风力较小,易保持清洁度。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"中",
                            "desc":"易感人群应适当减少室外活动。"
                        }
                    ]
                },
                {
                    "day":"30日(明天)",
                    "date":"2019-04-30",
                    "week":"星期二",
                    "wea":"多云转晴",
                    "wea_img":"yun",
                    "tem1":"24℃",
                    "tem2":"11℃",
                    "tem":"11℃",
                    "win":[
                        "南风",
                        "东北风"
                    ],
                    "win_speed":"<3级",
                    "hours":[
                        {
                            "day":"30日08时",
                            "wea":"多云",
                            "tem":"12℃",
                            "win":"西南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日11时",
                            "wea":"多云",
                            "tem":"19℃",
                            "win":"南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日14时",
                            "wea":"多云",
                            "tem":"22℃",
                            "win":"南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日17时",
                            "wea":"多云",
                            "tem":"24℃",
                            "win":"南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日20时",
                            "wea":"多云",
                            "tem":"18℃",
                            "win":"南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"30日23时",
                            "wea":"晴",
                            "tem":"13℃",
                            "win":"东北风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"01日02时",
                            "wea":"晴",
                            "tem":"12℃",
                            "win":"东北风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"01日05时",
                            "wea":"晴",
                            "tem":"11℃",
                            "win":"东北风",
                            "win_speed":"<3级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"弱",
                            "desc":"辐射较弱,涂擦SPF12-15、PA+护肤品。"
                        },
                        {
                            "title":"减肥指数",
                            "level":null,
                            "desc":"趁着假日好天气,管住嘴迈开腿。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"较易波动",
                            "desc":"血糖较易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"较舒适",
                            "desc":"建议穿薄外套或牛仔裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"较适宜",
                            "desc":"无雨且风力较小,易保持清洁度。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"中",
                            "desc":"易感人群应适当减少室外活动。"
                        }
                    ]
                },
                {
                    "day":"1日(后天)",
                    "date":"2019-05-01",
                    "week":"星期三",
                    "wea":"多云转阴",
                    "wea_img":"yun",
                    "tem1":"25℃",
                    "tem2":"13℃",
                    "tem":"13℃",
                    "win":[
                        "东南风",
                        "东风"
                    ],
                    "win_speed":"3-4级转<3级",
                    "hours":[
                        {
                            "day":"01日08时",
                            "wea":"晴",
                            "tem":"15℃",
                            "win":"东北风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"01日11时",
                            "wea":"多云",
                            "tem":"19℃",
                            "win":"东南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"01日14时",
                            "wea":"多云",
                            "tem":"24℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"01日17时",
                            "wea":"多云",
                            "tem":"25℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"01日20时",
                            "wea":"多云",
                            "tem":"21℃",
                            "win":"东南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"01日23时",
                            "wea":"阴",
                            "tem":"18℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"02日02时",
                            "wea":"阴",
                            "tem":"15℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"02日05时",
                            "wea":"阴",
                            "tem":"13℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"弱",
                            "desc":"辐射较弱,涂擦SPF12-15、PA+护肤品。"
                        },
                        {
                            "title":"</em><em>",
                            "level":null,
                            "desc":"夏天悄然到,肉已无处藏。风虽有点大,室内可健身。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"较易波动",
                            "desc":"血糖较易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"舒适",
                            "desc":"建议穿长袖衬衫单裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"较适宜",
                            "desc":"无雨且风力较小,易保持清洁度。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"良",
                            "desc":"气象条件有利于空气污染物扩散。"
                        }
                    ]
                },
                {
                    "day":"2日(周四)",
                    "date":"2019-05-02",
                    "week":"星期四",
                    "wea":"阴转多云",
                    "wea_img":"yun",
                    "tem1":"28℃",
                    "tem2":"16℃",
                    "tem":"18℃",
                    "win":[
                        "东南风",
                        "东风"
                    ],
                    "win_speed":"3-4级转<3级",
                    "hours":[
                        {
                            "day":"02日08时",
                            "wea":"阴",
                            "tem":"16℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"02日14时",
                            "wea":"阴",
                            "tem":"27℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"02日20时",
                            "wea":"阴",
                            "tem":"24℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"03日02时",
                            "wea":"多云",
                            "tem":"18℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"弱",
                            "desc":"辐射较弱,涂擦SPF12-15、PA+护肤品。"
                        },
                        {
                            "title":"</em><em>",
                            "level":null,
                            "desc":"夏天悄然到,肉已无处藏。风虽有点大,室内可健身。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"易波动",
                            "desc":"血糖易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"舒适",
                            "desc":"建议穿长袖衬衫单裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"较适宜",
                            "desc":"无雨且风力较小,易保持清洁度。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"良",
                            "desc":"气象条件有利于空气污染物扩散。"
                        }
                    ]
                },
                {
                    "day":"3日(周五)",
                    "date":"2019-05-03",
                    "week":"星期五",
                    "wea":"小雨转阴",
                    "wea_img":"yu",
                    "tem1":"27℃",
                    "tem2":"17℃",
                    "tem":"17℃",
                    "win":[
                        "东南风",
                        "东南风"
                    ],
                    "win_speed":"3-4级转<3级",
                    "hours":[
                        {
                            "day":"03日08时",
                            "wea":"多云",
                            "tem":"19℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"03日14时",
                            "wea":"阴",
                            "tem":"27℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"03日20时",
                            "wea":"小雨",
                            "tem":"21℃",
                            "win":"东南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"04日02时",
                            "wea":"阴",
                            "tem":"17℃",
                            "win":"东南风",
                            "win_speed":"<3级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"最弱",
                            "desc":"辐射弱,涂擦SPF8-12防晒护肤品。"
                        },
                        {
                            "title":"</em><em></em><em></em><em>",
                            "level":null,
                            "desc":"风雨相伴,坚持室内运动吧。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"易波动",
                            "desc":"血糖易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"舒适",
                            "desc":"建议穿长袖衬衫单裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"不宜",
                            "desc":"有雨,雨水和泥水会弄脏爱车。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"良",
                            "desc":"气象条件有利于空气污染物扩散。"
                        }
                    ]
                },
                {
                    "day":"4日(周六)",
                    "date":"2019-05-04",
                    "week":"星期六",
                    "wea":"多云",
                    "wea_img":"yun",
                    "tem1":"25℃",
                    "tem2":"16℃",
                    "tem":"18℃",
                    "win":[
                        "东风",
                        "东北风"
                    ],
                    "win_speed":"<3级",
                    "hours":[
                        {
                            "day":"04日08时",
                            "wea":"阴",
                            "tem":"19℃",
                            "win":"东南风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"04日14时",
                            "wea":"多云",
                            "tem":"23℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"04日20时",
                            "wea":"多云",
                            "tem":"20℃",
                            "win":"东风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"05日02时",
                            "wea":"多云",
                            "tem":"18℃",
                            "win":"东北风",
                            "win_speed":"<3级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"弱",
                            "desc":"辐射较弱,涂擦SPF12-15、PA+护肤品。"
                        },
                        {
                            "title":"减肥指数",
                            "level":null,
                            "desc":"夏天悄然到,肉已无处藏。天气较舒适,快去运动吧。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"较易波动",
                            "desc":"血糖较易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"舒适",
                            "desc":"建议穿长袖衬衫单裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"较适宜",
                            "desc":"无雨且风力较小,易保持清洁度。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"中",
                            "desc":"易感人群应适当减少室外活动。"
                        }
                    ]
                },
                {
                    "day":"5日(周日)",
                    "date":"2019-05-05",
                    "week":"星期日",
                    "wea":"阴",
                    "wea_img":"yin",
                    "tem1":"21℃",
                    "tem2":"14℃",
                    "tem":"21℃",
                    "win":[
                        "东南风",
                        "东风"
                    ],
                    "win_speed":"3-4级",
                    "hours":[
                        {
                            "day":"05日08时",
                            "wea":"多云",
                            "tem":"16℃",
                            "win":"东北风",
                            "win_speed":"<3级"
                        },
                        {
                            "day":"05日14时",
                            "wea":"阴",
                            "tem":"16℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"05日20时",
                            "wea":"阴",
                            "tem":"19℃",
                            "win":"东南风",
                            "win_speed":"3-4级"
                        },
                        {
                            "day":"06日02时",
                            "wea":"阴",
                            "tem":"21℃",
                            "win":"东风",
                            "win_speed":"3-4级"
                        }
                    ],
                    "index":[
                        {
                            "title":"紫外线指数",
                            "level":"最弱",
                            "desc":"辐射弱,涂擦SPF8-12防晒护肤品。"
                        },
                        {
                            "title":"</em><em>",
                            "level":null,
                            "desc":"夏天悄然到,肉已无处藏。风虽有点大,室内可健身。"
                        },
                        {
                            "title":"健臻·血糖指数",
                            "level":"较易波动",
                            "desc":"血糖较易波动,注意监测。"
                        },
                        {
                            "title":"穿衣指数",
                            "level":"较舒适",
                            "desc":"建议穿薄外套或牛仔裤等服装。"
                        },
                        {
                            "title":"洗车指数",
                            "level":"较适宜",
                            "desc":"无雨且风力较小,易保持清洁度。"
                        },
                        {
                            "title":"空气污染扩散指数",
                            "level":"良",
                            "desc":"气象条件有利于空气污染物扩散。"
                        }
                    ]
                }
            ]
        }

    原文链接:https://blog.csdn.net/qq_38832501/article/details/89680763
    ---------------------
    作者:Cc琎
    来源:CSDN
    原文:https://blog.csdn.net/qq_38832501/article/details/89680763
    版权声明:本文为博主原创文章,转载请附上博文链接!

  • 相关阅读:
    Android开发(二十一)——自动更新
    Android开发(十九)——ViewFlipper中的onClick事件和onFling事件冲突
    Android开发(十八)——头部、中部、底部布局技巧
    Android开发(十七)——关闭中间activity
    Android开发(十六)——Android listview onItemClick事件失效的原因
    Android开发(十五)——ListView中Items的间距margin
    Android开发(十四)——SimpleAdapter与自定义控件
    [ MongoDB ] 3.X权限认证控制
    批量修改主机密码并发送到邮箱
    [ ceph ] CEPH 部署完整版(CentOS 7 + luminous)
  • 原文地址:https://www.cnblogs.com/volodya/p/11039346.html
Copyright © 2011-2022 走看看