From 3d0cd21a7630894cedcac9adb9729e33321b1309 Mon Sep 17 00:00:00 2001 From: zhaoxiang <756958008@qq.com> Date: Sun, 29 Mar 2020 21:11:45 +0800 Subject: [PATCH] =?UTF-8?q?modified=20=E6=8E=A5=E5=8F=A3=E9=83=A8=E5=88=86?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=99=AE=E9=80=9A=E6=A8=A1=E5=BC=8F=E5=92=8C?= =?UTF-8?q?=E5=8A=A0=E5=AF=86=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/controller/InterfaceList.php | 6 ++++- application/http/middleware/ApiAuth.php | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/application/admin/controller/InterfaceList.php b/application/admin/controller/InterfaceList.php index 320b1c4..0ce0b72 100644 --- a/application/admin/controller/InterfaceList.php +++ b/application/admin/controller/InterfaceList.php @@ -182,7 +182,11 @@ class InterfaceList extends Base { $listInfo = AdminList::all(['status' => 1]); $tplStr = []; foreach ($listInfo as $value) { - array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'); + if($value['hash_type'] === 1) { + array_push($tplStr, 'Route::rule(\'' . addslashes($value->api_class) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'); + } else { + array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);'); + } } $tplOriginStr = str_replace(['{$API_RULE}'], [implode($tplStr, "\n ")], $tplOriginStr); diff --git a/application/http/middleware/ApiAuth.php b/application/http/middleware/ApiAuth.php index b80dcb2..f923a8e 100644 --- a/application/http/middleware/ApiAuth.php +++ b/application/http/middleware/ApiAuth.php @@ -25,16 +25,24 @@ class ApiAuth { if ($cached) { $apiInfo = Cache::get('ApiInfo:' . $apiHash); } else { - $apiInfo = AdminList::get(['hash' => $apiHash]); + $apiInfo = AdminList::get(['hash' => $apiHash, 'hash_type' => 2]); if ($apiInfo) { $apiInfo = $apiInfo->toArray(); + Cache::rm('ApiInfo:' . $apiInfo['api_class']); Cache::set('ApiInfo:' . $apiHash, $apiInfo); } else { - return json([ - 'code' => ReturnCode::DB_READ_ERROR, - 'msg' => '获取接口配置数据失败', - 'data' => [] - ])->header($header); + $apiInfo = AdminList::get(['api_class' => $apiHash, 'hash_type' => 1]); + if ($apiInfo) { + $apiInfo = $apiInfo->toArray(); + Cache::rm('ApiInfo:' . $apiInfo['hash']); + Cache::set('ApiInfo:' . $apiHash, $apiInfo); + } else { + return json([ + 'code' => ReturnCode::DB_READ_ERROR, + 'msg' => '获取接口配置数据失败', + 'data' => [] + ])->header($header); + } } } @@ -73,7 +81,7 @@ class ApiAuth { } /** - * 简易鉴权,更具APP_SECRET获取应用信=/. + * 简易鉴权,更具APP_SECRET获取应用信息 * @param $accessToken * @return bool|mixed * @author zhaoxiang