You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pdd-order-api/app/libs/tool/class.AppUrlHandler.php

100 lines
3.0 KiB
PHP

<?php
class AppUrlHandler implements ZcUrlHandler {
public function buildUrl($route, $params = '', $scheme = false, $host = false) {
$isNotForceHttps = preg_match('/^(timer|open)/', $route);
if (!$isNotForceHttps && $scheme === false && !AppConst::isDev()) {
$scheme = 'https';
}
$scheme = empty($scheme) ? self::getCurProtocol() : $scheme;
$host = ($host === false) ? $this->getHost() : $host;
$port = ($scheme == 'https') ? $_SERVER['SERVER_PORT'] : 80;
$port = in_array($port, [80, 443]) ? '' : (':' . $port);
$route = trim($route, '/');
if (preg_match('/v2\./i', $host) && $host != Zc::C('jflow.host')) {
$scriptName = substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], 'index.php'));
$scriptName = (($route == '') && ($scriptName == '/api/')) ? '/' : $scriptName;
} else {
$scriptName = '/';
}
if (is_array($params) && $params['__NOAPI__']) {
$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() {
return $_SERVER['HTTP_HOST'];
}
private function getCurProtocol() {
return 'http';
}
public function parseBack() {
$_GET['_route_'] = $_GET['_route_'] ? : Zc::C(ZcConfigConst::DefaultRoute);
if (isset($_GET['_route_'])) {
$_GET['route'] = $this->rewriteRoute($_GET['_route_']);
unset($_GET['_route_']);
}
}
private function rewriteRoute($route) {
$route = trim($route, '/');
if (AppConst::isUseAppModuleApp() && (stripos($route, 'control/decrypt/') === 0)) {
return 'pdd/' . $route;
}
if ((AppConst::isPddRubyApp() || AppConst::isPddTaoBaiKeApp()) && $this->isUseRealRoute($route)) {
return $route;
}
if (AppConst::isRubyWeb()) {
if (stripos($route, 'ruby/') === 0) {
return $route;
} else {
return 'ruby/' . $route;
}
} else if (AppConst::isRubyDesktop()) {
if (stripos($route, 'ruby_dt/') === 0) {
return $route;
} else {
return 'ruby_dt/' . $route;
}
} else if (AppConst::isPddTaoBaiKeApp()) {
if (stripos($route, 'taobaike/') === 0) {
return $route;
} else {
return 'taobaike/' . $route;
}
}
return $route;
}
private function isUseRealRoute($route){
if (preg_match('#(filter|timer|open|common|admin)\/.*#i', $route)) {
return true;
}
$realRouteList = array(
);
return in_array($route, $realRouteList);
}
}