:::

9-1-1 建立專屬的 API 類別

您沒有觀看影片的權限

您沒有觀看影片的權限

請先登入,登入後,確認您的權限後,即可觀看影片。

  1. API 類的範本如下:
    <?php
    namespace XoopsModules\首字大寫模組目錄;
    
    use XoopsModules\Tadtools\SimpleRest;
    use XoopsModules\Tadtools\Utility;
    
    require dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
    
    class 首字大寫模組目錄_api extends SimpleRest
    {
        public $uid = '';
        public $user = [];
        public $groups = [];
        private $token = '';
    
        public function __construct($token = '')
        {
            $this->token = $token;
            if (!isset($_SESSION['api_mode'])) {
                $_SESSION['api_mode'] = true;
            }
    
            if ($this->token) {
                $User = $this->getXoopsSUser($this->token);
                $this->uid = (int) $User['uid'];
                $this->groups = $User['groups'];
                $this->user = $User['user'];
    
                //判斷是否對該模組有管理權限 $_SESSION['模組目錄_adm']
                if (!isset($this->user['模組目錄_adm'])) {
                    $this->user['模組目錄_adm'] = $_SESSION['模組目錄_adm'] = ($this->uid) ? $this->isAdmin('模組目錄') : false;
                }
    
                // 判斷有無XXX的權限
                // if (!isset($this->user['權限名'])) {
                //     $_SESSION['權限名'] = $this->user['權限名'] = $this->powerChk('模組目錄', 權限編號);
                // }
    
            }
        }
    
        // 傳回目前使用者資訊
        public function user()
        {
            $data = ['uid' => (int) $this->uid, 'groups' => $this->groups, 'user' => $this->user];
            return $this->encodeJson($data);
        }
    
        // 轉成 json
        private function encodeJson($responseData)
        {
            if (empty($responseData)) {
                $statusCode = 404;
                $responseData = array('error' => '無資料');
            } else {
                $statusCode = 200;
            }
            $this->setHttpHeaders($statusCode);
    
            $jsonResponse = json_encode($responseData, 256);
            return $jsonResponse;
        }
    
    }
    

     

  2. 先建立 class\Tad_signup_api.php 並根據範本進行修改
    <?php
    namespace XoopsModules\Tad_signup;
    
    use XoopsModules\Tadtools\SimpleRest;
    use XoopsModules\Tadtools\Utility;
    
    require dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
    
    class Tad_signup_api extends SimpleRest
    {
        public $uid = '';
        public $user = [];
        public $groups = [];
        private $token = '';
    
        public function __construct($token = '')
        {
            $this->token = $token;
            if (!isset($_SESSION['api_mode'])) {
                $_SESSION['api_mode'] = true;
            }
    
            if ($this->token) {
                $User = $this->getXoopsSUser($this->token);
                $this->uid = (int) $User['uid'];
                $this->groups = $User['groups'];
                $this->user = $User['user'];
    
                //判斷是否對該模組有管理權限 $_SESSION['tad_signup_adm']
                if (!isset($this->user['tad_signup_adm'])) {
                    $this->user['tad_signup_adm'] = $_SESSION['tad_signup_adm'] = ($this->uid) ? $this->isAdmin('tad_signup') : false;
                }
    
                // 判斷有無開設活動的權限
                if (!isset($this->user['can_add'])) {
                    $this->user['can_add'] = $_SESSION['can_add'] = $this->powerChk('tad_signup', 1);
                }
    
            }
        }
    
        // 傳回目前使用者資訊
        public function user()
        {
            $data = ['uid' => (int) $this->uid, 'groups' => $this->groups, 'user' => $this->user];
            return $this->encodeJson($data);
        }
    
        // 轉成 json
        private function encodeJson($responseData)
        {
            if (empty($responseData)) {
                $statusCode = 404;
                $responseData = array('error' => '無資料');
            } else {
                $statusCode = 200;
            }
            $this->setHttpHeaders($statusCode);
    
            $jsonResponse = json_encode($responseData, 256);
            return $jsonResponse;
        }
    }
    

     

link to https://github.com/tadlearn/tad_signup/commit/2303d31793e16626afb2b9e62701d624eac08758 \


:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D1760%26tbsn%3D48

書籍目錄

展開 | 闔起

線上使用者

53人線上 (12人在瀏覽線上書籍)

會員: 0

訪客: 53

更多…