前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >修改Mini天气预报app

修改Mini天气预报app

作者头像
HHTjim 部落格
发布2022-09-26 11:25:44
8450
发布2022-09-26 11:25:44
举报
文章被收录于专栏:HHTjim'S 部落格

修改Mini天气预报app

作者:matrix 被围观: 1,502 次 发布时间:2013-10-03 分类:兼容并蓄 零零星星 | 无评论 »

这是一个创建于 3254 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

修改Mini天气预报app,之前使用的是专业气象的数据,这次改的189 API:http://api.189.cn/huafeng/api/getforecast24?access_token=91d1d9d25c62fd393e113116b07b6f601379679414323&[app](https://www.hhtjim.com/tag/app)_id=120032470000032374&city_id=城市ID

参考:http://open.189.cn/index.[php](https://www.hhtjim.com/tag/php)?m=api&c=index&a=show&id=359

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

主要代码:

代码语言:javascript
复制
  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的源码

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

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

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 修改Mini天气预报app
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档