PHP code example of kuga / openapi-core

1. Go to this page and download the library: Download kuga/openapi-core library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kuga / openapi-core example snippets


namespace Kuga\Api\Test;
use Kuga\Core\Api\AbstractApi;
class TestApi extends AbstractApi{
    public function create(){
        //获得业务参数对象
        $data = $this->_toParamObject($this->getParams());
        $dataArray = $data->toArray();

        //accessToken或JWT解密后得到了用户ID
        $currentUserId = $this->_userMemberId;
        return [
            'list'=>[],
            'userId'=>$currentUserId,
            'total'=>10
        ];
    }
}

$apiKeys = [
    ['1000']=>['secret'=>'abc'],
    ['1001']=>['secret'=>'def']
];
$requestObject = new \Kuga\Core\Api\Request\JWTRequest($_POST);
$requestObject->setOrigRequest($_POST);
$requestObject->setMethod('acc.app.list');
$requestObject->setHeaders($headers);//request header 数组
$requestObject->setDI($this->getDI());  //di对象是Phalcon的di对象

\Kuga\Core\Api\ApiService::setDi($this->getDI());
\Kuga\Core\Api\ApiService::initApiKeys($apiKeys);
\Kuga\Core\Api\ApiService::initApiJsonConfigFile('路径/api.json');
$result = \Kuga\Core\Api\ApiService::response($requestObject);
echo json_encode($result);