本文整理匯總了PHP中Varien_Http_Client::setUri方法的典型用法代碼示例。如果您正苦於以下問題:PHP Varien_Http_Client::setUri方法的具體用法?PHP Varien_Http_Client::setUri怎麽用?PHP Varien_Http_Client::setUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Varien_Http_Client
的用法示例。
在下文中一共展示了Varien_Http_Client::setUri方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _convert
/**
* Retrieve rate
*
* @param string $currencyFrom
* @param string $currencyTo
* @return float
*/
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
{
if ($currencyFrom != 'RUB' && $currencyTo != 'RUB') {
return null;
}
$direction = null;
if ($currencyTo == 'RUB') {
$direction = 'to';
}
if ($currencyFrom == 'RUB') {
$direction = 'from';
}
if (!$direction) {
return null;
}
try {
$response = $this->_httpClient->setUri($this->_url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/cbrf/timeout')))->request('GET')->getBody();
$xml = simplexml_load_string($response, null, LIBXML_NOERROR);
if (!$xml) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
return null;
}
return $this->processRates($xml->Valute, $direction, $currencyFrom, $currencyTo);
} catch (Exception $e) {
if ($retry == 0) {
$this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
}
}
return null;
}
示例2: __construct
/**
* Initialise our object with the full rates retrieved from Privatbankrates as the
* free version only allows us to get the complete set of rates. But that's ok, we are
* caching it and then processing the individual rates
*
* @throws Exception
*/
public function __construct()
{
$this->_httpClient = new Varien_Http_Client();
$url = $this->_url;
$response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/pm_privatbankrates/timeout')))->request('GET')->getBody();
// response is in json format
if (!$response) {
$this->_messages[] = Mage::helper('pm_privatbankrates')->__('Cannot retrieve rate from %s.', $url);
} else {
// check response content - returns array
$response = Zend_Json::decode($response);
if (array_key_exists('error', $response)) {
$this->_messages[] = Mage::helper('pm_privatbankrates')->__('API returned error %s: %s', $response['status'], $response['description']);
} elseif (array_key_exists('base_ccy', $response[0])) {
$rates = array();
$rates['UAH'] = array('buy' => 1, 'sale' => 1);
foreach ((array) $response as $currency) {
$rates[$currency['ccy']] = $currency;
}
$this->_rates = $rates;
} else {
Mage::log('Privatbankrates API request: %s', $url);
Mage::log('Privatbankrates API response: ' . print_r($response, true));
$this->_messages[] = Mage::helper('pm_privatbankrates')->__('Unknown response from API, check system.log for details.');
}
}
}
示例3: _convert
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
{
$url = sprintf($this->_url, $currencyFrom, $currencyTo);
try {
$response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/fixerio/timeout')))->request('GET')->getBody();
$converted = json_decode($response);
$rate = $converted->rates->{$currencyTo};
if (!$rate) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
return null;
}
//test for bcmath to retain precision
if (function_exists('bcadd')) {
return bcadd($rate, '0', 12);
}
return (double) $rate;
} catch (Exception $e) {
if ($retry == 0) {
return $this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
return null;
}
}
}
示例4: _convert
/**
* Retrieve rate
*
* @param string $currencyFrom
* @param string $currencyTo
* @param int $retry
* @return float
*/
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
{
$url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
$url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
try {
sleep(Mage::getStoreConfig('currency/google_finance/delay'));
$response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/google_finance/timeout')))->request('GET')->getBody();
$data = explode('bld>', $response);
if (empty($data[1])) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
return null;
}
$data = explode($currencyTo, $data[1]);
$exchangeRate = 1;
if (empty($data[0])) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
return null;
} else {
$exchangeRate = $data[0];
}
return (double) $exchangeRate * 1.0;
} catch (Exception $e) {
if ($retry == 0) {
$this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s', $url);
}
}
}
示例5: getHttpClient
/**
* Get the Http Client to use for the request to reCAPTCHA
*
* @return Varien_Http_Client
*/
public function getHttpClient()
{
if (is_null($this->_client)) {
$this->_client = new Varien_Http_Client();
}
$this->_client->setUri(self::REQUEST_URL);
return $this->_client;
}
示例6: restRequest
public function restRequest($method, $params)
{
$result = null;
$url = $this->_getRestUrl($method);
$data = $this->_restDataFormat($method, $params);
$httpClient = new Varien_Http_Client();
$result = $httpClient->setUri($url)->setHeaders('Content-Type: text/xml; charset=UTF-8')->setRawData($data)->request(Varien_Http_Client::POST)->getBody();
return $result;
}
示例7: _convert
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
{
$supported = $this->getSupportedCurrencies();
if (!(in_array($currencyFrom, $supported) && $currencyTo == 'BTC' || $currencyFrom == 'BTC' && in_array($currencyTo, $supported))) {
$this->_messages[] = Mage::helper('directory')->__('Conversion from %s to %s is not supported by BitPay Bitcoin Exchange Rates will fallback to use Webservicex.', $currencyFrom, $currencyTo);
try {
$default = Mage::getModel('directory/currency_import_webservicex');
return $default->convert($currencyFrom, $currencyTo);
} catch (Exception $e) {
$this->_messages[] = $e->getMessage();
}
}
try {
$response = $this->_httpClient->setUri($this->_url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/bitpay/timeout')))->request('GET')->getBody();
$prices = (array) json_decode($response);
if (!$prices) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
return null;
}
$altCurrency = $currencyFrom == "BTC" ? $currencyTo : $currencyFrom;
foreach ($prices as $price) {
if ($price->code == $altCurrency) {
$rate = $price->rate;
}
}
if (!$rate) {
return null;
}
if ($currencyFrom == "BTC") {
$result = (double) $rate;
} else {
$result = 1 / (double) $rate;
}
$this->_messages[] = Mage::helper('directory')->__('Retrieved rate from %s to %s.', $currencyFrom, $currencyTo);
return $result;
} catch (Exception $e) {
if ($retry == 0) {
$this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $_url);
}
}
}
示例8: tunnelAction
public function tunnelAction()
{
$httpClient = new Varien_Http_Client();
if ($ga = $this->getRequest()->getParam('ga')) {
if ($params = unserialize(base64_decode(urldecode($ga)))) {
$response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 15))->request('GET');
$headers = $response->getHeaders();
$this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
}
}
}
示例9: _convert
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
{
$url = str_replace('{{CURRENCY_FROM}}', $currencyFrom, $this->_url);
$url = str_replace('{{CURRENCY_TO}}', $currencyTo, $url);
try {
$response = $this->_httpClient->setUri($url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/webservicex/timeout')))->request('GET')->getBody();
$xml = simplexml_load_string($response, null, LIBXML_NOERROR);
if (!$xml) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
return null;
}
return (double) $xml;
} catch (Exception $e) {
if ($retry == 0) {
$this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
}
}
}
示例10: _convert
protected function _convert($currencyFrom, $currencyTo, $retry = 0)
{
$supported = $this->getSupportedCurrencies();
if (!(in_array($currencyFrom, $supported) && $currencyTo == 'BTC' || $currencyFrom == 'BTC' && in_array($currencyTo, $supported))) {
//$this->_messages[] = Mage::helper('bitcoin')->__('Conversion from %s to %s is not supported in Bitcoincharts.', $currencyFrom, $currencyTo);
//return null;
try {
$default = Mage::getModel('directory/currency_import_webservicex');
return $default->convert($currencyFrom, $currencyTo);
} catch (Exception $e) {
$this->_messages[] = $e->getMessage();
}
}
try {
$response = $this->_httpClient->setUri($this->_url)->setConfig(array('timeout' => Mage::getStoreConfig('currency/bitcoincharts/timeout')))->request('GET')->getBody();
$prices = (array) json_decode($response);
if (!$prices) {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $this->_url);
return null;
}
$altCurrency = $currencyFrom == "BTC" ? $currencyTo : $currencyFrom;
// 24h, 7d, 30d
// assume 24h
$rate = (array) $prices[$altCurrency];
if (!$rate) {
return null;
}
if ($currencyFrom == "BTC") {
$result = (double) $rate["24h"];
} else {
$result = 1 / (double) $rate["24h"];
}
return $result;
} catch (Exception $e) {
if ($retry == 0) {
$this->_convert($currencyFrom, $currencyTo, 1);
} else {
$this->_messages[] = Mage::helper('directory')->__('Cannot retrieve rate from %s.', $url);
}
}
}
示例11: tunnelAction
public function tunnelAction()
{
$httpClient = new Varien_Http_Client();
$gaData = $this->getRequest()->getParam('ga');
$gaHash = $this->getRequest()->getParam('h');
if ($gaData && $gaHash) {
$newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
if ($newHash == $gaHash) {
$params = json_decode(base64_decode(urldecode($gaData)), true);
if ($params) {
$response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 5))->request('GET');
$headers = $response->getHeaders();
$this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
}
}
}
}
示例12: tunnelAction
public function tunnelAction()
{
//if(!Mage::helper('magenotification')->checkLicenseKeyAdminController($this)){ return; }
$httpClient = new Varien_Http_Client();
$gaData = $this->getRequest()->getParam('ga');
$gaHash = $this->getRequest()->getParam('h');
if ($gaData && $gaHash) {
$newHash = Mage::helper('adminhtml/dashboard_data')->getChartDataHash($gaData);
if ($newHash == $gaHash) {
if ($params = unserialize(base64_decode(urldecode($gaData)))) {
$response = $httpClient->setUri(Mage_Adminhtml_Block_Dashboard_Graph::API_URL)->setParameterGet($params)->setConfig(array('timeout' => 5))->request('GET');
$headers = $response->getHeaders();
$this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody());
}
}
}
}
示例13: _beforeSave
/**
* Verify installation id in Worldpay registration system to reduce configuration failures (experimental)
*
* @return Phoenix_Worldpay_Model_Config_Backend_Instid
*/
protected function _beforeSave()
{
try {
if ($this->getValue()) {
$client = new Varien_Http_Client();
$client->setUri((string) Mage::getConfig()->getNode('phoenix/worldpay/verify_url'))->setConfig(array('timeout' => 10))->setHeaders('accept-encoding', '')->setParameterPost('inst_id', $this->getValue())->setMethod(Zend_Http_Client::POST);
$response = $client->request();
// $responseBody = $response->getBody();
// if (empty($responseBody) || $responseBody != 'VERIFIED') {
// verification failed. throw error message (not implemented yet).
// }
// okay, inst_id verified. continue saving.
}
} catch (Exception $e) {
// verification system unavailable. no further action.
}
return parent::_beforeSave();
}
示例14: localeTestAction
public function localeTestAction()
{
var_dump(Mage::getModel('inchoo_facebook/locale')->getOptionLocales());
//var_dump(Mage::app()->getLocale()->getOptionLocales());
return;
$client = new Varien_Http_Client();
$response = $client->setUri('http://www.facebook.com/translations/FacebookLocale.xml')->request('GET')->getBody();
$xml = simplexml_load_string($response, null, LIBXML_NOERROR);
if (!$xml) {
return null;
}
$locales = array();
foreach ($xml->locale as $item) {
$locales[(string) $item->codes->code->standard->representation] = (string) $item->englishName;
}
//var_dump($locales);
//Mage::app()->saveCache(serialize($locales), 'inchoo_facebook_locale', array(), 7*24*60*60);
//array(Mage_Core_Model_Config::CACHE_TAG)
//$locales = unserialize(Mage::app()->loadCache('inchoo_facebook_locale')); //false
var_dump($locales);
}
示例15: SendRequest
public function SendRequest($topic, $orderId, $customerId, $productId = 0, $categoryId = 0, $quoteId = 0)
{
$affiliate = 0;
$client = new Varien_Http_Client();
$company_app_name = $this->getStoreConfig('revenueconduit_app_name');
$store_name = $this->getStoreConfig('revenueconduit_store_name');
$storeId = Mage::app()->getStore()->getStoreId();
$url = Mage::getStoreConfig('web/unsecure/base_link_url', $storeId);
$host = "https://app.revenueconduit.com/magento_incoming_requests/receive";
$parameter = array("company_app_name" => $company_app_name, "store_name" => $store_name, 'domain' => $url);
if (!empty($_COOKIE) && array_key_exists('affiliate', $_COOKIE)) {
$affiliate = $_COOKIE['affiliate'];
}
$postParameters = array("topic" => $topic, "order_id" => $orderId, "customer_id" => $customerId, "product_id" => $productId, 'category_id' => $categoryId, 'referral_code_id' => $affiliate ? $affiliate : 0, 'quote_id' => $quoteId);
$client->setUri($host)->setConfig(array('timeout' => 30))->setParameterGet($parameter)->setParameterPost($postParameters)->setUrlEncodeBody(false)->setMethod(Zend_Http_Client::POST);
try {
$response = $client->request();
return $response->getBody();
} catch (Exception $e) {
Mage::log("Could not send the {$topic} request to RevenueConduit. Error Message: " . $e->getMessage(), null);
}
return null;
}