This commit is contained in:
2023-10-27 22:23:11 +08:00
parent 165f62113c
commit 7b14fa075e
3 changed files with 677 additions and 638 deletions
+43 -15
View File
@@ -25,35 +25,23 @@ abstract class ClientAbstracts implements IClient
const PUT = 'put'; const PUT = 'put';
private string $host = ''; private string $host = '';
private array $header = []; private array $header = [];
private int $timeout = 0; private int $timeout = 0;
private string $method = 'get'; private string $method = 'get';
private bool $isSSL = FALSE; private bool $isSSL = FALSE;
private string $agent = ''; private string $agent = '';
private string $ssl_cert_file = ''; private string $ssl_cert_file = '';
private string $ssl_key_file = ''; private string $ssl_key_file = '';
private string $ca = ''; private string $ca = '';
private int $port = 80; private int $port = 80;
protected int $num = 0; protected int $num = 0;
private ?array $_responseHeader = []; private ?array $_responseHeader = [];
private int $statusCode = 200; private int $statusCode = 200;
protected int $retryNum = 0; protected int $retryNum = 0;
protected int $retryTimeout = 0; protected int $retryTimeout = 0;
private bool $verifyPeer = TRUE; private bool $verifyPeer = TRUE;
private string $proxyHost = '';
private int $proxyPort = 0;
/** /**
@@ -84,6 +72,46 @@ abstract class ClientAbstracts implements IClient
} }
/**
* @return string
*/
public function getProxyHost(): string
{
return $this->proxyHost;
}
/**
* @return string
*/
public function getProxyPort(): string
{
return $this->proxyPort;
}
/**
* @param string $proxy
* @return ClientAbstracts
*/
public function withProxyHost(string $proxy): static
{
$this->proxyHost = $proxy;
return $this;
}
/**
* @param int $proxy
* @return ClientAbstracts
*/
public function withProxyPort(int $proxy): static
{
$this->proxyPort = $proxy;
return $this;
}
/** /**
* @param int $retryTimeout * @param int $retryTimeout
* @return $this * @return $this
@@ -636,7 +664,7 @@ abstract class ClientAbstracts implements IClient
protected function mergeParams($newData): ?string protected function mergeParams($newData): ?string
{ {
if (is_array($newData)) { if (is_array($newData)) {
return json_encode($newData,JSON_UNESCAPED_UNICODE); return json_encode($newData, JSON_UNESCAPED_UNICODE);
} }
return (string)$newData; return (string)$newData;
} }
+5
View File
@@ -115,6 +115,11 @@ class CurlClient extends ClientAbstracts
if ($method === self::POST || $method == self::UPLOAD) { if ($method === self::POST || $method == self::UPLOAD) {
curl_setopt($resource, CURLOPT_POST, 1); curl_setopt($resource, CURLOPT_POST, 1);
} }
[$proxy, $port] = [$this->getProxyHost(), $this->getProxyPort()];
if (!empty($proxy) && $port > 0) {
curl_setopt($resource, CURLOPT_PROXYPORT, $port);
curl_setopt($resource, CURLOPT_PROXY, $proxy);
}
curl_setopt($resource, CURLOPT_CUSTOMREQUEST, strtoupper($method)); curl_setopt($resource, CURLOPT_CUSTOMREQUEST, strtoupper($method));
$this->client = $resource; $this->client = $resource;
if (!empty($this->caPath)) { if (!empty($this->caPath)) {
+6
View File
@@ -19,6 +19,12 @@ trait TSwooleClient
if ($this->getConnectTimeout() > 0) { if ($this->getConnectTimeout() > 0) {
$params['timeout'] = $this->getConnectTimeout(); $params['timeout'] = $this->getConnectTimeout();
} }
[$proxy, $port] = [$this->getProxyHost(), $this->getProxyPort()];
if (!empty($proxy) && $port > 0) {
$params['http_proxy_host'] = $proxy;
$params['http_proxy_port'] = $port;
}
if (empty($sslCert) || empty($sslKey) || empty($sslCa)) { if (empty($sslCert) || empty($sslKey) || empty($sslCa)) {
return $params; return $params;
} }