本文整理汇总了PHP中Curl\Curl类的典型用法代码示例。如果您正苦于以下问题:PHP Curl类的具体用法?PHP Curl怎么用?PHP Curl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Curl类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: getData
/**
* docomoの対話APIを叩いてレスポンスを貰ってくる
*
* @param string $apikey docomoAPIキー
* @param string $context 会話のコンテキストID(API仕様参照)
* @param string $mode 会話のモード(API仕様参照
* @param string $nickname 会話している人間側の名前
* @param string $text 人間側の入力テキスト
* @return stdClass レスポンスのJSONをデコードしたオブジェクト
* @throws \Exception サーバとの通信に失敗した場合
*/
private function getData($apikey, $context, $mode, $nickname, $text)
{
$userData = ['utt' => (string) $text, 'context' => (string) $context, 'nickname' => (string) $nickname, 'mode' => (string) $mode];
$url = sprintf('https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=%s', rawurlencode($apikey));
Log::info("docomo対話APIを呼び出します");
Log::info("URL: " . $url);
Log::info("パラメータ:");
Log::info($userData);
$curl = new Curl();
$curl->setHeader('Content-Type', 'application/json; charset=UTF-8');
$ret = $curl->post($url, json_encode($userData));
if ($curl->error) {
Log::error(sprintf("docomo対話APIの呼び出しに失敗しました: %d: %s", $curl->error_code, $curl->error_message));
throw new \Exception('docomo dialogue error: ' . $curl->error_code . ': ' . $curl->error_message);
}
Log::info("docomoからのデータ:");
Log::info($ret);
if (is_object($ret) && isset($ret->utt)) {
if ($ret->utt == '') {
Log::warning(" docomo 指示文章が空です");
} else {
Log::success(" docomo 指示文章: " . $ret->utt);
}
return $ret;
}
Log::error("docomoから受け取ったデータが期待した形式ではありません:");
Log::error($ret);
throw new \Exception('Received an unexpected data from docomo server');
}
开发者ID:nonoliri,项目名称:chomado_bot,代码行数:40,代码来源:Chat.php
示例2: callWebservice
/**
*
* https://developer.priceminister.com/blog/fr/documentation/product-data/product-listing-secure
*
* @return mixed
*/
public function callWebservice()
{
$urlToCall = 'https://ws.priceminister.com/listing_ssl_ws';
$curl = new Curl();
$curl->get($urlToCall, ['action' => 'listing', 'login' => $this->credentials['login'], 'pwd' => $this->credentials['password'], 'version' => '2015-07-05', 'scope' => 'PRICING', 'kw' => $this->searchTerm, 'refs' => '', 'nbproductsperpage' => 20, 'pagenumber' => 1]);
return $curl->response;
}
开发者ID:pgrimaud,项目名称:marketplaces-search,代码行数:13,代码来源:PriceministerMarketplace.php
示例3: getAccessToken
protected function getAccessToken()
{
$url_query = '?grant_type=' . $this->grant_type;
$url_query .= '&appid=' . $this->appid;
$url_query .= '&secret=' . $this->secret;
$curl = new Curl();
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
$curl->get($this->token_api . $url_query);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
if (isset($curl->response->errcode)) {
switch ($curl->response->errcode) {
case '40002':
die($curl->response->errmsg);
break;
case '40013':
die($curl->response->errmsg);
break;
case '40125':
die($curl->response->errmsg);
break;
default:
throw new TokenExpiredException("未知错误");
break;
}
} else {
return $curl->response;
}
}
}
开发者ID:shsrain,项目名称:ShsrainWeChat,代码行数:32,代码来源:Token.php
示例4: run
public static function run($method, $params = [])
{
self::$defaultParam = ['method' => $method, 'module' => 'API', 'token_auth' => STAT_API_TOKEN, 'format' => 'JSON', 'expanded ' => true, 'idSite' => 1, 'filter_offset' => \yii::$app->request->get('filter_offset', 0), 'filter_limit' => \yii::$app->request->get('filter_limit', 50)];
$params['formatDate'] = isset($params['formatDate']) ? $params['formatDate'] : null;
if ($params['formatDate'] !== false) {
self::formatDate();
}
unset($params['formatDate']);
$params = array_merge(self::$defaultParam, $params);
$params = array_filter($params);
$curl = new Curl();
$curl->setJsonDecoder(function ($response) {
$json_obj = json_decode($response, true);
if (!($json_obj === null)) {
$response = $json_obj;
}
return $response;
});
$curl->get(STAT_API_URL, $params);
$curl->close();
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
return $curl->response;
}
}
开发者ID:oyoy8629,项目名称:yii-core,代码行数:26,代码来源:API.php
示例5: create
/**
* Create user cache.
*
* @param string $user Twitter screen name
* @return bool If successful true
* @throws CacheException Any errors
*/
public function create($user)
{
try {
$path = config("cache.path") . "/{$user}";
$json_file = "{$path}/data.json";
if (!$this->exists($user)) {
mkdir($path);
}
if (!file_exists($json_file)) {
touch($json_file);
}
$response = $this->twistOAuth->get("users/show", ["id" => $user]);
$image_url = str_replace("_normal", "", $response->profile_image_url_https);
$info = new SplFileInfo($image_url);
$curl = new Curl();
$curl->setUserAgent(SaveTweet::APP_NAME . "/" . SaveTweet::APP_VERSION . " with PHP/" . PHP_VERSION);
$curl->download($image_url, "{$path}/icon.{$info->getExtension()}");
$curl->close();
$data = ["name" => $response->name, "screen_name" => $response->screen_name, "id" => $response->id_str, "icon" => config("cache.http_path") . "/{$response->id_str}/icon.{$info->getExtension()}", "org_icon" => $image_url, "update_at" => time()];
$json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
(new SplFileObject($json_file, "w"))->fwrite($json);
return true;
} catch (RuntimeException $e) {
$this->_catch($e);
}
}
开发者ID:Hiroto-K,项目名称:SaveTweet,代码行数:33,代码来源:Cache.php
示例6: send
public function send($url, $method, array $parameters = [], array $postParameters = [], array $header = [], $content = '')
{
$this->curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$this->curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$method = strtolower($method);
$finalUrl = strpos($url, '//') !== false ? $url : $this->url . $url;
if (!empty($this->authorization) && empty($header['Authorization'])) {
$authClass = 'Bennsel\\WindowsAzureCurl\\Service\\Authorization\\' . $this->authorization;
$class = new $authClass($this->settings);
$header['Authorization'] = $class->getAuthorizationString($url, $method, $parameters, $header);
}
if ($content && is_object($content) && method_exists($content, 'toArray')) {
$parameters = $content->toArray();
}
foreach ($header as $key => $value) {
$this->curl->setHeader($key, $value);
}
$orgHeader = $header;
$r = $this->curl->{$method}($finalUrl, $parameters ?: $postParameters);
if ($this->curl->http_status_code == 301) {
$this->url = $this->curl->response_headers['Location'];
return $this->send($url, $method, $parameters, $postParameters, $orgHeader, $content);
}
return ResponseModelMapping::create($url, $r);
}
开发者ID:bennsel,项目名称:azure-for-php-curl,代码行数:25,代码来源:RestClient.php
示例7: deleteSubAccount
/**
* @param string $apiKey
* @param string $apiSecret
* @param int $subAccountId
*
* @return AccountResponse
*/
public static function deleteSubAccount($apiKey, $apiSecret, $subAccountId)
{
$apiEndpoint = sprintf('%s/subaccounts/%s', self::API_URL, $subAccountId);
$curl = new Curl();
$curl->delete($apiEndpoint, json_encode(['api_key' => $apiKey, 'api_secret' => $apiSecret]));
return self::parseResponse($curl);
}
开发者ID:mikeymike,项目名称:kraken,代码行数:14,代码来源:Account.php
示例8: getWithParams
/**
* HTTP GET wrapper for Curl.
* For requests with additional query parameters.
*
* @param string $url URL to GET request to.
* @return mixed Response data.
*/
public function getWithParams($url)
{
$curl = new Curl();
$curl->get($this->endpoint . $url . '&api_token=' . $this->token);
$curl->close();
return json_decode($curl->response);
}
开发者ID:maciekmp,项目名称:pipedrive-php-api,代码行数:14,代码来源:HTTP.php
示例9: trigger
static function trigger($channel, $event, $data)
{
WebpushPHP::validate();
$curl = new Curl();
$response = $curl->post(WebpushPHP::$apipath . '/trigger', ['token' => WebpushPHP::$token, 'secret' => WebpushPHP::$secret, 'channel' => $channel, 'event' => $event, 'data' => json_encode($data)]);
return $response;
}
开发者ID:default-settings,项目名称:webpush-php,代码行数:7,代码来源:WebpushPHP.php
示例10: deleteBounce
public function deleteBounce($email)
{
$param = ['api_user' => $this->apiUser, 'api_key' => $this->apiKey, 'email' => $email];
$curl = new Curl();
$response = $curl->get(self::API_BOUNCES_DELETE, $param);
return $response;
}
开发者ID:xiaoyang4011,项目名称:discuss,代码行数:7,代码来源:SendCloudApi.php
示例11: getTrackingInformation
private function getTrackingInformation()
{
$curl = new Curl();
$curl->get(self::BPOST_API_ENDPOINT . 'items?itemIdentifier=' . $this->getItemNumber());
if ($curl->error) {
throw new Exception('CURL error while fetching tracking information: ' . $curl->errorCode . ': ' . $curl->errorMessage);
}
// Curl library already decoded the JSON (cool!)
$response = $curl->response[0];
// Decode sender
$rawSender = $response->sender;
$this->sender = new SenderReceiver($rawSender->countryCode, $rawSender->municipality, $rawSender->postcode);
// Decode receiver
$rawReceiver = $response->receiver;
$this->receiver = new SenderReceiver($rawReceiver->countryCode, $rawReceiver->municipality, $rawReceiver->postcode, $rawReceiver->name);
// Some other stuff
$this->weight = (int) $response->weightInGrams;
$this->customerReference = $response->customerReference;
$this->requestedDeliveryMethod = $response->requestedDeliveryMethod;
// Decode events
$rawEvents = $response->events;
foreach ($rawEvents as $rawEvent) {
$lang = self::LANGUAGE;
$eventDescription = $this->translateKey($rawEvent->key);
$statusUpdate = new StatusUpdate($rawEvent->date, $rawEvent->time, $eventDescription, $rawEvent->location->{$lang});
array_push($this->statusUpdates, $statusUpdate);
}
}
开发者ID:savjee,项目名称:bpost-track,代码行数:28,代码来源:BpostPackage.php
示例12: _processTask
protected function _processTask()
{
try {
$curl = new Curl();
$curl->setUserAgent('got/Tarth');
if ($this->includeTarthHeader) {
$curl->setHeader(\Tarth\Tool\Task::HEADER_ALLERIA_CRC, \Tarth\Tool\Task::getTarthHeader($this));
}
if (isset($this->header)) {
foreach ($this->header as $key => $value) {
$curl->setHeader($key, $value);
}
}
call_user_func_array(array($curl, strtolower($this->method)), array($this->url, $this->data));
if ($curl->error) {
return false;
} else {
//响应码大于300为请求失败
return $curl->httpStatusCode < 300;
//接口返回为json格式,返回值中有code为0
//return $curl->response->code == 0;
}
} catch (Exception $e) {
}
}
开发者ID:pythias,项目名称:Tarth,代码行数:25,代码来源:ApiTask.php
示例13: getWeChatIp
public static function getWeChatIp()
{
$api = 'https://api.weixin.qq.com/cgi-bin/getcallbackip';
$url_query = '?access_token=' . self::$token->getToken();
$curl = new Curl();
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
$curl->get($api . $url_query);
if ($curl->error) {
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
} else {
if (isset($curl->response->errcode)) {
switch ($curl->response->errcode) {
case '40002':
die($curl->response->errmsg);
break;
case '40013':
die($curl->response->errmsg);
break;
case '40125':
die($curl->response->errmsg);
break;
default:
die('未知错误');
break;
}
} else {
return $curl->response;
}
}
}
开发者ID:shsrain,项目名称:ShsrainWeChat,代码行数:31,代码来源:WeChat.php
示例14: api
function api()
{
$apiKey = Input::get('apiKey');
if (!$apiKey) {
\App::abort(500);
}
$sysKey = config('settings.apiKey');
if ($sysKey !== $apiKey) {
\App::abort(500);
}
$base = Input::get('image');
$binary = base64_decode($base);
$fname = rand(0, 100) . ".jpg";
header('Content-Type: bitmap; charset=utf-8');
$file = fopen(base_path() . "/uploads/" . $fname, 'wb');
fwrite($file, $binary);
fclose($file);
$furl = asset('/uploads/' . $fname);
$curl = new Curl();
$key = config('settings.idol.key');
$url = config('settings.idol.orc_url');
$response = $curl->get($url, array('apikey' => $key, 'url' => $furl));
if ($response && isset($response->text_block)) {
return $response->text_block[0]->text;
} else {
return "error";
}
}
开发者ID:kunalvarma05,项目名称:eventup,代码行数:28,代码来源:HomeController.php
示例15: init
/**
* Init CLDR data and download default language
*/
public function init()
{
if (!is_file($file = $this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'core.zip')) {
$fp = fopen($file, "w");
$curl = new Curl();
$curl->setopt(CURLOPT_FILE, $fp);
$curl->setopt(CURLOPT_FOLLOWLOCATION, true);
$curl->setopt(CURLOPT_HEADER, false);
$curl->get(self::ZIP_CORE_URL);
if ($curl->error) {
throw new \Exception("Failed to download '" . self::ZIP_CORE_URL . "'.");
}
fclose($fp);
}
//extract ONLY supplemental json files
$archive = new \ZipArchive();
if ($archive->open($file) === true) {
for ($i = 0; $i < $archive->numFiles; $i++) {
$filename = $archive->getNameIndex($i);
if (preg_match('%^supplemental\\/(.*).json$%', $filename)) {
if (!is_dir($this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . dirname($filename))) {
mkdir($this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . dirname($filename), 0777, true);
}
if (!file_exists($this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . $filename)) {
copy("zip://" . $file . "#" . $filename, $this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . $filename);
$this->newDatasFile[] = $this->cldrCacheFolder . DIRECTORY_SEPARATOR . 'datas' . DIRECTORY_SEPARATOR . $filename;
}
}
}
$archive->close();
} else {
throw new \Exception("Failed to unzip '" . $file . "'.");
}
$this->generateSupplementalDatas();
}
开发者ID:M03G,项目名称:PrestaShop,代码行数:38,代码来源:Update.php
示例16: all
public function all($year)
{
$curl = new Curl();
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
$curl->setOpt(CURLOPT_RETURNTRANSFER, true);
$curl->get('http://localhost/stripe/index.php/api/v1/earnings/index/' . $year);
return $curl->response;
}
开发者ID:JohnOscar-Mendoza,项目名称:lb_cms,代码行数:8,代码来源:Earnings_model.php
示例17: fromFile
/**
* @param KrakenOptions $options
* @param KrakenImage $image
*
* @return CompressResponse
*/
public static function fromFile(KrakenOptions $options, KrakenImage $image)
{
$apiEndpoint = sprintf('%s/upload', self::API_URL);
$file = class_exists('CURLFile') ? new \CURLFile($image->getPath()) : sprintf('@%s', $image->getPath());
$curl = new Curl();
$curl->post($apiEndpoint, ['file' => $file, 'data' => json_encode($options->getConfiguredOptions())]);
return self::parseResponse($curl);
}
开发者ID:mikeymike,项目名称:kraken,代码行数:14,代码来源:Compress.php
示例18: scrapeWithYQL
/**
* @param $yql_query
* @param string $format ('xml', 'json')
* @return bool|string
*/
public function scrapeWithYQL($yql_query, $format = '')
{
$this->initCurl();
$encoded_yql_query = rawurldecode($yql_query);
$encoded_yql_query = str_replace("%2A", "*", $encoded_yql_query);
$this->curl->post(self::YAHOO_CONSOLE_URL, array('q' => $encoded_yql_query, 'format' => $format));
return $this->handleCurlResponse();
}
开发者ID:gyvastis,项目名称:yql-web-scraper,代码行数:13,代码来源:YQLWebScraper.php
示例19: getMailNo
/**
* @return string
*/
public function getMailNo()
{
$curl = new Curl();
$curl->get($this->_getBillnumUrl, ['method' => 'getBillNumBySys', 'xml' => $this->generateBillNumRequestData()]);
$xml_str = $curl->response;
$xml = simplexml_load_string(base64_decode($xml_str));
return (string) $xml->assignIds->assignId->billno;
}
开发者ID:whplay,项目名称:ohmate-shop,代码行数:11,代码来源:EmsPost.php
示例20: _html
protected function _html()
{
$curl = new Curl();
$curl->setHeader('User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36');
$curl->setOpt(CURLOPT_FOLLOWLOCATION, true);
$html = $curl->get($this->url);
return $html;
}
开发者ID:vNative,项目名称:vnative,代码行数:8,代码来源:Scrape.php
注:本文中的Curl\Curl类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论