diff --git a/application/api/controller/Base.php b/application/api/controller/Base.php index 14c5e6cb..eec469e4 100644 --- a/application/api/controller/Base.php +++ b/application/api/controller/Base.php @@ -66,11 +66,12 @@ class Base extends Controller * 返回数据给客户端并中断输出 * * @param string $msg 提示信息 - * @param int $code 状态码 * @param null $data 数据 + * @param int $code 状态码 * + * @throws HttpResponseException */ - protected function response($msg = '', $code = 200, $data = null) + protected function response($msg = '', $data = null, $code = 200) { $response = Response::create([ 'code' => $code, diff --git a/application/api/controller/Token.php b/application/api/controller/Token.php index 00df14dd..b0acf10f 100644 --- a/application/api/controller/Token.php +++ b/application/api/controller/Token.php @@ -33,8 +33,8 @@ class Token extends Base } } } catch (Exception $e) { - return $this->response($e->getMessage(), 500); + return $this->response($e->getMessage(), null, 500); } - return $this->response('success', 200, ['token' => $user->token]); + return $this->response('success', ['token' => $user->token]); } } diff --git a/application/api/controller/Upload.php b/application/api/controller/Upload.php index 313cc475..ee3e5c66 100644 --- a/application/api/controller/Upload.php +++ b/application/api/controller/Upload.php @@ -37,8 +37,8 @@ class Upload extends Base Db::commit(); } catch (Exception $e) { Db::rollback(); - return $this->response($e->getMessage(), 500); + return $this->response($e->getMessage(), null, 500); } - return $this->response('success', 200, $data); + return $this->response('success', $data); } } diff --git a/application/api/controller/User.php b/application/api/controller/User.php deleted file mode 100644 index 8f82c547..00000000 --- a/application/api/controller/User.php +++ /dev/null @@ -1,90 +0,0 @@ -response('success', 200, $this->user); - } - - /** - * 显示创建资源表单页. - * - * @return \think\Response - */ - public function create() - { - // - } - - /** - * 保存新建的资源 - * - * @param \think\Request $request - * @return \think\Response - */ - public function save(Request $request) - { - // - } - - /** - * 显示指定的资源 - * - * @param int $id - * @return \think\Response - */ - public function read($id) - { - - } - - /** - * 显示编辑资源表单页. - * - * @param int $id - * @return \think\Response - */ - public function edit($id) - { - // - } - - /** - * 保存更新的资源 - * - * @param \think\Request $request - * @param int $id - * @return \think\Response - */ - public function update(Request $request, $id) - { - // - } - - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id) - { - // - } -} diff --git a/application/http/middleware/WebAuth.php b/application/http/middleware/WebAuth.php index 9f311595..2a9b23c2 100644 --- a/application/http/middleware/WebAuth.php +++ b/application/http/middleware/WebAuth.php @@ -12,7 +12,7 @@ class WebAuth * @var array */ private $noNeedLogin = [ - 'Index/index', + 'Index/*', 'Upload/upload', 'Auth/*', ]; diff --git a/application/index/controller/Index.php b/application/index/controller/Index.php index 52ae03da..005cc557 100644 --- a/application/index/controller/Index.php +++ b/application/index/controller/Index.php @@ -14,4 +14,10 @@ class Index extends Base { return $this->fetch(); } + + public function api() + { + $this->assign('domain', $this->request->domain()); + return $this->fetch(); + } } diff --git a/application/index/view/common/base.html b/application/index/view/common/base.html index a560824a..59869a7d 100644 --- a/application/index/view/common/base.html +++ b/application/index/view/common/base.html @@ -60,6 +60,12 @@
首页
+ {if $config.open_api} + + +
接口
+
+ {/if} {if $user} diff --git a/application/index/view/index/api.html b/application/index/view/index/api.html new file mode 100644 index 00000000..948fb78c --- /dev/null +++ b/application/index/view/index/api.html @@ -0,0 +1,101 @@ +{extend name="common:base" /} + +{block name="title"}Upload API Document - {$config.site_name}{/block} + +{block name="main"} +
+
+

1. 获取Token

+
+
+
+ + + + + + + + + + + + + + + + + +
功能接口
请求方式POST
URL{$domain}/api/token
+
+
+
+

请求参数

+
+ + + + + + + + + + + + + + + + + + + + + + + +
参数名称类型是否必须说明
emailString邮箱
passwordString账号密码
+
+

返回数据说明

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
参数名称类型实例值说明
codeNumber200状态码,成功返回200,失败返回500
msgStringsuccess提示信息
timeNumber1544176295响应时间戳
dataarray|object{"token": "8961576c9090ef0902c4b89406f8d557"}获取的token数据
+
+
+
+{/block} diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index ec329411..bb09db69 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -10,7 +10,7 @@ {block name="main"}
- {if (bool)$config.allowed_tourist_upload or $user} + {if (bool) $config.allowed_tourist_upload or $user}

Image Upload

diff --git a/route/route.php b/route/route.php index 455121b3..941510b7 100644 --- a/route/route.php +++ b/route/route.php @@ -13,11 +13,10 @@ use think\facade\Route; Route::view('compatibility', 'index@tpl/compatibility'); -// [RESTFul Api Route] +// [Api Route] Route::group('api', function () { - Route::post('upload', 'api/Upload/index'); Route::post('token', 'api/Token/index'); - Route::resource('user', 'api/User'); + Route::post('upload', 'api/Upload/index'); }); return [];