联系客服: iP138.com客服 iP138客服 |

天气预报接口
北京市天气实况

16.3℃ 阴

风向风速:北风1级

相对湿度:31%

空气质量:54良

  • API接口QQ交流群:177096428   iP138 api接口
  • 数据修正QQ处理群:94181690    iP138数据修正

天气预报查询接口支持HTTPS(赠送1000次)

简介:获取全国今天天气及最近7天的天气预报情况

已连接应用数:4249

全国天气预报接口文档说明

全国天气预报接口地址

http协议:
国内大陆优化(支持ipv6)http://api.ipshudi.com/weather/
国际各洲覆盖(部份ipv6)http://api.ip138.com/weather/

https协议:
国内大陆优化(支持ipv6)https://api.ipshudi.com/weather/
国际各洲覆盖(部份ipv6)https://api.ip138.com/weather/

示例1(Linux命令行下执行)

请求方式

get

参数说明:
1. code string 行政区划代码 (可选)
2. ip string iP地址 (可选,默认为请求iP,仅当用户没有提供行政区划代码时有效)
3. callback string 回调函数(可选,默认为空)
4. token string 购买服务后会提供(必填)
5. type int 查询类型 1:今日天气 7:一周天气 (默认今日天气)
6. style int 天气icon样式 1|2|3

    样式1 样式2 样式3
curl "https://api.ip138.com/weather/?code=350229&callback=find&type=1" -H "token:cc87f3c77747bccbaaee35006da1ebb65e0bad57"

示例2

参数说明:
1. code string 行政区划代码 (可选)
2. ip string iP地址 (可选,默认为请求iP,仅当用户没有提供行政区划代码时有效)
3. callback string 回调函数(可选,默认为空)
4. token string 购买服务后会提供(必填)
5. type int 查询类型 1:今日天气 7:一周天气 (默认今日天气)
6. style int 天气icon样式 1|2|3

https://api.ip138.com/weather/?code=350229&type=1&callback=find&token=cc87f3c77747bccbaaee35006da1ebb65e0bad57

示例3(js引入推荐方案)

参数说明:
1. code string 行政区划代码 (可选)
2. ip string iP地址 (可选,默认为请求iP,仅当用户没有提供行政区划代码时有效)
3. callback string 回调函数 当前参数仅为jsonp格式数据提供(可选,默认为空)
4. type int 查询类型 1:今日天气 7:一周天气 (默认今日天气)
5. style int 天气icon样式 1|2|3
6. time string 时间戳(必填)
7. oid string 购买服务后提供(必填)
8. mid string 购买服务后提供(必填)
9. sign string 签名验证 (签名算法:md5("time=" + time + "&token=" + token))(必填)

https://api.ip138.com/weather/?code=350229&callback=find&time=20170102&oid={oid}&mid={mid}&sign=签名算法

选择获取行政区划代码:

行政区划代码列表说明

JSONP返回示例

说明:ret 值为 ok 时 返回data查询结果数据 为err时返回msg错误信息

{
    "ret": "ok",    // ret 值为 ok 时 返回 data 数据 为err时返回msg数据
    "code": "350103", // 行政区划代码
    "province":"福建省",
    "city":"福州市",
    "area":"台江区",
    "data": [
        time:"14:20",                           //更新时间
        dayIcon:"http://p.abcache.com/ip138/image/tianqi1/d00.png", //天气图标
        dayWeather:"晴转多云",                      //白天天气
        dayTemp:"18",                        //白天温度
        dayWind:"微风",                          //白天风力
        "nightIcon":"http://p.abcache.com/ip138/image/tianqi1/n01.png", //天气图标
        nightWeather:"中度霾转多云",              //夜晚天气
        nightTemp:"9",                          //夜晚温度
        nightWind:"微风",                        //夜晚风力
        temp"9",                                //实时温度
        "Icon":"http://p.abcache.com/ip138/image/tianqi1/d00.png" //天气图标
        weather:"多云",                          //实时天气
        wind:"北风1级",                          //实时风力
        humidity:"82"                           //湿度
        pm25:11                                 //pm
    ]
}

查询token使用情况

URL

https://api.ip138.com/status/

请求方式

get

参数

1. token `string`

示例

https://api.ip138.com/status/?token=cc87f3c77747bccbaaee35006da1ebb65e0bad57

响应

{
    "ret":"ok",
    "data":{
        "reqs":10,   //当前小时请求数
        "hour":3000, //当前小时购买次数
        "package":19767 //配额次数
    }
}