mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 提供接口路由默认生成
This commit is contained in:
parent
275a36ef21
commit
7a6706ec3c
@ -134,4 +134,25 @@ class InterfaceList extends Base {
|
|||||||
|
|
||||||
return $this->buildSuccess([]);
|
return $this->buildSuccess([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新接口路由
|
||||||
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||||
|
* @return array
|
||||||
|
* @throws \think\exception\DbException
|
||||||
|
*/
|
||||||
|
public function refresh() {
|
||||||
|
$apiRoutePath = ROOT_PATH . 'application/apiRoute.php';
|
||||||
|
$tplPath = ROOT_PATH . 'data/apiRoute.tpl';
|
||||||
|
$methodArr = ['*','POST','GET'];
|
||||||
|
|
||||||
|
$tplStr = file_get_contents($tplPath);
|
||||||
|
$listInfo = ApiList::all(['status' => 1]);
|
||||||
|
foreach ($listInfo as $value) {
|
||||||
|
$tplStr .= 'Route::rule(\'api/'.$value->hash.'\',\'api/'.$value->apiClass.'\', \''.$methodArr[$value->method].'\', [\'after_behavior\' => $afterBehavior]);';
|
||||||
|
}
|
||||||
|
|
||||||
|
file_put_contents($apiRoutePath, $tplStr);
|
||||||
|
return $this->buildSuccess([]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,10 @@ return [
|
|||||||
'admin/InterfaceList/index',
|
'admin/InterfaceList/index',
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
],
|
],
|
||||||
|
'InterfaceList/refresh' => [
|
||||||
|
'admin/InterfaceList/refresh',
|
||||||
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
],
|
||||||
'InterfaceList/changeStatus' => [
|
'InterfaceList/changeStatus' => [
|
||||||
'admin/InterfaceList/changeStatus',
|
'admin/InterfaceList/changeStatus',
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
['method' => 'get', 'after_behavior' => $afterBehavior]
|
||||||
|
@ -7,6 +7,6 @@ use app\util\ReturnCode;
|
|||||||
|
|
||||||
class Miss extends Base {
|
class Miss extends Base {
|
||||||
public function index() {
|
public function index() {
|
||||||
return $this->buildFailed(ReturnCode::NOT_EXISTS, '接口Hash异常:'.uniqid());
|
return $this->buildFailed(ReturnCode::NOT_EXISTS, '接口Hash异常');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ return [
|
|||||||
// 路由使用完整匹配
|
// 路由使用完整匹配
|
||||||
'route_complete_match' => false,
|
'route_complete_match' => false,
|
||||||
// 路由配置文件(支持配置多个)
|
// 路由配置文件(支持配置多个)
|
||||||
'route_config_file' => ['adminRoute', 'apiRoute'],
|
'route_config_file' => ['adminRoute', 'apiRoute', 'wikiRoute'],
|
||||||
// 是否强制使用路由
|
// 是否强制使用路由
|
||||||
'url_route_must' => true,
|
'url_route_must' => true,
|
||||||
// 域名部署
|
// 域名部署
|
||||||
|
@ -1,28 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* Api路由
|
* wiki路由
|
||||||
*/
|
*/
|
||||||
|
|
||||||
\think\Route::miss('api/Index/index');
|
|
||||||
|
|
||||||
$afterBehavior = ['\app\api\behavior\ApiAuth', '\app\api\behavior\ApiPermission', '\app\api\behavior\RequestFilter'];
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'[api]' => [
|
|
||||||
'5a9363c133719' => [
|
|
||||||
'api/BuildToken/getAccessToken',
|
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
|
||||||
],
|
|
||||||
'5a93646b40ab5' => [
|
|
||||||
'api/BuildToken/e1',
|
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
|
||||||
],
|
|
||||||
'5a93648c769f8' => [
|
|
||||||
'api/BuildToken/e2',
|
|
||||||
['method' => 'get', 'after_behavior' => $afterBehavior]
|
|
||||||
],
|
|
||||||
'__miss__' => ['api/Miss/index'],
|
|
||||||
],
|
|
||||||
'[wiki]' => [
|
'[wiki]' => [
|
||||||
'login' => [
|
'login' => [
|
||||||
'wiki/index/login',
|
'wiki/index/login',
|
8
data/apiRoute.tpl
Normal file
8
data/apiRoute.tpl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Api路由
|
||||||
|
*/
|
||||||
|
use think\Route;
|
||||||
|
|
||||||
|
Route::miss('api/Index/index');
|
||||||
|
$afterBehavior = ['\app\api\behavior\ApiAuth', '\app\api\behavior\ApiPermission', '\app\api\behavior\RequestFilter'];
|
Loading…
x
Reference in New Issue
Block a user