add clear

This commit is contained in:
2020-08-12 17:16:09 +08:00
parent aeb7a8c4b5
commit b8f240d910
+35 -5
View File
@@ -615,6 +615,35 @@ class HttpClient
}
}
/**
* @param $url
* @param $params
* @return array|mixed|Result
* 上传文件
*/
public function upload($url, $params)
{
try {
$output = $this->curlParse($url, $params);
if ($output === FALSE) {
return new Result(['code' => 500, 'message' => $output]);
}
[$header, $body, $status] = $this->explode($output);
if ($status != 200 && $status != 201) {
$data = new Result(['code' => $status, 'message' => $body, 'header' => $header]);
} else {
$data = $this->structure($body, $params, $header);
}
return $data;
} catch (\Throwable $exception) {
$response['code'] = 500;
$response['message'] = $exception->getMessage();
$response['data'] = array_slice($exception->getTrace(), 0, 6);
$response['header'] = [];
return new Result($response);
}
}
/**
* @param $url
* @param $data
@@ -631,14 +660,15 @@ class HttpClient
if ($headers = $this->parseHeaderMat()) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
if (!empty($this->agent)) {
curl_setopt($ch, CURLOPT_USERAGENT, $this->agent);
}
curl_setopt($ch, CURLOPT_SSLCERT, $this->getSslCertFile());
curl_setopt($ch, CURLOPT_SSLCERT, $this->getSslCertFile());
curl_setopt($ch, CURLOPT_SSLKEY, $this->getSslKeyFile());
if ($this->getSslCertFile()) {
curl_setopt($ch, CURLOPT_SSLCERT, $this->getSslCertFile());
}
if ($this->getSslKeyFile()) {
curl_setopt($ch, CURLOPT_SSLKEY, $this->getSslKeyFile());
}
curl_setopt($ch, CURLOPT_NOBODY, FALSE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 1); // 超时设置
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//返回内容