From 7c3ddddbd5e92a56f7db48815b948af19db2047c Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Thu, 29 Aug 2019 23:52:17 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E4=BC=98=E5=8C=96=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/wiki/controller/Api.php | 41 +++++++++-------------------- route/wikiRoute.php | 7 +++-- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/application/wiki/controller/Api.php b/application/wiki/controller/Api.php index d90a01e..73736b6 100644 --- a/application/wiki/controller/Api.php +++ b/application/wiki/controller/Api.php @@ -108,29 +108,15 @@ class Api extends Base { } public function detail() { - $groupHash = $this->request->route('groupHash'); - $hash = $this->request->route('hash', ''); - $this->appInfo['app_api_show'] = json_decode($this->appInfo['app_api_show'], true); - if (!isset($this->appInfo['app_api_show'][$groupHash]) || empty($this->appInfo['app_api_show'][$groupHash])) { - $this->error('请求非法', url('/wiki/index')); - } - + $hash = $this->request->get('hash'); if (!$hash) { - $hash = $this->appInfo['app_api_show'][$groupHash][0]; - } else { - if (!in_array($hash, $this->appInfo['app_api_show'][$groupHash])) { - $this->error('请求非法', url('/wiki/index')); - } + return $this->buildFailed(ReturnCode::NOT_EXISTS, '缺少必要参数'); } - $apiList = (new AdminList())->whereIn('hash', $this->appInfo['app_api_show'][$groupHash])->where(['group_hash' => $groupHash])->select(); - $apiList = Tools::buildArrFromObj($apiList); - $apiList = Tools::buildArrByNewKey($apiList, 'hash'); - - if (!$hash) { - $hash = $this->appInfo['app_api_show'][$groupHash][0]; + $apiList = (new AdminList())->whereIn('hash', $hash)->find(); + if (!$apiList) { + return $this->buildFailed(ReturnCode::NOT_EXISTS, '接口hash非法'); } - $detail = $apiList[$hash]; $request = AdminFields::all(['hash' => $hash, 'type' => 0]); $response = AdminFields::all(['hash' => $hash, 'type' => 1]); @@ -146,19 +132,16 @@ class Api extends Base { DataType::TYPE_MOBILE => 'Mobile' ); - $groupInfo = AdminGroup::get(['hash' => $groupHash]); + $groupInfo = AdminGroup::get(['hash' => $apiList['group_hash']]); $groupInfo->hot = $groupInfo->hot + 1; $groupInfo->save(); - return view('', [ - 'groupInfo' => $groupInfo->toArray(), - 'request' => $request, - 'response' => $response, - 'dataType' => $dataType, - 'apiList' => $apiList, - 'detail' => $detail, - 'hash' => $hash, - 'groupHash' => $groupHash + return $this->buildSuccess([ + 'request' => $request, + 'response' => $response, + 'dataType' => $dataType, + 'apiList' => $apiList, + 'url' => $this->request->domain() . '/api/' . $hash ]); } diff --git a/route/wikiRoute.php b/route/wikiRoute.php index 8eb4c34..7a80b0d 100644 --- a/route/wikiRoute.php +++ b/route/wikiRoute.php @@ -8,6 +8,9 @@ use think\facade\Route; Route::group('wiki', function() { + Route::rule( + 'Api/login', 'wiki/Api/login', 'post' + ); Route::group('Api', [ 'errorCode' => [ 'wiki/Api/errorCode', @@ -17,10 +20,6 @@ Route::group('wiki', function() { 'wiki/Api/groupList', ['method' => 'get'] ], - 'login' => [ - 'wiki/Api/login', - ['method' => 'post'] - ], 'detail' => [ 'wiki/Api/detail', ['method' => 'get']