App 接口入门 初识

你明白接口是什么, 就会写了.
函数和接口差不多
接口地址(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 调试
  1. 请求信息 : 2016-04-28 14:29:57 HTTP/1.1 GET : /purenfort/Api/index/index/name/admin/pwd/123456
  2. 运行时间 : 0.0170s ( Load:0.0086s Init:0.0009s Exec:0.0076s Template:-0.0000s )
  3. 吞吐率 : 58.82req/s
  4. 内存开销 : 2,965.76 kb
  5. 查询信息 : 2 queries 0 writes
  6. 文件加载 : 28
  7. 缓存信息 : 0 gets 0 writes
  8. 配置加载 : 152
  9. 会话信息 : SESSION_ID=tcvnuj7p79stp26lcqlpqvnrb1
  1. /var/www/html/purenfort/index.php ( 0.35 KB )
  2. /var/www/html/purenfort/ThinkPHP/ThinkPHP.php ( 4.63 KB )
  3. /var/www/html/purenfort/ThinkPHP/Library/Think/Think.class.php ( 12.31 KB )
  4. /var/www/html/purenfort/ThinkPHP/Library/Think/Storage.class.php ( 1.38 KB )
  5. /var/www/html/purenfort/ThinkPHP/Library/Think/Storage/Driver/File.class.php ( 3.54 KB )
  6. /var/www/html/purenfort/ThinkPHP/Mode/common.php ( 2.82 KB )
  7. /var/www/html/purenfort/ThinkPHP/Common/functions.php ( 47.80 KB )
  8. /var/www/html/purenfort/App/Common/Common/function.php ( 23.22 KB )
  9. /var/www/html/purenfort/ThinkPHP/Library/Think/Hook.class.php ( 4.02 KB )
  10. /var/www/html/purenfort/ThinkPHP/Library/Think/App.class.php ( 13.21 KB )
  11. /var/www/html/purenfort/ThinkPHP/Library/Think/Dispatcher.class.php ( 14.78 KB )
  12. /var/www/html/purenfort/ThinkPHP/Library/Think/Route.class.php ( 13.37 KB )
  13. /var/www/html/purenfort/ThinkPHP/Library/Think/Controller.class.php ( 10.84 KB )
  14. /var/www/html/purenfort/ThinkPHP/Library/Think/View.class.php ( 7.31 KB )
  15. /var/www/html/purenfort/ThinkPHP/Library/Behavior/BuildLiteBehavior.class.php ( 3.69 KB )
  16. /var/www/html/purenfort/ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php ( 3.89 KB )
  17. /var/www/html/purenfort/ThinkPHP/Library/Behavior/ContentReplaceBehavior.class.php ( 1.91 KB )
  18. /var/www/html/purenfort/ThinkPHP/Conf/convention.php ( 11.25 KB )
  19. /var/www/html/purenfort/App/Common/Conf/config.php ( 2.61 KB )
  20. /var/www/html/purenfort/ThinkPHP/Lang/zh-cn.php ( 2.56 KB )
  21. /var/www/html/purenfort/ThinkPHP/Conf/debug.php ( 1.50 KB )
  22. /var/www/html/purenfort/App/Api/Conf/config.php ( 0.05 KB )
  23. /var/www/html/purenfort/ThinkPHP/Library/Behavior/ReadHtmlCacheBehavior.class.php ( 5.60 KB )
  24. /var/www/html/purenfort/App/Api/Controller/IndexController.class.php ( 0.67 KB )
  25. /var/www/html/purenfort/ThinkPHP/Library/Think/Model.class.php ( 59.43 KB )
  26. /var/www/html/purenfort/ThinkPHP/Library/Think/Db.class.php ( 32.66 KB )
  27. /var/www/html/purenfort/ThinkPHP/Library/Think/Db/Driver/Mysql.class.php ( 10.78 KB )
  28. /var/www/html/purenfort/ThinkPHP/Library/Behavior/ShowPageTraceBehavior.class.php ( 5.25 KB )
  1. [ app_init ] --START--
  2. Run Behavior\BuildLiteBehavior [ RunTime:0.000012s ]
  3. [ app_init ] --END-- [ RunTime:0.000064s ]
  4. [ app_begin ] --START--
  5. Run Behavior\ReadHtmlCacheBehavior [ RunTime:0.000322s ]
  6. [ app_begin ] --END-- [ RunTime:0.000374s ]
  7. [ app_end ] --START--
    1. SHOW COLUMNS FROM `purenfort_user` [ RunTime:0.000553s ]
    2. SELECT * FROM `purenfort_user` WHERE ( `name` = 'admin' ) AND ( `pwd` = 'e10adc3949ba59abbe56e057f20f883e' ) [ RunTime:0.000226s ]

      评论
      添加红包

      请填写红包祝福语或标题

      红包个数最小为10个

      红包金额最低5元

      当前余额3.43前往充值 >
      需支付:10.00
      成就一亿技术人!
      领取后你会自动成为博主和红包主的粉丝 规则
      hope_wisdom
      发出的红包
      实付
      使用余额支付
      点击重新获取
      扫码支付
      钱包余额 0

      抵扣说明:

      1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
      2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

      余额充值