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


PHP Varien_Http_Client::setRawData方法代码示例

本文整理汇总了PHP中Varien_Http_Client::setRawData方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Http_Client::setRawData方法的具体用法?PHP Varien_Http_Client::setRawData怎么用?PHP Varien_Http_Client::setRawData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Varien_Http_Client的用法示例。


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

示例1: 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');
     }
 }
开发者ID:remtcs,项目名称:Implement-Module-for-prediction.io,代码行数:43,代码来源:MyrrixSDK.php

示例2: _getTransactionDetails

 /**
  * This function returns full transaction details for a specified transaction ID.
  *
  * @link http://www.authorize.net/support/ReportingGuide_XML.pdf
  * @link http://developer.authorize.net/api/transaction_details/
  * @param string $transactionId
  * @return Varien_Object
  */
 protected function _getTransactionDetails($transactionId)
 {
     $requestBody = sprintf('<?xml version="1.0" encoding="utf-8"?>' . '<getTransactionDetailsRequest xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd">' . '<merchantAuthentication><name>%s</name><transactionKey>%s</transactionKey></merchantAuthentication>' . '<transId>%s</transId>' . '</getTransactionDetailsRequest>', $this->getConfigData('login'), $this->getConfigData('trans_key'), $transactionId);
     $client = new Varien_Http_Client();
     $uri = $this->getConfigData('cgi_url_td');
     $client->setUri($uri ? $uri : self::CGI_URL_TD);
     $client->setConfig(array('timeout' => 45));
     $client->setHeaders(array('Content-Type: text/xml'));
     $client->setMethod(Zend_Http_Client::POST);
     $client->setRawData($requestBody);
     $debugData = array('request' => $requestBody);
     try {
         $responseBody = $client->request()->getBody();
         $debugData['result'] = $responseBody;
         $this->_debug($debugData);
         libxml_use_internal_errors(true);
         $responseXmlDocument = new Varien_Simplexml_Element($responseBody);
         libxml_use_internal_errors(false);
     } catch (Exception $e) {
         Mage::throwException(Mage::helper('paygate')->__('Payment updating error.'));
     }
     $response = new Varien_Object();
     $response->setResponseCode((string) $responseXmlDocument->transaction->responseCode)->setResponseReasonCode((string) $responseXmlDocument->transaction->responseReasonCode);
     return $response;
 }
开发者ID:par-orillonsoft,项目名称:magento_work,代码行数:33,代码来源:Authorizenet.php

示例3: _getXMLTracking

 /**
  * Send request for tracking
  *
  * @param array $trackings
  * @return void
  */
 protected function _getXMLTracking($trackings)
 {
     $xmlStr = '<?xml version="1.0" encoding="UTF-8"?>' . '<req:KnownTrackingRequest' . ' xmlns:req="http://www.dhl.com"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . ' xsi:schemaLocation="http://www.dhl.com TrackingRequestKnown.xsd" />';
     $xml = new SimpleXMLElement($xmlStr);
     $requestNode = $xml->addChild('Request', '', '');
     $serviceHeaderNode = $requestNode->addChild('ServiceHeader', '', '');
     $serviceHeaderNode->addChild('SiteID', (string) $this->getConfigData('id'));
     $serviceHeaderNode->addChild('Password', (string) $this->getConfigData('password'));
     $xml->addChild('LanguageCode', 'EN', '');
     foreach ($trackings as $tracking) {
         $xml->addChild('AWBNumber', $tracking, '');
     }
     /*
      * Checkpoint details selection flag
      * LAST_CHECK_POINT_ONLY
      * ALL_CHECK_POINTS
      */
     $xml->addChild('LevelOfDetails', 'ALL_CHECK_POINTS', '');
     /*
      * Value that indicates for getting the tracking details with the additional
      * piece details and its respective Piece Details, Piece checkpoints along with
      * Shipment Details if queried.
      *
      * S-Only Shipment Details
      * B-Both Shipment & Piece Details
      * P-Only Piece Details
      * Default is ‘S’
      */
     //$xml->addChild('PiecesEnabled', 'ALL_CHECK_POINTS');
     $request = $xml->asXML();
     $request = utf8_encode($request);
     $responseBody = $this->_getCachedQuotes($request);
     if ($responseBody === null) {
         $debugData = array('request' => $request);
         try {
             $client = new Varien_Http_Client();
             $client->setUri((string) $this->getConfigData('gateway_url'));
             $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
             $client->setRawData($request);
             $responseBody = $client->request(Varien_Http_Client::POST)->getBody();
             $debugData['result'] = $responseBody;
             $this->_setCachedQuotes($request, $responseBody);
         } catch (Exception $e) {
             $this->_errors[$e->getCode()] = $e->getMessage();
             $responseBody = '';
         }
         $this->_debug($debugData);
     }
     $this->_parseXmlTrackingResponse($trackings, $responseBody);
 }
开发者ID:okite11,项目名称:frames21,代码行数:56,代码来源:International.php

示例4: approveOrder

 public function approveOrder(Varien_Event_Observer $observer)
 {
     if (!$this->_helper->isActive()) {
         return;
     }
     if (!$this->_helper->isEligible()) {
         return;
     }
     $this->_helper->log("approveOrder: begin");
     $order = $observer->getEvent()->getOrder();
     $orderId = $order->getId();
     $orderIncrementId = $order->getIncrementId();
     $this->_helper->log("approveOrder: orderid: {$orderId} orderIncrementId: {$orderIncrementId}");
     $url = rtrim($this->_helper->getApiUrl(), '/') . '/approveOrder';
     $client = new Varien_Http_Client($url);
     $client->setMethod(Varien_Http_Client::POST)->setConfig(array('timeout' => 8000, 'maxredirects' => 2));
     $quoteId = $order->getQuoteId();
     $deliverytime = Mage::getModel('milkman_deliveries/deliverytime');
     $deliverytime->load($quoteId, 'quote_id');
     $sessionId = $deliverytime->getSessionId();
     $data = (object) ['privateKey' => $this->_helper->getPrivateKey(), 'sessionId' => $sessionId, 'externalTrackingCode' => $orderIncrementId];
     // $client->setParameterPost($data);
     $json = utf8_encode(json_encode($data, JSON_UNESCAPED_SLASHES));
     $this->_helper->log("approveOrder: json: {$json}");
     $client->setRawData($json);
     $error = true;
     try {
         $response = $client->request();
         $body = $response->getBody();
         if ($response->isSuccessful()) {
             $result = json_decode($body, true);
             $checkJson = JSON_ERROR_NONE == json_last_error();
             $checkSuccess = isset($result['result']['success']) && $result['result']['success'];
             if ($checkJson && $checkSuccess) {
                 $error = false;
                 $this->_helper->log("approveOrder: success");
             } else {
                 if (json_last_error() > 0) {
                     $this->_helper->log("approveOrder: json error code: " . json_last_error());
                 } else {
                     $this->_helper->log("approveOrder: data error");
                 }
             }
         } else {
             $this->_helper->log("approveOrder: rest error");
         }
     } catch (Exception $e) {
         $body = $response->getBody();
         $this->_helper->log("approveOrder: exception error");
     }
     $this->_helper->log("approveOrder: body: " . $body);
     if ($error) {
         $this->_helper->log("approveOrder: error");
         Mage::throwException($this->_helper->__("An error occurred during order confirmation."));
     }
 }
开发者ID:milkman-deliveries,项目名称:magento-milkman,代码行数:56,代码来源:Observer.php

示例5: postData

 public function postData($json, $endpoint)
 {
     $apiURL = Mage::getStoreConfig('settings/endpoint_url') . '/' . $endpoint;
     $appID = Mage::getStoreConfig('reachly_handleevent_options/section_one/field_app_id');
     $secretKey = Mage::getStoreConfig('reachly_handleevent_options/section_one/field_secret_key');
     $auth = $appID . ":" . base64_encode(hash_hmac('sha256', $json, $secretKey));
     $client = new Varien_Http_Client();
     $client->setUri($apiURL)->setMethod('POST')->setConfig(array('maxredirects' => 0, 'timeout' => 15));
     $client->setHeaders(array('Content-Length: ' . strlen($json), 'Authorization: ' . $auth));
     $client->setRawData($json, "application/json;charset=UTF-8");
     $reqCounter = 0;
     do {
         $success = true;
         try {
             $response = $client->request();
         } catch (Zend_Http_Client_Exception $e) {
             $success = false;
             $reqCounter++;
         }
     } while (!$success && $reqCounter < 3);
 }
开发者ID:Baumerts,项目名称:magento,代码行数:21,代码来源:Data.php


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