当前位置: 首页>>代码示例>>PHP>>正文


PHP curl_setopt函数代码示例

本文整理汇总了PHP中curl_setopt函数的典型用法代码示例。如果您正苦于以下问题:PHP curl_setopt函数的具体用法?PHP curl_setopt怎么用?PHP curl_setopt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了curl_setopt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendPushNotificationToGCM

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;
}
开发者ID:kousiksatish,项目名称:simple-gcm,代码行数:25,代码来源:internalgcmaccess.php

示例2: translate

 function translate($text, $d = '')
 {
     $s = 'en';
     if ($d == '') {
         $d = 'en';
     }
     if ($d != 'en') {
         $lang_pair = urlencode($s . '|' . $d);
         $q = rawurlencode($text);
         // Google's API translator URL
         $url = "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" . $q . "&langpair=" . $lang_pair;
         // Make sure to set CURLOPT_REFERER because Google doesn't like if you leave the referrer out
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_REFERER, "http://www.yoursite.com/translate.php");
         $body = curl_exec($ch);
         curl_close($ch);
         $json = json_decode($body, true);
         $tranlate = $json['responseData']['translatedText'];
         echo $tranlate;
     } else {
         echo $text;
     }
 }
开发者ID:nyros,项目名称:codeigniter_multilanguage,代码行数:25,代码来源:translate_helper.php

示例3: send_notification

 /**
  * 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;
 }
开发者ID:rbaltodanog,项目名称:audinsaapp,代码行数:30,代码来源:GCM.php

示例4: updateCurrencies

 public function updateCurrencies()
 {
     if (extension_loaded('curl')) {
         $data = array();
         $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency WHERE code != '" . $this->db->escape($this->config->get('config_currency')) . "' AND date_modified > '" . date(strtotime('-1 day')) . "'");
         foreach ($query->rows as $result) {
             $data[] = $this->config->get('config_currency') . $result['code'] . '=X';
         }
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'http://download.finance.yahoo.com/d/quotes.csv?s=' . implode(',', $data) . '&f=sl1&e=.csv');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $content = curl_exec($ch);
         curl_close($ch);
         $lines = explode("\n", trim($content));
         foreach ($lines as $line) {
             $currency = substr($line, 4, 3);
             $value = substr($line, 11, 6);
             if ((double) $value) {
                 $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '" . (double) $value . "', date_modified = NOW() WHERE code = '" . $this->db->escape($currency) . "'");
             }
         }
         $this->db->query("UPDATE " . DB_PREFIX . "currency SET value = '1.00000', date_modified = NOW() WHERE code = '" . $this->db->escape($this->config->get('config_currency')) . "'");
         $this->cache->delete('currency');
     }
 }
开发者ID:vverhun,项目名称:hoho,代码行数:25,代码来源:currency.php

示例5: getUserInfo

 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));
 }
开发者ID:besimhu,项目名称:CraftCMS-Boilerplate,代码行数:27,代码来源:Github.php

示例6: httpRequest

 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;
     }
 }
开发者ID:samwaters,项目名称:litlephp,代码行数:30,代码来源:Communication.php

示例7: getTotalUsedCredits

 /**
  * @param $main_account_username
  * @param $main_account_password
  * @param $customer_username
  * @param DateTime $date
  * @return int
  * @throws Exception
  */
 public function getTotalUsedCredits($main_account_username, $main_account_password, $customer_username, DateTime $date)
 {
     $totalCreditUsed = 0;
     $this->customer = $customer_username;
     $this->date = $date;
     $this->main_account_username = $main_account_username;
     $this->main_account_password = $main_account_password;
     $this->date = $this->date->add(new DateInterval("P1D"));
     //the api call doesnt include the current date so we move a day ahead
     $dtToday = $this->date->format("Y-m-d");
     $requestString = "https://www.voipinfocenter.com/API/Request.ashx?command=calloverview&username={$this->main_account_username}&password={$this->main_account_password}&customer={$this->customer}&date={$dtToday}%2000:00:00&recordcount=500";
     $curlRes = curl_init($requestString);
     curl_setopt($curlRes, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($curlRes, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($curlRes, CURLOPT_SSL_VERIFYHOST, false);
     $requestResult = curl_exec($curlRes);
     $this->date = $this->date->sub(new DateInterval("P1D"));
     //revert date add
     if (is_null($requestResult) || empty($requestResult)) {
         throw new Exception("Empty result from API server");
     }
     $xmlObject = new SimpleXMLElement($requestResult);
     $callsTempContainer = (array) $xmlObject->Calls;
     $callsTempContainer = $callsTempContainer['Call'];
     foreach ($callsTempContainer as $currentCallObj) {
         // if date is equal to date passed
         $parsedDate = strtotime($currentCallObj['StartTime']);
         if ($this->date->format("Y-m-d") === date("Y-m-d", $parsedDate)) {
             $totalCreditUsed += floatval($currentCallObj['Charge']);
         }
     }
     return $totalCreditUsed;
 }
开发者ID:branJakJak,项目名称:biOwAyPiTransperKreditz,代码行数:41,代码来源:CallOverview.php

示例8: updateIndex

function updateIndex($lang, $file)
{
    $fileData = readFileData($file);
    $filename = $file->getPathName();
    list($filename) = explode('.', $filename);
    $path = $filename . '.html';
    $id = str_replace($lang . '/', '', $filename);
    $id = str_replace('/', '-', $id);
    $id = trim($id, '-');
    $url = implode('/', array(ES_URL, ES_INDEX, $lang, $id));
    $data = array('contents' => $fileData['contents'], 'title' => $fileData['title'], 'url' => $path);
    $data = json_encode($data);
    $size = strlen($data);
    $fh = fopen('php://memory', 'rw');
    fwrite($fh, $data);
    rewind($fh);
    echo "Sending request:\n\tfile: {$file}\n\turl: {$url}\n";
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_PUT, true);
    curl_setopt($ch, CURLOPT_INFILE, $fh);
    curl_setopt($ch, CURLOPT_INFILESIZE, $size);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    $metadata = curl_getinfo($ch);
    if ($metadata['http_code'] > 400) {
        echo "[ERROR] Failed to complete request.\n";
        var_dump($response);
        exit(2);
    }
    curl_close($ch);
    fclose($fh);
    echo "Sent {$file}\n";
}
开发者ID:ramonakira,项目名称:docs,代码行数:33,代码来源:populate_search_index.php

示例9: curlSetopts

 private function curlSetopts($ch, $method, $payload, $request_headers)
 {
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
     curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     curl_setopt($ch, CURLOPT_USERAGENT, 'HAC');
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
     curl_setopt($ch, CURLOPT_TIMEOUT, 30);
     if ($this->debug) {
         curl_setopt($ch, CURLOPT_VERBOSE, true);
     }
     if ('GET' == $method) {
         curl_setopt($ch, CURLOPT_HTTPGET, true);
     } else {
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
         if (!empty($request_headers)) {
             curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
         }
         if (!empty($payload)) {
             if (is_array($payload)) {
                 $payload = http_build_query($payload);
             }
             curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
         }
     }
 }
开发者ID:robertholf,项目名称:PipelineDeals-API-PHP-Adapter,代码行数:29,代码来源:pipelinedeals.php

示例10: downloadPackage

 function downloadPackage($src, $dst)
 {
     if (ini_get('allow_url_fopen')) {
         $file = @file_get_contents($src);
     } else {
         if (function_exists('curl_init')) {
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, $src);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($ch, CURLOPT_TIMEOUT, 180);
             $safeMode = @ini_get('safe_mode');
             $openBasedir = @ini_get('open_basedir');
             if (empty($safeMode) && empty($openBasedir)) {
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             }
             $file = curl_exec($ch);
             curl_close($ch);
         } else {
             return false;
         }
     }
     file_put_contents($dst, $file);
     return file_exists($dst);
 }
开发者ID:vgrish,项目名称:el,代码行数:25,代码来源:validate.install.php

示例11: test_instam

 function test_instam($key)
 {
     // returns array, or FALSE
     // snap(basename(__FILE__) . __LINE__, $key_val);
     // http://www.instamapper.com/api?action=getPositions&key=4899336036773934943
     $url = "http://www.instamapper.com/api?action=getPositions&key={$key}";
     $data = "";
     if (function_exists("curl_init")) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $data = curl_exec($ch);
         curl_close($ch);
     } else {
         // not CURL
         if ($fp = @fopen($url, "r")) {
             while (!feof($fp) && strlen($data) < 9000) {
                 $data .= fgets($fp, 128);
             }
             fclose($fp);
         } else {
             //					print "-error 1";		// @fopen fails
             return FALSE;
         }
     }
     /*
     InstaMapper API v1.00
     1263013328977,bold,1236239763,34.07413,-118.34940,25.0,0.0,335
     1088203381874,CABOLD,1236255869,34.07701,-118.35262,27.0,0.4,72
     */
     //			dump($data);
     $ary_data = explode("\n", $data);
     return $ary_data;
 }
开发者ID:sharedgeo,项目名称:TicketsCAD-SharedGeo-Dev,代码行数:34,代码来源:test_instam.php

示例12: make_api_call

function make_api_call($url, $http_method, $post_data = array(), $uid = null, $key = null)
{
    $full_url = 'https://app.onepagecrm.com/api/v3/' . $url;
    $ch = curl_init($full_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $http_method);
    $timestamp = time();
    $auth_data = array($uid, $timestamp, $http_method, sha1($full_url));
    $request_headers = array();
    // For POST and PUT requests we will send data as JSON
    // as with regular "form data" request we won't be able
    // to send more complex structures
    if ($http_method == 'POST' || $http_method == 'PUT') {
        $request_headers[] = 'Content-Type: application/json';
        $json_data = json_encode($post_data);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
        $auth_data[] = sha1($json_data);
    }
    // Set auth headers if we are logged in
    if ($key != null) {
        $hash = hash_hmac('sha256', implode('.', $auth_data), $key);
        $request_headers[] = "X-OnePageCRM-UID: {$uid}";
        $request_headers[] = "X-OnePageCRM-TS: {$timestamp}";
        $request_headers[] = "X-OnePageCRM-Auth: {$hash}";
    }
    curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
    $result = json_decode(curl_exec($ch));
    curl_close($ch);
    if ($result->status > 99) {
        echo "API call error: {$result->message}\n";
        return null;
    }
    return $result;
}
开发者ID:aprilla2crash,项目名称:shopify-tools,代码行数:34,代码来源:webhooks.php

示例13: executeCurl

 private function executeCurl($url, array $params)
 {
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, $url);
     if (isset($params["POST"])) {
         curl_setopt($ch, CURLOPT_POST, 1);
         $queryString = urlencode(http_build_query($params["POST"]));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $queryString);
     }
     if (isset($params["PUT"])) {
         //@TODO
         throw new Exception('The PUT is currently not supported');
     }
     if (isset($params["GET"])) {
         curl_setopt($ch, CURLOPT_HTTPGET, 1);
         $queryString = urlencode(http_build_query($params["GET"]));
         curl_setopt($ch, CURLOPT_URL, $url . '?' . $queryString);
     }
     if (isset($params["HEADERS"])) {
         curl_setopt($ch, CURLOPT_HEADER, 1);
         curl_setopt($ch, CURLOPT_HTTPHEADER, $params["HEADERS"]);
     }
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     $response = curl_exec($ch);
     curl_close($ch);
     return $response;
 }
开发者ID:psosulski,项目名称:meta,代码行数:27,代码来源:ApiService.php

示例14: toastup

function toastup($channel, $message)
{
    $channel_uri = urldecode($channel);
    $toast_xml = '<?xml version="1.0" encoding="utf-8" ?>
		<wp:Notification xmlns:wp="WPNotification">
			<wp:Toast>
				<wp:Text1>' . 信息: . '</wp:Text1>
				<wp:Text2>' . $message . '</wp:Text2>
			</wp:Toast>
		</wp:Notification>';
    $headers = array('Content-Type: text/xml', "Content-Length: " . strlen($toast_xml), "X-WindowsPhone-Target: toast", "X-NotificationClass: 2");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $channel_uri);
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 2);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "{$toast_xml}");
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    $response = curl_getinfo($ch);
    curl_close($ch);
    return $response['http_code'];
}
开发者ID:ruizhipeng,项目名称:smuradio-1,代码行数:26,代码来源:toast.php

示例15: fetch

 /**
  * @param $url
  * @param $destination
  * @return bool|null
  */
 public function fetch($url, $destination)
 {
     try {
         $ret = null;
         $url = $this->addhttp($url);
         $ch = curl_init($url . '/favicon.ico');
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
         $contents = curl_exec($ch);
         $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         if ($httpCode == 200) {
             $fp = fopen($destination, 'w+');
             fwrite($fp, $contents);
             fclose($fp);
             $ret = true;
             if ($this->converter) {
                 $ret = $this->converter->convert($destination);
             }
         }
         curl_close($ch);
         return $ret;
     } catch (\Exception $e) {
         // hmm ok, let the next Fetcher try its luck
     }
     return null;
 }
开发者ID:ivoba,项目名称:favicon-fetcher,代码行数:32,代码来源:FaviconIcoFetcher.php


注:本文中的curl_setopt函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。