Home >Backend Development >PHP Problem >What does PHP use to develop app interfaces?

What does PHP use to develop app interfaces?

(*-*)浩
(*-*)浩Original
2019-10-17 13:26:383040browse

You can use the REST mode to develop the App interface. First create a public controller, and then build other controllers to inherit it.

What does PHP use to develop app interfaces?

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[&#39;code&#39;] = &#39;404&#39;;
            $data[&#39;msg&#39;] = &#39;apptoken无效&#39;;
            $data[&#39;data&#39;] = null;
            $this -> response($data, &#39;json&#39;);
            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(&#39;post.apptoken&#39;);
        parent::checkAppToken($apptoken);
        
        // 验证 用户 token
        $usertoken = I(&#39;post.usertoken&#39;);
        parent::checkUserToken($usertoken);
        
        // 各种需要验证的验证 ……
        
    }
    
    // 各种业务方法
    public function index(){
        // 返回数据
        $this -> response($data, &#39;json&#39;);
        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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn