Ⅰ 公共平台沒開發怎樣可以有天氣預報
在這篇教程中,我們將介紹如何在微信公眾平台上開發天氣預報功能。我們將使用中國天氣網的氣象數據介面來獲取天氣信息。
這篇教程將介紹以下內容:
獲取中國天氣網的氣象數據
在微信公眾平台中回復天氣
一、中國天氣網
中國天氣網提供了豐富的氣象數據介面。下面我們介紹主要的幾個:
國家根節點介面:
http://flash.weather.com.cn/wmaps/xml/china.xml
該介面以XML格式列出所有的省(自治區、直轄市)的中文名稱(quName)和拼音名稱(pyName)及省會城市的天氣信息,其中廣東的數據如下:
<city quName="廣東" pyName="guangdong" cityname="廣州" state1="2" state2="7" stateDetailed="陰轉小雨" tem1="8" tem2="15" windState="微風"/>
該介面的主要功能是通過它獲取省級節點的拼音名稱。以廣東為例:其pyName是「Guangdong」。
省級節點介面(以廣東為例):
http://flash.weather.com.cn/wmaps/xml/Guangdong.xml
該介面以XML格式列出當前省下轄所有市的中文名稱(quName)、拼音名稱(pyName)、中心坐標、天氣信息以及城市編碼。其中深圳的數據如下所示:
<city cityX="409" cityY="257" cityname="深圳" centername="深圳" fontColor="FFFFFF" pyName="shenzhen" state1="1" state2="1" stateDetailed="多雲" tem1="12" tem2="18" temNow="12" windState="微風" windDir="東北風" windPower="1級" humidity="74%" time="21:15" url="101280601"/>
在這個介面中主要獲取城市名稱及相應的城市編碼。例如,深圳的城市編碼為:101280601。可以編寫程序將全國城市拓撲結構採集下來。也可以使用方倍工作室已經採集好的,點擊這里下載。
實時天氣數據(以深圳為例):
http://www.weather.com.cn/data/sk/101280601.html
該介面以JSON格式列出當前城市的實時天氣狀況。如下所示:
{
"weatherinfo": {
"city": "深圳",
"cityid": "101280601",
"temp": "12",
"WD": "東北風",
"WS": "1級",
"SD": "75%",
"WSE": "1",
"time": "21:20",
"isRadar": "1",
"Radar": "JC_RADAR_AZ9755_JB"
}
}
實時天氣數據參數說明下所示:
六日天氣數據(以深圳為例):
http://m.weather.com.cn/data/101280601.html
該介面以JSON格式列出當前城市的六日天氣狀況。如下所示:
{
"weatherinfo": {
"city": "深圳",
"city_en": "shenzhen",
"date_y": "2014年2月15日",
"date": "",
"week": "星期六",
"fchh": "18",
"cityid": "101280601",
"temp1": "12℃~18℃",
"temp2": "16℃~21℃",
"temp3": "17℃~23℃",
"temp4": "11℃~18℃",
"temp5": "10℃~15℃",
"temp6": "12℃~17℃",
"tempF1": "53.6℉~64.4℉",
"tempF2": "60.8℉~69.8℉",
"tempF3": "62.6℉~73.4℉",
"tempF4": "51.8℉~64.4℉",
"tempF5": "50℉~59℉",
"tempF6": "53.6℉~62.6℉",
"weather1": "多雲",
"weather2": "陰",
"weather3": "多雲",
"weather4": "中雨",
"weather5": "多雲",
"weather6": "陰",
"img1": "1",
"img2": "99",
"img3": "2",
"img4": "99",
"img5": "1",
"img6": "99",
"img7": "8",
"img8": "99",
"img9": "1",
"img10": "99",
"img11": "2",
"img12": "99",
"img_single": "1",
"img_title1": "多雲",
"img_title2": "多雲",
"img_title3": "陰",
"img_title4": "陰",
"img_title5": "多雲",
"img_title6": "多雲",
"img_title7": "中雨",
"img_title8": "中雨",
"img_title9": "多雲",
"img_title10": "多雲",
"img_title11": "陰",
"img_title12": "陰",
"img_title_single": "多雲",
"wind1": "微風",
"wind2": "微風",
"wind3": "微風",
"wind4": "東北風3-4級",
"wind5": "微風",
"wind6": "微風",
"fx1": "微風",
"fx2": "微風",
"fl1": "小於3級",
"fl2": "小於3級",
"fl3": "小於3級",
"fl4": "3-4級",
"fl5": "小於3級",
"fl6": "小於3級",
"index": "較舒適",
"index_d": "建議著薄外套、開衫牛仔衫褲等服裝。年老體弱者應適當添加衣物,宜著夾克衫、薄毛衣等。",
"index48": "較舒適",
"index48_d": "建議著薄外套、開衫牛仔衫褲等服裝。年老體弱者應適當添加衣物,宜著夾克衫、薄毛衣等。",
"index_uv": "最弱",
"index48_uv": "最弱",
"index_xc": "適宜",
"index_tr": "適宜",
"index_co": "舒適",
"st1": "19",
"st2": "13",
"st3": "23",
"st4": "16",
"st5": "24",
"st6": "18",
"index_cl": "適宜",
"index_ls": "適宜",
"index_ag": "不易發"
}
}
未來六日天氣數據主要參數說明如下表所示:
以上介面是我們做天氣預報功能將使用到的介面。
二、微信公眾平台開發
1. 需要將城市編碼對照表導入到資料庫中,以下是SAE導入後截圖
2. 將城市名轉為城市代碼的方法,這將在用戶發送城市名的時候調用
1 function fromNameToCode($name)
2 {
3 $mysql_host = SAE_MYSQL_HOST_M;
4 $mysql_host_s = SAE_MYSQL_HOST_S;
5 $mysql_port = SAE_MYSQL_PORT;
6 $mysql_user = SAE_MYSQL_USER;
7 $mysql_password = SAE_MYSQL_PASS;
8 $mysql_database = SAE_MYSQL_DB;
9
10 $mysql_table = "weather";
11 $mysql_state = "SELECT * FROM ".$mysql_table." WHERE `cityName` = '".$name."'";
12
13 $con = mysql_connect($mysql_host.':'.$mysql_port, $mysql_user, $mysql_password, true);
14 if (!$con){
15 die('Could not connect: ' . mysql_error());
16 }
17 mysql_query("SET NAMES 'UTF8'");
18 mysql_select_db($mysql_database, $con);
19 $result = mysql_query($mysql_state);
20 $cityCode = "";
21 while($row = mysql_fetch_array($result))
22 {
23 $cityCode = $row['cityCode'];
24 break;
25 }
26 mysql_close($con);
27 return $cityCode;
28 }
3. 編寫介面調用函數,用於向天氣網發送cURL請求,獲取數據
1 function httpRequest($url)
2 {
3 $ch = curl_init();
4 curl_setopt($ch, CURLOPT_URL, $url);
5 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
6 $output = curl_exec($ch);
7 curl_close($ch);
8 if ($output === FALSE){
9 return "cURL Error: ". curl_error($ch);
10 }
11 return $output;
12 }
4. 編寫獲取天氣數據的函數,這里獲取實時天氣和未來3日天氣,並將返回結果封裝成圖文信息的數組
1 function getWeatherInfo($cityName)
2 {
3 $cityCode = fromNameToCode($cityName);
4
5 if ($cityCode == "")
6 {
7 return "錯誤的城市名或者此城市不在資料庫中!";
8 }
9
10 //獲取實時天氣
11 $url = "http://www.weather.com.cn/data/sk/".$cityCode.".html";
12 $output = httpRequest($url);
13 $weather = json_decode($output, true);
14 $info = $weather['weatherinfo'];
15
16 $weatherArray = array();
17 $weatherArray[] = array("Title"=>$info['city']."天氣預報", "Description"=>"", "PicUrl"=>"", "Url" =>"");
18 if ((int)$cityCode < 101340000){
19 $result = "實況 溫度:".$info['temp']."℃ 濕度:".$info['SD']." 風速:".$info['WD'].$info['WSE']."級";
20 $weatherArray[] = array("Title"=>str_replace("%", "﹪", $result), "Description"=>"", "PicUrl"=>"", "Url" =>"");
21 }
22
23 //獲取六日天氣
24 $url = "http://m.weather.com.cn/data/".$cityCode.".html";
25 $output = httpRequest($url);
26 $weather = json_decode($output, true);
27 $info = $weather['weatherinfo'];
28
29 if (!empty($info['index_d'])){
30 $weatherArray[] = array("Title" =>$info['index_d'], "Description" =>"", "PicUrl" =>"", "Url" =>"");
31 }
32
33 $weekArray = array("日","一","二","三","四","五","六");
34 $maxlength = 3;
35 for ($i = 1; $i <= $maxlength; $i++) {
36 $offset = strtotime("+".($i-1)." day");
37 $subTitle = date("m月d日",$offset)." 周".$weekArray[date('w',$offset)]." ".$info['temp'.$i]." ".$info['weather'.$i]." ".$info['wind'.$i];
38 $weatherArray[] = array("Title" =>$subTitle, "Description" =>"", "PicUrl" =>"http://discuz.comli.com/weixin/weather/"."d".sprintf("%02u",$info['img'.(($i *2)-1)]).".jpg", "Url" =>"");
39 }
40
41 return $weatherArray;
42 }
5. 在微信公眾平台介面函數中處理收到的文本消息時,文本將為城市名,直接調用獲取天氣的函數
1 /*
2 方倍工作室
3 CopyRight 2013 All Rights Reserved
4 */
5
6 define("TOKEN", "weixin");
7
8 $wechatObj = new wechatCallbackapiTest();
9 if (!isset($_GET['echostr'])) {
10 $wechatObj->responseMsg();
11 }else{
12 $wechatObj->valid();
13 }
14
15 class wechatCallbackapiTest
16 {
17 public function valid()
18 {
19 $echoStr = $_GET["echostr"];
20 if($this->checkSignature()){
21 echo $echoStr;
22 exit;
23 }
24 }
25
26 private function checkSignature()
27 {
28 $signature = $_GET["signature"];
29 $timestamp = $_GET["timestamp"];
30 $nonce = $_GET["nonce"];
31 $token = TOKEN;
32 $tmpArr = array($token, $timestamp, $nonce);
33 sort($tmpArr);
34 $tmpStr = implode($tmpArr);
35 $tmpStr = sha1($tmpStr);
36
37 if($tmpStr == $signature){
38 return true;
39 }else{
40 return false;
41 }
42 }
43
44 public function responseMsg()
45 {
46 $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
47 if (!empty($postStr)){
48 $this->logger("R ".$postStr);
49 $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
50 $RX_TYPE = trim($postObj->MsgType);
51
52 switch ($RX_TYPE)
53 {
54 case "event":
55 $result = $this->receiveEvent($postObj);
56 break;
57 case "text":
58 $result = $this->receiveText($postObj);
59 break;
60 }
61 $this->logger("T ".$result);
62 echo $result;
63 }else {
64 echo "";
65 exit;
66 }
67 }
68
69 private function receiveEvent($object)
70 {
71 $content = "";
72 switch ($object->Event)
73 {
74 case "subscribe":
75 $content = "歡迎關注方倍工作室 ";
76 break;
77 case "unsubscribe":
78 $content = "取消關注";
79 break;
80 }
81 $result = $this->transmitText($object, $content);
82 return $result;
83 }
84
85 private function receiveText($object)
86 {
87 $keyword = trim($object->Content);
88
89 include("weather.php");
90 $content = getWeatherInfo($keyword);
Ⅱ 成都的氣象資料
http://www.cdmb.gov.cn/list_weather.asp?ClassID=020101&absolutepage=1&SearchText= 成都氣象局
查詢每日天氣,有去年3月份至今的天氣資料。
Ⅲ 成都市城鄉房屋租賃公共服務管理信息系統怎麼進不去了
網址變為 zw.cdzj.cheng.gov.cn
按照國務院加強政府網站域名管理的要求,我局房產網上政務版大廳及相關外網應用權將統一啟用後綴為cdzj.cheng.gov.cn的新域名地址,原cdfgj.gov.cn後綴域名地址將停用。請通過住建局官網「住房類政務服務」版塊點擊「在線辦事」進行訪問,
域名地址 zw.cdzj.cheng.gov.cn,由此帶來的不便敬請諒解
Ⅳ 成都公共場所空氣質量檢測哪裡可以的要正規的,謝謝
疾控中心就可以的,希望可以幫到你
Ⅳ 公共氣象服務到底是做什麼的
1、承擔省級公眾氣象服務產品的製作,承擔面向省級(全省性)媒體的公眾氣象服務信息和氣象災害預警信息的發布;承擔省級突發公共事件氣象服務信息發布工作;承擔省級(全省性)公眾氣象服務業務系統的建設和運行;承擔省級(全省性)氣象服務信息發布手段的建設和推廣等。
6、承擔對全省氣象部門公共氣象服務的業務指導;負責甘肅麥克氣象信息技術有限公司的管理和經營;承擔全省氣象服務科學研究和合作交流等。
7、承擔省級公眾氣象服務的增值服務和專業有償氣象服務等。
8、承辦省氣象局交辦的其他事項等。
Ⅵ 成都市氣象局怎麼樣
簡介:成都市氣象局是四川省成都市政府主管氣象工作的工作部門,實行氣象部門和成都市人民政府雙重領導的管理體制,屬公益性事業單位。1985年被成都市委、市政府命名為全市首批「市級文明單位」。 2000年,被成都市委、市政府授予「市級文明單位標兵稱號,並經2007年抽查合格,繼續保留 」市級文明單位標兵榮譽稱號。
注冊資本:259萬人民幣
Ⅶ 成都市2018年九月氣象信息
日期 最高氣溫℃ 最低氣溫℃ 天氣 風向 風力
2018-09-01 28 22 雨 北風 微風
2018-09-02 26 21 雨 北風 微風
2018-09-03 27 21 雨 北風 微風
2018-09-04 28 23 雨 西風 微風
2018-09-05 29 22 雨 北風 微風
2018-09-06 30 22 多雲 微風 微風
2018-09-07 30 22 小雨 微風 微風
2018-09-08 29 21 多雲 微風 微風
2018-09-09 28 21 小雨 微風 微風
2018-09-10 28 20 小雨 微風 微風
2018-09-11 27 20 小雨 微風 微風
2018-09-12 27 20 小雨 微風 微風
2018-09-13 27 20 中雨 微風 微風
2018-09-14 26 19 小雨 微風 微風
2018-09-15 26 19 多雲 微風 微風
2018-09-16 25 19 多雲 微風 微風
2018-09-17 25 18 小雨 微風 微風
2018-09-18 25 18 多雲 微風 微風
2018-09-19 24 18 多雲 微風 微風
2018-09-20 25 18 多雲 微風 微風
2018-09-21 25 18 多雲 微風 微風
2018-09-22 25 18 小雨 微風 微風
2018-09-23 25 18 多雲 微風 微風
2018-09-24 25 18 多雲 微風 微風
2018-09-25 24 18 小雨 微風 微風
2018-09-26 24 17 小雨 微風 微風
2018-09-27 23 17 小雨 微風 微風
2018-09-28 23 17 小雨 微風 微風
2018-09-29 23 17 小雨 微風 微風
2018-09-30 23 17 小雨 微風 微風
具體的天氣變動還是要以九月份7天內近期的為准。
Ⅷ 成都氣象預報
在拜讀搜索欄的上方點擊「更多」,進去後點擊「常用搜索」,進去後在天氣預報欄內輸入「成都」,就搞定了。
Ⅸ 成都氣象
這種專業的問題我建議你上氣像局的網看看相關的資歷料.
Ⅹ 哪個網站可以查到成都的歷史氣象資料
氣象局的