:::
台灣即時空氣質量指數(AQI)
台灣即時空氣質量指數(AQI) 更新說明
- 名稱拼法差異太大,故改成以城市代號為主,避免查無資料(https://campus-xoops.tn.edu.tw/modules/tad_modules/index.php?module_sn=100 可查詢)
- 可重複安裝區塊
- 美化區塊
「 台灣即時空氣質量指數(AQI) 」簡介
台灣即時空氣品質(AQI),有相關空氣資料的監測點如下(儘量已編號為主,較為準確):
基隆市
- 基隆(keelung)
1586
新北市
- 汐止(xizhi)
1587 - 萬里(wanli)
1588 - 新店(xindian)
1589 - 土城(tucheng)
1590 - 板橋(banqiao)
1591 - 新莊(xinzhuang)
1592 - 菜寮(cailiao)
1593 - 林口(linkou)
1594 - 淡水(tamsui)
1595 - 三重(sanchong)
1651 - 永和(yonghe)
1654
台北市
- 士林(shilin)
1596 - 中山(zhongshan)
1597 - 萬華(wanhua)
1598 - 古亭(guting)
1599 - 松山(songshan)
1600 - 大同(datong)
1601 - 陽明(yangming)
1648
桃園縣
- 桃園(taoyuan)
1602 - 大園(dayuan)
1603 - 觀音(guanyin)
1604 - 平鎮(pingzhen)
1605 - 龍潭(longtan)
1606 - 中壢(zhongli)
1652
新竹縣
- 湖口(hukou)
1607 - 竹東(zhudong)
1608
新竹市
- 新竹(hsinchu)
1609
苗栗縣
- 頭份(toufen)
1610 - 苗栗(miaoli)
1611 - 三義(sanyi)
1612
台中市
- 豐原(fengyuan)
1613 - 沙鹿(shalu)
1614 - 大里(dali)
1615 - 忠明(zhongming)
1616 - 西屯(xitun)
1617
彰化縣
- 彰化(changhua)
1618 - 線西(xianxi)
1619 - 二林(erlin)
1620
南投縣
- 南投(nantou)
1621 - 竹山(zhushan)
1653 - 埔里(puli)
1656
雲林縣
- 斗六(douliu)
1622 - 崙背(lunbei)
1623 - 台西(taixi)
1626 - 麥寮(mailiao)
1661
嘉義縣
- 新港(xingang)
1624 - 朴子(puzi)
1625
嘉義市
- 嘉義(chiayi)
1627
台南市
- 新營(xinying)
1628 - 善化(shanhua)
1629 - 安南(annan)
1630 - 台南(tainan)
1631
高雄市
- 美濃(meinong)
1632 - 橋頭(qiaotou)
1633 - 仁武(renwu)
1634 - 鳳山(fengshan)
1635 - 大寮(daliao)
1636 - 林園(linyuan)
1637 - 楠梓(nanzi)
1638 - 左營(zuoying)
1639 - 前金(qianjin)
1640 - 前鎮(qianzhen)
1641 - 小港(xiaogang)
1642 - 復興(fuxing)
1655
屏東縣
- 屏東(pingtung)
1643 - 潮州(chaozhou)
1644 - 恆春(hengchun)
1645
宜蘭縣
- 宜蘭(yilan)
1649 - 冬山(dongshan)
1650
台東縣
- 台東(taitung)
1646 - 關山(guanshan)
1660
花蓮縣
- 花蓮(hualien)
1647
金門縣
- 金門(kinmen)
1658
澎湖縣
- 馬公(magong)
1659
馬祖
- 馬祖(matzu)
1657 - 東引(dongyin)
8768
安裝方式
- 到區塊管理,新增一個自訂區塊。
- 將底下內容貼到自訂區塊中
$cityid = '1631'; $city = 'tainan'; //若有上方代號,此處可不填 //欲更改城市位置,可至 https://campus-xoops.tn.edu.tw/modules/tad_modules/index.php?module_sn=100 查看縣市鄉鎮的英文名稱,並於上方填入城市代號(必填)及英文名稱(選填)即可。 //以下請勿動 if (empty($cityid)) { $url = 'http://api.waqi.info/search/?token=32f529a1fc2b16476338548abb4f281f22509d94&keyword=' . $city; $data = get_aqi_json($url); if (!empty($data)) { $json = json_decode($data, 1); $cityid = $json['data'][0]['uid']; } else { echo "<a href='http://aqicn.org/city/taiwan/$city/' target='_blank'>抓不到指定城市 $city 的城市代號資料,請稍後重試</a>"; } } if (!function_exists('get_aqi_json')) { function get_aqi_json($url) { $data = ''; if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_REFERER, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2); $data = curl_exec($ch); curl_close($ch); } else { $arrContextOptions = array( "ssl" => array( "verify_peer" => false, "verify_peer_name" => false, ), ); $data = file_get_contents($url, false, stream_context_create($arrContextOptions)); } return $data; } } if (!empty($cityid)) { $url1 = "https://api.waqi.info/api/feed/@{$cityid}/obs.hk.json"; $data1 = get_aqi_json($url1); if (!empty($data1)) { $aqi = json_decode($data1, 1); $cityname = $aqi['rxs']['obs'][0]['msg']['city']['name']; $detail = $aqi['rxs']['obs'][0]['msg']['city']['url']; $microtime = microtime(true) * 1000; $url2 = "http://feed.aqicn.org/xservices/refresh:{$cityid}?_" . $microtime; $data2 = get_aqi_json($url2); if (!empty($data2)) { $now = json_decode($data2, 1); $aqiv = $now['aqiv']; $utime = date('Y年m月d日 H時i分', $now['mtime']); if ($aqiv <= 50) { $n = 1; $rank = "優"; $desc = "空氣質量令人滿意,基本無空氣污染"; $suggest = "各類人群可正常活動"; $color = '#009966'; $color2 = 'rgba(0, 153, 102, 0.1)'; } elseif ($aqiv <= 100) { $n = 2; $rank = "良"; $desc = "空氣質量可接受,但某些污染物可能對極少數異常敏感人群健康有較弱影響"; $suggest = "極少數異常敏感人群應減少戶外活動"; $color = '#FFDE33'; $color2 = 'rgba(255, 222, 51, 0.1)'; } elseif ($aqiv <= 150) { $n = 3; $rank = "輕度污染"; $desc = "易感人群症狀有輕度加劇,健康人群出現刺激症狀"; $suggest = "兒童、老年人及心臟病、呼吸系統疾病患者應減少長時間、高強度的戶外鍛鍊"; $color = '#FF9933'; $color2 = 'rgba(255, 153, 51, 0.1)'; } elseif ($aqiv <= 200) { $n = 4; $rank = "中度污染"; $desc = "進一步加劇易感人群症狀,可能對健康人群心臟、呼吸系統有影響"; $suggest = "兒童、老年人及心臟病、呼吸系統疾病患者避免長時間、高強度的戶外鍛鍊,一般人群適量減少戶外運動"; $color = '#CC0033'; $color2 = 'rgba(204, 0, 51, 0.1)'; } elseif ($aqiv <= 300) { $n = 5; $rank = "重度污染"; $desc = "心臟病和肺病患者症狀顯著加劇,運動耐受力降低,健康人群普遍出現症狀"; $suggest = "兒童、老年人及心臟病、肺病患者應停留在室內,停止戶外運動,一般人群減少戶外運動"; $color = '#660099'; $color2 = 'rgba(102, 0, 153, 0.1)'; } else { $n = 6; $rank = "嚴重污染"; $desc = "健康人群運動耐受力降低,有明顯強烈症狀,提前出現某些疾病"; $suggest = "兒童、老年人和病人應停留在室內,避免體力消耗,一般人群避免戶外活動"; $color = '#7E0023'; $color2 = 'rgba(126, 0, 35, 0.1)'; } $widget = " <div style='border: 1px solid $color; border-radius: 6px; width: 100%; background: $color2; padding: 0x; '> <div style=\"font-family: 'Microsoft JhengHei','Segoe UI',Arial,Verdana,fantasy; margin: 10px 15px;\"> <div style='font-size: 1.3em'; font-weight: bold;><a href='{$detail}' target='_blank'>{$cityname}</a>的即時空氣品質</div> <div style='font-size: 0.8em';>{$utime}</div> </div> <div style=\"font-family: 'Microsoft JhengHei','Segoe UI',Arial,Verdana,fantasy; margin: 10px 10px; padding: 6px 15px; background-color: white; position: relative; overflow: hidden;\"> <div style='font-size: 2.2em;'> <span style='font-family: Verdana; background-color: {$color}; color: white; border-radius: 6px;padding: 2px 10px;text-shadow: rgb(3, 3, 3) 1px 1px 1px;'>{$aqiv}</span> <span style='color: {$color};'>{$rank}</span> </div> <div style=\"font-family: 'Segoe UI',Arial,Verdana,fantasy; margin: 10px 15px 0px; font-size:12px;\"> <div>{$desc}</div> <div>{$suggest}</div> </div> <img src='https://campus-xoops.tn.edu.tw/uploads/aqi_{$n}.svg' style='width:160px; height:160px; position: absolute; top:-28px; right:-30px;'> </div> </div>"; echo $widget; } else { echo "<a href='http://aqicn.org/city/taiwan/$city/' target='_blank'>抓不到指定城市 $city 的空氣資料,請稍後重試,或點此連到原始網站觀看資料</a>"; } } else { echo "<a href='http://aqicn.org/city/taiwan/$city/' target='_blank'>抓不到指定城市 $city 的資料,請稍後重試,或點此連到原始網站觀看資料</a>"; } } else { echo "<a href='http://aqicn.org/city/taiwan/$city/' target='_blank'>抓不到指定城市 $city 的城市代號資料,請稍後重試,或點此連到原始網站觀看資料</a>"; } - 內容類型請設為
PHP腳本 - 位置建議放在
左邊
台灣即時空氣質量指數(AQI) 更新項目
台灣即時空氣質量指數(AQI)
1.2
(2018-06-15 17:17:21 起被下載 1129 次)
- 名稱拼法差異太大,故改成以城市代號為主,避免查無資料(https://campus-xoops.tn.edu.tw/modules/tad_modules/index.php?module_sn=100 可查詢)
- 可重複安裝區塊
- 美化區塊
台灣即時空氣質量指數(AQI)
1.1
(2018-06-15 11:35:11 起被下載 13 次)
重新改寫,以支援台灣各地點。
欲更改城市位置,可至 https://campus-xoops.tn.edu.tw/modules/tad_modules/index.php?module_sn=100 查看縣市鄉鎮的英文名稱,並於上方填入英文名稱即可。
台灣即時空氣質量指數(AQI)
1
(2018-06-14 15:29:46 起被下載 8 次)
正式釋出