您的位置:首页 > 移动开发

App 接口入门 初识

2016-04-28 16:51 435 查看
你明白接口是什么, 就会写了.

函数和接口差不多

接口地址(url) ==== 函数名

GET或POST数据 ==== 函数的参数

这个接口输出的数据 ===== 函数的返回值

这三个你可以自定义, 也可以和开发APP的人商量着来定义

首先 app通过url 请求数据可以通过post和get来实现,服务器经过处理后返回json数据即可完成了要求。
http://192.168.1.240/purenfort/Api/index/index/name/admin/pwd/123456 url get 发送name 和pwd

页面显示数据:

{"result":"success","info":[{"id":"1","name":"admin","user_name":"\u8d85\u7ba1","pwd":"e10adc3949ba59abbe56e057f20f883e","email":"","mobile":"","address":"","img":"\/Uploads\/2016\/01\/27\/230_2016012756a8dc83e70c85891.jpg","remark":"","create_time":"0","last_login_time":"1461814955","loginip":"192.168.1.34","status":"1","type":"0","sign":null}]}

执行代码为:

 if(IS_GET){

            

            $name=$_GET['name'];

            $password=$_GET['pwd'];

            $map['name']=$name;

            $map['pwd']=md5($password);

            $user=D('user')->where($map)->select();

            if($user!=null){

            $data['result']="success";

            $data['info']=$user;

        }else{

         $data['result']="failed";

            $data['code']=1;

        }            

            print_r(json_encode( $data));

     }
执行失败或者成功都要返回相应的result结果,如果失败则要返回code说明失败原因。info则是相关数据。
安全性考虑,由于接口实际上是url,访问时肯定要进行身份识别,所以后续的话,肯定会进行权限的限定。

基本

文件
流程
错误
SQL
调试

请求信息 : 2016-04-28 14:29:57 HTTP/1.1 GET : /purenfort/Api/index/index/name/admin/pwd/123456
运行时间 : 0.0170s ( Load:0.0086s Init:0.0009s Exec:0.0076s Template:-0.0000s )
吞吐率 : 58.82req/s
内存开销 : 2,965.76 kb
查询信息 : 2 queries 0 writes

文件加载 : 28
缓存信息 : 0 gets 0 writes

配置加载 : 152
会话信息 : SESSION_ID=tcvnuj7p79stp26lcqlpqvnrb1

/var/www/html/purenfort/index.php ( 0.35 KB )
/var/www/html/purenfort/ThinkPHP/ThinkPHP.php ( 4.63 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Think.class.php ( 12.31 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Storage.class.php ( 1.38 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.54 KB )
/var/www/html/purenfort/ThinkPHP/Mode/common.php ( 2.82 KB )
/var/www/html/purenfort/ThinkPHP/Common/functions.php ( 47.80 KB )
/var/www/html/purenfort/App/Common/Common/function.php ( 23.22 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Hook.class.php ( 4.02 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/App.class.php ( 13.21 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.78 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Route.class.php ( 13.37 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Controller.class.php ( 10.84 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/View.class.php ( 7.31 KB )
/var/www/html/purenfort/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.69 KB )
/var/www/html/purenfort/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.89 KB )
/var/www/html/purenfort/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB )
/var/www/html/purenfort/ThinkPHP/Conf/convention.php ( 11.25 KB )
/var/www/html/purenfort/App/Common/Conf/config.php ( 2.61 KB )
/var/www/html/purenfort/ThinkPHP/Lang/zh-cn.php ( 2.56 KB )
/var/www/html/purenfort/ThinkPHP/Conf/debug.php ( 1.50 KB )
/var/www/html/purenfort/App/Api/Conf/config.php ( 0.05 KB )
/var/www/html/purenfort/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.60 KB )
/var/www/html/purenfort/App/Api/Controller/IndexController.class.php ( 0.67 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Model.class.php ( 59.43 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Db.class.php ( 32.66 KB )
/var/www/html/purenfort/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php ( 10.78 KB )
/var/www/html/purenfort/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.25 KB )

[ app_init ] --START--
Run Behavior\BuildLiteBehavior [ RunTime:0.000012s ]
[ app_init ] --END-- [ RunTime:0.000064s ]
[ app_begin ] --START--
Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000322s ]
[ app_begin ] --END-- [ RunTime:0.000374s ]
[ app_end ] --START--

SHOW COLUMNS FROM `purenfort_user` [ RunTime:0.000553s ]
SELECT * FROM `purenfort_user` WHERE ( `name` = 'admin' ) AND ( `pwd` = 'e10adc3949ba59abbe56e057f20f883e' ) [ RunTime:0.000226s ]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: