mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-06 03:58:00 +08:00
added 完成Api文档授权查看
This commit is contained in:
parent
509bde90b1
commit
79635f5308
108
Application/Admin/Controller/DocumentController.class.php
Normal file
108
Application/Admin/Controller/DocumentController.class.php
Normal file
@ -0,0 +1,108 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @since 2017/06/23 创建
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Admin\Controller;
|
||||
|
||||
|
||||
class DocumentController extends BaseController {
|
||||
public function index() {
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function ajaxGetIndex() {
|
||||
$postData = I('post.');
|
||||
$start = $postData['start'] ? $postData['start'] : 0;
|
||||
$limit = $postData['length'] ? $postData['length'] : 20;
|
||||
$draw = $postData['draw'];
|
||||
$total = D('ApiDocument')->count();
|
||||
$info = D('ApiDocument')->limit($start, $limit)->select();
|
||||
$data = array(
|
||||
'draw' => $draw,
|
||||
'recordsTotal' => $total,
|
||||
'recordsFiltered' => $total,
|
||||
'data' => $info
|
||||
);
|
||||
$this->ajaxReturn($data, 'json');
|
||||
}
|
||||
|
||||
public function add() {
|
||||
if (IS_POST) {
|
||||
$data['createTime'] = NOW_TIME;
|
||||
$data['endTime'] = I('post.keep') * 3600 + NOW_TIME;
|
||||
$data['key'] = I('post.key');
|
||||
D('ApiDocument')->add($data);
|
||||
$this->ajaxSuccess('添加成功');
|
||||
} else {
|
||||
$key = md5(microtime());
|
||||
$this->assign('key', $key);
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function open() {
|
||||
$key = I('post.key');
|
||||
$res = D('ApiDocument')->where(array('key' => $key))->save(array('status' => 1));
|
||||
if ($res === false) {
|
||||
$this->ajaxError('操作失败');
|
||||
} else {
|
||||
S($key, null);
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 禁用
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function close() {
|
||||
$key = I('post.key');
|
||||
$res = D('ApiDocument')->where(array('key' => $key))->save(array('status' => 0));
|
||||
if ($res === false) {
|
||||
$this->ajaxError('操作失败');
|
||||
} else {
|
||||
S($key, null);
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function del() {
|
||||
$key = I('post.key');
|
||||
$res = D('ApiDocument')->where(array('key' => $key))->delete();
|
||||
if ($res === false) {
|
||||
$this->ajaxError('操作失败');
|
||||
} else {
|
||||
S($key, null);
|
||||
$this->ajaxSuccess('操作成功');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Key延时
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
public function addTime() {
|
||||
if (IS_POST) {
|
||||
$addTime = I('post.keep') * 3600;
|
||||
$key = I('post.key');
|
||||
S($key, null);
|
||||
D('ApiDocument')->where(array('key' => $key))->save(array('endTime' => array('exp', 'endTime+' . $addTime)));
|
||||
$this->ajaxSuccess('修改成功');
|
||||
} else {
|
||||
$key = I('get.key');
|
||||
$this->assign('key', $key);
|
||||
$this->display();
|
||||
}
|
||||
}
|
||||
}
|
13
Application/Admin/Model/ApiDocumentModel.class.php
Normal file
13
Application/Admin/Model/ApiDocumentModel.class.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @since 2017/06/26 创建
|
||||
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
||||
*/
|
||||
|
||||
namespace Admin\Model;
|
||||
|
||||
|
||||
class ApiDocumentModel extends BaseModel {
|
||||
|
||||
}
|
57
Application/Admin/View/Document/add.html
Normal file
57
Application/Admin/View/Document/add.html
Normal file
@ -0,0 +1,57 @@
|
||||
add.html<extend name="Public/base" />
|
||||
<block name="main">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>文档秘钥管理 - 新增秘钥</legend>
|
||||
<div class="layui-field-box">
|
||||
<form class="layui-form" action="">
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">访问秘钥</label>
|
||||
<div class="layui-input-inline" style="width: 280px">
|
||||
<input name="key" value="{$key}" readonly class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">有效时长</label>
|
||||
<div class="layui-input-inline" style="width: 280px">
|
||||
<input type="text" name="keep" value="" placeholder="请输入有效时长" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">单位:小时</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<script>
|
||||
layui.use('form', function(){
|
||||
var form = layui.form();
|
||||
form.on('submit(admin-form)', function(data){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '{:U("add")}',
|
||||
data: data.field,
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
parent.location.reload();
|
||||
}else{
|
||||
parent.layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</block>
|
57
Application/Admin/View/Document/addTime.html
Normal file
57
Application/Admin/View/Document/addTime.html
Normal file
@ -0,0 +1,57 @@
|
||||
add.html<extend name="Public/base" />
|
||||
<block name="main">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>文档秘钥管理 - 延时秘钥</legend>
|
||||
<div class="layui-field-box">
|
||||
<form class="layui-form" action="">
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">访问秘钥</label>
|
||||
<div class="layui-input-inline" style="width: 280px">
|
||||
<input name="key" value="{$key}" readonly class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">系统自动生成,不允许修改</div>
|
||||
</div>
|
||||
<div class="layui-form-item layui-form-text">
|
||||
<label class="layui-form-label">延长时间</label>
|
||||
<div class="layui-input-inline" style="width: 280px">
|
||||
<input type="text" name="keep" value="" placeholder="请输入有效时长" class="layui-input">
|
||||
</div>
|
||||
<div class="layui-form-mid layui-word-aux">单位:小时</div>
|
||||
</div>
|
||||
<div class="layui-form-item">
|
||||
<div class="layui-input-block">
|
||||
<button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
|
||||
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<script>
|
||||
layui.use('form', function(){
|
||||
var form = layui.form();
|
||||
form.on('submit(admin-form)', function(data){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '{:U("addTime")}',
|
||||
data: data.field,
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
parent.location.reload();
|
||||
}else{
|
||||
parent.layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</block>
|
176
Application/Admin/View/Document/index.html
Normal file
176
Application/Admin/View/Document/index.html
Normal file
@ -0,0 +1,176 @@
|
||||
<extend name="Public/base" />
|
||||
<block name="main">
|
||||
<script type="text/javascript" src="__PUBLIC__/dataTable/jquery.dataTables.min.js"></script>
|
||||
<link rel="stylesheet" href="__PUBLIC__/css/dataTable.css">
|
||||
<fieldset class="layui-elem-field">
|
||||
<legend>秘钥列表</legend>
|
||||
<div class="layui-field-box">
|
||||
<span class="layui-btn layui-btn-normal api-add"><i class="layui-icon"></i> 新增</span>
|
||||
<table class="layui-table" id="list-admin" lay-even>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>访问秘钥</th>
|
||||
<th>过期时间</th>
|
||||
<th>访问次数</th>
|
||||
<th>最近访问</th>
|
||||
<th>状态</th>
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</fieldset>
|
||||
</block>
|
||||
<block name="myScript">
|
||||
<script>
|
||||
/**
|
||||
* 格式化时间戳
|
||||
* @param fmt
|
||||
* @returns {*}
|
||||
* @constructor
|
||||
*/
|
||||
Date.prototype.Format = function (fmt) {
|
||||
var o = {
|
||||
"M+": this.getMonth() + 1, //月份
|
||||
"d+": this.getDate(), //日
|
||||
"h+": this.getHours(), //小时
|
||||
"m+": this.getMinutes(), //分
|
||||
"s+": this.getSeconds(), //秒
|
||||
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
|
||||
"S": this.getMilliseconds() //毫秒
|
||||
};
|
||||
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
|
||||
for (var k in o)
|
||||
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
|
||||
return fmt;
|
||||
};
|
||||
|
||||
layui.use(['layer', 'form'], function() {
|
||||
$(document).on('click', '.confirm', function () {
|
||||
var ownObj = $(this);
|
||||
layer.confirm(ownObj.attr('data-info'), {
|
||||
btn: ['确定','取消'] //按钮
|
||||
}, function(){
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: ownObj.attr('data-url'),
|
||||
data: {key:ownObj.attr('data-id')},
|
||||
success: function(msg){
|
||||
if( msg.code == 1 ){
|
||||
location.reload();
|
||||
}else{
|
||||
layer.msg(msg.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.addTime', function () {
|
||||
var ownObj = $(this);
|
||||
layer.open({
|
||||
type: 2,
|
||||
area: ['80%', '80%'],
|
||||
maxmin: true,
|
||||
content: ownObj.attr('data-url')+'&key='+ownObj.attr('data-id')
|
||||
});
|
||||
});
|
||||
|
||||
$('.api-add').on('click', function () {
|
||||
layer.open({
|
||||
type: 2,
|
||||
area: ['80%', '80%'],
|
||||
maxmin: true,
|
||||
content: '{:U("add")}'
|
||||
});
|
||||
});
|
||||
|
||||
var myFun = function (query) {
|
||||
query = query || '';
|
||||
return $('#list-admin').DataTable({
|
||||
dom: 'rt<"bottom"ifpl><"clear">',
|
||||
ordering: false,
|
||||
autoWidth: false,
|
||||
searching:false,
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url:'{:U("ajaxGetIndex")}' + query,
|
||||
type: 'POST',
|
||||
dataSrc: function ( json ) {
|
||||
if( json.code == 0 ){
|
||||
parent.layer.msg(json.msg, {
|
||||
icon: 5,
|
||||
shade: [0.6, '#393D49'],
|
||||
time:1500
|
||||
});
|
||||
}else{
|
||||
return json.data;
|
||||
}
|
||||
}
|
||||
},
|
||||
columnDefs:[
|
||||
{
|
||||
"targets":1,
|
||||
"render": function(data){
|
||||
return new Date(data*1000).Format("yyyy-MM-dd hh:mm:ss");
|
||||
}
|
||||
},
|
||||
{
|
||||
"targets":3,
|
||||
"render": function(data){
|
||||
return new Date(data*1000).Format("yyyy-MM-dd hh:mm:ss");
|
||||
}
|
||||
},
|
||||
{
|
||||
"targets":4,
|
||||
"render": function(data){
|
||||
if(data == 1){
|
||||
return '<span style="border-radius: 2px;background-color: #5FB878;padding:5px 10px;color: #ffffff">已启用</span>';
|
||||
}else{
|
||||
return '<span style="border-radius: 2px;background-color: #FF5722;padding:5px 10px;color: #ffffff">已禁用</span>';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"targets":5,
|
||||
"render":function(data, type, row){
|
||||
var returnStr = '';
|
||||
if(row.status == 1){
|
||||
returnStr += '<span class="layui-btn layui-btn-danger confirm" ' +
|
||||
'data-id="' + row.key +'" data-info="你确定禁用当前Key么?" data-url="{:U(\'close\')}">禁用</span>';
|
||||
}else{
|
||||
returnStr += '<span class="layui-btn layui-btn-warm confirm" ' +
|
||||
'data-id="' + row.key +'" data-info="你确定启用当前Key么?" data-url="{:U(\'open\')}">启用</span>';
|
||||
}
|
||||
returnStr += '<span class="layui-btn addTime layui-btn-normal" ' +
|
||||
'data-id="' + row.key +'" data-url="{:U(\'addTime\')}">延长时间</span>';
|
||||
returnStr += '<span class="layui-btn layui-btn-danger confirm" ' +
|
||||
'data-id="' + row.key +'" data-info="你确定删除当前菜单么?" data-url="{:U(\'del\')}">删除</span>';
|
||||
return returnStr;
|
||||
}
|
||||
}
|
||||
],
|
||||
iDisplayLength : 20,
|
||||
aLengthMenu : [20, 30, 50],
|
||||
columns: [
|
||||
{"data": "key"},
|
||||
{"data": "endTime"},
|
||||
{"data": "times" },
|
||||
{"data": "lastTime" },
|
||||
{"data": "status" },
|
||||
{"data": null }
|
||||
]
|
||||
});
|
||||
};
|
||||
var myTable = myFun();
|
||||
$('.sub').on("click", function(){
|
||||
myTable.destroy();
|
||||
myTable = myFun('&'+ $('#form-admin-add').serialize());
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</block>
|
@ -14,31 +14,62 @@ use Think\Controller;
|
||||
|
||||
class WikiController extends Controller {
|
||||
|
||||
public function apiList(){
|
||||
public function _initialize() {
|
||||
$uid = session('uid');
|
||||
if (!$uid) {
|
||||
$key = session('wikiKey');
|
||||
if (!$key) {
|
||||
$key = I('get.key');
|
||||
if(!$key){
|
||||
$this->error('缺少授权秘钥!', U('Index/index'));
|
||||
}
|
||||
}
|
||||
$keyInfo = S($key);
|
||||
if (!$keyInfo) {
|
||||
$keyInfo = M('ApiDocument')->where(array('key' => $key, 'status' => 1))->find();
|
||||
if (!$keyInfo) {
|
||||
$this->error('当前授权秘钥已失效!', U('Index/index'));
|
||||
} else {
|
||||
S($key, $keyInfo);
|
||||
}
|
||||
}
|
||||
if (NOW_TIME > $keyInfo['endTime']) {
|
||||
$this->error('当前授权秘钥已失效!', U('Index/index'));
|
||||
}
|
||||
session('wikiKey', $key);
|
||||
M('ApiDocument')->where(array('key' => $key))->save(array(
|
||||
'lastTime' => NOW_TIME,
|
||||
'lastIp' => get_client_ip(),
|
||||
'times' => array('exp', 'times+1')
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
public function apiList() {
|
||||
$listData = M('ApiList')->select();
|
||||
$this->assign('list', $listData);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function apiField(){
|
||||
public function apiField() {
|
||||
$hash = I('get.hash');
|
||||
if( empty($hash) ){
|
||||
if (empty($hash)) {
|
||||
$this->redirect('apiList');
|
||||
}else{
|
||||
} else {
|
||||
$request = M('ApiFields')->where(array('hash' => $hash, 'type' => 0))->select();
|
||||
$response = M('ApiFields')->where(array('hash' => $hash, 'type' => 1))->select();
|
||||
$apiInfo = M('ApiList')->where(array('hash' => $hash))->find();
|
||||
$this->assign('apiInfo', $apiInfo);
|
||||
$dataType = array(
|
||||
DataType::TYPE_INTEGER => 'Integer',
|
||||
DataType::TYPE_STRING => 'String',
|
||||
DataType::TYPE_STRING => 'String',
|
||||
DataType::TYPE_BOOLEAN => 'Boolean',
|
||||
DataType::TYPE_ENUM => 'Enum',
|
||||
DataType::TYPE_FLOAT => 'Float',
|
||||
DataType::TYPE_FILE => 'File',
|
||||
DataType::TYPE_ARRAY => 'Array',
|
||||
DataType::TYPE_OBJECT => 'Object',
|
||||
DataType::TYPE_MOBILE => 'Mobile'
|
||||
DataType::TYPE_ENUM => 'Enum',
|
||||
DataType::TYPE_FLOAT => 'Float',
|
||||
DataType::TYPE_FILE => 'File',
|
||||
DataType::TYPE_ARRAY => 'Array',
|
||||
DataType::TYPE_OBJECT => 'Object',
|
||||
DataType::TYPE_MOBILE => 'Mobile'
|
||||
);
|
||||
$this->assign('dataType', $dataType);
|
||||
$this->assign('request', $request);
|
||||
@ -47,39 +78,39 @@ class WikiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function errorCode(){
|
||||
public function errorCode() {
|
||||
$codeArr = ReturnCode::getConstants();
|
||||
$errorInfo = array(
|
||||
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::PARAM_INVALID => '数据类型非法',
|
||||
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::PARAM_INVALID => '数据类型非法',
|
||||
ReturnCode::ACCESS_TOKEN_TIMEOUT => '身份令牌过期',
|
||||
ReturnCode::SESSION_TIMEOUT => 'SESSION过期',
|
||||
ReturnCode::UNKNOWN => '未知错误',
|
||||
ReturnCode::EXCEPTION => '系统异常',
|
||||
ReturnCode::CURL_ERROR => 'CURL操作异常'
|
||||
ReturnCode::SESSION_TIMEOUT => 'SESSION过期',
|
||||
ReturnCode::UNKNOWN => '未知错误',
|
||||
ReturnCode::EXCEPTION => '系统异常',
|
||||
ReturnCode::CURL_ERROR => 'CURL操作异常'
|
||||
);
|
||||
$this->assign('errorInfo', $errorInfo);
|
||||
$this->assign('codeArr', $codeArr);
|
||||
$this->display();
|
||||
}
|
||||
|
||||
public function calculation(){
|
||||
public function calculation() {
|
||||
$this->display();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user