本文整理汇总了PHP中Varien_Http_Client::request方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Http_Client::request方法的具体用法?PHP Varien_Http_Client::request怎么用?PHP Varien_Http_Client::request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Http_Client
的用法示例。
在下文中一共展示了Varien_Http_Client::request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: license
/**
* license the app
*
*/
public static function license($activationKey, $productToken)
{
$url = 'https://ls.amazonaws.com/';
$client = new Varien_Http_Client($url);
$client->setMethod(Zend_Http_Client::GET);
$client->setParameterGet("Action", "ActivateDesktopProduct");
$client->setParameterGet("ActivationKey", $activationKey);
$client->setParameterGet("ProductToken", $productToken);
$response = $client->request();
if ($response->isSuccessful()) {
$body = $response->getRawBody();
$xml = new SimpleXMLElement($body);
$result = array();
$result["access"] = $xml->ActivateDesktopProductResult->AWSAccessKeyId;
$result["secret"] = $xml->ActivateDesktopProductResult->SecretAccessKey;
$result["usertoken"] = $xml->ActivateDesktopProductResult->UserToken;
// uncomment to debug raw submission response
//Mage::log("result=" . print_r($result,true));
return $result;
} else {
Mage::log("Activation failed to URL: " . $url . ", HTTP response code was not 200");
Mage::log("Raw response: " . print_r($response, true));
return false;
}
}
示例2: indexAction
/**
* run synchronize customer to Magestore
*/
public function indexAction()
{
// Turn Off
die('x');
$session = Mage::getSingleton('core/session');
$limit = $this->getRequest()->getParam('limit', 10);
$start = (int) $session->getLastAccountId();
// Customer info
$customers = Mage::getResourceModel('customer/customer_collection');
$customers->addFieldToFilter('entity_id', array('gt' => $start))->addAttributeToSelect('email')->addAttributeToSelect('firstname')->addAttributeToSelect('lastname')->addAttributeToSelect('password_hash')->getSelect()->limit($limit)->order('entity_id ASC');
if (!$customers->count()) {
echo '0';
return;
}
$customerData = array();
foreach ($customers as $customer) {
$customerData[] = array('email' => $customer->getEmail(), 'firstname' => $customer->getFirstname(), 'lastname' => $customer->getLastname(), 'password_hash' => $customer->getPasswordHash());
$start = $customer->getId();
}
// Run query
$url = Mage::getStoreConfig('subsystem/general/account') . 'add';
$client = new Varien_Http_Client($url);
$client->setParameterPost('pk', Magestore_Subsystem_Model_Observer::PK);
$client->setParameterPost('data', Zend_Json::encode($customerData));
$response = $client->request(Varien_Http_Client::POST);
// Update start to session
$session->setLastAccountId($start);
echo $start;
echo '<br>' . $response->getBody();
}
示例3: queryMaxMind
function queryMaxMind($params)
{
$servers = array("http://minfraud1.maxmind.com", "http://minfraud2.maxmind.com");
$return = array();
$error = false;
foreach ($servers as $server) {
$http = new Varien_Http_Client($server . "/app/ccv2r");
$http->setParameterPost($params);
try {
$response = $http->request('POST');
} catch (Exception $e) {
continue;
}
if ($response->getStatus() != '200') {
continue;
}
foreach (explode(";", $response->getBody()) as $keyval) {
$bits = explode("=", $keyval);
if (count($bits) > 1) {
list($key, $value) = $bits;
$return[$key] = $value;
}
}
if (!empty($return)) {
break;
}
}
if (empty($return)) {
$return['errmsg'] = "Could not contact MaxMind servers.";
$return['err'] = "FATAL_ERROR";
}
return $return;
}
示例4: apiCall
/**
* Create an api request and inject the app token.
*
* @param string Path to the rest method being called
* @param string Request method: GET, POST, PUT or DELETE
* @param mixed An array of parameters or raw post data. Raw data isn't accepted for GET.
* @return null
* @throws Exception Invalid or failed requests throw exceptions.
*/
protected function apiCall($path, $requestMethod, $params = array())
{
$requestMethod = strtoupper($requestMethod);
switch ($requestMethod) {
case 'GET':
$setParamMethod = 'setParameterGet';
if (!is_array($params)) {
throw new Exception('GET parameters can\'t be provided as raw data.');
}
break;
case 'POST':
case 'PUT':
case 'DELETE':
$setParamMethod = 'setParameterPost';
break;
default:
throw new Exception('Invalid request method');
}
$client = new Varien_Http_Client($this->serverLocation . $path);
$client->setMethod($requestMethod);
if (is_array($params)) {
foreach ($params as $paramKey => $paramValue) {
call_user_func(array($client, $setParamMethod), $paramKey, $paramValue);
}
} else {
$client->setRawData($params);
}
$response = $client->request();
if ($response->isSuccessful()) {
return json_decode($response->getBody());
} else {
throw new Exception('Request failed');
}
}
示例5: executeApiCall
/**
* Only executed if sendOrderStatus validates true for orderStatuses, order data and API data is fetched
* URL is then formed and sent as a GET request, response is then decoded with boolean values. Exception
* thrown if the request cannot be successfully made. Warning thrown if connection is successfully but
* credentials are not correct
*
* @param $order
* @param $orderStatus
* @throws throwException
*/
public function executeApiCall($order, $orderStatus)
{
$apiUrl = Mage::helper('orderstatus')->getApiUrl();
$apiServiceName = Mage::helper('orderstatus')->getApiServiceName();
$apiUsername = Mage::helper('orderstatus')->getApiUsername();
$apiPassword = Mage::helper('orderstatus')->getApiPassword();
$apiMethod = Mage::helper('orderstatus')->getApiMethod();
$apiDebuggingEnabled = Mage::helper('orderstatus')->isDebuggingEnabled();
$orderNumber = $order->getIncrementId();
$orderDateStatusChanged = $order->getUpdatedAt();
$orderStatus = $orderStatus;
$apiRequest = $apiUrl . $apiMethod . "?service=" . $apiServiceName . "&username=" . $apiUsername . "&password=" . $apiPassword . "&orderno=" . $orderNumber . "&date=" . str_replace(" ", "_", $orderDateStatusChanged) . "&status=" . $orderStatus;
try {
$client = new Varien_Http_Client($apiRequest);
$client->setMethod(Varien_Http_Client::GET);
$response = $client->request();
if ($apiDebuggingEnabled) {
Mage::getSingleton('adminhtml/session')->addWarning("API Request : " . $apiRequest);
Mage::getSingleton('adminhtml/session')->addWarning("API Response : " . $response->getBody());
}
if ($response->isSuccessful()) {
Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API connection was successful.');
$responseJson = json_decode($response->getBody());
if ($responseJson->serviceresult->success == 1) {
Mage::getSingleton('adminhtml/session')->addSuccess('Order status was successfully sent to Touch Retail.');
} else {
Mage::getSingleton('adminhtml/session')->addWarning('Unable to send order status to Touch Retail, please check your API method System > Configuration menu.');
}
} else {
Mage::getSingleton('adminhtml/session')->addWarning('Unable to connect to Touch Retail, please check your API credentials in System > Configuration menu.');
}
} catch (Exception $e) {
Mage::throwException('Unable to send your API request, this maybe due to a malformed URL.');
}
}
示例6: request
/**
* @param array $data Array of each installed Fontis extensions version
* @return string
* @throws Exception
*/
public function request($data)
{
$client = new Varien_Http_Client(Mage::helper('fontis_info')->getInfoUrl(), array('keepalive' => true));
$client->setParameterPost('data', $data);
// If we accept gzip encoding and the response isn't actually chunked, Zend_Http_Response will throw
// an exception. Unfortunately, this means we can't use gzip encoded responses at this time.
$client->setHeaders('Accept-encoding', 'identity');
$response = $client->request(Varien_Http_Client::POST);
if ($response->isError()) {
// if the request fails, throw an exception
throw new Exception('Error getting info data: ' . $response->getStatus() . ' ' . $response->getMessage());
}
return $response->getBody();
}
示例7: codesAction
/**
* Retrieve js scripts by parsing remote Google Optimizer page
*/
public function codesAction()
{
if ($this->getRequest()->getQuery('url')) {
$client = new Varien_Http_Client($this->getRequest()->getQuery('url'));
$response = $client->request(Varien_Http_Client::GET);
$result = array();
if (preg_match_all('/<textarea[^>]*id="([_a-zA-Z0-9]+)"[^>]*>([^<]+)<\\/textarea>/', $response->getRawBody(), $matches)) {
$c = count($matches[1]);
for ($i = 0; $i < $c; $i++) {
$id = $matches[1][$i];
$code = $matches[2][$i];
$result[$id] = $code;
}
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
示例8: _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();
}
示例9: 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;
}
示例10: checkAction
/**
* Return some checking result
*
* @return void
*/
public function checkAction()
{
$apiUrl = Mage::helper('orderstatus')->getApiUrl();
$apiServiceName = Mage::helper('orderstatus')->getApiServiceName();
$apiUsername = Mage::helper('orderstatus')->getApiUsername();
$apiPassword = Mage::helper('orderstatus')->getApiPassword();
$apiMethod = Mage::helper('orderstatus')->getApiMethod();
$apiDebuggingEnabled = Mage::helper('orderstatus')->isDebuggingEnabled();
$apiRequest = $apiUrl . $apiMethod . "?service=" . $apiServiceName . "&username=" . $apiUsername . "&password=" . $apiPassword;
Mage::log($apiRequest);
try {
$client = new Varien_Http_Client($apiRequest);
$client->setMethod(Varien_Http_Client::GET);
$response = $client->request();
Mage::log($response);
if ($apiDebuggingEnabled) {
Mage::getSingleton('adminhtml/session')->addWarning("API Request : " . $apiRequest);
Mage::getSingleton('adminhtml/session')->addWarning("API Response : " . $response->getBody());
}
if ($response->isSuccessful()) {
Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API connection was successful.');
$responseJson = json_decode($response->getBody());
if ($responseJson->serviceresult && $responseJson->serviceresult->success == 1) {
Mage::getSingleton('adminhtml/session')->addSuccess('Touch Retail API credentials are valid.');
Mage::app()->getResponse()->setBody($responseJson->serviceresult->success);
} else {
Mage::getSingleton('adminhtml/session')->addwarning('Touch Retail API credentials are invalid.');
Mage::app()->getResponse()->setBody($responseJson->serviceresult->errormessage);
}
} else {
Mage::getSingleton('adminhtml/session')->addWarning('Unable to connect to Touch Retail, please check your API credentials .');
Mage::app()->getResponse()->setBody($responseJson->serviceresult->errormessage);
}
} catch (Exception $e) {
Mage::throwException('Unable to send your API request, this maybe due to a malformed URL.');
}
}
示例11: _verifyResponse
/**
* Veritfy the gateway response
*
* @param string $apiKey
* @param string $token
* @param string $timestamp
* @param string $signature
* @return boolean
*/
public function _verifyResponse($purchase_id)
{
$client_id = Mage::helper('sign2pay')->getSign2payClientId();
$client_secret = Mage::helper('sign2pay')->getSign2payClientSecret();
$client = new Varien_Http_Client('https://app.sign2pay.com/api/v2/payment/status/' . $purchase_id);
$client->setMethod(Varien_Http_Client::GET);
$client->setAuth($client_id, $client_secret);
try {
$response = $client->request();
$body = json_decode($response->getBody());
if (array_key_exists('status', $body) || $body['status'] == 'processing') {
return true;
} else {
return false;
}
} catch (Zend_Http_Client_Exception $e) {
Mage::logException($e);
return false;
}
}
示例12: _postRequest
protected function _postRequest(Varien_Object $request)
{
$debugData = array('request' => $request->getData());
$result = Mage::getModel('paygate/authorizenet_result');
$client = new Varien_Http_Client();
$uri = $this->getConfigData('cgi_url');
$client->setUri($uri ? $uri : self::CGI_URL);
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$client->setParameterPost($request->getData());
$client->setMethod(Zend_Http_Client::POST);
try {
$response = $client->request();
} catch (Exception $e) {
$result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
$debugData['result'] = $result->getData();
$this->_debug($debugData);
Mage::throwException($this->_wrapGatewayError($e->getMessage()));
}
$responseBody = $response->getBody();
$r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
if ($r) {
$result->setResponseCode((int) str_replace('"', '', $r[0]))->setResponseSubcode((int) str_replace('"', '', $r[1]))->setResponseReasonCode((int) str_replace('"', '', $r[2]))->setResponseReasonText($r[3])->setApprovalCode($r[4])->setAvsResultCode($r[5])->setTransactionId($r[6])->setInvoiceNumber($r[7])->setDescription($r[8])->setAmount($r[9])->setMethod($r[10])->setTransactionType($r[11])->setCustomerId($r[12])->setMd5Hash($r[37])->setCardCodeResponseCode($r[38])->setCAVVResponseCode(isset($r[39]) ? $r[39] : null);
} else {
Mage::throwException(Mage::helper('paygate')->__('Error in payment gateway.'));
}
$debugData['result'] = $result->getData();
$this->_debug($debugData);
return $result;
}
示例13: _postRequest
/**
* Send request to gateway
*
* @param Mage_Chronopay_Model_Gateway_Request
* @return mixed
*/
protected function _postRequest(Mage_Chronopay_Model_Gateway_Request $request)
{
$result = Mage::getModel('chronopay/gateway_result');
$client = new Varien_Http_Client();
$url = $this->getConfigData('cgi_url');
$client->setUri($url ? $url : self::CGI_URL);
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$client->setParameterPost($request->getData());
$client->setMethod(Zend_Http_Client::POST);
$debugData = array('request' => $request->getData());
try {
$response = $client->request();
$body = $response->getRawBody();
if (preg_match('/(T\\|(.+)\\|[\\r\\n]{0,}){0,1}(Y\\|(.+)?|\\|)|(N\\|(.+[\\r\\n]{0,}.+){0,})/', $body, $matches)) {
$transactionId = $matches[2];
$message = isset($matches[4]) ? trim($matches[4], '|') : '';
if (isset($matches[5], $matches[6])) {
$result->setError($matches[6]);
Mage::throwException($matches[6]);
}
if ($message == 'Completed') {
$result->setTransaction($request->getTransaction());
}
if (strlen($transactionId)) {
$result->setTransaction($transactionId);
}
if (!$result->getTransaction()) {
Mage::throwException(Mage::helper('chronopay')->__('The transaction ID is invalid.'));
}
} else {
Mage::throwException(Mage::helper('chronopay')->__('Invalid response format.'));
}
} catch (Exception $e) {
$result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
$exceptionMsg = Mage::helper('chronopay')->__('Gateway request error: %s', $e->getMessage());
$debugData['result'] = $result->getData();
$this->_debug($debugData);
Mage::throwException($exceptionMsg);
}
$debugData['result'] = $result->getData();
$this->_debug($debugData);
return $result;
}
示例14: processAdminRequest
protected function processAdminRequest($params, $requestTimeout = 60)
{
try {
$client = new Varien_Http_Client();
$client->setUri($this->getAdminUrl())->setConfig(array('timeout' => $requestTimeout))->setParameterPost($params)->setMethod(Zend_Http_Client::POST);
$response = $client->request();
$responseBody = $response->getBody();
if (empty($responseBody)) {
Mage::throwException($this->_getHelper()->__('vacc API failure. The request has not been processed.'));
}
// create array out of response
} catch (Exception $e) {
Mage::log($e->getMessage());
Mage::throwException($this->_getHelper()->__('vacc API connection error. The request has not been processed.'));
}
return $responseBody;
}
示例15: _postRequest
protected function _postRequest(Varien_Object $request)
{
$result = AO::getModel('paygate/authorizenet_result');
$client = new Varien_Http_Client();
$uri = $this->getConfigData('cgi_url');
$client->setUri($uri ? $uri : self::CGI_URL);
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$client->setParameterPost($request->getData());
$client->setMethod(Zend_Http_Client::POST);
if ($this->getConfigData('debug')) {
foreach ($request->getData() as $key => $value) {
$requestData[] = strtoupper($key) . '=' . $value;
}
$requestData = join('&', $requestData);
$debug = AO::getModel('paygate/authorizenet_debug')->setRequestBody($requestData)->setRequestSerialized(serialize($request->getData()))->setRequestDump(print_r($request->getData(), 1))->save();
}
try {
$response = $client->request();
} catch (Exception $e) {
$result->setResponseCode(-1)->setResponseReasonCode($e->getCode())->setResponseReasonText($e->getMessage());
if (!empty($debug)) {
$debug->setResultSerialized(serialize($result->getData()))->setResultDump(print_r($result->getData(), 1))->save();
}
AO::throwException(AO::helper('paygate')->__('Gateway request error: %s', $e->getMessage()));
}
$responseBody = $response->getBody();
$r = explode(self::RESPONSE_DELIM_CHAR, $responseBody);
if ($r) {
$result->setResponseCode((int) str_replace('"', '', $r[0]))->setResponseSubcode((int) str_replace('"', '', $r[1]))->setResponseReasonCode((int) str_replace('"', '', $r[2]))->setResponseReasonText($r[3])->setApprovalCode($r[4])->setAvsResultCode($r[5])->setTransactionId($r[6])->setInvoiceNumber($r[7])->setDescription($r[8])->setAmount($r[9])->setMethod($r[10])->setTransactionType($r[11])->setCustomerId($r[12])->setMd5Hash($r[37])->setCardCodeResponseCode($r[39]);
} else {
AO::throwException(AO::helper('paygate')->__('Error in payment gateway'));
}
if (!empty($debug)) {
$debug->setResponseBody($responseBody)->setResultSerialized(serialize($result->getData()))->setResultDump(print_r($result->getData(), 1))->save();
}
return $result;
}