请求URL

@param string $url
@param string $data
@param string $header
@param array $option
@return mixed
350715
public static function doCurl($url, $data = null, $header = null, $option = [])
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        
        // 请求头
        empty($header) || curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        
        // HTTPS
        if (strpos($url, 'https://') !== false) {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        
        // 提交数据
        if (! empty($data)) {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, self::transPostFile($data));
        }
        
        // 代理
        if (isset($option['proxy'])) {
            $proxy_config = $option['proxy'];
            curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
            curl_setopt($ch, CURLOPT_PROXY, $proxy_config['host']);
            curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_config['port']);
            isset($proxy_config['user']) && curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxy_config['user'] . ':' . $proxy_config['passwd']);
        }
        
        // 跳转
        isset($option['location']) && curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $option['location']);
        
        // 超时
        isset($option['timeout']) && curl_setopt($ch, CURLOPT_TIMEOUT, $option['timeout']);
        
        // 头信息
        isset($option['header']) && curl_setopt($ch, CURLOPT_HEADER, $option['header']);
        
        $res = curl_exec($ch);
        curl_close($ch);
        return $res;
    }
979766
public static function sendPost($_url, $_data, $_headers = [],
                                    $_return_header = true)
    {
        return self::sendCurl($_url,
                array(
                CURLOPT_SSL_VERIFYHOST => false,
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_FOLLOWLOCATION => 0,
                CURLOPT_POST => 1,
                CURLOPT_POSTFIELDS => $_data,
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                CURLOPT_HTTPHEADER => $_headers,
                CURLOPT_HEADER => $_return_header
        ));
    }
1354459
protected function _doRequest($method, $url, $data, $options)
    {
        $request = $this->_createRequest(
            $method,
            $url,
            $data,
            $options
        );

        return $this->send($request, $options);
    }
240303
public function get($url, $headers = [], $options = [])
    {
        return $this->request('GET', $url, null, $headers, $options);
    }
1073189
protected function call($url, $data, $type = self::TYPE_POST)
    {
        try {
            $options = [
                'query' => [
                    'access_token' => $this->token,
                ],
            ];

            if ($this->secret) {
                $options['query']['appsecret_proof'] = $this->secret;
            }

            switch ($type) {
                case self::TYPE_DELETE:
                case self::TYPE_POST:
                    $options = array_merge($options, [
                        'headers' => [
                            'Content-Type' => 'application/json'
                        ],
                        'body' => json_encode($data),
                    ]);
                    break;
                case self::TYPE_GET:
                    $options['query'] = array_merge($options['query'], $data);
                    break;
            }
            
            $response = $this->client->request(
                $type,
                $url,
                $options
            );

            $this->debug($data, $response->getBody(), $response->getStatusCode());

            return json_decode($response->getBody(), true);
        } catch (ClientException $ex) {
            $this->debug($data, $ex->getResponse()->getBody(), $ex->getResponse()->getStatusCode());

            return json_decode($ex->getResponse()->getBody(), true);
        }
    }
578209
public function delete($url, $data = [])
    {
        $this->setOpt(CURLOPT_URL, $this->_buildURL($url, $data));
        $this->setOpt(CURLOPT_CUSTOMREQUEST, 'DELETE');

        return $this->exec();
    }
1301300
public function options($url, $data = [], array $options = [])
    {
        $options = $this->_mergeOptions($options);
        $url = $this->buildUrl($url, [], $options);

        return $this->_doRequest(Request::METHOD_OPTIONS, $url, $data, $options);
    }
1079526
public function post($url, $data = [])
    {
        $this->setOpt(CURLOPT_URL, $this->_buildURL($url));
        $this->setOpt(CURLOPT_POST, true);
        $this->setOpt(CURLOPT_POSTFIELDS, $this->_postfields($data));

        return $this->exec();
    }
906283
private function exec($url, $data = '', $method = 'post', $header = [])
    {
        $res = false;
        $this->try = 0;
        $this->result = '';
        $this->action('start');

        while ($this->try < $this->tryMax) {
            $this->try++;
            $res = $this->realExec($url, $data, $method, $header);
            if ($res) {
                break;
            }
        }

        $this->action('stop');
        return $res;
    }
1107005
public function head($url, $data = null, $header = [])
    {
        return $this->exec($url, false, 'head', $header);
    }
211227
public function setURL($url, $data = array())
    {
        $this->baseUrl = $url;
        $this->url = $this->buildURL($url, $data);
        $this->setOpt(CURLOPT_URL, $this->url);
    }
1169402
public function delete($url, $data = [], array $options = [])
    {
        $options = $this->_mergeOptions($options);
        $url = $this->buildUrl($url, [], $options);

        return $this->_doRequest(Request::METHOD_DELETE, $url, $data, $options);
    }
772015
public static function postRequest($url, $data)
    {
        $url = str_replace("&amp;", "&", urldecode(trim($url)));

        $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data)));
        $context = stream_context_create($options);

        try {
            $data = @file_get_contents($url, false, $context);
            return $data;
        } catch (\Exception $e) {
            return false;
        }
    }
29670
public function post($url, array $data, array $headers = null)
    {
        $headers = is_null($headers) ? ['Content-Type: application/json; charset=utf-8'] : $headers;
        return $this->sendRequest('POST', $url, $headers, $data);
    }
938022
public function delete($url, $data = null, $headers = [], $options = [])
    {
        return $this->createRequestShortcut('DELETE', $url, $data, $headers, $options);
    }
904372
public function get($url, $data = null, $header = [])
    {
        $url = URLUtil::addParameter($url, $data);
        return $this->exec($url, $data, 'get', $header);
    }
744508
protected static function http($url, $param, $data = '', $method = 'GET'){
        $opts = array(
            CURLOPT_TIMEOUT        => 30,
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_SSL_VERIFYHOST => false,
        );

        /* 根据请求类型设置特定参数 */
        $opts[CURLOPT_URL] = $url . '?' . http_build_query($param);

        if(strtoupper($method) == 'POST'){
            $opts[CURLOPT_POST] = 1;
            $opts[CURLOPT_POSTFIELDS] = $data;

            if(is_string($data)){ //发送JSON数据
                $opts[CURLOPT_HTTPHEADER] = array(
                    'Content-Type: application/json; charset=utf-8',
                    'Content-Length: ' . strlen($data),
                );
            }
        }

        /* 初始化并执行curl请求 */
        $ch = curl_init();
        curl_setopt_array($ch, $opts);
        $data  = curl_exec($ch);
        $error = curl_error($ch);
        curl_close($ch);

        //发生错误，抛出异常
        if($error) throw new \Exception('请求发生错误：' . $error);

        return  $data;
    }