You can use the REST mode to develop the App interface. First create a public controller, and then build other controllers to inherit it.
Determine the format and information code of the returned data content; (Recommended learning: PHP video tutorial)
<?php // App接口公共控制器 AppController namespace Api\Controller; use Think\Controller\RestController; class AppController extends RestController { // 自动加载的东西 function _initialize() { } // 验证 客户端 token protected function checkAppToken($apptoken){ // 引入 function.php 中定义的检测 apptoken 的函数 if(checkingAppToken($apptoken)){ return true; }else{ $data['code'] = '404'; $data['msg'] = 'apptoken无效'; $data['data'] = null; $this -> response($data, 'json'); exit(); } } // 验证 用户 token protected function checkUserToken($usertoken){ } // 各种验证 …… } ?>
Other interface controllers inherit AppController
<?php // 内容控制器 ContentsController namespace Api\Controller; class ContentsController extends AppController { // 自动加载验证 function _initialize() { parent::_initialize(); // 验证 客户端 token $apptoken = I('post.apptoken'); parent::checkAppToken($apptoken); // 验证 用户 token $usertoken = I('post.usertoken'); parent::checkUserToken($usertoken); // 各种需要验证的验证 …… } // 各种业务方法 public function index(){ // 返回数据 $this -> response($data, 'json'); exit(); } } ?>
The above is the detailed content of What does PHP use to develop app interfaces?. For more information, please follow other related articles on the PHP Chinese website!