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;
 }
function sendPushNotificationToGCM($registration_ids, $message)
{
    $GCM_SERVER_API_KEY = $_ENV["GCM_SERVER_API_KEY"];
    $url = 'https://fcm.googleapis.com/fcm/send';
    $fields = array('registration_ids' => $registration_ids, 'data' => $message);
    // Update your Google Cloud Messaging API Key
    if (!defined('GOOGLE_API_KEY')) {
        define("GOOGLE_API_KEY", $GCM_SERVER_API_KEY);
    }
    $headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
Example #4
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);
 }
Example #5
0
 public function getUserInfo()
 {
     $url = 'https://api.github.com/user?' . http_build_query(array('access_token' => $this->token->access_token));
     // Create a curl handle to a non-existing location
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //Set curl to return the data instead of printing it to the browser.
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
     # timeout after 10 seconds, you can increase it
     curl_setopt($ch, CURLOPT_URL, $url);
     #set the url and get string together
     curl_setopt($ch, CURLOPT_USERAGENT, 'dukt-oauth');
     #set the url and get string together
     $json = '';
     if (($json = curl_exec($ch)) === false) {
         throw new \Exception(curl_error($ch));
     }
     curl_close($ch);
     $user = json_decode($json);
     if (!isset($user->id)) {
         throw new \Exception($json);
     }
     // Create a response from the request
     return array('uid' => $user->id, 'nickname' => $user->login, 'name' => $user->name, 'email' => $user->email, 'urls' => array('GitHub' => 'http://github.com/' . $user->login, 'Blog' => $user->blog));
 }
Example #6
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;
 }
Example #7
0
 function make_call($call_options)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $call_options['route']);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
     curl_setopt($ch, CURLOPT_USERPWD, $call_options['credentials']);
     curl_setopt($ch, CURLOPT_USERAGENT, $call_options['userAgent']);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ' . $call_options['contentType']));
     switch ($call_options['method']) {
         case CS_REST_PUT:
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CS_REST_PUT);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Length: ' . strlen($call_options['data'])));
             curl_setopt($ch, CURLOPT_POSTFIELDS, $call_options['data']);
             break;
         case CS_REST_POST:
             curl_setopt($ch, CURLOPT_POST, true);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $call_options['data']);
             break;
         case CS_REST_DELETE:
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, CS_REST_DELETE);
             break;
     }
     $response = curl_exec($ch);
     if (!$response && $response !== '') {
         trigger_error('Error making request with curl_error: ' . curl_error($ch));
     }
     $this->_log->log_message('API Call Info for ' . $call_options['method'] . ' ' . curl_getinfo($ch, CURLINFO_EFFECTIVE_URL) . ': ' . curl_getinfo($ch, CURLINFO_SIZE_UPLOAD) . ' bytes uploaded. ' . curl_getinfo($ch, CURLINFO_SIZE_DOWNLOAD) . ' bytes downloaded' . ' Total time (seconds): ' . curl_getinfo($ch, CURLINFO_TOTAL_TIME), get_class($this), CS_REST_LOG_VERBOSE);
     $result = array('code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), 'response' => $response);
     curl_close($ch);
     return $result;
 }
Example #8
0
 private function _processXmlResponse($url, $xml = '')
 {
     /* 
     A private utility method used by other public methods to process XML responses.
     */
     if (extension_loaded('curl')) {
         $ch = curl_init() or die(curl_error());
         $timeout = 10;
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
         if (!empty($xml)) {
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/xml', 'Content-length: ' . strlen($xml)));
         }
         $data = curl_exec($ch);
         curl_close($ch);
         if ($data) {
             return new \SimpleXMLElement($data);
         } else {
             return false;
         }
     }
     if (!empty($xml)) {
         throw new Exception('Set xml, but curl does not installed.');
     }
     return simplexml_load_file($url);
 }
Example #9
0
 /**
  * A proxy curl implementation to get the content of the url.
  *
  * @param string $url
  *
  * @return string
  * @throws CurlException
  */
 public function get($url)
 {
     $ch = curl_init($url);
     if (!ini_get('open_basedir')) {
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     }
     if (self::$proxy) {
         curl_setopt($ch, CURLOPT_PROXY, self::$proxy);
     }
     curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 40);
     curl_setopt($ch, CURLOPT_REFERER, $this->getReferrer());
     /*curl_setopt($ch, CURLOPT_HEADER, true);
       curl_setopt($ch, CURLINFO_HEADER_OUT, true);*/
     sleep(mt_rand(10, 20));
     $content = curl_exec($ch);
     $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $this->connectedURL = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
     if (404 === $code) {
         throw new CurlException('Content not found.');
     }
     if ($content === false) {
         // there was a problem
         $error = curl_error($ch);
         throw new CurlException('Error retrieving "' . $url . '" (' . $error . ')');
     }
     if (false !== strpos($content, 'Error 525')) {
         throw new CurlException('Error in a source site.');
     }
     return $content;
 }
Example #10
0
 function _doRequest($method, $url, $vars)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
     curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
     if ($method == 'POST') {
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
     }
     $data = curl_exec($ch);
     curl_close($ch);
     if ($data) {
         if ($this->callback) {
             $callback = $this->callback;
             $this->callback = false;
             return call_user_func($callback, $data);
         } else {
             return $data;
         }
     } else {
         return curl_error($ch);
     }
 }
Example #11
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;
}
Example #12
0
function fetchdata($keyid, $uuid)
{
    $mydata = "<?xml version='1.0' encoding='UTF-8'?>\n<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>\n<soapenv:Body>\n<ns2:queryRQ xmlns:ns2='http://soap.fiap.org/'>\n<transport xmlns='http://gutp.jp/fiap/2009/11/'>\n<header>\n<query id='" . $uuid . "' type='storage'>\n<key id='{$keyid}' attrName='time' select='maximum' />\n</query>\n</header>\n</transport>\n</ns2:queryRQ>\n</soapenv:Body>\n</soapenv:Envelope>";
    $url = "http://161.200.90.122/axis2/services/FIAPStorage";
    $headers = array("Content-type: text/xml", "Content-length: " . strlen($mydata), "SOAPAction: http://soap.fiap.org/query");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $mydata);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    $data = curl_exec($ch);
    if ($data === false) {
        $error = curl_error($ch);
        echo $error;
        die('error occured');
    } else {
        $xml = simplexml_load_string($data);
        $ns = $xml->getNamespaces(true);
        $child = (string) $xml->children($ns['soapenv'])->Body->children($ns['ns2'])->queryRS->children($ns[''])->transport->body->point->value;
        $para[1] = $child;
        $child2 = (string) $xml->children($ns['soapenv'])->Body->children($ns['ns2'])->queryRS->children($ns[''])->transport->body->point->value->attributes();
        $para[2] = $child2;
    }
    curl_close($ch);
    return $para;
}
 public function responseMsg()
 {
     //初始化curl
     $ch = curl_init() or die(curl_error());
     //echo "error1";
     //设置URL参数
     curl_setopt($ch, CURLOPT_URL, "http://www.yhkailun.com/?C=ShowTimes");
     //要求CURL返回数据
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     //执行请求
     $result = curl_exec($ch) or die(curl_error());
     //取得返回的结果,并显示  javascript:void(0);
     //echo $result;
     //echo curl_error($ch);
     //关闭CURL
     curl_close($ch);
     $pa = '%<div class="showTimesItem"*?>(.*?)<div id="footerHolderBar"*?>%si';
     preg_match_all($pa, $result, $match);
     $result = $match[1];
     $data = array();
     if (!empty($result)) {
         foreach ($result as $val) {
             $after = $this->pregstring($val);
             $last = $last . $after . "\n";
         }
     }
     $textTpl = "<a href='http://www.yhkailun.com/?C=ShowTimes'>楚门凯伦</a>\n咨询电话:81717555\n\n【影讯】\n" . $last . "\n";
     return $textTpl;
 }
Example #14
0
 /**
  * @inheritdoc
  */
 public function executeHttpRequest($url, $method = self::METHOD_GET, $data = [])
 {
     $ch = curl_init();
     if ($method === self::METHOD_GET) {
         if ($data) {
             $query = $this->buildQuery($data);
             if (strpos($url, '?') !== false) {
                 $url .= $query;
             } else {
                 $url .= '?' . $query;
             }
         }
     } else {
         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
     }
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
     $body = curl_exec($ch);
     $info = curl_getinfo($ch);
     $code = $info['http_code'];
     if ($code === 200) {
         return $body;
     } else {
         $error = curl_errno($ch);
         $msg = curl_error($ch);
         throw new HttpException($code, sprintf('%s %s', $error, $msg));
     }
 }
 public function send($payload)
 {
     $headers = array('Content-Type: application/x-www-form-urlencoded');
     $post_string = http_build_query($payload);
     $cacertPath = dirname(__FILE__) . '/cacert.pem';
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $this->config->apiAddress);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     if (file_exists($cacertPath)) {
         $this->log('cacert.pem file found, verifying API endpoint');
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
         curl_setopt($ch, CURLOPT_CAINFO, $cacertPath);
     } else {
         $this->log('cacert.pem file not found, the API endpoint will not be verified', true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     }
     curl_exec($ch);
     $curl_error = curl_error($ch);
     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if ($http_code !== 200) {
         throw new \Exception('cURL error code ' . $http_code . ': ' . $curl_error);
     }
 }
Example #16
0
function postToIDS($url, $data)
{
    $agent = $_SERVER["HTTP_USER_AGENT"];
    $curlData = http_build_query($data);
    $curlData = str_replace(" ", '%20', $curlData);
    $curlData = str_replace("+", '%20', $curlData);
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    //curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
    //curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($curl, CURLOPT_USERAGENT, $agent);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $curlData);
    $response = curl_exec($curl);
    echo '<!-- CURLINFO_EFFECTIVE_URL' . PHP_EOL;
    var_dump(curl_getinfo($curl, CURLINFO_EFFECTIVE_URL));
    echo PHP_EOL . '/-->' . PHP_EOL;
    if ($response === false) {
        echo "curl error: " . curl_error($curl);
    } else {
        $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
    }
    curl_close($curl);
    return $http_status;
}
Example #17
0
 /**
  * @param $method - API method, including version number
  * @param array $params - Query params
  * @param string $requestType - (get|post|put|delete)
  * @param string $format - (json|xml)
  * @param bool|true $isAuth
  *
  * @return mixed
  * @throws Exception
  *
  */
 public function call($method, $params = array(), $requestType = 'get', $format = 'json', $isAuth = true)
 {
     if (!is_array($params)) {
         throw new Exception('Query params must be an array.');
     }
     $type = strtoupper($requestType);
     if (!in_array($type, array('GET', 'POST', 'PUT', 'DELETE'))) {
         $type = 'GET';
     }
     $params['format'] = $format;
     $options = array(CURLOPT_URL => $this->_url . $method, CURLOPT_CUSTOMREQUEST => $type, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_HEADERFUNCTION => array($this, '_parseHeaders'));
     $ch = curl_init();
     if ($type == 'GET') {
         $options[CURLOPT_URL] = $this->_url . $method . '?' . http_build_query($params);
     } else {
         $options[CURLOPT_POST] = true;
         $options[CURLOPT_POSTFIELDS] = http_build_query($params);
     }
     if ($isAuth) {
         $options[CURLOPT_HTTPHEADER] = $this->_getAuthHeader($method, $params);
     }
     curl_setopt_array($ch, $options);
     $response = curl_exec($ch);
     $error = curl_error($ch);
     $this->_httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     curl_close($ch);
     if ($error) {
         throw new Exception($error);
     }
     return $response;
 }
Example #18
0
function get_access_token($code, $state, $client_id="https://apps.rhiaro.co.uk/seeulator"){
  
  $params = "me={$_SESSION['me']}&code=$code&redirect_uri=".urlencode($state)."&state=".urlencode($state)."&client_id=$client_id";
  $token_ep = discover_endpoint($_SESSION['me'], "token_endpoint");
  $ch = curl_init($token_ep);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
  curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  $response = Array();
  parse_str(curl_exec($ch), $response);
  $info = curl_getinfo($ch);
  curl_close($ch);
  
  if(isset($response) && ($response === false || $info['http_code'] != 200)){
    $errors["Login error"] = $info['http_code'];
    if(curl_error($ch)){
      $errors["curl error"] = curl_error($ch);
    }
    return $errors;
  }else{
    $_SESSION['access_token'] = $response['access_token'];
    return true;
  }
  
}
Example #19
0
function get_data($url, $form_properties)
{
    /* IF CURL_EXEC RETURNS NOTHING and no errors are being generated, check
    the selinux configuration or disable selinux completely.*/
    $timeout = 5;
    wl("in get data");
    wl("url:" . $url);
    if ($form_properties == "") {
        $ch = curl_init();
        wl("no form properties");
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    } else {
        define('POSTURL', $url);
        define('POSTVARS', $form_properties);
        wl("with form properties");
        //sample url and form properties
        //define('POSTURL', 'http://data.bls.gov/cgi-bin/surveymost');
        //define('POSTVARS', 'series_id=LNS14000000&survey=ln&format=&html_tables=&delimiter=&catalog=&print_line_length=&lines_per_page=&row_stub_key=&year=&date=&net_change_start=&net_change_end=&percent_change_start=&percent_change_end=');
        $ch = curl_init(POSTURL);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, POSTVARS);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    }
    wl("Still here");
    curl_error($ch);
    $data = curl_exec($ch);
    wl("still in get_data");
    curl_close($ch);
    wl(strlen($data));
    echo "<BR>Length of data returned from url: " . strlen($data) . "<BR>";
    return $data;
}
Example #20
0
/**
 * 执行curl请求
 *
 * @param string  $url    要请求的url地址
 * @param array   $param  要携带的参数
 * @param string  $method 请求类型 get/post
 * @param bool    $weixin 是否为微信请求
 *
 * @return string 返回值为字符串,请求成功返回请求之后获取的值,请求失败返回失败原因
 * @author   邹广圆 中企动力移动产品业务部
 * @datetime 2015-12-02 12:08
 */
function http($url, $param = array(), $method = 'get', $weixin = true)
{
    $xhr = curl_init();
    $xhrOpts = array(CURLOPT_HEADER => 0, CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $url);
    //        判断method
    if ($method == 'get') {
        $xhrOpts[CURLOPT_HTTPGET] = 1;
    } else {
        $xhrOpts[CURLOPT_POST] = 1;
        if ($param) {
            //    判断是否携带参数
            $xhrOpts[CURLOPT_POSTFIELDS] = $param;
        }
    }
    //        判断是否为微信请求
    if ($weixin) {
        $xhrOpts[CURLOPT_SSL_VERIFYPEER] = false;
        $xhrOpts[CURLOPT_SSL_VARIFYHOST] = false;
    }
    curl_setopt_array($xhr, $xhrOpts);
    $res = curl_exec($xhr);
    $dores = $res ? $res : curl_error($xhr);
    curl_close($xhr);
    return $dores;
}
Example #21
0
 /**
  * Returns the output of a remote URL. Any [curl option](http://php.net/curl_setopt)
  * may be used.
  *
  *     // Do a simple GET request
  *     $data = Remote::get($url);
  *
  *     // Do a POST request
  *     $data = Remote::get($url, array(
  *         CURLOPT_POST       => true,
  *         CURLOPT_POSTFIELDS => http_build_query($array),
  *     ));
  *
  * @param   string   remote URL
  * @param   array    curl options
  * @return string
  * @throws Exception
  */
 public static function remote($url, array $options = null)
 {
     // The transfer must always be returned
     $options[CURLOPT_RETURNTRANSFER] = true;
     // Open a new remote connection
     $remote = curl_init($url);
     // Set connection options
     if (!curl_setopt_array($remote, $options)) {
         throw new Exception('Failed to set CURL options, check CURL documentation: http://php.net/curl_setopt_array');
     }
     // Get the response
     $response = curl_exec($remote);
     // Get the response information
     $code = curl_getinfo($remote, CURLINFO_HTTP_CODE);
     if ($code and ($code < 200 or $code > 299)) {
         $error = $response;
     } elseif ($response === false) {
         $error = curl_error($remote);
     }
     // Close the connection
     curl_close($remote);
     if (isset($error)) {
         throw new Exception(sprintf('Error fetching remote %s [ status %s ] %s', $url, $code, $error));
     }
     return $response;
 }
Example #22
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;
     }
 }
Example #23
0
 public function cpanel()
 {
     $whmusername = "******";
     $whmhash = "somelonghash";
     # some hash value
     $query = "https://127.0.0.1:2087/....";
     $curl = curl_init();
     # Create Curl Object
     curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
     # Allow certs that do not match the domain
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
     # Allow self-signed certs
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
     # Return contents of transfer on curl_exec
     $header[0] = "Authorization: WHM {$whmusername}:" . preg_replace("'(\r|\n)'", "", $whmhash);
     # Remove newlines from the hash
     curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
     # Set curl header
     curl_setopt($curl, CURLOPT_URL, $query);
     # Set your URL
     $result = curl_exec($curl);
     # Execute Query, assign to $result
     if ($result == false) {
         error_log("curl_exec threw error \"" . curl_error($curl) . "\" for {$query}");
     }
     curl_close($curl);
     print $result;
 }
Example #24
0
 /**
  * Returns the output of a remote URL. Any [curl option](http://php.net/curl_setopt)
  * may be used.
  *
  *     // Do a simple GET request
  *     $data = Remote::get($url);
  *
  *     // Do a POST request
  *     $data = Remote::get($url, array(
  *         CURLOPT_POST       => TRUE,
  *         CURLOPT_POSTFIELDS => http_build_query($array),
  *     ));
  *
  * @param   string   remote URL
  * @param   array    curl options
  * @return  string
  * @throws  Kohana_Exception
  */
 public static function remote($url, array $options = NULL)
 {
     // The transfer must always be returned
     $options[CURLOPT_RETURNTRANSFER] = TRUE;
     // Open a new remote connection
     $remote = curl_init($url);
     // Set connection options
     if (!curl_setopt_array($remote, $options)) {
         throw new Kohana_Exception('Failed to set CURL options, check CURL documentation: :url', array(':url' => 'http://php.net/curl_setopt_array'));
     }
     // Get the response
     $response = curl_exec($remote);
     // Get the response information
     $code = curl_getinfo($remote, CURLINFO_HTTP_CODE);
     if ($code and $code < 200 or $code > 299) {
         $error = $response;
     } elseif ($response === FALSE) {
         $error = curl_error($remote);
     }
     // Close the connection
     curl_close($remote);
     if (isset($error)) {
         throw new Kohana_OAuth_Exception('Error fetching remote :url [ status :code ] :error', array(':url' => $url, ':code' => $code, ':error' => $error));
     }
     return $response;
 }
Example #25
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;
 }
Example #26
0
 public static function httpRequest($req, $hash_config = NULL)
 {
     $config = Obj2xml::getConfig($hash_config);
     if ((int) $config['print_xml']) {
         echo $req;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_PROXY, $config['proxy']);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
     curl_setopt($ch, CURLOPT_URL, $config['url']);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
     curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, true);
     curl_setopt($ch, CURLOPT_TIMEOUT, $config['timeout']);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     //curl_setopt($ch, CURLOPT_SSLVERSION, 3);
     $output = curl_exec($ch);
     //$responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     if (!$output) {
         throw new \Exception(curl_error($ch));
     } else {
         curl_close($ch);
         if ((int) $config['print_xml']) {
             echo $output;
         }
         return $output;
     }
 }
Example #27
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;
 }
Example #28
0
 /**
  * Sending Push Notification
  */
 public function send_notification($registation_ids, $message)
 {
     // include config
     include_once './config.php';
     // Set POST variables
     $url = 'https://android.googleapis.com/gcm/send';
     $fields = array('registration_ids' => $registation_ids, 'data' => $message);
     $headers = array('Authorization: key=' . GOOGLE_API_KEY, 'Content-Type: application/json');
     // Open connection
     $ch = curl_init();
     // Set the url, number of POST vars, POST data
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_POST, true);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Disabling SSL Certificate support temporarly
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
     // Execute post
     $result = curl_exec($ch);
     if ($result === FALSE) {
         die('Curl failed: ' . curl_error($ch));
     }
     // Close connection
     curl_close($ch);
     echo $result;
 }
Example #29
0
 private function doRequest($method, $url, array $header, $data)
 {
     $curlInit = curl_init();
     $parsed_url = parse_url($url);
     if (isset($parsed_url['scheme']) && $parsed_url['scheme'] !== 'http' && $parsed_url['scheme'] !== 'https') {
         return false;
     }
     if ($method === 'GET') {
         curl_setopt($curlInit, CURLOPT_POST, 0);
     } elseif ($method === 'POST') {
         curl_setopt($curlInit, CURLOPT_POST, 1);
         curl_setopt($curlInit, CURLOPT_POSTFIELDS, $data);
     }
     curl_setopt($curlInit, CURLOPT_URL, $url);
     curl_setopt($curlInit, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curlInit, CURLINFO_HEADER_OUT, true);
     curl_setopt($curlInit, CURLOPT_TIMEOUT, $this->timeout);
     if (!empty($header)) {
         curl_setopt($curlInit, CURLOPT_HTTPHEADER, $header);
     }
     if (!empty($this->proxy_host) && !in_array($parsed_url["host"], $this->proxy_exclude)) {
         curl_setopt($curlInit, CURLOPT_PROXY, $this->proxy_host);
         curl_setopt($curlInit, CURLOPT_PROXYPORT, $this->proxy_port);
     }
     $response = new stdClass();
     $response->content = curl_exec($curlInit);
     $response->header = curl_getInfo($curlInit, CURLINFO_HEADER_OUT);
     $response->status = (int) curl_getInfo($curlInit, CURLINFO_HTTP_CODE);
     $response->contentType = curl_getInfo($curlInit, CURLINFO_CONTENT_TYPE);
     $response->error = curl_error($curlInit);
     curl_close($curlInit);
     return $response;
 }
Example #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;
     }
 }