modified 接口部分兼容普通模式和加密模式

This commit is contained in:
zhaoxiang 2020-03-29 21:11:45 +08:00
parent 5c926c57b8
commit 3d0cd21a76
2 changed files with 20 additions and 8 deletions

View File

@ -182,8 +182,12 @@ class InterfaceList extends Base {
$listInfo = AdminList::all(['status' => 1]);
$tplStr = [];
foreach ($listInfo as $value) {
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);
file_put_contents($apiRoutePath, $tplOriginStr);

View File

@ -25,9 +25,16 @@ 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 {
$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([
@ -37,6 +44,7 @@ class ApiAuth {
])->header($header);
}
}
}
$accessToken = $request->header('access-token', '');
if (!$accessToken) {
@ -73,7 +81,7 @@ class ApiAuth {
}
/**
* 简易鉴权更具APP_SECRET获取应用信=/.
* 简易鉴权更具APP_SECRET获取应用信
* @param $accessToken
* @return bool|mixed
* @author zhaoxiang <zhaoxiang051405@gmail.com>