zoukankan      html  css  js  c++  java
  • Html5+移动端小应用分享(得见)

    应用截图

    整个应用由移动端+php后端处理构成

    移动端在DCloud平台下HBuilder开发和编译,使用了MUI框架;

    目录结构如下:

    php后端处理代码部署在了新浪云应用当中

    response.php代码如下:

      1 <?php
      2     header("Content-Type:text/html; charset=utf-8");
      3     function getCurlData($url){
      4         $ch = curl_init();
      5         $header = array(
      6             'apikey: XXXXXXX',
      7         );
      8         // 添加apikey到header
      9         curl_setopt($ch, CURLOPT_HTTPHEADER  , $header);
     10         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     11         // 执行HTTP请求
     12         curl_setopt($ch , CURLOPT_URL , $url);
     13         $res = curl_exec($ch);
     14         return $res;
     15     }
     16     //object转数组
     17     function object_array($array){
     18         if(is_object($array)){
     19             $array = (array)$array;
     20         }
     21         if(is_array($array)){
     22             foreach($array as $key=>$value){
     23                 $array[$key] = object_array($value);
     24             }
     25         }
     26         return $array;
     27     }
     28     $type = $_REQUEST['type'];
     29     if(empty($type)){
     30         ob_clean();//清除之前输出内容
     31         echo json_encode(array('error'=>1,'msg'=>'参数错误'));die();
     32     }
     33     $url = "";
     34     
     35     switch($type){
     36         case "todayhistory":
     37             $month = (int)$_REQUEST['month'];
     38             $day = (int)$_REQUEST['day'];
     39             $url = "http://apis.baidu.com/netpopo/todayhistory/todayhistory?month=".$month."&day=".$day."&appkey=1307ee261de8bbcf83830de89caae73f";
     40             ob_clean();//清除之前输出内容
     41             echo getCurlData($url);
     42             die();
     43             break;
     44         case "todaytv":
     45             $reqType = (int)$_REQUEST['req_type'];//1:获取电视频道列表;2:查询电视节目
     46             $tvid = (int)$_REQUEST['tvid'];
     47             $starttime = strtotime(date('Y-m-d 00:00:00'));
     48             $endtime = strtotime(date('Y-m-d 23:59:59'));
     49             $url = $reqType==1?"http://apis.baidu.com/netpopo/tv/tv_channel":"http://apis.baidu.com/netpopo/tv/tv?tvid=".$tvid."&starttime=".$starttime."&endtime=".$endtime;
     50             ob_clean();//清除之前输出内容
     51             $res = object_array(json_decode(getCurlData($url)));
     52             if($res['code']==1){
     53                 echo json_encode($res);die();
     54             }else{
     55                 //三级联动数据格式[{value: '110000',text: '北京市',children: [{value: "110101",text: "北京+市",children: [{value: "110101",text: "东城区"}]}]}]
     56                 $list = array();
     57                 if($reqType==1){
     58                     foreach($res['data'] as $row){
     59                         //"id": "1","name": "中央台","parentid": "0","istv": "0"
     60                         $id = (int)$row['id'];
     61                         $one = array('value'=>$id,'text'=>$row['name'],'children'=>array());
     62                         foreach($res['data'] as $rw){
     63                             $parentid = (int)$rw['parentid'];
     64                             if($parentid==$id){
     65                                 $two = array('value'=>$rw['id'],'text'=>$rw['name'],'children'=>array());
     66                                 foreach($res['data'] as $rw2){
     67                                     $parentid2 = (int)$rw2['parentid'];
     68                                     if($parentid2==$rw['id']){
     69                                         $three = array('value'=>$rw2['id'],'text'=>$rw2['name'],'children'=>array());
     70                                         $two['children'][] = $three;
     71                                     }
     72                                 }
     73                                 $one['children'][] = $two;
     74                             }
     75                         }
     76                         $list[] = $one;
     77                     }
     78                 }else{
     79                     foreach($res['data'] as $row){
     80                         $one = array('starttime'=>date('H:i',$row['starttime']),'name'=>$row['name']);
     81                         $list[] = $one;
     82                     }
     83                 }
     84                 
     85                 ob_clean();//清除之前输出内容
     86                 echo json_encode(array('error'=>0,'data'=>$list));die();
     87             }
     88             break;
     89         case 'mobileck':
     90             $mobile = $_REQUEST['mobile'];
     91             if(empty($mobile)){
     92                 ob_clean();//清除之前输出内容
     93                 echo json_encode(array('error'=>1,'msg'=>'参数错误'));die();
     94             }
     95             $url = "http://appyun.sinaapp.com/index.php?app=mobile&controller=index&action=api&outfmt=json&mobile=".$mobile;
     96             ob_clean();//清除之前输出内容
     97             $res = object_array(json_decode(getCurlData($url)));
     98             $data = array('Province'=>$res['Province'],'City'=>$res['City'],'Operators'=>$res['Operators']);
     99             ob_clean();//清除之前输出内容
    100             echo json_encode(array('error'=>0,'data'=>$data));die();
    101             break;
    102         default:
    103             ob_clean();//清除之前输出内容
    104             echo json_encode(array('error'=>1,'data'=>array(),'msg'=>'暂无数据'));die();
    105     }
    106 ?>

    这个应用整体显得还很粗糙,不规范,也没能十分好的掌握html5+技术,希望自己能今早掌握。

    自己本身是个php开发人员,html5+技术让自己也能轻松的实现移动应用开发,这点挺让人兴奋的!

    源码与app百度云地址:http://pan.baidu.com/s/1pJkSnnt 密码:bgcx

    参考资料
    http://dcloudio.github.io/mui/
    http://sae.sina.com.cn
    http://apistore.baidu.com/

  • 相关阅读:
    财富感悟:赚大钱的经典语录
    男人成为富翁必备五大特质
    上帝不会辜负每一个有梦的孩子(转)
    一百个绝佳句型
    欢迎光临腾飞品牌网和腾飞悬赏任务网
    金钱在哪里?财富就在你心里
    小本创业30条生意妙经
    告诉你钱途无量的六大创业领域
    告诉你一个简单、深刻的经商道理
    十二条创业经验:包你做梦都赚钱
  • 原文地址:https://www.cnblogs.com/hero-89/p/4731177.html
Copyright © 2011-2022 走看看