首页 空气质量指数 空气质量指数示例代码 历史空气质量指数查询[PHP]

历史空气质量指数查询示例代码[PHP]

作者: 阅读数:2105 上传时间:2016-03-10

历史空气质量指数查询

<?php

require_once 'curl.func.php';

$appkey = 'your_appkey_here';//你的appkey
$city = '杭州';//utf8
$url = "https://api.jisuapi.com/aqi/history?appkey=$appkey&city=$city";
$result = curlOpen($url, ['ssl'=>true]);
$jsonarr = json_decode($result, true);
//exit(var_dump($jsonarr));
if($jsonarr['status'] != 0)
{
    echo $jsonarr['msg'];
    exit();
}

$result = $jsonarr['result'];
echo $result['cityid'].' '.$result['city'].'
'; foreach($result['hour'] as $hour) { echo $hour['so2'].' '.$hour['so224'].' '.$hour['no2'].' '.$hour['no224'].' '.$hour['co'].' '.$hour['co24'].' '.$hour['o3'].' '.$hour['o38'].' '.$hour['o324'].' '.$hour['pm10'].' '.$hour['pm1024'].' '.$hour['pm2_5'].' '.$hour['pm2_524'].' '.$hour['iso2'].' '.$hour['ino2'].' '.$hour['ico'].' '.$hour['io3'].' '.$hour['io38'].' '.$hour['ipm10'].' '.$hour['ipm2_5'].' '.$hour['aqi'].' '.$hour['primarypollutant'].' '.$hour['quality'].' '.$hour['timepoint'].' '.$hour['color']. '
'; } foreach($result['day'] as $day) { echo $day['so2'].' '.$day['so224'].' '.$day['no2'].' '.$day['no224'].' '.$day['co'].' '.$day['co24'].' '.$day['o3'].' '.$day['o38'].' '.$day['o324'].' '.$day['pm10'].' '.$day['pm1024'].' '.$day['pm2_5'].' '.$day['pm2_524'].' '.$day['iso2'].' '.$day['ino2'].' '.$day['ico'].' '.$day['io3'].' '.$day['io38'].' '.$day['ipm10'].' '.$day['ipm2_5'].' '.$day['aqi'].' '.$day['primarypollutant'].' '.$day['quality'].' '.$day['date'].' '.$day['color']. '
'; }