免费实时天气接口

项目需求:

每天实时更新城市天气,结果找到的接口要么是收费才能使用,要么是每天限制频率。
在这里插入图片描述
但这不能让我放弃,本着将抠门进行到底的想法,不断的寻找,终于找到了这个接口,实时更新气象,包含天气,气压,风力,温度,湿度,空气质量等等一系列数据,关键是它免费,仔细一看居然是腾讯的,不敢相信,我以为腾讯就会骗我在王者里氪金呢,可把我激动坏了。

接口介绍

以下是接口里面的参数介绍

网址https://wis.qq.com/weather/common
sourcepc
weather_typeobserve
province安徽
city芜湖
county无为

source参数代表请求类型,可以填写pc或者wx,默认填写pc即可
weather_type这个参数可以填写多个数值,用|分割开来,可以查询到填写每个数值对应的数据,
observe 当前天气
alarm 预警
tips 天气介绍
index 穿衣,舒适度等
air 空气质量
rise 日出
province参数填写省份,必填项
city参数填写市,必填项
county填写县区,非必填项

实际操作

好了,现在直接上代码给大家CV

$.ajax({
	url: 'https://wis.qq.com/weather/common?source=pc&weather_type=observe|forecast_24h|air&province=安徽&city=芜湖&county=无为', 
	dataType: 'jsonp',
	success: function(res){}
 });
 

是不是很简单,这个接口设置的是get请求,我偷懒就直接把参数填写在url里面,这里面中重要的是要设置dataType为jsonp,否则就会出现跨域问题,感兴趣的小伙伴可以自行百度。

结果展示

{
    "data": {
        "air": {
            "aqi": 38,
            "aqi_level": 1,
            "aqi_name": "优",
            "co": "?",
            "no2": "?",
            "o3": "?",
            "pm10": "?",
            "pm2.5": "?",
            "so2": "?",
            "update_time": "202108081900"
        },
        "forecast_24h": {
            "0": {
                "day_weather": "阴",
                "day_weather_code": "02",
                "day_weather_short": "阴",
                "day_wind_direction": "东风",
                "day_wind_direction_code": "2",
                "day_wind_power": "4",
                "day_wind_power_code": "1",
                "max_degree": "34",
                "min_degree": "24",
                "night_weather": "晴",
                "night_weather_code": "00",
                "night_weather_short": "晴",
                "night_wind_direction": "东北风",
                "night_wind_direction_code": "1",
                "night_wind_power": "3",
                "night_wind_power_code": "0",
                "time": "2021-08-07"
            },
            "1": {
                "day_weather": "多云",
                "day_weather_code": "01",
                "day_weather_short": "多云",
                "day_wind_direction": "东风",
                "day_wind_direction_code": "2",
                "day_wind_power": "3",
                "day_wind_power_code": "0",
                "max_degree": "34",
                "min_degree": "24",
                "night_weather": "多云",
                "night_weather_code": "01",
                "night_weather_short": "多云",
                "night_wind_direction": "东风",
                "night_wind_direction_code": "2",
                "night_wind_power": "3",
                "night_wind_power_code": "0",
                "time": "2021-08-08"
            },
            "2": {
                "day_weather": "阴",
                "day_weather_code": "02",
                "day_weather_short": "阴",
                "day_wind_direction": "东北风",
                "day_wind_direction_code": "1",
                "day_wind_power": "3",
                "day_wind_power_code": "0",
                "max_degree": "31",
                "min_degree": "25",
                "night_weather": "雷阵雨",
                "night_weather_code": "04",
                "night_weather_short": "雷阵雨",
                "night_wind_direction": "东北风",
                "night_wind_direction_code": "1",
                "night_wind_power": "3",
                "night_wind_power_code": "0",
                "time": "2021-08-09"
            },
            "3": {
                "day_weather": "雷阵雨",
                "day_weather_code": "04",
                "day_weather_short": "雷阵雨",
                "day_wind_direction": "东风",
                "day_wind_direction_code": "2",
                "day_wind_power": "3",
                "day_wind_power_code": "0",
                "max_degree": "31",
                "min_degree": "24",
                "night_weather": "中雨",
                "night_weather_code": "08",
                "night_weather_short": "中雨",
                "night_wind_direction": "东风",
                "night_wind_direction_code": "2",
                "night_wind_power": "3",
                "night_wind_power_code": "0",
                "time": "2021-08-10"
            },
            "4": {
                "day_weather": "大雨",
                "day_weather_code": "09",
                "day_weather_short": "大雨",
                "day_wind_direction": "东风",
                "day_wind_direction_code": "2",
                "day_wind_power": "3",
                "day_wind_power_code": "0",
                "max_degree": "30",
                "min_degree": "24",
                "night_weather": "大雨",
                "night_weather_code": "09",
                "night_weather_short": "大雨",
                "night_wind_direction": "东风",
                "night_wind_direction_code": "2",
                "night_wind_power": "4",
                "night_wind_power_code": "1",
                "time": "2021-08-11"
            },
            "5": {
                "day_weather": "大雨",
                "day_weather_code": "09",
                "day_weather_short": "大雨",
                "day_wind_direction": "东北风",
                "day_wind_direction_code": "1",
                "day_wind_power": "4",
                "day_wind_power_code": "1",
                "max_degree": "26",
                "min_degree": "23",
                "night_weather": "小雨",
                "night_weather_code": "07",
                "night_weather_short": "小雨",
                "night_wind_direction": "东北风",
                "night_wind_direction_code": "1",
                "night_wind_power": "4",
                "night_wind_power_code": "1",
                "time": "2021-08-12"
            },
            "6": {
                "day_weather": "小雨",
                "day_weather_code": "07",
                "day_weather_short": "小雨",
                "day_wind_direction": "东北风",
                "day_wind_direction_code": "1",
                "day_wind_power": "4",
                "day_wind_power_code": "1",
                "max_degree": "26",
                "min_degree": "23",
                "night_weather": "小雨",
                "night_weather_code": "07",
                "night_weather_short": "小雨",
                "night_wind_direction": "东北风",
                "night_wind_direction_code": "1",
                "night_wind_power": "4",
                "night_wind_power_code": "1",
                "time": "2021-08-13"
            },
            "7": {
                "day_weather": "小雨",
                "day_weather_code": "07",
                "day_weather_short": "小雨",
                "day_wind_direction": "东北风",
                "day_wind_direction_code": "1",
                "day_wind_power": "4",
                "day_wind_power_code": "1",
                "max_degree": "27",
                "min_degree": "22",
                "night_weather": "多云",
                "night_weather_code": "01",
                "night_weather_short": "多云",
                "night_wind_direction": "东北风",
                "night_wind_direction_code": "1",
                "night_wind_power": "4",
                "night_wind_power_code": "1",
                "time": "2021-08-14"
            }
        },
        "observe": {
            "degree": "29",
            "humidity": "65",
            "precipitation": "0",
            "pressure": "1003",
            "update_time": "202108082050",
            "weather": "多云",
            "weather_code": "01",
            "weather_short": "多云",
            "wind_direction": "2",
            "wind_power": "2"
        }
    },
    "message": "OK",
    "status": 200
}

如果存在问题请大家批评指正!!!

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
根据提供的引用内容,天气预报API免费接口的使用步骤如下: 1. 首先,需要免费获取历史天气查询API的AppKey。\[2\] 2. 将获取到的AppKey替换示例代码中的"appKey"。\[3\] 3. 执行脚本,即可进行天气预报的查询。\[3\] 示例代码中的`ApiRequest`类是一个封装了天气查询功能的类,其中的`verify`方法用于发送请求并获取天气信息。你可以根据自己的需求进行开发和调整。\[3\] 需要注意的是,示例代码中的`city_id`参数用于指定城市的ID,`weather_date`参数用于指定查询的日期。日期的格式为"YYYY-MM-DD",且不能大于等于今日日期。\[3\] 以上是关于天气预报API免费接口的使用方法。希望对你有帮助! #### 引用[.reference_title] - *1* [免费天气预报接口](https://blog.csdn.net/weichangIT/article/details/80255206)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [免费天气预报查询 API、历史天气查询 API 接口使用示例【源码可用】](https://blog.csdn.net/JAVASOFT008/article/details/130812391)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值