请求的统一接口。

@param $method
@param $url
@param $options
@return Response
@throws \Exception
160100
public function request($method, $url, $options)
    {
        $this->_curl = curl_init();
        $this->setUrl($url);
        $this->_setHttpVersionOption();
        $this->setHttpMethodOption($method);
        if (is_array($options) && !empty($options)) {
            self::setOptions($this->_curl, $options);
        }
        return new Response($this->_curl);
    }
1249794
public function getRequest($method, $url, array $options = [])
    {
        return $this->createRequest($method, $url, null, $options);
    }
593038
public function execute($method, $url, array $post = array())
	{
		$curl = curl_init($url);

		curl_setopt($curl, CURLOPT_FOLLOWLOCATION, TRUE);
		curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
		curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
		curl_setopt($curl, CURLOPT_USERAGENT, $this->user_agent());

		if ($post)
		{
			curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
		}

		$response = curl_exec($curl);

		if ($response === FALSE OR curl_getinfo($curl, CURLINFO_HTTP_CODE) !== 200)
		{
			throw new Exception_Curl('Curl: Download Error: :error, status :status on url :url', array(':url' => $url, ':status' => curl_getinfo($curl, CURLINFO_HTTP_CODE), ':error' => curl_error($curl)));
		}

		$this->_current_url = urldecode(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));

		return $response;
	}
625913
protected function buildRequest(string $method, string $url, array $options = []): array
    {
        if ($this->forcedAcceptJson) {
            $this->headers['accept'] = 'application/json';
        }
        if (count($this->headers) > 0) {
            if (!array_key_exists(RequestOptions::HEADERS, $options) || !is_array($options[RequestOptions::HEADERS])) {
                $options[RequestOptions::HEADERS] = [];
            }
            foreach ($this->headers as $headerName => $headerValue) {
                $options[RequestOptions::HEADERS][$headerName] = $headerValue;
            }
        }

        $options = $this->addAuthHeader($options);

        return [
            self::OPTION_METHOD => $method,
            self::OPTION_URL => $this->buildUrl($url),
            self::OPTION_OPTIONS => $options
        ];
    }
603257
protected function request($url, $method = self::GET, $params = array(), $options = array())
    {
        if (is_array($params)) {
            if ($method === self::GET || $method === self::DELETE) {
                $url .= (stripos($url, '?') ? '&' : '?').http_build_query($params);
                $params = '';
            } elseif (($method === self::POST || $method === self::PUT || $method === self::PATCH)
                && (empty($options['files']) && empty($options['json']) )
                && !is_string($params)
            ) {
                $params = http_build_query($params);
            }
        }

        curl_setopt($this->curl, CURLOPT_HEADER, 1);
        curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);

        curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($this->curl, CURLOPT_URL, $url);

        // 使用证书
        if (isset($options['sslcert_path']) && isset($options['sslkey_path'])) {
            if (!file_exists($options['sslcert_path']) || !file_exists($options['sslkey_path'])) {
                throw new \Exception('Certfile is not correct');
            }

            // 设置证书
            // 使用证书：cert 与 key 分别属于两个.pem文件
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, true);

            // 严格校验
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($this->curl, CURLOPT_SSLCERTTYPE, 'PEM');
            curl_setopt($this->curl, CURLOPT_SSLCERT, $options['sslcert_path']);
            curl_setopt($this->curl, CURLOPT_SSLKEYTYPE, 'PEM');
            curl_setopt($this->curl, CURLOPT_SSLKEY, $options['sslkey_path']);
        } else {
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
        }

        // Check for files
        if (isset($options['files']) && count($options['files'])) {
            foreach ($options['files'] as $index => $file) {
                $params[$index] = $this->createCurlFile($file);
            }

            version_compare(PHP_VERSION, '5.5', '>') || curl_setopt($this->curl, CURLOPT_SAFE_UPLOAD, false);

            curl_setopt($this->curl, CURLOPT_POST, 1);
            curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
        } else {
            if (isset($options['json'])) {
                $params = json_encode($params, JSON_UNESCAPED_UNICODE);
                $options['headers'][] = 'content-type:application/json';
            }

            if (!empty($params)) {
                curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
            }
        }

        // Check for custom headers
        if (isset($options['headers']) && count($options['headers'])) {
            curl_setopt($this->curl, CURLOPT_HTTPHEADER, $options['headers']);
        }

        // Check for custom headers
        if (isset($options['timeout'])) {
            curl_setopt($this->curl, CURLOPT_TIMEOUT, $options['timeout']);
        }

        // Check for basic auth
        if (isset($options['auth']['type']) && 'basic' === $options['auth']['type']) {
            curl_setopt($this->curl, CURLOPT_USERPWD, $options['auth']['username'].':'.$options['auth']['password']);
        }

        $response = $this->doCurl();

        // Separate headers and body
        $headerSize = $response['curl_info']['header_size'];
        $header = substr($response['response'], 0, $headerSize);
        $body = substr($response['response'], $headerSize);

        return (object)array(
            'curl_info'    => $response['curl_info'],
            'content_type' => $response['curl_info']['content_type'],
            'status_code'  => $response['curl_info']['http_code'],
            'headers'      => $this->splitHeaders($header),
            'body'         => $body,
        );
    }
800246
public function send(string $method, string $url, array $options): HttpResponse
    {
        try {
            return new HttpResponse($this->buildClient()->request($method, $url, $this->mergeOptions([
                'query' => $this->parseQueryParams($url),
            ], $options)));
        } catch (\GuzzleHttp\Exception\ConnectException $e) {
            throw new Exceptions\ConnectionException($e->getMessage(), 0, $e);
        }
    }
403167
public function getGuzzleResponse(
        string $uri,
        array $options = [],
        string $method = GuzzleClientInterface::METHOD_GET
    ): ResponseInterface {
        try {
            return $this->request(
                $method,
                $uri,
                $options
            );
        } catch (GuzzleException $e) {
            throw new GuzzleClientException($e);
        }
    }
115406
private function request(string $method, string $url, array $options = [])
    {
        try {
            $response = $this->guzzleClient->request($method, $url, $options);
        } catch (RequestException $exception) {
            ResultProcessor::handleGuzzleRequestException($exception);
        }

        return ResultProcessor::processResult($url, $response);
    }
917006
public function request($method, $uri = null, array $options = [])
    {
        return $this->doRequest($method, $uri, $options);
    }
1138130
private function request($method, $uri, array $options = array())
    {
        $options['auth'] = array($this->accessKey, $this->secretKey);

        return $this->httpClient->request($method, $uri, $options);
    }
1286517
public function request($method, $uri, $options = [])
    {
        if ($this->authorization !== null) {
            $authHeader = sprintf('%s %s', $this->authorization->getAuthType(), $this->authorization->getCredentials());
            $headers = isset($options['headers']) ? $options['headers'] : [];
            $headers['Authorization'] = $authHeader;
            $options['headers'] = $headers;
        }

        if (!isset($options['retries'])) {
            $options['retries'] = $this->maxRetries;
        }

        return $this->requestHub($method, $uri, $options);
    }
1187411
protected function request($method, $endpoint, $options = [])
    {
        return $this->unwrapResponse($this->getHttpClient($this->getBaseOptions())->{$method}($endpoint, $options));
    }
1043481
public function get($url, $params = array(), $options = array())
    {
        $client = new \GuzzleHttp\Client($options);
        $query = $this->getQueryParam4AccessToken();
        $params = array_merge($params, $query);
        $response = $client->get($url, array(
            'query' => $params
        ));
        if ($this->isSuccessful($response)) {
            return $this->getJson($response); // $response->json();
        } else {
            throw new Exception("微信服务器未有效的响应请求");
        }
    }
401339
private function _request(string $method, array $params = [], array $optional = [])
    {
        $url = $this->_parseUrl($method, $params + $optional);
        if ($url === false) {
            throw new InvalidRequestException('Could not parse URL!');
        }

        $req = Request::get($url);
        $req->strict_ssl = $this->_verifySsl;
        $req->max_redirects = $this->_maxRedirects;
        $req->setConnectionTimeout(5);

        try {
            $buffer = $req->send();
        } catch (ConnectionErrorException $e) {
            throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e);
        }

        if (!empty($buffer)) {
            try {
                return $this->_finishResponse($this->_parseResponse($buffer), $method, $params + $optional);
            } catch (InvalidResponseException $e) {
                throw new InvalidRequestException($e->getMessage(), $e->getCode(), $e);
            }
        }

        throw new InvalidRequestException('Empty response!');
    }
138019
public function sendRequest(
        MethodInterface $method,
        $requestMethod,
        $url,
        array $options = []
    ) {
        try {
            $response = $this->client->request($requestMethod, $url, $options);
            return json_decode($response->getBody(), true);
        } catch (ClientException $e) {
            throw $this->mapper->get($e, $method);
        } catch (\Exception $e) {
            throw new Exception\UnexpectedError('Unexpected error', $e->getCode(), $e);
        }
    }
287374
protected function sendRequest($url, $method = 'get', array $options = [])
    {
        return $this->send(
          new Request($method, $url),
          $this->client,
          $options
        );
    }
188866
public static function doRequest($method, $url, $options = [])
    {
        $curl = curl_init();
        // GET参数设置
        if (!empty($options['query'])) {
            $url .= (stripos($url, '?') !== false ? '&' : '?') . http_build_query($options['query']);
        }
        // CURL头信息设置
        if (!empty($options['headers'])) {
            curl_setopt($curl, CURLOPT_HTTPHEADER, $options['headers']);
        }
        // POST数据设置
        if (strtolower($method) === 'post') {
            curl_setopt($curl, CURLOPT_POST, true);
            curl_setopt($curl, CURLOPT_POSTFIELDS, self::_buildHttpData($options['data']));
        }
        // 证书文件设置
        if (!empty($options['ssl_cer'])) if (file_exists($options['ssl_cer'])) {
            curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM');
            curl_setopt($curl, CURLOPT_SSLCERT, $options['ssl_cer']);
        } else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_cer]");
        // 证书文件设置
        if (!empty($options['ssl_key'])) if (file_exists($options['ssl_key'])) {
            curl_setopt($curl, CURLOPT_SSLKEYTYPE, 'PEM');
            curl_setopt($curl, CURLOPT_SSLKEY, $options['ssl_key']);
        } else throw new InvalidArgumentException("Certificate files that do not exist. --- [ssl_key]");
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
        list($content) = [curl_exec($curl), curl_close($curl)];
        // 清理 CURL 缓存文件
        if (!empty(self::$cache_curl)) foreach (self::$cache_curl as $key => $file) {
            Tools::delCache($file);
            unset(self::$cache_curl[$key]);
        }
        return $content;
    }