更新
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
// 本地互通辅助入口:只加载原项目配置,不复制其中的数据库或第三方凭据。
|
||||
$root = getenv('IAM_SOURCE_PROJECT_ROOT');
|
||||
$root = is_string($root) ? realpath($root) : false;
|
||||
$path = strtolower((string) parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH));
|
||||
$method = strtoupper($_SERVER['REQUEST_METHOD'] ?? 'GET');
|
||||
$read = ['auth.admin/myself', 'auth.admin/lists', 'auth.admin/all', 'auth.admin/detail',
|
||||
'auth.role/lists', 'auth.role/all', 'auth.role/detail', 'auth.menu/lists', 'auth.menu/all', 'auth.menu/detail',
|
||||
'dept.dept/lists', 'dept.dept/all', 'dept.dept/detail'];
|
||||
$write = ['identity.session/login', 'identity.session/verify', 'identity.session/password', 'identity.session/logout', 'identity.hospitalsso/issue', 'identity.hospitalsso/exchange'];
|
||||
foreach (['auth.admin', 'auth.role', 'auth.menu', 'dept.dept'] as $controller) {
|
||||
foreach (['add', 'edit', 'delete'] as $action) { $write[] = $controller . '/' . $action; }
|
||||
}
|
||||
$allowed = array_map(static fn ($route) => '/adminapi/' . $route, $method === 'GET' ? $read : ($method === 'POST' ? $write : []));
|
||||
if (!in_array($path, $allowed, true) || array_key_exists('s', $_GET)) {
|
||||
http_response_code(404);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo '{"code":0,"msg":"接口不存在","data":{}}';
|
||||
exit;
|
||||
}
|
||||
if (!$root || !is_file($root . '/vendor/autoload.php') || !is_file($root . '/config/install.lock')) {
|
||||
http_response_code(503);
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
echo '{"code":0,"msg":"原项目服务尚未配置","data":{}}';
|
||||
exit;
|
||||
}
|
||||
require $root . '/vendor/autoload.php';
|
||||
// 多应用组件根据入口文件名选应用;保持原 index.php 语义,避免把本辅助器当成应用名。
|
||||
$_SERVER['SCRIPT_FILENAME'] = $root . '/public/index.php';
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
$_SERVER['PHP_SELF'] = '/index.php';
|
||||
$_SERVER['PATH_INFO'] = (string) parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH);
|
||||
$application = new class($root . DIRECTORY_SEPARATOR) extends think\App {
|
||||
public function loadEnv(string $envName = ''): void
|
||||
{
|
||||
parent::loadEnv($envName);
|
||||
// 互通入口始终要求真实密码,不沿用原项目本地免密调试开关。
|
||||
$this->env->set('APP_DEBUG', false);
|
||||
$this->env->set('LOCAL_DEBUG_LOGIN_SKIP_PASSWORD', false);
|
||||
}
|
||||
};
|
||||
$application->initialize();
|
||||
// 即使原 Request 配置存在兼容路由,也固定到外层白名单核验过的真实地址。
|
||||
$canonicalPath = str_replace('/identity.hospitalsso/', '/identity.hospitalSso/', $path);
|
||||
$application->request->setPathinfo(ltrim($canonicalPath, '/'));
|
||||
$http = $application->http;
|
||||
$response = $http->run();
|
||||
$response->send();
|
||||
$http->end($response);
|
||||
Reference in New Issue
Block a user