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