Skip to content

Commit 3d0cd21

Browse files
committed
modified 接口部分兼容普通模式和加密模式
1 parent 5c926c5 commit 3d0cd21

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

application/admin/controller/InterfaceList.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ public function refresh() {
182182
$listInfo = AdminList::all(['status' => 1]);
183183
$tplStr = [];
184184
foreach ($listInfo as $value) {
185-
array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);');
185+
if($value['hash_type'] === 1) {
186+
array_push($tplStr, 'Route::rule(\'' . addslashes($value->api_class) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);');
187+
} else {
188+
array_push($tplStr, 'Route::rule(\'' . addslashes($value->hash) . '\',\'api/' . addslashes($value->api_class) . '\', \'' . $methodArr[$value->method] . '\')->middleware([\'ApiAuth\', \'ApiPermission\', \'RequestFilter\', \'ApiLog\']);');
189+
}
186190
}
187191
$tplOriginStr = str_replace(['{$API_RULE}'], [implode($tplStr, "\n ")], $tplOriginStr);
188192

application/http/middleware/ApiAuth.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,24 @@ public function handle($request, \Closure $next) {
2525
if ($cached) {
2626
$apiInfo = Cache::get('ApiInfo:' . $apiHash);
2727
} else {
28-
$apiInfo = AdminList::get(['hash' => $apiHash]);
28+
$apiInfo = AdminList::get(['hash' => $apiHash, 'hash_type' => 2]);
2929
if ($apiInfo) {
3030
$apiInfo = $apiInfo->toArray();
31+
Cache::rm('ApiInfo:' . $apiInfo['api_class']);
3132
Cache::set('ApiInfo:' . $apiHash, $apiInfo);
3233
} else {
33-
return json([
34-
'code' => ReturnCode::DB_READ_ERROR,
35-
'msg' => '获取接口配置数据失败',
36-
'data' => []
37-
])->header($header);
34+
$apiInfo = AdminList::get(['api_class' => $apiHash, 'hash_type' => 1]);
35+
if ($apiInfo) {
36+
$apiInfo = $apiInfo->toArray();
37+
Cache::rm('ApiInfo:' . $apiInfo['hash']);
38+
Cache::set('ApiInfo:' . $apiHash, $apiInfo);
39+
} else {
40+
return json([
41+
'code' => ReturnCode::DB_READ_ERROR,
42+
'msg' => '获取接口配置数据失败',
43+
'data' => []
44+
])->header($header);
45+
}
3846
}
3947
}
4048

@@ -73,7 +81,7 @@ public function handle($request, \Closure $next) {
7381
}
7482

7583
/**
76-
* 简易鉴权,更具APP_SECRET获取应用信=/.
84+
* 简易鉴权,更具APP_SECRET获取应用信息
7785
* @param $accessToken
7886
* @return bool|mixed
7987
* @author zhaoxiang <zhaoxiang051405@gmail.com>

0 commit comments

Comments
 (0)