add clear

This commit is contained in:
as2252258@163.com
2020-01-07 12:35:04 +08:00
parent 40ac73f40f
commit d586e2aee2
2 changed files with 49 additions and 12 deletions
+48 -9
View File
@@ -252,14 +252,33 @@ class HttpClient
*/ */
private function parseUrlHost(&$url) private function parseUrlHost(&$url)
{ {
if (!empty($this->host)) { return $this->parseHost($url);
return $this->host; }
/**
* @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)) { $host = $this->cutRequestUrl($url);
$url = str_replace('http://', '', $url); if ($this->checkIsIp($host)) {
} else if ($this->isHttps($url)) { return $host;
$url = str_replace('https://', '', $url);
} }
return System::gethostbyname($host);
}
/**
* @param $url
* @return mixed
*/
private function cutRequestUrl(&$url)
{
$url = $this->replaceHost($url);
$explode = explode('/', $url); $explode = explode('/', $url);
$first = array_shift($explode); $first = array_shift($explode);
if (strpos($first, ':') !== false) { if (strpos($first, ':') !== false) {
@@ -269,10 +288,30 @@ class HttpClient
} }
$url = '/' . implode('/', $explode); $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);
} }
/** /**
+1 -3
View File
@@ -34,9 +34,7 @@ class Account extends SmallProgram
$this->request->addHeader('Content-Type', 'text/xml'); $this->request->addHeader('Content-Type', 'text/xml');
$this->request->setUseSwoole($this->config->isUsrSwoole()); $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);
} }
/** /**