天气预报API接口
输出查询天气的城市信息

接口地址: https://api.ooomn.com/api/weather

返回格式: json

请求方式: GET,POST

请求示例: https://api.ooomn.com/api/weather?city=北京

请求参数说明:

名称 必填 类型 说明
city string 不要带市和区, 支持市区县, 不支持乡镇级别; 如: 青岛、北京、上海
ip string 查询IP所在城市天气

返回参数说明:

名称 类型 说明
cityid String 城市ID
date String 当前日期
week String 当前星期
country String 国家名称
city String 城市名称
wea String 天气情况
wea_img String 天气对应图标
tem String 实时温度
tem_day String 白天温度(高温)
tem_night String 白天温度(低温)
win String 风向
win_speed String 风力等级
win_meter String 风速
humidity String 湿度
visibility String 能见度
pressure String 气压hPa
air String 空气质量
air_level String 空气质量等级
air_tips String 空气质量描述
update_time String 气象台更新时间

返回示例:

{
    "code": 200,
    "msg": "success",
    "data": {
        "cityid": "101010100",
        "date": "2021-12-26",
        "week": "星期日",
        "country": "中国",
        "city": "北京",
        "wea": "晴",
        "wea_img": "qing",
        "tem": "-5℃",
        "tem_day": "1℃",
        "tem_night": "-8℃",
        "win": "西南风",
        "win_speed": "1级",
        "win_meter": "4km/h",
        "humidity": "27%",
        "visibility": "22km",
        "pressure": "1032",
        "air": "78",
        "air_level": "良",
        "air_tips": "空气好,可以外出活动,除极少数对污染物特别敏感的人群以外,对公众没有危害!",
        "update_time": "2021-12-26 21:56"
    },
    "user_ip": "14.145.89.26"
}

请求参数设置:

参数名称 参数值 操作


					{
    "code": 200,
    "msg": "success",
    "data": {
        "cityid": "101010100",
        "date": "2021-12-26",
        "week": "星期日",
        "country": "中国",
        "city": "北京",
        "wea": "晴",
        "wea_img": "qing",
        "tem": "-5℃",
        "tem_day": "1℃",
        "tem_night": "-8℃",
        "win": "西南风",
        "win_speed": "1级",
        "win_meter": "4km/h",
        "humidity": "27%",
        "visibility": "22km",
        "pressure": "1032",
        "air": "78",
        "air_level": "良",
        "air_tips": "空气好,可以外出活动,除极少数对污染物特别敏感的人群以外,对公众没有危害!",
        "update_time": "2021-12-26 21:56"
    },
    "user_ip": "14.145.89.26"
}				

错误码格式说明:

名称 类型 说明

代码示例:

<?php
header('Content-Type: text/json; charset=utf-8');
$city = $_GET['city'];
$ip = $_GET['ip'];
$api = 'https://api.ooomn.com/api/weather?city=' . $city . '&ip=' . $ip;
$url = YunTu($api);
echo $url;

function YunTu($url)
{
$ch = curl_init();
$timeout = 30;
$ua= $_SERVER['HTTP_USER_AGENT'];
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$urls = $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER,$urls);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:'.$ip, 'CLIENT-IP:'.$ip));
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
$content = curl_exec($ch);
curl_close($ch);
return $content;
}
?>