zoukankan      html  css  js  c++  java
  • php接口

    入口

    <?php
    
    class Api_IphoneController extends actions_api {
    
        var $identity = null;
    
        function init() {
            parent::init();
            $this->setView('api');
        }
    
        function indexAction() {
            $json = $_REQUEST;
            //print_r(json_decode($json['json'],true));exit;
            if (array_key_exists('json', $json)) {
                $json_info = json_decode($json['json'], true);
                //$this->debuglog($json['json']); // debug
            } else {
                echo "无请求参数,请输入请求参数!";
                die();
            }
            //通过reqCode转入控制层
            switch ($json_info["reqCode"]) {
                case 'edu00001':
                    // 获取新闻,分页获取
                    // 请求{"reqCode":"edu00001","data":{"nowpage":"1","pageNum":"10","user_id":"10","bigclassid":"221"}}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('newslist', 'news', 'api', $json_info);
                    break;
    
                case 'edu00002':
                    // 获取所有老师
                    // 请求{"reqCode":"edu00002"}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('allteacher', 'teacher', 'api', $json_info);
                    break;
    
                case 'edu00003':
                    // 新闻top5
                    // 请求{"reqCode":"edu00003","data":{"user_id":"105"}}
                    // 响应 
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('newstop5', 'news', 'api', $json_info);
                    break;
    
    
                case 'edu00004':
                    // 获取收件箱消息,分页获取
                    // 请求{"reqCode":"edu00004","data":{"user_id":"105","nowpage":"1","pageNum":"10"}}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('msginlist', 'message', 'api', $json_info);
                    break;
    
                case 'edu00005':
                    // 所有班级
                    // 请求{"reqCode":"edu00005"}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('allclassinfo', 'student', 'api', $json_info);
                    break;
    
                case 'edu00006':
                    // 登录
                    // 请求{"reqCode":"edu00006","data":{"username":"test3","password":"123456"}}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('login', 'auth', 'api', $json_info);
                    break;
    
                case 'edu00007':
                    // 班级信息
                    // 请求{"reqCode":"edu00007","data":{"class_id":"19"}}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('classinfo', 'student', 'api', $json_info);
                    break;
    
                case 'edu00008':
                    // 新闻分类
                    // 请求{"reqCode":"edu00008"}
                    // 响应
                    $json_info = json_decode($json['json'], true);
    
                    $this->_forward('newstype', 'news', 'api', $json_info);
                    break;
    
                case 'edu00009':
                    // 学生信息
                    // 请求{"reqCode":"edu00009","data":{"user_id":"166"}}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('studentinfo', 'student', 'api', $json_info);
                    break;
    
                case 'edu00010':
                    // 消息发送
                    // 请求{"reqCode":"edu00010","data":{"from_id":"21","to_id":"105,22,23","topic":"消息主题","content":"消息内容"}}
                    // 响应
                    $json_info = json_decode($json['json'], true);
                    $this->_forward('msgsend', 'message', 'api', $json_info);
                    break;
                default:
                    echo '请求代码错误!!';
            }
        }
    
    }

    处理

      1 <?php
      2 class Api_NewsController extends actions_api {
      3     public $doMain = 'http://testserver.njlrxx.com/';
      4 
      5 
      6     //接口中可以直接操作sql语句进行一些处理
      7     function init() {
      8         parent::init();
      9         $this->setView('api');
     10         $this->dao_newsrecord = new dao_newsrecord();
     11         $this->dao_module = new dao_module();
     12         $this->dao_message = new dao_message();
     13         $this->dao_user = new dao_user();
     14         $this->dao_news = new dao_news();
     15         $this->inData = $this->_getParam('data',false);//请求参数
     16         $this->reqCode = $this->_getParam('reqCode',false);
     17         $this->outData = array('status'=>0,'msg'=>'','data'=>array(),'reqCode'=>$this->reqCode);//输出参数
     18     }
     19     
     20 
     21     //新闻分类
     22     function newstypeAction()
     23     {
     24         $where['BigClass.typeid = ?'] = array("type"=>1,"val"=>60);
     25         $aBigClass = $this->dao_news->getBigClass($where, 'BigClassID ASC', 3);
     26         if(COUNT($aBigClass) == 0)
     27         {
     28             $this->outData['msg'] = '暂无数据';
     29             $this->printOut();
     30         }
     31         $this->outData['status'] = 1;
     32         $this->outData['msg'] = '获取成功';
     33         $this->outData['data'] = $aBigClass;
     34         $this->printOut();
     35     }
     36 
     37 
     38     //图片新闻前五条
     39     function newstop5Action(){
     40         $where['News.picnews = ?'] = array("type"=>1,"val"=>1);
     41         $aNewsData = $this->dao_news->getNews2($where, 'NewsID DESC', 5, FALSE , false, array('NewsID','picname','Title'));
     42         foreach($aNewsData as &$val)
     43         {
     44             $val['webview_url'] = $this->doMain.'api/news/newsview/NewsID/'.$val['NewsID'].'/user_id/'.$this->inData['user_id'];
     45         }
     46         if(COUNT($aNewsData) == 0)
     47         {
     48             $this->outData['msg'] = '暂无数据';
     49             $this->printOut();
     50         }
     51         $this->outData['status'] = 1;
     52         $this->outData['msg'] = '获取成功';
     53         $this->outData['data'] = $aNewsData;
     54         $this->printOut();
     55     }
     56 
     57     function newslistAction(){
     58         $nowPage = !empty($this->inData['nowpage'])?$this->inData['nowpage']:1;    //$this->_getParam('nowpage',1);
     59         $pageNum = !empty($this->inData['pageNum'])?$this->inData['pageNum']:10;    //$this->_getParam('pageNum',10);
     60         $bigclassid = !empty($this->inData['bigclassid'])?$this->inData['bigclassid']:false;    
     61          if(!$bigclassid)
     62         {
     63             $this->outData['msg'] = '缺少分类参数';
     64             $this->printOut();
     65         }
     66         $offset = ($nowPage - 1)*$pageNum;
     67         $where['News.bigclassid = ?'] = array("type"=>1,"val"=>$bigclassid);
     68         $total = $this->dao_news->getNews2($where, '', false, false , true);
     69         $aNewsData = $this->dao_news->getNews2($where, 'NewsID DESC', $pageNum, $offset , false, array('NewsID','Title','UpdateTime','convert(text,Content) as Content'));
     70 
     71         foreach($aNewsData as &$val)
     72         {
     73             $val['webview_url'] = $this->doMain.'api/news/newsview/NewsID/'.$val['NewsID'].'/user_id/'.$this->inData['user_id'];
     74             $val['Content'] = $this->substring($this->clearhtml($val["Content"]),16);
     75         }
     76         if($total == 0)
     77         {
     78             $this->outData['msg'] = '暂无数据';
     79             $this->printOut();
     80         }
     81         $this->outData['next'] = 0;
     82         if($total > ($nowPage * $pageNum))
     83         {
     84             $this->outData['next'] = 1;
     85         }
     86         $this->outData['status'] = 1;
     87         $this->outData['msg'] = '获取成功';
     88         $this->outData['data'] = $aNewsData;
     89 
     90         $this->printOut();
     91     }
     92 
     93     function newsviewAction(){
     94         $newsID = $this->_getParam("NewsID",0);//新闻id
     95         $userID = $this->_getParam("user_id");//uid
     96 
     97         //$whereUser['lx_user.id = ?'] = array("type"=>1,"val"=>$user_id);
     98         //$aUser = $this->dao_user->getUser($whereUser);
     99     
    100         $whereNews['News.NewsID = ?'] = array("type"=>1,"val"=>$newsID);
    101         $aNews = $this->dao_news->getNews($whereNews);
    102 
    103         $aNewsData = $aNews ? $aNews[0] : false;
    104         if(!$aNewsData && $aNewsData['checkked'] == 1 && $userID)//是否审核
    105         {
    106             $this->dao_news->updateNews(array('click'=>'`click`+1','NewsID'=>$newsID));//更新新闻点击次数
    107              //阅读人记录到数据库中
    108             $aNewsrecord = array();
    109             $aNewsrecord['news_id'] = $NewsID;
    110             $aNewsrecord['user_id'] = $userID;
    111             $aNewsrecord['user_name'] = !is_null($aUser[0]["name"]) ? $aUser[0]["name"] : $aUser[0]["surname"].$aUser[0]["givenname"];
    112             $aNewsrecord['user_avatar'] = $aUser[0]["avatar"];
    113             $aNewsrecord['time'] = time();
    114             $whereNewsrecord = array();
    115             $whereNewsrecord['lx_newsrecord.news_id = ?'] = array("type"=>1,"val"=>$NewsID);
    116             $whereNewsrecord['lx_newsrecord.user_id = ?'] = array("type"=>1,"val"=>$userID);
    117             $result = $this->dao_newsrecord->getNewsrecord($whereNewsrecord);
    118             if($result){
    119                 $aNewsrecord['id'] = $result[0]['id'];
    120                 $this->dao_newsrecord->updateNewsrecord($aNewsrecord);
    121             }else{
    122                 $this->dao_newsrecord->addNewsrecord($aNewsrecord);
    123             }
    124         }
    125         $aNewsData['Content'] =  str_replace('src="/webedit/uploadfile/','src="http://www.njlrxx.com/webedit/uploadfile/',$aNewsData['Content']);
    126 
    127         $this->view_->assign('aNewsData', $aNewsData);
    128         $this->view_->assign('userID', $userID);
    129         $this->view_->display('news_view_iphone.tpl');
    130     }
    131 }
  • 相关阅读:
    5、打开界面
    C++模版完全解析
    运维二三事儿
    tcpdump命令使用方法
    putty源码阅读----plink
    nginx--提供一键安装脚本
    vt100控制符
    zabbix---简介
    Dictionary
    装箱、拆箱
  • 原文地址:https://www.cnblogs.com/ggkxg/p/6046714.html
Copyright © 2011-2022 走看看