add clear
This commit is contained in:
+12
-5
@@ -15,6 +15,7 @@ class WxClient
|
|||||||
|
|
||||||
private $url = '';
|
private $url = '';
|
||||||
private $isSSL = false;
|
private $isSSL = false;
|
||||||
|
private $agent = '';
|
||||||
|
|
||||||
const POST = 'post';
|
const POST = 'post';
|
||||||
const GET = 'get';
|
const GET = 'get';
|
||||||
@@ -71,6 +72,11 @@ class WxClient
|
|||||||
$this->url = $url;
|
$this->url = $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAgent(string $agent)
|
||||||
|
{
|
||||||
|
$this->agent = $agent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param bool $isSSL
|
* @param bool $isSSL
|
||||||
*/
|
*/
|
||||||
@@ -165,10 +171,12 @@ class WxClient
|
|||||||
{
|
{
|
||||||
$host = $this->getHostIp();
|
$host = $this->getHostIp();
|
||||||
$client = new Client($host, $port, $this->isSSL);
|
$client = new Client($host, $port, $this->isSSL);
|
||||||
|
if (!empty($this->agent)) {
|
||||||
|
$this->header['User-Agent'] = $this->agent;
|
||||||
|
}
|
||||||
if (!empty($this->header)) {
|
if (!empty($this->header)) {
|
||||||
$client->setHeaders($this->header);
|
$client->setHeaders($this->header);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (strtolower($this->method)) {
|
switch (strtolower($this->method)) {
|
||||||
case self::GET:
|
case self::GET:
|
||||||
$client->get($url);
|
$client->get($url);
|
||||||
@@ -219,25 +227,24 @@ class WxClient
|
|||||||
}
|
}
|
||||||
$url = $url . '?' . $_data;
|
$url = $url . '?' . $_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_TIMEOUT, 5);// 超时设置
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5);// 超时设置
|
||||||
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
curl_setopt($ch, CURLOPT_HEADER, FALSE);
|
||||||
if (!empty($this->header)) {
|
if (!empty($this->header)) {
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
|
||||||
}
|
}
|
||||||
|
if (!empty($this->agent)) {
|
||||||
|
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
|
||||||
|
}
|
||||||
if ($this->isSSL) {
|
if ($this->isSSL) {
|
||||||
curl_setopt($ch, CURLOPT_SSLCERT, $this->header['ssl_cert_file']);
|
curl_setopt($ch, CURLOPT_SSLCERT, $this->header['ssl_cert_file']);
|
||||||
curl_setopt($ch, CURLOPT_SSLKEY, $this->header['ssl_key_file']);
|
curl_setopt($ch, CURLOPT_SSLKEY, $this->header['ssl_key_file']);
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
|
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
|
||||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);// 超时设置
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1);// 超时设置
|
||||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容
|
||||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
|
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
|
||||||
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
|
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
|
||||||
|
|
||||||
return $ch;
|
return $ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user