From d586e2aee2d819acc2e3e902785bae663d12d7f2 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Tue, 7 Jan 2020 12:35:04 +0800 Subject: [PATCH] add clear --- common/HttpClient.php | 57 ++++++++++++++++++++++++++++++++++++------- qq/Account.php | 4 +-- 2 files changed, 49 insertions(+), 12 deletions(-) diff --git a/common/HttpClient.php b/common/HttpClient.php index dbc7ca1..65d6dd2 100644 --- a/common/HttpClient.php +++ b/common/HttpClient.php @@ -252,14 +252,33 @@ class HttpClient */ private function parseUrlHost(&$url) { - if (!empty($this->host)) { - return $this->host; + return $this->parseHost($url); + } + + /** + * @param $url + * @return string + */ + private function parseHost(&$url) + { + $host = empty($this->host) ? $url : $this->host; + if ($this->checkIsIp($host)) { + return $host; } - if ($this->isHttp($url)) { - $url = str_replace('http://', '', $url); - } else if ($this->isHttps($url)) { - $url = str_replace('https://', '', $url); + $host = $this->cutRequestUrl($url); + if ($this->checkIsIp($host)) { + return $host; } + return System::gethostbyname($host); + } + + /** + * @param $url + * @return mixed + */ + private function cutRequestUrl(&$url) + { + $url = $this->replaceHost($url); $explode = explode('/', $url); $first = array_shift($explode); if (strpos($first, ':') !== false) { @@ -269,10 +288,30 @@ class HttpClient } $url = '/' . implode('/', $explode); } - if (preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $first)) { - return $first; + return $first; + } + + /** + * @param $host + * @return string|string[] + */ + private function replaceHost($host) + { + if ($this->isHttp($host)) { + $host = str_replace('http://', '', $host); + } else if ($this->isHttps($host)) { + $host = str_replace('https://', '', $host); } - return System::gethostbyname($first); + return $host; + } + + /** + * @param $url + * @return false|int + */ + private function checkIsIp($url) + { + return preg_match('/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/', $url); } /** diff --git a/qq/Account.php b/qq/Account.php index 98d37f5..248617e 100644 --- a/qq/Account.php +++ b/qq/Account.php @@ -34,9 +34,7 @@ class Account extends SmallProgram $this->request->addHeader('Content-Type', 'text/xml'); $this->request->setUseSwoole($this->config->isUsrSwoole()); - var_dump($this->config, $this->request); - - return $this->request->get('sns/jscode2session', $param); + return $this->request->get('/sns/jscode2session', $param); } /**