改名
This commit is contained in:
@@ -372,7 +372,7 @@ class Curl
|
|||||||
*/
|
*/
|
||||||
public function get($path, $params = [])
|
public function get($path, $params = [])
|
||||||
{
|
{
|
||||||
return $this->request($path, self::GET, $params);
|
return $this->request($this->joinGetParams($path, $params), self::GET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -467,7 +467,7 @@ class Curl
|
|||||||
return $this->curl_multi[$hash];
|
return $this->curl_multi[$hash];
|
||||||
}
|
}
|
||||||
|
|
||||||
$resource = $this->do(curl_init($host . $path), $host . $path, $method, $params);
|
$resource = $this->do(curl_init($host . $path), $host . $path, $method);
|
||||||
if ($method === self::POST && !empty($params)) {
|
if ($method === self::POST && !empty($params)) {
|
||||||
curl_setopt($resource, CURLOPT_POSTFIELDS, HttpParse::parse($params));
|
curl_setopt($resource, CURLOPT_POSTFIELDS, HttpParse::parse($params));
|
||||||
}
|
}
|
||||||
@@ -479,6 +479,26 @@ class Curl
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $path
|
||||||
|
* @param $params
|
||||||
|
* @return mixed|resource
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function upload($path, $params)
|
||||||
|
{
|
||||||
|
[$host, $isHttps, $path] = $this->matchHost($path);
|
||||||
|
$resource = $this->do(curl_init($host . $path), $host . $path, self::POST);
|
||||||
|
|
||||||
|
@curl_setopt($resource, CURLOPT_POSTFIELDS, $params);
|
||||||
|
|
||||||
|
if ($isHttps !== false) {
|
||||||
|
return $this->execute($this->curlHandlerSslSet($resource));
|
||||||
|
}
|
||||||
|
return $this->execute($resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $resource
|
* @param $resource
|
||||||
* @return bool
|
* @return bool
|
||||||
@@ -506,11 +526,10 @@ class Curl
|
|||||||
* @param $resource
|
* @param $resource
|
||||||
* @param $path
|
* @param $path
|
||||||
* @param $method
|
* @param $method
|
||||||
* @param array $params
|
|
||||||
* @return resource
|
* @return resource
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function do($resource, $path, $method, $params = [])
|
private function do($resource, $path, $method)
|
||||||
{
|
{
|
||||||
curl_setopt($resource, CURLOPT_TIMEOUT, $this->timeout); // 超时设置
|
curl_setopt($resource, CURLOPT_TIMEOUT, $this->timeout); // 超时设置
|
||||||
curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, $this->connection_timeout); // 超时设置
|
curl_setopt($resource, CURLOPT_CONNECTTIMEOUT, $this->connection_timeout); // 超时设置
|
||||||
@@ -532,11 +551,6 @@ class Curl
|
|||||||
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
|
curl_setopt($resource, CURLOPT_FOLLOWLOCATION, TRUE);// 跟踪重定向
|
||||||
curl_setopt($resource, CURLOPT_ENCODING, 'gzip,deflate');
|
curl_setopt($resource, CURLOPT_ENCODING, 'gzip,deflate');
|
||||||
|
|
||||||
$method = strtoupper($method);
|
|
||||||
if ($method === self::GET) {
|
|
||||||
$path = $this->joinGetParams($path, $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($method === self::POST) {
|
if ($method === self::POST) {
|
||||||
curl_setopt($resource, CURLOPT_POST, 1);
|
curl_setopt($resource, CURLOPT_POST, 1);
|
||||||
}
|
}
|
||||||
|
|||||||
+107
@@ -34,6 +34,113 @@ if (!function_exists('make')) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('isUrl')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $url
|
||||||
|
* @param bool $get_info
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
function isUrl($url, $get_info = true)
|
||||||
|
{
|
||||||
|
$queryMatch = '/((http[s]?):\/\/)?(([\w-_]+\.)+\w+(:\d+)?)(\/.*)?/';
|
||||||
|
if (!preg_match($queryMatch, $url, $outPut)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$port = str_replace(':', '', $outPut[5]);
|
||||||
|
|
||||||
|
[$isHttps, $domain, $port, $path] = [$outPut[2] == 'https', $outPut[3], $port, $outPut[6] ?? ''];
|
||||||
|
if ($isHttps && empty($port)) {
|
||||||
|
$port = 443;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($outPut);
|
||||||
|
|
||||||
|
return [$isHttps == 'https', $domain, $port, $path];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('split_request_uri')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $url
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
function split_request_uri($url)
|
||||||
|
{
|
||||||
|
if (($parse = isUrl($url, null)) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
[$isHttps, $domain, $port, $path] = $parse;
|
||||||
|
$uri = $isHttps ? 'https://' . $domain : 'http://' . $domain;
|
||||||
|
if (!empty($port)) {
|
||||||
|
$uri .= ':' . $port;
|
||||||
|
}
|
||||||
|
return [$uri, $path];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('hadDomain')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $url
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
function hadDomain($url)
|
||||||
|
{
|
||||||
|
if (($parse = isUrl($url, null)) === false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
[$isHttps, $domain, $port, $path] = $parse;
|
||||||
|
$uri = $isHttps ? 'https://' . $domain : 'http://' . $domain;
|
||||||
|
if (!empty($port)) {
|
||||||
|
$uri .= ':' . $port;
|
||||||
|
}
|
||||||
|
return $uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!function_exists('isDomain')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $url
|
||||||
|
* @param $replace
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
function isDomain($url)
|
||||||
|
{
|
||||||
|
return !isIp($url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!function_exists('isIp')) {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $url
|
||||||
|
* @return false|array
|
||||||
|
*/
|
||||||
|
function isIp($url)
|
||||||
|
{
|
||||||
|
return preg_match('/(\d{1,3}\.){3}\.\d{1,3}(:\d{1,5})?/', $url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!function_exists('loadByDir')) {
|
if (!function_exists('loadByDir')) {
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user