This commit is contained in:
2026-06-12 23:57:21 +08:00
parent 1d9d761798
commit 7bcb789ed2
6 changed files with 698 additions and 785 deletions
+21 -21
View File
@@ -44,15 +44,15 @@ class CurlClient extends ClientAbstracts
*/
private function getCurlHandler(string $path, string $method, $params): void
{
$host = $this->isSSL() ? 'https://' . $this->getHost() : 'http://' . $this->getHost();
$host = $this->isSSL ? 'https://' . $this->host : 'http://' . $this->host;
if ($this->getPort() != 443 && $this->getPort() != 80) {
$host .= ':' . $this->getPort();
}
$this->do(curl_init($host . $path), $host . $path, $method);
if ($this->isSSL()) {
if ($this->isSSL) {
$this->curlHandlerSslSet();
}
$contents = $this->getData();
$contents = $this->_data;
if (empty($params) && empty($contents)) {
return;
}
@@ -75,14 +75,14 @@ class CurlClient extends ClientAbstracts
*/
private function curlHandlerSslSet(): void
{
if (!empty($this->getSslKeyFile()) && file_exists($this->getSslKeyFile())) {
curl_setopt($this->client, CURLOPT_SSLKEY, $this->getSslKeyFile());
if (!empty($this->ssl_key_file) && file_exists($this->ssl_key_file)) {
curl_setopt($this->client, CURLOPT_SSLKEY, $this->ssl_key_file);
}
if (!empty($this->getSslCertFile()) && file_exists($this->getSslCertFile())) {
curl_setopt($this->client, CURLOPT_SSLCERT, $this->getSslCertFile());
if (!empty($this->ssl_cert_file) && file_exists($this->ssl_cert_file)) {
curl_setopt($this->client, CURLOPT_SSLCERT, $this->ssl_cert_file);
}
if (!empty($this->getCa()) && file_exists($this->getCa())) {
curl_setopt($this->client, CURLOPT_CAINFO, $this->getCa());
if (!empty($this->ca) && file_exists($this->ca)) {
curl_setopt($this->client, CURLOPT_CAINFO, $this->ca);
}
}
@@ -97,8 +97,8 @@ class CurlClient extends ClientAbstracts
private function do(mixed $resource, string $path, string $method): void
{
curl_setopt($resource, CURLOPT_URL, $path);
curl_setopt($resource, CURLOPT_TIMEOUT, $this->getTimeout()); // 超时设置
curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, $this->getConnectTimeout()); // 超时设置
curl_setopt($resource, CURLOPT_TIMEOUT, $this->timeout); // 超时设置
curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout); // 超时设置
curl_setopt($resource, CURLOPT_HEADER, TRUE);
curl_setopt($resource, CURLOPT_FAILONERROR, TRUE);
curl_setopt($resource, CURLOPT_HTTPHEADER, $this->parseHeaderMat());
@@ -107,8 +107,8 @@ class CurlClient extends ClientAbstracts
}
curl_setopt($resource, CURLOPT_FORBID_REUSE, FALSE);
curl_setopt($resource, CURLOPT_FRESH_CONNECT, FALSE);
if (!empty($this->getAgent())) {
curl_setopt($resource, CURLOPT_USERAGENT, $this->getAgent());
if (!empty($this->agent)) {
curl_setopt($resource, CURLOPT_USERAGENT, $this->agent);
}
curl_setopt($resource, CURLOPT_NOBODY, FALSE);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
@@ -117,7 +117,7 @@ class CurlClient extends ClientAbstracts
if ($method === self::POST || $method == self::UPLOAD) {
curl_setopt($resource, CURLOPT_POST, 1);
}
[$proxy, $port] = [$this->getProxyHost(), $this->getProxyPort()];
[$proxy, $port] = [$this->proxyHost, $this->proxyPort];
if (!empty($proxy) && $port > 0) {
curl_setopt($resource, CURLOPT_PROXYPORT, $port);
curl_setopt($resource, CURLOPT_PROXY, $proxy);
@@ -157,8 +157,8 @@ class CurlClient extends ClientAbstracts
if ($output !== FALSE) {
$this->explode($output);
} else {
$this->setStatusCode(curl_errno($this->client));
$this->setBody(curl_error($this->client));
$this->statusCode = curl_errno($this->client);
$this->body = curl_error($this->client);
}
$this->close();
}
@@ -175,8 +175,8 @@ class CurlClient extends ClientAbstracts
$this->execute();
} else {
$this->setStatusCode(curl_errno($this->client));
$this->setBody(curl_error($this->client));
$this->statusCode = curl_errno($this->client);
$this->body = curl_error($this->client);
}
}
@@ -207,8 +207,8 @@ class CurlClient extends ClientAbstracts
if (in_array($statusCode, [502, 404])) {
$this->retry();
} else {
$this->setStatusCode($statusCode);
$this->setBody(substr($output, $headerSize));
$this->statusCode = $statusCode;
$this->body = substr($output, $headerSize);
$this->setResponseHeader(explode("\r\n", $header));
}
}
@@ -220,7 +220,7 @@ class CurlClient extends ClientAbstracts
private function parseHeaderMat(): array
{
$headers = [];
foreach ($this->getHeader() as $key => $val) {
foreach ($this->header as $key => $val) {
$headers[$key] = $key . ': ' . $val;
}
return array_values($headers);