超级好用的PM2.5空气质量指数API接口

先看一下接口返回的内容, 共10个有用字段, 超级良心, 白菜价

空气质量、pm2.5、pm10、o3、no2、so2、是否需要戴口罩, 是否适宜外出, 是否适宜开窗, 是否需要关闭净化器

注意,您需要通过 https://tianqiapi.com/user/login?pid=1 申请API服务

PHP调用示例

$appid = '23035354';
$appsecret = '8YvlPNrz';
$version = 'v10';//v10标识为空气质量指数接口
$url = 'https://www.tianqiapi.com/api?version='.$version.'&appid='.$appid.'&appsecret=' . $appsecret;
$data= file_get_contents($url);
$json = json_decode($data, true);
print_r($json);

返回json代码

{
    "air":"99",
    "air_level":"良",
    "air_tips":"空气好,可以外出活动,除极少数对污染物特别敏感的人群以外,对公众没有危害!",
    "pm25":"66",
    "pm25_desc":"良",
    "pm10":"147",
    "pm10_desc":"良",
    "o3":"29",
    "o3_desc":"优",
    "no2":"62",
    "no2_desc":"良",
    "so2":"11",
    "so2_desc":"优",
    "kouzhao":"无需戴口罩",
    "waichu":"适宜外出",
    "kaichuang":"适宜开窗",
    "jinghuaqi":"关闭净化器",
    "cityid":"101120101",
    "city":"济南",
    "cityEn":"jinan",
    "country":"中国",
    "countryEn":"China"
}

返回数组

Array
(
    [air] => 92
    [air_level] => 良
    [air_tips] => 空气好,可以外出活动,除极少数对污染物特别敏感的人群以外,对公众没有危害!
    [pm25] => 35
    [pm25_desc] => 优
    [pm10] => 60
    [pm10_desc] => 良
    [o3] => 193
    [o3_desc] => 轻度
    [no2] => 22
    [no2_desc] => 优
    [so2] => 6
    [so2_desc] => 优
    [kouzhao] => 无需戴口罩
    [waichu] => 适宜外出
    [kaichuang] => 适宜开窗
    [jinghuaqi] => 关闭净化器
    [cityid] => 101120201
    [city] => 青岛
    [cityEn] => qingdao
    [country] => 中国
    [countryEn] => China
)

你可能感兴趣的:(PHP)