获取二维码

@param        $url

@return string
338446
static function getQrcode($url) {
        $qrCode = new QrCode();
        $qrCode->setText($url)
               ->setSize(300)
               ->setPadding(10)
               ->setErrorCorrection('low')
               ->setForegroundColor(['r' => 0,
                                     'g' => 0,
                                     'b' => 0,
                                     'a' => 0])
               ->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 0])
               ->setLabel('')
               ->setLabelFontSize(16)
               ->setImageType(QrCode::IMAGE_TYPE_PNG);
        mkdir(ROOT_PATH . '/runtime/temp/qrcode/', 0777, true);
        $filename = '/runtime/temp/' . md5($url) . '.png';
        $qrCode->save(ROOT_PATH . $filename);
        return ROOT_PATH . $filename;
    }
1162718
private function setUrl($url)
    {
        // 如果 $url 以 http(s):// 开头，则无视 baseUrl。
        if (!preg_match('#^https?://#', $url) && $this->_baseUrl != null && $this->_baseUrl != '') {
            $url = rtrim(trim($this->_baseUrl), '/') . '/' . ltrim(trim($url), '/');
        }
        if (preg_match('#^https://#', $url)) {
            curl_setopt($this->_curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
            curl_setopt($this->_curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($this->_curl, CURLOPT_SSL_VERIFYHOST, false);
        }
        curl_setopt($this->_curl, CURLOPT_URL, $url);
    }
868365
private function checkUrlBind($url)
    {
        $bind = $this->router->getBind($this->domain);

        if (!empty($bind)) {
            $this->parseBindAppendParam($bind);

            // 记录绑定信息
            Container::get('app')->log('[ BIND ] ' . var_export($bind, true));

            // 如果有URL绑定 则进行绑定检测
            $type = substr($bind, 0, 1);
            $bind = substr($bind, 1);

            $bindTo = [
                '\\' => 'bindToClass',
                '@'  => 'bindToController',
                ':'  => 'bindToNamespace',
            ];

            if (isset($bindTo[$type])) {
                return $this->{$bindTo[$type]}($url, $bind);
            }
        }

        return false;
    }
957703
protected function getLocaleFromUrl(string $url)
    {
        $locale = trim(substr($url, 0, 3), '/');
        if (strlen($locale) > 2 || strlen($locale) < 2) {
            return false;
        }

        return $locale;
    }
981514
public function parseUrl($url)
    {
        $scheme   = parse_url($url, PHP_URL_SCHEME);
        $domain   = parse_url($url, PHP_URL_HOST);
        $basename = pathinfo($url, PATHINFO_BASENAME);

        $parts = explode('.', $basename);

        if(count($parts) == 3)
        {
            $type  =  array_pop($parts);
            $format = array_pop($parts);
            $file   = array_pop($parts);
        }
        else
        {
            $type   = '*';
            $format = array_pop($parts);
            $file   = array_pop($parts);
        }

        $path = str_replace(array($scheme.'://', $scheme.':'), '', dirname($url));

        if (strpos($path, $domain.'/') === 0) {
            $path = substr($path, strlen($domain)+1);
        }

        $parts = explode('/', $path);

        $info = array(
            'type'    => $type,
            'domain'  => $domain,
            'package' => array_shift($parts),
            'path'    => implode('/', $parts),
            'file'    => $file,
            'format'  => $format ?: '*',
        );

        return $info;
    }
569100
public function parseUrlPath($url)
    {
        // 分隔符替换 确保路由定义使用统一的分隔符
        $url = str_replace('|', '/', $url);
        $url = trim($url, '/');
        $var = [];

        if (false !== strpos($url, '?')) {
            // [模块/控制器/操作?]参数1=值1&参数2=值2...
            $info = parse_url($url);
            $path = explode('/', $info['path']);
            parse_str($info['query'], $var);
        } elseif (strpos($url, '/')) {
            // [模块/控制器/操作]
            $path = explode('/', $url);
        } elseif (false !== strpos($url, '=')) {
            // 参数1=值1&参数2=值2...
            $path = [];
            parse_str($url, $var);
        } elseif($url) {
            $path = [$url];
        }else{
            $path = [];
        }

        return [$path, $var];
    }
1099712
public function urlQuerystring($url)
    {
        $querystring = $this->querystring();
        if (isset($this->timestamp) && !Utils::contains($querystring, $this->timestamp)) {
            $querystring = empty($querystring) ? ('?' . $this->timestamp) : ($querystring . '&' . $this->timestamp);
        }

        return ltrim($url . $querystring . $this->urlHash(), '/');
    }
218361
public static function retrieveUri($url)
    {
        $uri = new Psr7Uri($url);
        return (string)(new Psr7Uri())
            ->withPath($uri->getPath())
            ->withQuery($uri->getQuery())
            ->withFragment($uri->getFragment());
    }
55127
public function getDataUri($url=null)
    {
        if ($url) {
            static::setText($url);
        }
        
        if (empty($this->image)) {
            $this->create();
        }

        ob_start();
        call_user_func('image'.$this->image_type, $this->image);
        $contents = ob_get_clean();

        return 'data:image/'.$this->image_type.';base64,'.base64_encode($contents);
    }
655240
public static function getPathAndQueryFromUrl($url)
    {
        $parsedUrl = parse_url($url);
        $result = '';
        if (isset($parsedUrl['path'])) {
            if (substr($parsedUrl['path'], 0, 1) == '/') {
                $parsedUrl['path'] = substr($parsedUrl['path'], 1);
            }
            $result .= $parsedUrl['path'];
        }
        if (isset($parsedUrl['query'])) {
            $result .= '?' . $parsedUrl['query'];
        }
        return $result;
    }
883187
public static function convertUtfUrl($url)
    {
        $parts = (array) parse_url($url);

        if (isset($parts['host'])) {
            if (function_exists('idn_to_ascii')) {
                $parts['host'] = idn_to_ascii($parts['host']);
            }
        }

        if (isset($parts['path'])) {
            $parts['path'] = implode('/', array_map('urlencode', explode('/', $parts['path'])));
        }

        if (isset($parts['query'])) {
            parse_str($parts['query'], $query);

            $parts['query'] = http_build_query($query);
        }

        return self::buildUrl($parts);
    }
988540
static public function rUrl($url)
    {
        $module = null;
        if (strpos($url, 'http') !== 0 && ($pos = strpos($url, ':')) !== false) {    // 1. "x:a/b" module or xUrl
            $module = trim(substr($url, 0, $pos), '/');
            $url   = trim(substr($url, $pos + 1), '/');
        }
        
        if (strpos($url, 'http') === 0) {
            $url = str_replace(static::url($module . ':'), '', $url);
        }
        
        return trim($url, '/');
    }
473727
protected function parseUrl($url)
    {
        $depr = $this->rule->getConfig('app.pathinfo_depr');
        $bind = $this->rule->getRouter()->getBind();

        if (!empty($bind) && preg_match('/^[a-z]/is', $bind)) {
            $bind = str_replace('/', $depr, $bind);
            // 如果有模块/控制器绑定
            $url = $bind . ('.' != substr($bind, -1) ? $depr : '') . ltrim($url, $depr);
        }

        list($path, $var) = $this->rule->parseUrlPath($url);

        return $path;

//        // 解析模块
//        $module = array_shift($path);
//
//        if ($this->param['auto_search']) {
//            $controller = $this->autoFindController($module, $path);
//        } else {
//            // 解析控制器
//            $controller = !empty($path) ? array_shift($path) : null;
//        }
//
//        // 解析操作
//        $action = !empty($path) ? array_shift($path) : null;
//
//        // 解析额外参数
//        if ($path) {
//            if ($this->rule->getConfig('url_param_type')) {
//                $var += $path;
//            } else {
//                preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) {
//                    $var[$match[1]] = strip_tags($match[2]);
//                }, implode('|', $path));
//            }
//        }
//
//        $panDomain = Request::panDomain();
//
//        if ($panDomain && $key = array_search('*', $var)) {
//            // 泛域名赋值
//            $var[$key] = $panDomain;
//        }
//
//        // 设置当前请求的参数
//        Request::setRouteVars($var);
//
//        // 封装路由
//        $route = [$module, $controller, $action];
//
//        if ($this->hasDefinedRoute($route, $bind)) {
//            throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url));
//        }
//
//        return $route;
    }
475216
public function generateUrl($url)
    {
        $extern = false;
        if ((0 === strrpos($url, 'http://'))
            || (0 === strrpos($url, 'https://'))) {
            $extern = true;
        }

        $http = (isset($_SERVER['HTTPS'])) ? 'https://' : 'http://';

        if (!$extern) {
            return ($this->getRoot() == '/')
                ? (($this->getRoot() == $url) ? '' : $url) : $http.$_SERVER['SERVER_NAME'].$this->getRoot().$url;
        } else {
            return $url;
        }
    }
347777
public static function getDomainFromURL($url)
	{
		$url = str_replace(self::getProtocolFromURL($url) . '://', '', $url);
		
		return explode('/', $url)[0];
	}
657345
public function get(string $url): string
    {
        $ch = curl_init($url);

        if ( ! ini_get('open_basedir')) {
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        }

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36');
        curl_setopt($ch, CURLOPT_URL, $url);

        $content = curl_exec($ch);
        if ($content === false) {
            // there was a problem
            $error = curl_error($ch);
            throw new CurlException('Error retrieving "'.$url.'" ('.$error.')');
        }

        return $content;
    }
675200
public static function getHeaderFromUrl($url) {
		// @codingStandardsIgnoreStart
		$url = @parse_url($url);
		// @codingStandardsIgnoreEnd
		if (empty($url)) {
			return false;
		}

		$url = array_map('trim', $url);
		$url['port'] = (!isset($url['port'])) ? '' : (':' . (int)$url['port']);
		$path = (isset($url['path'])) ? $url['path'] : '';

		if (empty($path)) {
			$path = '/';
		}

		$path .= (isset($url['query'])) ? "?$url[query]" : '';

		$defaults = [
			'http' => [
				'header' => "Accept: text/html\r\n" .
					"Connection: Close\r\n" .
					"User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64)\r\n",
			]
		];
		stream_context_get_default($defaults);

		if (isset($url['host']) && $url['host'] !== gethostbyname($url['host'])) {
			$url = "$url[scheme]://$url[host]$url[port]$path";
			$headers = get_headers($url);
			if (is_array($headers)) {
				return $headers;
			}
		}
		return false;
	}