修改Mini天气预报app-LMLPHP

地址:http://demo.hhtjim.com

修改Mini天气预报app,之前使用的是专业气象的数据,这次改的189 API:http://api.189.cn/huafeng/api/getforecast24?access_token=91d1d9d25c62fd393e113116b07b6f601379679414323&app_id=120032470000032374&city_id=城市ID

参考:http://open.189.cn/index.php?m=api&c=index&a=show&id=359

城市ID列表 :http://open.189.cn/sharedata/cms/uploadfile/2012/1102/113459s3unXsSCAn.zip

主要代码:

  function getWeathers($city) {
$wcity = file_get_contents("Liebiao.txt");
         $pattern = "/([0-9]+)=" . $city . '/';
preg_match_all ($pattern,$wcity,$titleList, PREG_PATTERN_ORDER);//使用preg_match_all正则匹配数据并保存到$titleList数组中
            if ($titleList[0] == null) {
             return null;
         }
$CITYID = explode('=',$titleList[0][0]);
$Date = file_get_contents('http://api.189.cn/huafeng/api/getforecast24?access_token=91d1d9d25c62fd393e113116b07b6f601379679414323&app_id=120032470000032374&city_id='.$CITYID[0]);
$cityinfO = explode('"',$Date);
//echo $cityinfO[5];//$cityinfO[5] 城市名
return $cityinfO;
}

     if ($_POST != null && $_POST["city"] != null) {
         $cityinfOO = getWeathers($_POST["city"]);
         if ($cityinfOO == null) {?>
         <div class="alert alert-block" style="margin: 20px">
             <button type="button" class="close" data-dismiss="alert">
                 &times;
             </button>
             <h4>警告!</h4>
              发生错误了亲,您输入的城市「<?php echo $_POST["city"]?>」好像没有找到哦! <a href="http://www.hhtjim.com/message-wall#comment">通知admin</a>
         </div>
         <?php return null;
         }
        // $cityinfO = $weather;

         ?>
         <table class="table table-striped table-bordered" style="margin-left: 20px;width: 500px">
             <thead>
                 <th>实时天气信息</th>
             </thead>

             <tbody>
         <?php
echo "<tr><td>省份:</td><td>".$cityinfOO[7]."</td></tr>";
         echo "<tr><td>城市:</td><td>".$cityinfOO[5]."</td></tr>";
         echo "<tr><td>城市ID:</td><td>".$cityinfOO[9]."</td></tr>";
         echo "<tr><td>气象:</td><td>".$cityinfOO[13]."</td></tr>";
         echo "<tr><td>气温:</td><td>".$cityinfOO[19]."℃~".$cityinfOO[17]."℃</td></tr>";
         echo "<tr><td>风向:</td><td>".$cityinfOO[15]."</td></tr>";
echo "<tr><td>更新时间:</td><td>".$cityinfOO[11]."</td></tr>";
         ?>
             </tbody>

         </table>
         <?php
     }
     ?>

Mini天气预报app之前使用的是admin5的源码

修改Mini天气预报app-LMLPHP

下载:http://pan.baidu.com/s/1cJSpO

http://www.400gb.com/file/30696317

参考:PHP利用天气API获取天气信息

03-04 15:07