From 339532536f452801d9cd5e30f7f79ac7db006e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 3 Apr 2020 17:22:44 +0800 Subject: [PATCH] add clear --- wchat/common/HttpClient.php | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/wchat/common/HttpClient.php b/wchat/common/HttpClient.php index 81a28e3..67f5409 100644 --- a/wchat/common/HttpClient.php +++ b/wchat/common/HttpClient.php @@ -460,13 +460,7 @@ class HttpClient private function generate_client($host, $url, $data) { $client = new SClient($host, $this->getHostPort(), $this->isSSL); - $client->set([ - 'ssl_host_name' => $this->host, - 'ssl_cert_file' => $this->getSslCertFile(), - 'ssl_key_file' => $this->getSslKeyFile(), - 'ssl_verify_peer' => true, - 'ssl_cafile' => $this->getCa(), - ]); + $client->set($this->settings()); if (!empty($this->agent)) { $this->header['User-Agent'] = $this->agent; } @@ -506,6 +500,24 @@ class HttpClient return $client; } + + private function settings() + { + $sslCert = $this->getSslCertFile(); + $sslKey = $this->getSslKeyFile(); + $sslCa = $this->getCa(); + if (empty($sslCert) || empty($sslKey) || empty($sslCa)) { + return []; + } + $params['ssl_host_name'] = $this->host; + $params['ssl_cert_file'] = $this->getSslCertFile(); + $params['ssl_key_file'] = $this->getSslKeyFile(); + $params['ssl_verify_peer'] = true; + $params['ssl_cafile'] = $sslCa; + + return $params; + } + /** * @param $url * @param array $data