From 79635f530891da849480614e58e6ff0786d9e974 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Mon, 26 Jun 2017 13:35:10 +0800 Subject: [PATCH] =?UTF-8?q?added=20=E5=AE=8C=E6=88=90Api=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=8E=88=E6=9D=83=E6=9F=A5=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/DocumentController.class.php | 108 +++++++++++ .../Admin/Model/ApiDocumentModel.class.php | 13 ++ Application/Admin/View/Document/add.html | 57 ++++++ Application/Admin/View/Document/addTime.html | 57 ++++++ Application/Admin/View/Document/index.html | 176 ++++++++++++++++++ .../Home/Controller/WikiController.class.php | 101 ++++++---- 6 files changed, 477 insertions(+), 35 deletions(-) create mode 100644 Application/Admin/Controller/DocumentController.class.php create mode 100644 Application/Admin/Model/ApiDocumentModel.class.php create mode 100644 Application/Admin/View/Document/add.html create mode 100644 Application/Admin/View/Document/addTime.html create mode 100644 Application/Admin/View/Document/index.html diff --git a/Application/Admin/Controller/DocumentController.class.php b/Application/Admin/Controller/DocumentController.class.php new file mode 100644 index 0000000..6bce712 --- /dev/null +++ b/Application/Admin/Controller/DocumentController.class.php @@ -0,0 +1,108 @@ + + */ + +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 + */ + 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 + */ + 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 + */ + 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 + */ + 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(); + } + } +} \ No newline at end of file diff --git a/Application/Admin/Model/ApiDocumentModel.class.php b/Application/Admin/Model/ApiDocumentModel.class.php new file mode 100644 index 0000000..f2a1cf4 --- /dev/null +++ b/Application/Admin/Model/ApiDocumentModel.class.php @@ -0,0 +1,13 @@ + + */ + +namespace Admin\Model; + + +class ApiDocumentModel extends BaseModel { + +} \ No newline at end of file diff --git a/Application/Admin/View/Document/add.html b/Application/Admin/View/Document/add.html new file mode 100644 index 0000000..9bc46ea --- /dev/null +++ b/Application/Admin/View/Document/add.html @@ -0,0 +1,57 @@ +add.html + +
+ 文档秘钥管理 - 新增秘钥 +
+
+
+ +
+ +
+
系统自动生成,不允许修改
+
+
+ +
+ +
+
单位:小时
+
+
+
+ + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/Application/Admin/View/Document/addTime.html b/Application/Admin/View/Document/addTime.html new file mode 100644 index 0000000..6db4e74 --- /dev/null +++ b/Application/Admin/View/Document/addTime.html @@ -0,0 +1,57 @@ +add.html + +
+ 文档秘钥管理 - 延时秘钥 +
+
+
+ +
+ +
+
系统自动生成,不允许修改
+
+
+ +
+ +
+
单位:小时
+
+
+
+ + +
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/Application/Admin/View/Document/index.html b/Application/Admin/View/Document/index.html new file mode 100644 index 0000000..4d0068b --- /dev/null +++ b/Application/Admin/View/Document/index.html @@ -0,0 +1,176 @@ + + + + +
+ 秘钥列表 +
+ 新增 + + + + + + + + + + + +
访问秘钥过期时间访问次数最近访问状态操作
+
+
+
+ + + \ No newline at end of file diff --git a/Application/Home/Controller/WikiController.class.php b/Application/Home/Controller/WikiController.class.php index cfaaee9..1354240 100644 --- a/Application/Home/Controller/WikiController.class.php +++ b/Application/Home/Controller/WikiController.class.php @@ -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(); }