PHP code example of klib / jk-laravel-feapi

1. Go to this page and download the library: Download klib/jk-laravel-feapi 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/ */

    

klib / jk-laravel-feapi example snippets




return [

    'apps' => [
        # 类名称 => 具体位置,CFEApiExample 是一个测试样例
        'example' => 'KLib\FEApiLaravel\CFEApiExample',
    ],

];


// API 程序入口,URL 中需要传入3个参数,分别是 pid【平台id】, ic【对应的API名称】, im 【对应的方法名称】
// for example: /api?ic=example&im=additive&fps[a]=5&fps[b]=6
Route::any('/api', function (Request $request, Application $app) {
    return CFEApiScheduler::GetResult($request, $app);
})->name('feapi');


Route::any('/man', function (Request $request, Application $app) {
    $feobj = CFEApiScheduler::CreateApi($request, $app);

    if($request->isMethod('post')) {
        // 如果有post 值,有可能是提交了手册的密码
        $inpwd = $request->input('verfiypassword');
        // 登录
        $feobj->signinVerifyPassword($inpwd);

    }

    return view('feapi::man', ['api_obj' => $feobj, 'api_routername'=>'feapi', 'api_routerparam' => [] ]);
})->name("feman");




namespace App;

use KLib\FEApiLaravel\AbsFEApiParamMan;
use KLib\FEApiLaravel\IHaveErr;

class CFEExamApi extends AbsFEApiParamMan implements IHaveErr
{

    /**
     * 进行API 定义
     * $this->createApi('apiname', 'refname', 'Describe.')->setParamDefine(['key1' => ['info1' => 'desc1', 'value1' => 'default value' ], 'key2' => ['info1' => 'desc1', 'value1' => null ] ]);
     * @return AbsFEApiParamMan
     */
    public function apiDefine()
    {
        $param_arr = [];
        $param_arr['a'] = ['info' => 'desc1', 'value' => 0 ];
        $param_arr['b'] = ['info' => 'desc2', 'value' => 0 ];

        $this->createApi('tryname', 'realname', '这只是一个测试用的API.')
            ->setLimitMethod(['GET', 'POST'])
            ->setParamDefine($param_arr);

    }

    /**
     * 设置文档登录的密码
     * @return string
    */
    public function getPasswordOfMan()
    {
        return 'abc123';
    }

    /**
     * 定义手册信息
     * @return AbsFEApiParamMan
    */
    public function manDefine() {
        parent::manDefine();
        $this->getApiDefineObj('tryname')->setSampleResult($this->realname([5,6]))->setResultdesc('这只是一个测试');
    }

    /**
     * 这是一个测试用的Api接口
     * @param $param_arr API参数数组
     * @return mixed
     */
    public function realname($param_arr) {
        return $param_arr;
    }
}