mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
modified 移植wiki接口
This commit is contained in:
parent
5bce5133e6
commit
6a8030c5ff
59
application/wiki/controller/Api.php
Normal file
59
application/wiki/controller/Api.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
* @since 2019-08-11
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace app\wiki\controller;
|
||||
|
||||
|
||||
use app\util\ReturnCode;
|
||||
|
||||
class Api extends Base {
|
||||
|
||||
public function errorCode() {
|
||||
$codeArr = ReturnCode::getConstants();
|
||||
$codeArr = array_flip($codeArr);
|
||||
$result = [];
|
||||
$errorInfo = [
|
||||
ReturnCode::SUCCESS => '请求成功',
|
||||
ReturnCode::INVALID => '非法操作',
|
||||
ReturnCode::DB_SAVE_ERROR => '数据存储失败',
|
||||
ReturnCode::DB_READ_ERROR => '数据读取失败',
|
||||
ReturnCode::CACHE_SAVE_ERROR => '缓存存储失败',
|
||||
ReturnCode::CACHE_READ_ERROR => '缓存读取失败',
|
||||
ReturnCode::FILE_SAVE_ERROR => '文件读取失败',
|
||||
ReturnCode::LOGIN_ERROR => '登录失败',
|
||||
ReturnCode::NOT_EXISTS => '不存在',
|
||||
ReturnCode::JSON_PARSE_FAIL => 'JSON数据格式错误',
|
||||
ReturnCode::TYPE_ERROR => '类型错误',
|
||||
ReturnCode::NUMBER_MATCH_ERROR => '数字匹配失败',
|
||||
ReturnCode::EMPTY_PARAMS => '丢失必要数据',
|
||||
ReturnCode::DATA_EXISTS => '数据已经存在',
|
||||
ReturnCode::AUTH_ERROR => '权限认证失败',
|
||||
ReturnCode::OTHER_LOGIN => '别的终端登录',
|
||||
ReturnCode::VERSION_INVALID => 'API版本非法',
|
||||
ReturnCode::CURL_ERROR => 'CURL操作异常',
|
||||
ReturnCode::RECORD_NOT_FOUND => '记录未找到',
|
||||
ReturnCode::DELETE_FAILED => '删除失败',
|
||||
ReturnCode::ADD_FAILED => '添加记录失败',
|
||||
ReturnCode::UPDATE_FAILED => '更新记录失败',
|
||||
ReturnCode::PARAM_INVALID => '数据类型非法',
|
||||
ReturnCode::ACCESS_TOKEN_TIMEOUT => '身份令牌过期',
|
||||
ReturnCode::SESSION_TIMEOUT => 'SESSION过期',
|
||||
ReturnCode::UNKNOWN => '未知错误',
|
||||
ReturnCode::EXCEPTION => '系统异常',
|
||||
];
|
||||
|
||||
foreach ($errorInfo as $key => $value) {
|
||||
$result[] = [
|
||||
'en_code' => $codeArr[$key],
|
||||
'code' => $key,
|
||||
'chinese' => $value,
|
||||
];
|
||||
}
|
||||
|
||||
return $this->buildSuccess($result);
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@
|
||||
namespace app\wiki\controller;
|
||||
|
||||
|
||||
use app\util\ReturnCode;
|
||||
use think\facade\Config;
|
||||
use think\Controller;
|
||||
use think\exception\HttpResponseException;
|
||||
@ -29,6 +30,26 @@ class Base extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function buildSuccess($data, $msg = '操作成功', $code = ReturnCode::SUCCESS) {
|
||||
$return = [
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return json($return);
|
||||
}
|
||||
|
||||
public function buildFailed($code, $msg, $data = []) {
|
||||
$return = [
|
||||
'code' => $code,
|
||||
'msg' => $msg,
|
||||
'data' => $data
|
||||
];
|
||||
|
||||
return json($return);
|
||||
}
|
||||
|
||||
public function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []) {
|
||||
if (is_null($url)) {
|
||||
$url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
|
||||
|
@ -1,38 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* wiki路由
|
||||
* Wiki路由
|
||||
* @since 2019-08-12
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
return [
|
||||
'[wiki]' => [
|
||||
'login' => [
|
||||
'wiki/index/login',
|
||||
['method' => 'get']
|
||||
],
|
||||
'doLogin' => [
|
||||
'wiki/index/doLogin',
|
||||
['method' => 'post']
|
||||
],
|
||||
'index' => [
|
||||
'wiki/index/index',
|
||||
['method' => 'get']
|
||||
],
|
||||
'calculation' => [
|
||||
'wiki/index/calculation',
|
||||
['method' => 'get']
|
||||
],
|
||||
'errorCode' => [
|
||||
'wiki/index/errorCode',
|
||||
['method' => 'get']
|
||||
],
|
||||
'detail/:groupHash/[:hash]' => [
|
||||
'wiki/index/detail',
|
||||
['method' => 'get']
|
||||
],
|
||||
'logout' => [
|
||||
'wiki/index/logout',
|
||||
['method' => 'get']
|
||||
],
|
||||
'__miss__' => ['wiki/index/index'],
|
||||
],
|
||||
];
|
||||
use think\facade\Route;
|
||||
|
||||
Route::group('wiki', function() {
|
||||
Route::rule(
|
||||
'Api/errorCode', 'wiki/Api/errorCode', 'get'
|
||||
);
|
||||
|
||||
//MISS路由定义
|
||||
Route::miss('admin/Miss/index');
|
||||
})->middleware('AdminResponse');
|
||||
|
Loading…
x
Reference in New Issue
Block a user