mirror of
https://gitee.com/apiadmin/ApiAdmin.git
synced 2025-04-05 05:42:45 +08:00
48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
declare (strict_types=1);
|
|
|
|
namespace app\middleware;
|
|
|
|
use app\util\ReturnCode;
|
|
|
|
class WikiAuth {
|
|
|
|
/**
|
|
* ApiAuth鉴权
|
|
* @param \think\facade\Request $request
|
|
* @param \Closure $next
|
|
* @return mixed|\think\response\Json
|
|
* @author zhaoxiang <zhaoxiang051405@gmail.com>
|
|
*/
|
|
public function handle($request, \Closure $next) {
|
|
$header = config('apiadmin.CROSS_DOMAIN');
|
|
$ApiAuth = $request->header('Api-Auth', '');
|
|
if ($ApiAuth) {
|
|
$userInfo = cache('Login:' . $ApiAuth);
|
|
if (!$userInfo) {
|
|
$userInfo = cache('WikiLogin:' . $ApiAuth);
|
|
} else {
|
|
$userInfo = json_decode($userInfo, true);
|
|
$userInfo['app_id'] = -1;
|
|
}
|
|
if (!$userInfo || !isset($userInfo['id'])) {
|
|
return json([
|
|
'code' => ReturnCode::AUTH_ERROR,
|
|
'msg' => 'ApiAuth不匹配',
|
|
'data' => []
|
|
])->header($header);
|
|
} else {
|
|
$request->API_WIKI_USER_INFO = $userInfo;
|
|
}
|
|
|
|
return $next($request);
|
|
} else {
|
|
return json([
|
|
'code' => ReturnCode::AUTH_ERROR,
|
|
'msg' => '缺少ApiAuth',
|
|
'data' => []
|
|
])->header($header);
|
|
}
|
|
}
|
|
}
|