开发者社区> 桃子红了呐> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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 '请求代码错误!!';
        }
    }

}
复制代码

处理

复制代码
<?php
class Api_NewsController extends actions_api {
    public $doMain = 'http://testserver.njlrxx.com/';


    //接口中可以直接操作sql语句进行一些处理
    function init() {
        parent::init();
        $this->setView('api');
        $this->dao_newsrecord = new dao_newsrecord();
        $this->dao_module = new dao_module();
        $this->dao_message = new dao_message();
        $this->dao_user = new dao_user();
        $this->dao_news = new dao_news();
        $this->inData = $this->_getParam('data',false);//请求参数
        $this->reqCode = $this->_getParam('reqCode',false);
        $this->outData = array('status'=>0,'msg'=>'','data'=>array(),'reqCode'=>$this->reqCode);//输出参数
    }
    

    //新闻分类
    function newstypeAction()
    {
        $where['BigClass.typeid = ?'] = array("type"=>1,"val"=>60);
        $aBigClass = $this->dao_news->getBigClass($where, 'BigClassID ASC', 3);
        if(COUNT($aBigClass) == 0)
        {
            $this->outData['msg'] = '暂无数据';
            $this->printOut();
        }
        $this->outData['status'] = 1;
        $this->outData['msg'] = '获取成功';
        $this->outData['data'] = $aBigClass;
        $this->printOut();
    }


    //图片新闻前五条
    function newstop5Action(){
        $where['News.picnews = ?'] = array("type"=>1,"val"=>1);
        $aNewsData = $this->dao_news->getNews2($where, 'NewsID DESC', 5, FALSE , false, array('NewsID','picname','Title'));
        foreach($aNewsData as &$val)
        {
            $val['webview_url'] = $this->doMain.'api/news/newsview/NewsID/'.$val['NewsID'].'/user_id/'.$this->inData['user_id'];
        }
        if(COUNT($aNewsData) == 0)
        {
            $this->outData['msg'] = '暂无数据';
            $this->printOut();
        }
        $this->outData['status'] = 1;
        $this->outData['msg'] = '获取成功';
        $this->outData['data'] = $aNewsData;
        $this->printOut();
    }

    function newslistAction(){
        $nowPage = !empty($this->inData['nowpage'])?$this->inData['nowpage']:1;    //$this->_getParam('nowpage',1);
        $pageNum = !empty($this->inData['pageNum'])?$this->inData['pageNum']:10;    //$this->_getParam('pageNum',10);
        $bigclassid = !empty($this->inData['bigclassid'])?$this->inData['bigclassid']:false;    
         if(!$bigclassid)
        {
            $this->outData['msg'] = '缺少分类参数';
            $this->printOut();
        }
        $offset = ($nowPage - 1)*$pageNum;
        $where['News.bigclassid = ?'] = array("type"=>1,"val"=>$bigclassid);
        $total = $this->dao_news->getNews2($where, '', false, false , true);
        $aNewsData = $this->dao_news->getNews2($where, 'NewsID DESC', $pageNum, $offset , false, array('NewsID','Title','UpdateTime','convert(text,Content) as Content'));

        foreach($aNewsData as &$val)
        {
            $val['webview_url'] = $this->doMain.'api/news/newsview/NewsID/'.$val['NewsID'].'/user_id/'.$this->inData['user_id'];
            $val['Content'] = $this->substring($this->clearhtml($val["Content"]),16);
        }
        if($total == 0)
        {
            $this->outData['msg'] = '暂无数据';
            $this->printOut();
        }
        $this->outData['next'] = 0;
        if($total > ($nowPage * $pageNum))
        {
            $this->outData['next'] = 1;
        }
        $this->outData['status'] = 1;
        $this->outData['msg'] = '获取成功';
        $this->outData['data'] = $aNewsData;

        $this->printOut();
    }

    function newsviewAction(){
        $newsID = $this->_getParam("NewsID",0);//新闻id
        $userID = $this->_getParam("user_id");//uid

        //$whereUser['lx_user.id = ?'] = array("type"=>1,"val"=>$user_id);
        //$aUser = $this->dao_user->getUser($whereUser);
    
        $whereNews['News.NewsID = ?'] = array("type"=>1,"val"=>$newsID);
        $aNews = $this->dao_news->getNews($whereNews);

        $aNewsData = $aNews ? $aNews[0] : false;
        if(!$aNewsData && $aNewsData['checkked'] == 1 && $userID)//是否审核
        {
            $this->dao_news->updateNews(array('click'=>'`click`+1','NewsID'=>$newsID));//更新新闻点击次数
             //阅读人记录到数据库中
            $aNewsrecord = array();
            $aNewsrecord['news_id'] = $NewsID;
            $aNewsrecord['user_id'] = $userID;
            $aNewsrecord['user_name'] = !is_null($aUser[0]["name"]) ? $aUser[0]["name"] : $aUser[0]["surname"].$aUser[0]["givenname"];
            $aNewsrecord['user_avatar'] = $aUser[0]["avatar"];
            $aNewsrecord['time'] = time();
            $whereNewsrecord = array();
            $whereNewsrecord['lx_newsrecord.news_id = ?'] = array("type"=>1,"val"=>$NewsID);
            $whereNewsrecord['lx_newsrecord.user_id = ?'] = array("type"=>1,"val"=>$userID);
            $result = $this->dao_newsrecord->getNewsrecord($whereNewsrecord);
            if($result){
                $aNewsrecord['id'] = $result[0]['id'];
                $this->dao_newsrecord->updateNewsrecord($aNewsrecord);
            }else{
                $this->dao_newsrecord->addNewsrecord($aNewsrecord);
            }
        }
        $aNewsData['Content'] =  str_replace('src="/webedit/uploadfile/','src="http://www.njlrxx.com/webedit/uploadfile/',$aNewsData['Content']);

        $this->view_->assign('aNewsData', $aNewsData);
        $this->view_->assign('userID', $userID);
        $this->view_->display('news_view_iphone.tpl');
    }
}



版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
PHP开发API接口签名生成及验证
PHP开发API接口签名生成及验证
0 0
php接口安全设计浅谈
php接口安全设计浅谈
0 0
ecshop | php接入支付宝申报海关接口的总结【避坑】
ecshop | php接入支付宝申报海关接口的总结【避坑】
0 0
PHP:APP接口开发
PHP:APP接口开发
0 0
新浪短网址接口源码,并使用PHP模拟登陆来自动更新
新浪短网址接口源码,并使用PHP模拟登陆来自动更新
0 0
PHP 调用第三方API接口 、带参数跳转PHP
PHP 调用第三方API接口 、带参数跳转PHP
0 0
【PHP面向对象】接口跟抽象类的区别和各自的用法
【PHP面向对象】接口跟抽象类的区别和各自的用法
0 0
PHP快递查询API接口,有需要的可直接用
PHP快递查询API接口,有需要的可直接用
0 0
grape动态PHP结构(三)——API接口
这里的v1、v2就是模块,由于客户端版本一直在迭代的,那么一些老版本的客户端调用的接口就得保留起来,使得兼容。新版本就直接调用新接口。
0 0
PHP API接口测试小工具
前端时间给手机客户端做接口,当时弱爆了,写完API接口后,也不怎么测试,最后是等客户端调用的时候检验API的正确性。
0 0
文章
问答
文章排行榜
最热
最新
相关电子书
更多
PHP安全开发_从白帽角度做安全
立即下载
PHP在机器学习上的应用及云深度学习平台的架构设计与实现
立即下载
PHP与APM_技术内幕和最佳实践
立即下载