修改bug

20240120-ljl-routeConfig
ljl 11 months ago
parent 9fcfa9626d
commit 13350ae6c0

@ -1,56 +1,59 @@
<?php <?php
class AppUrlHandler implements ZcUrlHandler { class AppUrlHandler implements ZcUrlHandler {
public function buildUrl($route, $params = '', $scheme = false, $host = false) { public function buildUrl($route, $params = '', $scheme = false, $host = false) {
$scheme = ($scheme === false) ? $this->getCurProtocol() : $scheme; $isNotForceHttps = preg_match('/^(timer|open)/', $route);
$host = ($host === false) ? $this->getHost() : $host; if (!$isNotForceHttps && $scheme === false && !AppConst::isDev()) {
$port = (filter_var($host, FILTER_VALIDATE_IP) !== false) ? $_SERVER['SERVER_PORT'] : (($scheme == 'https') ? 443 : 80); $scheme = 'https';
}
$route = trim($route, '/');
$scriptName = $this->getScriptName();
$url = $scheme . '://' . $host . (in_array($port, [80, 443]) ? '' : ':' . $port) . substr($scriptName, 0, strpos($scriptName, 'index.php')) . $route;
if (is_array($params)) {
$params = http_build_query($params, '', '&');
}
if ($params) {
$url .= '?' . ltrim($params, '&');
}
return $url;
}
private function getScriptName() { $scheme = empty($scheme) ? self::getCurProtocol() : $scheme;
$scriptName = $_SERVER['SCRIPT_NAME']; $host = ($host === false) ? $this->getHost() : $host;
$port = ($scheme == 'https') ? $_SERVER['SERVER_PORT'] : 80;
$port = in_array($port, [80, 443]) ? '' : (':' . $port);
if (AppConst::isUseAppModuleApp()) { $route = trim($route, '/');
if (strpos($scriptName, '/pdd-order') === 0) { if (preg_match('/v2\./i', $host) && $host != Zc::C('jflow.host')) {
$scriptName = substr($scriptName, strlen('/pdd-order')); $scriptName = substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'index.php'));
} elseif (strpos($_SERVER['SCRIPT_NAME'], '/pdd') === 0) { $scriptName = (($route == '') && ($scriptName == '/api/')) ? '/' : $scriptName;
$scriptName = substr($scriptName, strlen('/pdd')); } else {
} $scriptName = '/';
}
if (is_array($params) && $params['__NOAPI__']) {
$scriptName = '/';
} }
return $scriptName; $url = "{$scheme}://{$host}{$port}{$scriptName}{$route}";
if (is_array($params)) {
unset($params['__NOAPI__']);
$params = http_build_query($params, '', '&');
}
if ($params) {
$url .= '?' . ltrim($params, '&');
}
return $url;
} }
private function getHost() { private function getHost() {
return $_SERVER['HTTP_HOST']; return $_SERVER['HTTP_HOST'];
} }
private function getCurProtocol() {
return AppConst::getCurProtocol();
}
public function parseBack() { private function getCurProtocol() {
$_GET['_route_'] = $_GET['_route_'] ? : Zc::C(ZcConfigConst::DefaultRoute); return 'http';
if (isset($_GET['_route_'])) { }
$_GET['route'] = $this->rewriteRoute($_GET['_route_']);
unset($_GET['_route_']); public function parseBack() {
} $_GET['_route_'] = $_GET['_route_'] ? : Zc::C(ZcConfigConst::DefaultRoute);
} if (isset($_GET['_route_'])) {
$_GET['route'] = $this->rewriteRoute($_GET['_route_']);
private function rewriteRoute($route){ unset($_GET['_route_']);
}
}
private function rewriteRoute($route){
$route = trim($route, '/'); $route = trim($route, '/');
if (AppConst::isUseAppModuleApp() && (stripos($route, 'control/decrypt/') === 0)) { if (AppConst::isUseAppModuleApp() && (stripos($route, 'control/decrypt/') === 0)) {
@ -88,10 +91,6 @@ class AppUrlHandler implements ZcUrlHandler {
return true; return true;
} }
if (preg_match('/^pdd\/control\/decrypt/', $route)) {
return true;
}
$realRouteList = array( $realRouteList = array(
); );

Loading…
Cancel
Save