private function curlConnection($method = 'GET', $url, array $data = null, $timeout, $charset)
 {
     if (strtoupper($method) === 'POST') {
         $postFields = $data ? http_build_query($data, '', '&') : "";
         $contentLength = "Content-length: " . strlen($postFields);
         $methodOptions = array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $postFields);
     } else {
         $contentLength = null;
         $methodOptions = array(CURLOPT_HTTPGET => true);
     }
     $options = array(CURLOPT_HTTPHEADER => array("Content-Type: application/x-www-form-urlencoded; charset=" . $charset, $contentLength), CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CONNECTTIMEOUT => $timeout);
     $options = $options + $methodOptions;
     $curl = curl_init();
     curl_setopt_array($curl, $options);
     $resp = curl_exec($curl);
     $info = curl_getinfo($curl);
     $error = curl_errno($curl);
     $errorMessage = curl_error($curl);
     curl_close($curl);
     $this->setStatus((int) $info['http_code']);
     $this->setResponse((string) $resp);
     if ($error) {
         throw new Exception("CURL can't connect: {$errorMessage}");
         return false;
     } else {
         return true;
     }
 }
 public function query($method, $parameters = null)
 {
     $request = xmlrpc_encode_request($method, $parameters);
     $headers = array("Content-type: text/xml", "Content-length: " . strlen($request));
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->url);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
     if ($this->timeout) {
         curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
     }
     $rawResponse = curl_exec($curl);
     $curlErrno = curl_errno($curl);
     $curlError = curl_error($curl);
     curl_close($curl);
     if ($curlErrno) {
         throw new NetworkException($curlError, $curlErrno);
     }
     $result = xmlrpc_decode($rawResponse);
     if (xmlrpc_is_fault($result)) {
         throw new NetworkException($result['faultString'], $result['faultCode']);
     }
     return $result;
 }
Пример #3
1
 /**
  * 执行一个 HTTP 请求
  *
  * @param string 	$url 	执行请求的URL 
  * @param mixed	$params 表单参数
  * 							可以是array, 也可以是经过url编码之后的string
  * @param mixed	$cookie cookie参数
  * 							可以是array, 也可以是经过拼接的string
  * @param string	$method 请求方法 post / get
  * @param string	$protocol http协议类型 http / https
  * @return array 结果数组
  */
 public static function makeRequest($url, $params, $cookie, $method = 'post', $protocol = 'http')
 {
     $query_string = self::makeQueryString1($params);
     $cookie_string = self::makeCookieString($cookie);
     $ch = curl_init();
     if ('get' == $method) {
         curl_setopt($ch, CURLOPT_URL, "{$url}?{$query_string}");
     } else {
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
     }
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
     // disable 100-continue
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
     if (!empty($cookie_string)) {
         curl_setopt($ch, CURLOPT_COOKIE, $cookie_string);
     }
     if ('https' == $protocol) {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     }
     $ret = curl_exec($ch);
     $err = curl_error($ch);
     if (false === $ret || !empty($err)) {
         $errno = curl_errno($ch);
         $info = curl_getinfo($ch);
         curl_close($ch);
         return array('result' => false, 'errno' => $errno, 'msg' => $err, 'info' => $info);
     }
     curl_close($ch);
     return array('result' => true, 'msg' => $ret);
 }
Пример #4
1
 function curlRequest($ip, $name)
 {
     $qs = 'http://' . $this->service . '/' . $this->version . '/' . $name . '/' . '?ip=' . $ip . '&format=json&key=' . $this->apiKey;
     $app = JFactory::getApplication();
     if (!function_exists('curl_init')) {
         //$app->enqueueMessage('The AcyMailing geolocation plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.','error');
         $this->errors[] = 'The AcyMailing geolocation plugin needs the CURL library installed but it seems that it is not available on your server. Please contact your web hosting to set it up.';
         return false;
     }
     if (!function_exists('json_decode')) {
         //$app->enqueueMessage('The AcyMailing geolocation plugin can only work with PHP 5.2 at least. Please ask your web hosting to update your PHP version','error');
         $this->errors[] = 'The AcyMailing geolocation plugin can only work with PHP 5.2 at least. Please ask your web hosting to update your PHP version';
         return false;
     }
     if (!isset($this->curl)) {
         $this->curl = curl_init();
         curl_setopt($this->curl, CURLOPT_FAILONERROR, TRUE);
         if (@ini_get('open_basedir') == '' && @ini_get('safe_mode' == 'Off')) {
             curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, TRUE);
         }
         curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, $this->timeout);
         curl_setopt($this->curl, CURLOPT_TIMEOUT, $this->timeout);
     }
     curl_setopt($this->curl, CURLOPT_URL, $qs);
     $json = curl_exec($this->curl);
     if (curl_errno($this->curl) || $json === FALSE) {
         $this->errors[] = 'cURL failed. Error: ' . curl_error($this->curl);
         //$app->enqueueMessage('cURL failed. Error: ' . $err);
         return false;
     }
     $response = json_decode($json);
     return $response;
 }
Пример #5
0
 function hash_call($methodName, $nvpStr)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->API_ENDPOINT);
     curl_setopt($ch, CURLOPT_VERBOSE, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     if ($this->USE_PROXY) {
         curl_setopt($ch, CURLOPT_PROXY, $this->PROXY_HOST . ":" . $this->PROXY_PORT);
     }
     $nvpreq = "METHOD=" . urlencode($methodName) . "&VERSION=" . urlencode($this->VERSION) . "&PWD=" . urlencode($this->API_PASSWORD) . "&USER="******"&SIGNATURE=" . urlencode($this->API_SIGNATURE) . $nvpStr;
     curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
     $response = curl_exec($ch);
     $nvpResArray = $this->deformatNVP($response);
     $nvpReqArray = $this->deformatNVP($nvpreq);
     $_SESSION['nvpReqArray'] = $nvpReqArray;
     if (curl_errno($ch)) {
         die("CURL send a error during perform operation: " . curl_errno($ch));
     } else {
         curl_close($ch);
     }
     return $nvpResArray;
 }
Пример #6
0
 static function getPacientInfo(Pacient $pacient)
 {
     $curl = curl_init();
     //инициализация сеанса
     $timeout = 20;
     // кол-во секунд ожидание ответа
     curl_setopt($curl, CURLOPT_URL, self::$omsUrl);
     //урл сайта к которому обращаемся
     curl_setopt($curl, CURLOPT_HEADER, 1);
     //выводим заголовки
     curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
     curl_setopt($curl, CURLOPT_POST, 1);
     //передача данных методом POST
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     //теперь curl вернет нам ответ, а не выведет
     curl_setopt($curl, CURLOPT_POSTFIELDS, array('SecondName' => $pacient->fam, 'FirstName' => $pacient->im, 'MiddleName' => $pacient->ot, "searchType" => "2", 'Birthday' => $pacient->dr));
     curl_setopt($curl, CURLOPT_USERAGENT, 'MSIE 5');
     //эта строчка как-бы говорит: "я не скрипт, я IE5" :)
     curl_setopt($curl, CURLOPT_REFERER, "http://ya.ru");
     //а вдруг там проверяют наличие рефера
     $res = curl_exec($curl);
     if (curl_errno($curl)) {
         return curl_errno($curl);
     } else {
         if (self::isTruePolis($res)) {
             $data = self::getPacientData($res);
             //$pacient->fill($data);
             //print_r($data)
             return $data;
             //return $data;
         } else {
             return false;
         }
     }
 }
Пример #7
0
 function send()
 {
     //check the fields to make sure that they are not NULL
     $this->isComplete();
     $url = $this->host . $this->postPath;
     $postBody = json_encode($this->data);
     $sign = md5("POST" . $url . $postBody . $this->appMasterSecret);
     $url = $url . "?sign=" . $sign;
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $postBody);
     $result = curl_exec($ch);
     $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $curlErrNo = curl_errno($ch);
     $curlErr = curl_error($ch);
     curl_close($ch);
     //print($result . "\r\n");
     if ($httpCode == "0") {
         // Time out
         throw new Exception("Curl error number:" . $curlErrNo . " , Curl error details:" . $curlErr . "\r\n");
     } else {
         if ($httpCode != "200") {
             // We did send the notifition out and got a non-200 response
             throw new Exception("Http code:" . $httpCode . " details:" . $result . "\r\n");
         } else {
             return $result;
         }
     }
 }
Пример #8
0
 /**
  * Fetch JSON data from an HTTP endpoint
  *
  * Parameters
  *  $hostname - the hostname of the endpoint
  *  $port     - the port to connect to
  *  $protocol - the protocol used (http or https)
  *  $url      - the endpoint url on the host
  *
  *  Return an array of the form
  *  [ "errors" => true/false, "details" => "json_decoded data",
  *    "curl_stats" => "stats from the curl call"]
  */
 static function fetch_json($hostname, $port, $protocol, $url)
 {
     $ch = curl_init("{$protocol}://{$hostname}:{$port}{$url}");
     curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     $json = curl_exec($ch);
     $info = curl_getinfo($ch);
     $ret = ["errors" => false];
     if (curl_errno($ch)) {
         $errmsg = "Attempt to hit API failed, sorry. ";
         $errmsg .= "Curl said: " . curl_error($ch);
         return ["errors" => true, "details" => $errmsg];
     } elseif ($info['http_code'] != 200) {
         $errmsg = "Attempt to hit API failed, sorry. ";
         $errmsg .= "Curl said: HTTP Status {$info['http_code']}";
         return ["errors" => true, "details" => $errmsg];
     } else {
         $ret["curl_stats"] = ["{$hostname}:{$port}" => curl_getinfo($ch)];
         $ret["details"] = json_decode($json, true);
     }
     curl_close($ch);
     return $ret;
 }
Пример #9
0
 /**
  * @return array
  * @throws Payone_Api_Exception_InvalidResponse
  */
 protected function doRequest()
 {
     $response = array();
     $urlArray = $this->generateUrlArray();
     $urlHost = $urlArray['host'];
     $urlPath = isset($urlArray['path']) ? $urlArray['path'] : '';
     $urlScheme = $urlArray['scheme'];
     $urlQuery = $urlArray['query'];
     $curl = curl_init($urlScheme . "://" . $urlHost . $urlPath);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $urlQuery);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_TIMEOUT, self::DEFAULT_TIMEOUT);
     $result = curl_exec($curl);
     $this->setRawResponse($result);
     if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
         throw new Payone_Api_Exception_InvalidResponse();
     } elseif (curl_error($curl)) {
         $response[] = "errormessage=" . curl_errno($curl) . ": " . curl_error($curl);
     } else {
         $response = explode("\n", $result);
     }
     curl_close($curl);
     return $response;
 }
Пример #10
0
function post_req($url_str, $username, $password, $headers_arr, $req_str)
{
    fwrite(STDERR, $url_str);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url_str);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req_str);
    // Don't get the headers
    //curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers_arr);
    // execute the request
    $output = curl_exec($ch);
    $errno = curl_errno($ch);
    $error = curl_error($ch);
    if ($errno !== 0) {
        curl_close($ch);
        return array("success" => FALSE, "message" => "Error sending request to service {$url_str}: {$error}");
    }
    $sc_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($sc_code !== 200) {
        $ct = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        curl_close($ch);
        if (strcasecmp($ct, "application/json") == 0) {
            $err_obj = json_decode($output, true);
            return array("success" => FALSE, "message" => $err_obj['user_message']);
        }
        return array("success" => FALSE, "message" => "Service returned http code: {$sc_code}");
    }
    // close curl resource to free up system resources
    curl_close($ch);
    return array("success" => TRUE, "output" => $output);
}
Пример #11
0
/**
 * @brief GET a resource
 *
 * Make the HTTP GET call to retrieve the record pointed to by the URL. 
 *
 * @param url URL of resource
 *
 * @result Contents of resource
 */
function get($url, $userAgent = '', $timeout = 0)
{
    global $config;
    $data = '';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    //curl_setopt ($ch, CURLOPT_HEADER,		  1);
    curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    if ($userAgent != '') {
        curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
    }
    if ($timeout != 0) {
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    }
    if ($config['proxy_name'] != '') {
        curl_setopt($ch, CURLOPT_PROXY, $config['proxy_name'] . ':' . $config['proxy_port']);
    }
    $curl_result = curl_exec($ch);
    //echo $curl_result;
    if (curl_errno($ch) != 0) {
        echo "CURL error: ", curl_errno($ch), " ", curl_error($ch);
    } else {
        $info = curl_getinfo($ch);
        //$header = substr($curl_result, 0, $info['header_size']);
        //echo $header;
        $http_code = $info['http_code'];
        //echo "<p><b>HTTP code=$http_code</b></p>";
        if (HttpCodeValid($http_code)) {
            $data = $curl_result;
        }
    }
    return $data;
}
Пример #12
0
 /**
  * 发送Http请求到推送服务
  * @param String $server
  * @param Array $data
  */
 private static function http($server, $data)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $server);
     curl_setopt($ch, CURLOPT_TIMEOUT, 3);
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     $response = curl_exec($ch);
     if (curl_errno($ch)) {
         throw new \Exception('curl_error  ' . curl_error($ch));
     } else {
         if (strtolower($response) == 'ok') {
             curl_close($ch);
             return true;
         } else {
             if (preg_match('/not\\s+sub/', $response)) {
             } else {
                 $info = curl_getinfo($ch);
                 throw new \Exception('response_error  ' . $response . ' ' . json_encode($info));
             }
         }
     }
     curl_close($ch);
     return false;
 }
Пример #13
0
 /**
  * @inheritdoc
  */
 public function request($action, array $getData = [], array $postData = [])
 {
     try {
         $curlOptions = [CURLOPT_RETURNTRANSFER => true];
         if ($postData) {
             $json = json_encode($postData, JSON_PRETTY_PRINT);
             if ($json === false) {
                 throw new RequesterException('Failed to serialize data into JSON. Data: ' . var_export($postData, true));
             }
             $curlOptions = $curlOptions + [CURLOPT_POSTFIELDS => $json, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Content-Length: ' . strlen($json)]];
         }
         $getParams = $getData ? '?' . http_build_query($getData) : '';
         $curl = curl_init($this->endpoint->getUrl() . $action . $getParams);
         curl_setopt_array($curl, $curlOptions);
         $result = curl_exec($curl);
         if ($result === false) {
             throw new RequesterException(sprintf('cURL error: [%d] %s', curl_errno($curl), curl_error($curl)));
         }
         $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
         curl_close($curl);
     } catch (RequesterException $e) {
         throw $e;
     } catch (\Exception $e) {
         $result = empty($result) ? '' : ', result: ' . $result;
         throw new RequesterException('An error occurred during the transfer' . $result, null, $e);
     }
     if ($httpCode !== 200) {
         throw new RequesterException(sprintf("Request resulted in HTTP code '%d'. Response result:\n%s", $httpCode, $result));
     }
     return new Response($result);
 }
Пример #14
0
 protected function command($cmd, $request)
 {
     $param = '<' . $this->type . ' id="1" res="request" cmd="' . $cmd . '"';
     $request['account'] = empty($request['account']) ? $this->getUsername() : $request['account'];
     $request['pwd_user'] = empty($request['pwd_user']) ? $this->getPassword() : $request['pwd_user'];
     if (!empty($request)) {
         foreach ($request as $key => $value) {
             $param .= ' ' . $key . '="' . $value . '"';
         }
     }
     $param .= "/>";
     $xml = '<?xml version="1.0" standalone="yes"?><root>' . $param . '</root>';
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->url);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
     $response = curl_exec($curl);
     if (!curl_errno($curl)) {
         $info = curl_getinfo($curl);
         //echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];
     } else {
         throw new \Exception(curl_error($curl));
     }
     return simplexml_load_string($response);
 }
Пример #15
0
 public static function callApi($url, $auth_token, $method = 'POST', $data = null)
 {
     $headers = array("Accept: application/json", "Content-Type: application/json");
     if ($auth_token) {
         $headers[] = "Authorization: OAuth oauth_token={$auth_token}";
     }
     $json_data = false;
     if (is_array($data)) {
         $json_data = json_encode($data);
         $headers[] = "Content-Length: " . strlen($json_data);
     }
     $request = HttpRequest::request($url, $method, $json_data, $headers);
     if ($request) {
         $results = json_decode($request);
         if (isset($results->int_err_code)) {
             throw new \ErrorException('There was an error returned from the API: ' . $results->msg . ' (' . $results->int_err_code . ')', 160);
         } elseif (isset($results->err)) {
             throw new \ErrorException('There was an error returned from the API: ' . $results->message . ' (' . $results->err . ')', 160);
         } else {
             return $results;
         }
     } else {
         $error = "API call returned an HTTP status code of " . curl_errno($ch);
         throw new \ErrorException($error, 107);
     }
 }
Пример #16
0
 public function call($xml)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "https://test.ipg-online.com/ipgapi/services");
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
     curl_setopt($ch, CURLOPT_HTTPAUTH, 'CURLAUTH_BASIC');
     curl_setopt($ch, CURLOPT_USERPWD, $this->config->get('firstdata_remote_user_id') . ':' . $this->config->get('firstdata_remote_password'));
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
     curl_setopt($ch, CURLOPT_CAINFO, $this->config->get('firstdata_remote_ca'));
     curl_setopt($ch, CURLOPT_SSLCERT, $this->config->get('firstdata_remote_certificate'));
     curl_setopt($ch, CURLOPT_SSLKEY, $this->config->get('firstdata_remote_key'));
     curl_setopt($ch, CURLOPT_SSLKEYPASSWD, $this->config->get('firstdata_remote_key_pw'));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
     //curl_setopt($ch, CURLOPT_STDERR, fopen(DIR_LOGS . "/headers.txt", "w+"));
     curl_setopt($ch, CURLOPT_VERBOSE, true);
     $response = curl_exec($ch);
     $this->logger('Post data: ' . print_r($this->request->post, 1));
     $this->logger('Request: ' . $xml);
     $this->logger('Curl error #: ' . curl_errno($ch));
     $this->logger('Curl error text: ' . curl_error($ch));
     $this->logger('Curl response info: ' . print_r(curl_getinfo($ch), 1));
     $this->logger('Curl response: ' . $response);
     curl_close($ch);
     return $response;
 }
Пример #17
0
 public function POST($data)
 {
     $this->genPostData($data);
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, $this->url);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
     curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
     curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
     curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
     curl_setopt($curl, CURLOPT_POST, 1);
     curl_setopt($curl, CURLOPT_POSTFIELDS, $this->postData);
     curl_setopt($curl, CURLOPT_TIMEOUT, 30);
     curl_setopt($curl, CURLOPT_HEADER, 0);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     $tmpInfo = curl_exec($curl);
     if (curl_errno($curl)) {
         print "[error] CURL ERROR: " . curl_error($curl) . "\r\n";
     }
     curl_close($curl);
     $this->returnCode = ord($tmpInfo[0]) * 64 + ord($tmpInfo[1]);
     if ($this->returnCode === 0) {
         $this->retData = substr($tmpInfo, 8);
     }
 }
Пример #18
0
 private static function sendRequest($request)
 {
     $t1 = microtime(true);
     $ch = curl_init();
     $options = array(CURLOPT_USERAGENT => self::userAgent(), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADER => true, CURLOPT_NOBODY => false, CURLOPT_CUSTOMREQUEST => $request->method, CURLOPT_URL => $request->url);
     if (!empty($request->headers)) {
         $headers = array();
         foreach ($request->headers as $key => $val) {
             array_push($headers, "{$key}: {$val}");
         }
         $options[CURLOPT_HTTPHEADER] = $headers;
     }
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
     if (!empty($request->body)) {
         $options[CURLOPT_POSTFIELDS] = $request->body;
     }
     curl_setopt_array($ch, $options);
     $result = curl_exec($ch);
     $t2 = microtime(true);
     $duration = round($t2 - $t1, 3);
     $ret = curl_errno($ch);
     if ($ret !== 0) {
         $r = new Response(-1, $duration, array(), null, curl_error($ch));
         curl_close($ch);
         return $r;
     }
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
     $headers = self::parseHeaders(substr($result, 0, $header_size));
     $body = substr($result, $header_size);
     curl_close($ch);
     return new Response($code, $duration, $headers, $body, null);
 }
Пример #19
0
 public function actionPost($url, $params, $multipart = FALSE, $version = CURL_HTTP_VERSION_NONE)
 {
     if (function_exists('curl_init')) {
         $ch = curl_init();
         $timeout = 60;
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_HTTP_VERSION, $version);
         curl_setopt($ch, CURLOPT_POST, TRUE);
         if ($multipart) {
             curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         } else {
             curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
         }
         curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
         $data = curl_exec($ch);
         if ($data === FALSE) {
             throw new Exception(curl_errno($ch));
         }
         curl_close($ch);
         return $data;
     } else {
         return FALSE;
     }
 }
Пример #20
0
function exec_curl_request($handle)
{
    $response = curl_exec($handle);
    if ($response === false) {
        $errno = curl_errno($handle);
        $error = curl_error($handle);
        error_log("Curl retornou um erro {$errno}: {$error}\n");
        curl_close($handle);
        return false;
    }
    $http_code = intval(curl_getinfo($handle, CURLINFO_HTTP_CODE));
    curl_close($handle);
    if ($http_code >= 500) {
        // do not wat to DDOS server if something goes wrong
        sleep(10);
        return false;
    } else {
        if ($http_code != 200) {
            $response = json_decode($response, true);
            error_log("Request has failed with error {$response['error_code']}: {$response['description']}\n");
            if ($http_code == 401) {
                throw new Exception('Invalid access token provided');
            }
            return false;
        } else {
            $response = json_decode($response, true);
            if (isset($response['description'])) {
                error_log("Request was successfull: {$response['description']}\n");
            }
            $response = $response['result'];
        }
    }
    return $response;
}
Пример #21
0
 public function pdt($txn)
 {
     $params = array('at' => $this->atPaypal, 'tx' => $txn, 'cmd' => '_notify-synch');
     $content = '';
     foreach ($params as $key => $val) {
         $content .= '&' . $key . '=' . urlencode($val);
     }
     $c = curl_init();
     curl_setopt($c, CURLOPT_URL, $this->paypalEndpoint);
     curl_setopt($c, CURLOPT_VERBOSE, TRUE);
     curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
     curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($c, CURLOPT_POST, 1);
     curl_setopt($c, CURLOPT_POSTFIELDS, $content);
     $response = curl_exec($c);
     if (!$response) {
         echo "FAILED: " . curl_error($c) . "(" . curl_errno($c) . ")";
         curl_close($c);
         return false;
     } else {
         $str = urldecode($response);
         $res = explode("\n", strip_tags($str));
         $result = array();
         foreach ($res as $val) {
             $r = explode("=", $val);
             if (count($r) > 1) {
                 $result[$r[0]] = $r[1];
             }
         }
         curl_close($c);
         return $result;
     }
 }
Пример #22
0
 public function call($data)
 {
     if ($this->config->get('pp_express_test') == 1) {
         $api_endpoint = 'https://api-3t.sandbox.paypal.com/nvp';
         $user = $this->config->get('pp_express_sandbox_username');
         $password = $this->config->get('pp_express_sandbox_password');
         $signature = $this->config->get('pp_express_sandbox_signature');
     } else {
         $api_endpoint = 'https://api-3t.paypal.com/nvp';
         $user = $this->config->get('pp_express_username');
         $password = $this->config->get('pp_express_password');
         $signature = $this->config->get('pp_express_signature');
     }
     $settings = array('USER' => $user, 'PWD' => $password, 'SIGNATURE' => $signature, 'VERSION' => '109.0', 'BUTTONSOURCE' => 'Code4Fun_2.0_EC');
     $this->log($data, 'Call data');
     $defaults = array(CURLOPT_POST => 1, CURLOPT_HEADER => 0, CURLOPT_URL => $api_endpoint, CURLOPT_USERAGENT => "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1", CURLOPT_FRESH_CONNECT => 1, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FORBID_REUSE => 1, CURLOPT_TIMEOUT => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0, CURLOPT_POSTFIELDS => http_build_query(array_merge($data, $settings), '', "&"));
     $ch = curl_init();
     curl_setopt_array($ch, $defaults);
     if (!($result = curl_exec($ch))) {
         $this->log(array('error' => curl_error($ch), 'errno' => curl_errno($ch)), 'cURL failed');
     }
     $this->log($result, 'Result');
     curl_close($ch);
     return $this->cleanReturn($result);
 }
Пример #23
0
 function getUrl($url)
 {
     $this->lastUrl = $url;
     //echo "GET $url \n";
     // Faire un get mais en fournissant les cookies de session et tout ...
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HTTPGET, 1);
     //curl_setopt($ch, CURLOPT_VERBOSE, 1);
     curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie_file);
     // pour envoi des cookies
     curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie_file);
     // pour reception des cookies
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux i686; fr; rv:1.9.1.1) Gecko/20090715 Firefox/3.5.1");
     //curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $redirect = 0;
     $getResult = $this->curl_redirect_exec($ch, $redirect);
     //echo "$redirect redirection ! \n";
     if (curl_errno($ch)) {
         print curl_error($ch);
     }
     curl_close($ch);
     return $getResult;
 }
Пример #24
0
 public static function curlFetch($url = '', $http_post = false, $postData = array(), $curlOpts = array())
 {
     $url = trim($url);
     if ($url == '') {
         return false;
     }
     # ========================================================
     # Curl get/post to a specific url
     # ========================================================
     $ch = curl_init();
     if ($ch) {
         # init success! Now, set options
         $options = array(CURLOPT_URL => $url, CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_FOLLOWLOCATION => true, CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36', CURLOPT_ENCODING => 'gzip', CURLOPT_TIMEOUT => 15);
         $options = $curlOpts + $options;
         if ($http_post) {
             $options[CURLOPT_POST] = true;
             $options[CURLOPT_POSTFIELDS] = $postData;
         }
         curl_setopt_array($ch, $options);
         $res = curl_exec($ch);
         if (curl_errno($ch) == 0) {
             # request successful! Response is in $res
             curl_close($ch);
             return $res;
         } else {
             # request failed!
             curl_close($ch);
             return false;
         }
     } else {
         # curl init failed
         return false;
     }
 }
Пример #25
0
function login($email = null, $password = null)
{
    //brian@sufferhub.com
    //BiteMe123!
    //set url for curl
    $url = "https://www.strava.com/api/v2/authentication/login";
    //set post fields
    $fields = array('email' => urlencode($email), 'password' => urlencode($password));
    foreach ($fields as $key => $value) {
        $fields_string .= $key . '=' . $value . '&';
    }
    rtrim($fields_string, '&');
    //set curl options
    $options = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HEADER => false, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => "", CURLOPT_USERAGENT => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)", CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => 120, CURLOPT_TIMEOUT => 120, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields_string);
    //get curl results
    $ch = curl_init($url);
    curl_setopt_array($ch, $options);
    $content = curl_exec($ch);
    $err = curl_errno($ch);
    $errmsg = curl_error($ch);
    $header = curl_getinfo($ch);
    curl_close($ch);
    //decode result
    $data = json_decode($content);
    if (isset($data->token)) {
        //check if the authentication was a success
        //save auth data in a fsession
        $_SESSION['id'] = $data->athlete->id;
        $_SESSION['token'] = $data->token;
        return true;
    } else {
        return false;
    }
}
Пример #26
0
 /**
  * Выполнить запрос
  * @param $command - команда
  * @param array $params - параметры команды
  * @return NssResponse
  */
 public function request($command, array $params = [])
 {
     if (empty($this->ip)) {
         throw new InvalidParamException('IP not defined.');
     }
     if (empty($this->port)) {
         throw new InvalidParamException('Port not defined.');
     }
     $ch = curl_init($this->ip);
     curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER => 1, CURLOPT_PROXY => false, CURLOPT_TIMEOUT => $this->timeout, CURLOPT_CONNECTTIMEOUT => $this->connectTimeout, CURLOPT_PORT => $this->port, CURLOPT_POSTFIELDS => $this->createBody($command, $params)]);
     $this->answer = @curl_exec($ch);
     if (curl_errno($ch) || empty($this->answer)) {
         $this->answer = new NssResponse();
         $this->answer->error = 'По техническим причинам функция недоступна. Попробуйте позже.';
         Yii::error(curl_error($ch), 'nss-direct');
     } else {
         $this->answer = @simplexml_load_string($this->answer);
         if ($this->answer === false) {
             $this->answer = new NssResponse();
             $this->answer->error = 'От сервера пришел неверный ответ.';
         }
     }
     curl_close($ch);
     return $this->answer;
 }
Пример #27
0
 /**
  * Makes a request to the FetchApp API.
  * This function is adaptated from
  * <a href="https://github.com/jasontwong/fetchapp">jasontwong's FetchApp Library</a>
  * @param $url
  * @param $method
  * @param null $data
  * @return mixed
  * @throws \Exception
  */
 public static function makeRequest($url, $method, $data = null)
 {
     $credentials = self::$AuthenticationKey . ':' . self::$AuthenticationToken;
     $headers = array('Content-type: application/xml', 'Authorization: Basic ' . base64_encode($credentials));
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_TIMEOUT, 600);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
     if (!is_null($data)) {
         // Apply the XML to our curl call
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     }
     $ch_data = curl_exec($ch);
     if (curl_errno($ch)) {
         throw new \Exception(curl_error($ch));
     }
     curl_close($ch);
     if (trim($ch_data)) {
         if ($ch_data == "Couldn't authenticate you") {
             throw new \Exception($ch_data);
         } else {
             return simplexml_load_string($ch_data);
         }
         return simplexml_load_string($ch_data);
     } else {
         return false;
     }
 }
Пример #28
0
 /**
  * Make an api request
  *
  * @param string $resource
  * @param array $params
  * @param string $method
  */
 public function call($resource, $params = array())
 {
     $queryString = 'access_token=' . $this->getAccessToken();
     if (!empty($params) && is_array($params)) {
         $queryString .= http_build_query($params);
     }
     $requestUrl = self::API_URL . $resource . '/?' . $queryString;
     $curl = curl_init();
     $curl_options = array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $requestUrl, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => array('Accept: application/json', 'appid: nike'));
     curl_setopt_array($curl, $curl_options);
     $response = curl_exec($curl);
     $curl_info = curl_getinfo($curl);
     //@todo test for curl error
     if ($response === FALSE) {
         throw new Exception(curl_error($curl), curl_errno($curl));
     }
     curl_close($curl);
     //@todo test for any non 200 response
     if ($curl_info['http_code'] != 200) {
         throw new Exception("Response: Bad response - HTTP Code:" . $curl_info['http_code']);
     }
     $jsonArray = json_decode($response);
     if (!is_object($jsonArray)) {
         throw new Exception("Response: Response was not a valid response");
     }
     return $jsonArray;
 }
Пример #29
0
 public function success()
 {
     $this->load_library('http_lib', 'http');
     if (!isset($_GET['payment_id'])) {
         $this->http->response_code(400);
         exit;
     }
     global $payment_cfg;
     $id = urlencode($_GET['payment_id']);
     $url = $payment_cfg['ttt']['api_url'] . $id . '/';
     $ch = curl_init();
     //curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $payment_cfg['ttt']['api_headers']);
     $response = curl_exec($ch);
     $curl_error = curl_errno($ch);
     curl_close($ch);
     $response_array = json_decode($return, true);
     if (@$response_array['success']) {
         $nick = $response_array['payment']['custom_fields']['Field_12972']['value'];
         $status = $response_array['payment']['status'];
         $payment_id = $_GET['payment_id'];
         $payment_data = $response;
         $this->model->ttt_payment_success($payment_id, $nick, $status == 'Credit' ? 'success' : 'failed', $payment_data);
     }
     $this->http->redirect(base_url() . "litcafe/ttt-workshop/register/");
 }
Пример #30
-1
 /**
  * Make API request
  *
  * @param string $method string API method to request
  * @param array $params Additional request parameters
  * @return array / boolean Response array / boolean false on failure
  */
 public function request($method, $params = array())
 {
     $this->_errors = array();
     if (empty($method)) {
         //Check if API method is not empty
         $this->_errors = array('API method is missing');
         return false;
     }
     //Our request parameters
     $requestParams = array('METHOD' => $method, 'VERSION' => $this->_version) + $this->_credentials;
     //Building our NVP string
     $request = http_build_query($requestParams + $params);
     //cURL settings
     $curlOptions = array(CURLOPT_URL => $this->_endPoint, CURLOPT_VERBOSE => 1, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_CAINFO => dirname(__FILE__) . '/cacert.pem', CURLOPT_RETURNTRANSFER => 1, CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $request);
     $ch = curl_init();
     curl_setopt_array($ch, $curlOptions);
     //Sending our request - $response will hold the API response
     $response = curl_exec($ch);
     //Checking for cURL errors
     if (curl_errno($ch)) {
         $this->_errors = curl_error($ch);
         curl_close($ch);
         return false;
         //Handle errors
     } else {
         curl_close($ch);
         $responseArray = array();
         parse_str($response, $responseArray);
         // Break the NVP string to an array
         return $responseArray;
     }
 }