added 提供接口路由默认生成

This commit is contained in:
zhaoxiang 2018-02-27 22:16:13 +08:00
parent 275a36ef21
commit 7a6706ec3c
6 changed files with 36 additions and 22 deletions

View File

@ -134,4 +134,25 @@ class InterfaceList extends Base {
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([]);
}
}

View File

@ -115,6 +115,10 @@ return [
'admin/InterfaceList/index',
['method' => 'get', 'after_behavior' => $afterBehavior]
],
'InterfaceList/refresh' => [
'admin/InterfaceList/refresh',
['method' => 'get', 'after_behavior' => $afterBehavior]
],
'InterfaceList/changeStatus' => [
'admin/InterfaceList/changeStatus',
['method' => 'get', 'after_behavior' => $afterBehavior]

View File

@ -7,6 +7,6 @@ use app\util\ReturnCode;
class Miss extends Base {
public function index() {
return $this->buildFailed(ReturnCode::NOT_EXISTS, '接口Hash异常:'.uniqid());
return $this->buildFailed(ReturnCode::NOT_EXISTS, '接口Hash异常');
}
}

View File

@ -93,7 +93,7 @@ return [
// 路由使用完整匹配
'route_complete_match' => false,
// 路由配置文件(支持配置多个)
'route_config_file' => ['adminRoute', 'apiRoute'],
'route_config_file' => ['adminRoute', 'apiRoute', 'wikiRoute'],
// 是否强制使用路由
'url_route_must' => true,
// 域名部署

View File

@ -1,28 +1,9 @@
<?php
/**
* Api路由
* wiki路由
*/
\think\Route::miss('api/Index/index');
$afterBehavior = ['\app\api\behavior\ApiAuth', '\app\api\behavior\ApiPermission', '\app\api\behavior\RequestFilter'];
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]' => [
'login' => [
'wiki/index/login',

8
data/apiRoute.tpl Normal file
View 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'];