/** * Make a call to Payment Bridge service with given request parameters * * @param array $request * @return array * @throws Mage_Core_Exception */ protected function _call(array $request) { $response = null; $debugData = array('request' => $request); try { $http = new Varien_Http_Adapter_Curl(); $config = array('timeout' => 30); $http->setConfig($config); $http->write(Zend_Http_Client::POST, $this->getPbridgeEndpoint(), '1.1', array(), $this->_prepareRequestParams($request)); $response = $http->read(); $http->close(); } catch (Exception $e) { $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode()); $this->_debug($debugData); throw $e; } $this->_debug($response); if ($response) { $response = preg_split('/^\\r?$/m', $response, 2); $response = Mage::helper('core')->jsonDecode(trim($response[1])); $debugData['result'] = $response; $this->_debug($debugData); if ($http->getErrno()) { Mage::logException(new Exception(sprintf('Payment Bridge CURL connection error #%s: %s', $http->getErrno(), $http->getError()))); Mage::throwException(Mage::helper('enterprise_pbridge')->__('Unable to communicate with Payment Bridge service.')); } if (isset($response['status']) && $response['status'] == 'Success') { $this->_response = $response; return true; } } $this->_handleError($response); $this->_response = $response; return false; }
/** * This method will send call to external end points using GET or POST method * * @param type $apiType url that needs to be called * @param type $requestType GET or POST * @param type $data model data that needs to be send with url * @return type json * @throws Exception */ public function send($apiType, $requestType, $data) { $curlAdapter = new Varien_Http_Adapter_Curl(); $curlAdapter->setConfig(array('timeout' => 20)); $body_param = Mage::helper('core')->jsonEncode($data); $header = $this->getHeader(); try { $curlAdapter->write($requestType, $apiType, '1.1', $header, $body_param); $result = $curlAdapter->read(); $response = preg_split('/^\\r?$/m', $result, 2); $response = trim($response[1]); $res = NULL; if (!is_null($response) && !empty($response)) { $res = Mage::helper('core')->jsonDecode($response); } else { Mage::log('Encountered problems trying to contact Terapeak'); Mage::log($curlAdapter->getError()); } } catch (Exception $e) { //eat the execption. We should not crash the magento instance if our extention throws exceptions Mage::log('Exception when trying to send data to Terapeak:'); Mage::log($e); } return $res; }
public function isValidVies($taxvat, $countryCode) { if ('UK' === $countryCode) { $countryCode = 'GB'; } if (!isset($this->_patterns[$countryCode])) { $this->_message = 'The provided CountryCode is invalid for the VAT number'; return false; } // $vies = new SoapClient('http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'); // $check = new firecheckoutCheckVat($countryCode, $taxvat); // try { // $ret = $vies->checkVat($check); // } catch (SoapFault $e) { // $ret = $e->faultstring; // $pattern = '/\{ \'([A-Z_]*)\' \}/'; // $n = preg_match($pattern, $ret, $matches); // $ret = $matches[1]; // $faults = array( // 'INVALID_INPUT' => 'The provided CountryCode is invalid or the VAT number is empty', // 'SERVICE_UNAVAILABLE' => 'The SOAP service is unavailable, try again later', // 'MS_UNAVAILABLE' => 'The Member State service is unavailable, try again later or with another Member State', // 'TIMEOUT' => 'The Member State service could not be reached in time, try again later or with another Member State', // 'SERVER_BUSY' => 'The service cannot process your request. Try again later.' // ); // $this->_message = $faults[$ret]; // return false; // } // return true; try { $http = new Varien_Http_Adapter_Curl(); $http->setConfig(array('timeout' => 30)); $http->write(Zend_Http_Client::POST, 'http://ec.europa.eu/taxation_customs/vies/viesquer.do', '1.1', array(), http_build_query(array('ms' => $countryCode, 'iso' => $countryCode, 'vat' => $taxvat))); $response = $http->read(); $http->close(); } catch (Exception $e) { throw $e; } $response = str_replace(array("\n", "\r", "\t"), '', $response); if (empty($response) || strstr($response, 'Yes, valid VAT number')) { // if service is not available of correct vat number return true; } elseif (strstr($response, 'No, invalid VAT number')) { $this->_message = 'Invalid VAT number'; } elseif (strstr($response, 'Service unavailable')) { $this->_message = 'The VAT validation service unavailable. Please re-submit your request later.'; } elseif (strstr($response, 'Member State service unavailable')) { $this->_message = 'The VAT validation service unavailable. Please re-submit your request later.'; } elseif (strstr($response, 'Error: Incomplete')) { $this->_message = 'The provided CountryCode is invalid or the VAT number is empty'; } elseif (strstr($response, 'Request time-out')) { $this->_message = 'The VAT validation service cannot process your request. Try again later.'; } elseif (strstr($response, 'System busy')) { $this->_message = 'The VAT validation service cannot process your request. Try again later.'; } else { $this->_message = 'Unknown VAT validation service message. Try again later.'; } return false; }
/** * Do the API call * * @param string $methodName * @param array $request * @return array * @throws Mage_Core_Exception */ public function call($methodName, array $request) { $request = $this->_addMethodToRequest($methodName, $request); $eachCallRequest = $this->_prepareEachCallRequest($methodName); if ($this->getUseCertAuthentication()) { if ($key = array_search('SIGNATURE', $eachCallRequest)) { unset($eachCallRequest[$key]); } } $request = $this->_exportToRequest($eachCallRequest, $request); $debugData = array('url' => $this->getApiEndpoint(), $methodName => $request); try { $http = new Varien_Http_Adapter_Curl(); $config = array('timeout' => 30, 'verifypeer' => $this->_config->verifyPeer); if ($this->getUseProxy()) { $config['proxy'] = $this->getProxyHost() . ':' . $this->getProxyPort(); } if ($this->getUseCertAuthentication()) { $config['ssl_cert'] = $this->getApiCertificate(); } $http->setConfig($config); $http->write(Zend_Http_Client::POST, $this->getApiEndpoint(), '1.1', $this->_headers, $this->_buildQuery($request)); $response = $http->read(); } catch (Exception $e) { $debugData['http_error'] = array('error' => $e->getMessage(), 'code' => $e->getCode()); $this->_debug($debugData); throw $e; } $response = preg_split('/^\\r?$/m', $response); $response = trim(end($response)); $response = $this->_deformatNVP($response); $debugData['response'] = $response; $this->_debug($debugData); $response = $this->_postProcessResponse($response); // handle transport error if ($http->getErrno()) { Mage::logException(new Exception(sprintf('PayPal NVP CURL connection error #%s: %s', $http->getErrno(), $http->getError()))); $http->close(); Mage::throwException(Mage::helper('paypal')->__('Unable to communicate with the PayPal gateway.')); } // cUrl resource must be closed after checking it for errors $http->close(); if (!$this->_validateResponse($methodName, $response)) { Mage::logException(new Exception(Mage::helper('paypal')->__("PayPal response hasn't required fields."))); Mage::throwException(Mage::helper('paypal')->__('There was an error processing your order. Please contact us or try again later.')); } $this->_callErrors = array(); if ($this->_isCallSuccessful($response)) { if ($this->_rawResponseNeeded) { $this->setRawSuccessResponseData($response); } return $response; } $this->_handleCallErrors($response); return $response; }
protected function _loadUrl($url) { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 30)); $curl->write(Zend_Http_Client::GET, $url, '1.0'); $text = $curl->read(); $text = preg_split('/^\\r?$/m', $text, 2); $text = trim($text[1]); return $text; }
/** * Check if survey url valid (exists) or not * * @return boolen */ public static function isSurveyUrlValid() { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 5))->write(Zend_Http_Client::GET, self::getSurveyUrl(), '1.0'); $response = $curl->read(); if (Zend_Http_Response::extractCode($response) == 200) { return true; } return false; }
/** * If file is accessible return true or false * * @return bool */ private function _isFileAccessible() { $defaultUnsecureBaseURL = (string) Mage::getConfig()->getNode('default/' . Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL); $http = new Varien_Http_Adapter_Curl(); $http->setConfig(array('timeout' => $this->_verificationTimeOut)); $http->write(Zend_Http_Client::POST, $defaultUnsecureBaseURL . $this->_filePath); $responseBody = $http->read(); $responseCode = Zend_Http_Response::extractCode($responseBody); $http->close(); return $responseCode == 200; }
public function createApiPost($path, $data) { try { $config = array('timeout' => 30); $http = new Varien_Http_Adapter_Curl(); $feed_url = self::YOTPO_API_URL . DS . $this->app_key . DS . $path; $http->setConfig($config); $http->write(Zend_Http_Client::POST, $feed_url, '1.1', array('Content-Type: application/json'), json_encode($data)); $resData = $http->read(); } catch (Exception $e) { Mage::log('error: ' . $e); } }
public function sendRequest($request, $parameters = array()) { if (!$this->code || !$this->username || !$this->password) { return false; } if ($request != 'verifyUser' && !$this->session) { return false; } $parameters['sessionKey'] = $this->session; $parameters['request'] = $request; $parameters['version'] = '1.0'; $parameters['clientCode'] = $this->code; $url = $this->getUrl(); $http = new Varien_Http_Adapter_Curl(); $http->setConfig(array('timeout' => 100)); // $http->write(Zend_Http_Client::POST, $parameters); $http->write(Zend_Http_Client::POST, $url, CURL_HTTP_VERSION_1_0, array(), $parameters); $responseBody = Zend_Http_Response::extractBody($http->read()); $http->close(); if (Mage::getStoreConfig('eepohs_erply/general/log_requests')) { Mage::log("REQUEST URL: " . $url . "\nREQUEST PARAMETERS:\n" . print_r($parameters, true) . "\nRESPONSE:\n" . $responseBody, null, self::REQUEST_LOG); } // $http = new Varien_Http_Adapter_Curl(); // $config = array('timeout' => 30); // // $http->setConfig($config); // $http->write(Zend_Http_Client::POST, $url, '1.0', array(), http_build_query($parameters)); // $content = Zend_Http_Response::extractBody($http->read()); // print_r(Zend_Http_Response::extractHeaders($http->read())); //return $content; // $ch = curl_init(); // curl_setopt($ch, CURLOPT_URL, $url); // curl_setopt($ch, CURLOPT_HEADER, 1); // curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($ch, CURLOPT_POST, true); // curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters); // // if (curl_exec($ch) === false) // return false; // // $content = curl_multi_getcontent($ch); // curl_close($ch); // list($header1, $header2, $body) = explode("\r\n\r\n", $content, 3); return $responseBody; }
/** * @param array $url * @return array */ public function getCurlOptions($url) { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 5)); $curl->write(Zend_Http_Client::GET, $url); $response = $curl->read(); if ($response === false) { return false; } $response = preg_split('/^\\r?$/m', $response, 2); $response = trim($response[1]); $options = explode("\n", $response); $curl->close(); return $options; }
public function getClientData() { $eadesignUrl = 'https://www.eadesign.ro/'; $extension = 'Eadesigndev_Awb'; $moduleVersion = Mage::getConfig()->getModuleConfig($extension)->version; $baseUrl = 'track/index/update?url=' . Mage::getBaseUrl(); $version = '&version=' . $moduleVersion; $moduleExtension = '&extension=' . $extension; $url = $eadesignUrl . $baseUrl . $version . $moduleExtension; $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 3)); $curl->write(Zend_Http_Client::GET, $url, '1.0'); $curl->read(); $curl->close(); }
/** * Perform a CURL call and log request end response to logfile * * @param array $params * @return mixed */ public function call($params, $url) { try { $http = new Varien_Http_Adapter_Curl(); $config = array('timeout' => 30); $http->setConfig($config); $http->write(Zend_Http_Client::POST, $url, '1.1', array(), http_build_query($params)); $response = $http->read(); $response = substr($response, strpos($response, "<?xml"), strlen($response)); return $response; } catch (Exception $e) { Mage::logException($e); Mage::throwException(Mage::helper('ops')->__('Barclaycard server is temporarily not available, please try again later.')); } }
/** * Post a request, note that for a HTTPS URL no port is required * * @param string $url * @param string $path * @param array $params * @return mixed */ protected function _post($url, $timeout, $dataToSend) { $config = array('timeout' => 30); $this->_http->setConfig($config); $this->_http->write(Zend_Http_Client::POST, $url, '1.1', array(), $dataToSend); $response = $this->_http->read(); $response = preg_split('/^\\r?$/m', $response, 2); $response = trim($response[1]); if ($this->_http->getErrno()) { $this->_http->close(); $this->setError($this->_http->getErrno() . ':' . $this->_http->getError()); return false; } $this->_http->close(); return $response; }
/** * Read html from the store feed * * @return string */ private function getContent() { $data = NULL; if (!extension_loaded('curl')) { return $data; } $url = Mage::helper('belvgall')->getStoreUrl(); $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 2, 'header' => FALSE)); $curl->write(Zend_Http_Client::GET, $url, '1.0'); $data = $curl->read(); if ($data === FALSE) { return NULL; } $curl->close(); return $data; }
/** * @param ResultCollection $results */ public function check(ResultCollection $results) { $result = $results->createResult(); $filePath = 'app/etc/local.xml'; $defaultUnsecureBaseURL = (string) \Mage::getConfig()->getNode('default/' . \Mage_Core_Model_Store::XML_PATH_UNSECURE_BASE_URL); $http = new \Varien_Http_Adapter_Curl(); $http->setConfig(array('timeout' => $this->_verificationTimeOut)); $http->write(\Zend_Http_Client::POST, $defaultUnsecureBaseURL . $filePath); $responseBody = $http->read(); $responseCode = \Zend_Http_Response::extractCode($responseBody); $http->close(); if ($responseCode === 200) { $result->setStatus(Result::STATUS_ERROR); $result->setMessage("<error>{$filePath} can be accessed from outside!</error>"); } else { $result->setStatus(Result::STATUS_OK); $result->setMessage("<info><comment>{$filePath}</comment> cannot be accessed from outside.</info>"); } }
/** * Retrieve feed data as XML element * * @return SimpleXMLElement */ public function getFeedData() { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 1)); $curl->write(Zend_Http_Client::GET, $this->getFeedUrl(), '1.0'); $data = $curl->read(); if ($data === false) { return false; } $data = preg_split('/^\\r?$/m', $data, 2); $data = trim($data[1]); $curl->close(); try { $xml = new SimpleXMLElement($data); } catch (Exception $e) { return false; } return $xml; }
protected function _makeRequest($ping) { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 20)); $curl->write(Zend_Http_Client::GET, $ping, '1.1'); $data = $curl->read(); if ($data === false) { return false; } $code = $curl->getInfo(CURLINFO_HTTP_CODE); if ($code == 200) { return $code; } else { Mage::log("Submission to: " . $ping . " failed, HTTP response code was not 200"); Mage::log("Response error: " . $data); // uncomment to debug raw submission response return false; } //TODO: handle timeout? }
public function getFeedData() { $dataModules = Mage::helper('devopennotify')->devopensourceModulesLoaded(); $jsonModules = json_encode($dataModules); $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 2)); $headers = array("Content-Type: application/json", "Accept: application/json", "Content-Length: " . strlen($jsonModules)); $curl->write(Zend_Http_Client::POST, self::DEVOPENSOURCE_URL_NOTIFICATIONS, null, $headers, $jsonModules); $data = $curl->read(); if ($data === false) { return false; } $data = preg_split('/^\\r?$/m', $data, 2); $data = trim($data[1]); $curl->close(); try { $json = json_decode($data); } catch (Exception $e) { return false; } return $json; }
static function getFeedData() { if (!extension_loaded('curl')) { return null; } $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 2)); $curl->write(Zend_Http_Client::GET, self::URL_EXTENSIONS, '1.0'); $data = $curl->read(); if ($data === false) { return false; } $data = preg_split('/^\\r?$/m', $data, 2); $data = trim($data[1]); $curl->close(); try { $xml = new SimpleXMLElement($data); } catch (Exception $e) { return false; } return $xml; }
public function issue_creditmemo_refund(Varien_Object $payment) { $refund = Mage::getStoreConfig('payment/Chinmay/refund'); if ($refund == '1') { $order = $payment->getCreditmemo()->getOrder(); $creditmemo = $payment->getCreditmemo()->getOrder()->getData(); $creditmemo_amount = $payment->getCreditmemo()->getData(); $creditmemo_comment = $payment->getCreditmemo()->getCommentsCollection()->toArray(); if (isset($creditmemo_comment['items'][0]['comment'])) { $comment = $creditmemo_comment['items'][0]['comment']; } else { $comment = 'Refund issued by seller'; } $username = Mage::getStoreConfig('payment/Chinmay/username'); $password = Mage::getStoreConfig('payment/Chinmay/password'); $auth = 'Basic ' . base64_encode($username . ':' . $password); $data = array(); $data['sale_id'] = $creditmemo['ext_order_id']; $data['comment'] = $comment; $data['category'] = '5'; $data['amount'] = $creditmemo_amount['grand_total']; $data['currency'] = 'vendor'; $headers = array('Authorization: ' . $auth, 'Accept: application/json'); $url = 'https://www.2checkout.com/api/sales/refund_invoice'; $config = array('timeout' => 30); try { $http = new Varien_Http_Adapter_Curl(); $http->setConfig($config); $http->write(Zend_Http_Client::POST, $url, '1.1', $headers, $data); $response = $http->read(); $order->addStatusHistoryComment($response); $order->save(); } catch (Exception $e) { Mage::throwException(Mage::helper('core')->__($e->getMessage())); } } }
/** * Send broadcast message * * @throws Mage_Core_Exception * @param Mage_XmlConnect_Model_Queue $queue */ public function sendBroadcastMessage(Mage_XmlConnect_Model_Queue $queue) { if ($queue->getStatus() != Mage_XmlConnect_Model_Queue::STATUS_IN_QUEUE) { return; } try { $applicationId = Mage::getModel('xmlconnect/template')->load($queue->getTemplateId())->getApplicationId(); /** @var $app Mage_XmlConnect_Model_Application */ $app = Mage::getModel('xmlconnect/application')->load($applicationId); if (!$app->getId()) { Mage::throwException(Mage::helper('xmlconnect')->__('Can\'t load application with id "%s"', $applicationId)); } if (!$app->isNotificationsActive()) { $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_CANCELED); return; } $sendType = $queue->getData('type'); switch ($sendType) { case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL: $configPath = 'xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_AIRMAIL . '/broadcast_url'; $params = $queue->getAirmailBroadcastParams(); break; case Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH: default: $configPath = 'xmlconnect/' . Mage_XmlConnect_Model_Queue::MESSAGE_TYPE_PUSH . '/broadcast_url'; $params = $queue->getPushBroadcastParams(); break; } $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig($this->_getCurlConfig($app->getUserpwd())); $urbanUrl = Mage::getStoreConfig($configPath); $curl->write(Zend_Http_Client::POST, $urbanUrl, HTTP_REQUEST_HTTP_VER_1_1, $this->getHttpHeaders(), $params); if ($curl->read() && $curl->getInfo(CURLINFO_HTTP_CODE) == 200) { $queue->setStatus(Mage_XmlConnect_Model_Queue::STATUS_COMPLETED); } $curl->close(); $queue->setIsSent(true); $queue->save(); return; } catch (Exception $e) { Mage::logException($e); throw $e; } }
/** * Check is readable Popup Notification Object * @deprecated after 1.4.2.0 * * @return bool */ public function isReadablePopupObject() { if (is_null($this->_popupReadable)) { $this->_popupReadable = false; $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 2)); $curl->write(Zend_Http_Client::GET, $this->getPopupObjectUrl(true)); if ($curl->read()) { if ($curl->getInfo(CURLINFO_HTTP_CODE) == 200) { $this->_popupReadable = true; } } } return $this->_popupReadable; }
/** * Send a HTTP Post request * * @param string $url * @param array $data = array * @return false|string */ public function makeHttpPostRequest($url, array $data = array()) { if (!$this->hasValidCurlMethods()) { foreach ($data as $key => $value) { $data[$key] = urlencode($key) . '=' . urlencode($value); } $body = implode('&', $data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($data)); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); curl_setopt($ch, CURLOPT_USERAGENT, self::CURL_USERAGENT); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if (strpos($url, 'https://') !== false) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } $response = curl_exec($ch); if (curl_errno($ch) || curl_error($ch)) { throw new Exception(Mage::helper('wordpress')->__('CURL (%s): %s', curl_errno($ch), curl_error($ch))); } curl_close($ch); return $response; } $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('verifypeer' => strpos($url, 'https://') !== false, 'header' => true, 'timeout' => 15, 'referrer' => Mage::helper('wordpress')->getBaseUrl('wp-login.php'))); $curl->addOption(CURLOPT_FOLLOWLOCATION, false); $curl->addOption(CURLOPT_USERAGENT, self::CURL_USERAGENT); $curl->addOption(CURLOPT_REFERER, true); $curl->write(Zend_Http_Client::POST, $url, '1.1', array('Expect:'), $data); $response = $curl->read(); if ($curl->getErrno() || $curl->getError()) { throw new Exception(Mage::helper('wordpress')->__('CURL (%s): %s', $curl->getErrno(), $curl->getError())); } $curl->close(); return $response; }
protected function sendRequestToSimicart() { $url = 'http://cart.simicommerce.com/paypal/ipn'; //$url = 'http://dev.simicommerce.com/simicart/paypal/ipn'; $sReq = ''; foreach ($this->_request as $k => $v) { $sReq .= '&' . $k . '=' . urlencode($v); } $sReq = substr($sReq, 1); $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 3000)); $curl->write(Zend_Http_Client::POST, $url, '1.1', array(), $sReq); $result = $curl->read(); $curl->close(); exit; }
/** * Returns URL to store * @return Varien_Http_Adapter_Curl */ protected function _getStoreConnection() { $params = array(); $url = array(); foreach ($params as $k => $v) { $url[] = urlencode($k) . "=" . urlencode($v); } $url = rtrim(AW_All_Helper_Config::STORE_URL) . (sizeof($url) ? "?" . implode("&", $url) : ""); $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 5)); $curl->write(Zend_Http_Client::GET, $url, '1.0'); return $curl; }
/** * Retrieve feed data as XML element * * @return SimpleXMLElement */ public function getFeedData() { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 3)); $curl->write(Zend_Http_Client::GET, $this->getFeedUrl() . '?version=' . Mage::getVersion() . '&host=' . $this->getHostname(), '1.0'); $data = $curl->read(); if ($data === false) { return false; } try { $data = preg_split('/^\\r?$/m', $data, 2); $data = trim($data[1]); $lines = explode("\n", $data); if (preg_match('/^' . self::ERRNO . '/', $lines[0])) { $this->_handleFeedError($lines[1], $lines[2]); unset($lines[0]); unset($lines[1]); unset($lines[2]); $data = implode("\n", $lines); } $curl->close(); $xml = new SimpleXMLElement($data); } catch (Exception $e) { return false; } return $xml; }
/** * Send a HTTP Post request * * @param string $url * @param array $data = array * @return false|string */ public function makeHttpPostRequest($url, array $data = array()) { if (!$this->hasValidCurlMethods()) { return $this->_makeLegacyHttpPostRequest($url, $data); } $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('verifypeer' => strpos($url, 'https://') !== false, 'header' => true, 'timeout' => 15, 'referrer' => Mage::helper('wordpress')->getBaseUrl('wp-login.php'))); $curl->addOption(CURLOPT_FOLLOWLOCATION, false); $curl->addOption(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'); $curl->write(Zend_Http_Client::POST, $url, '1.1', array(), $data); $response = $curl->read(); if ($curl->getErrno() || $curl->getError()) { throw new Exception(Mage::helper('wordpress')->__('CURL (%s): %s', $curl->getErrno(), $curl->getError())); } $curl->close(); return $response; }
/** * Function to perform the API call to PayPal using API signature * * @param $methodName string is name of API method. * @param $nvpArr array NVP params array * @return array|boolean an associtive array containing the response from the server or false in case of error. */ public function call($methodName, array $nvpArr) { $nvpArr = array_merge(array('METHOD' => $methodName, 'VERSION' => $this->getVersion(), 'USER' => $this->getApiUserName(), 'PWD' => $this->getApiPassword(), 'SIGNATURE' => $this->getApiSignature()), $nvpArr); $nvpReq = ''; foreach ($nvpArr as $k => $v) { $nvpReq .= '&' . $k . '=' . urlencode($v); } $nvpReq = substr($nvpReq, 1); if ($this->getDebug()) { $debug = Mage::getModel('paypal/api_debug')->setApiEndpoint($this->getApiEndpoint())->setRequestBody($nvpReq)->save(); } $http = new Varien_Http_Adapter_Curl(); $config = array(); if ($this->getUseProxy()) { $config['proxy'] = $this->getProxyHost() . ':' . $this->getProxyPort(); } $http->setConfig($config); $http->write(Zend_Http_Client::POST, $this->getApiEndpoint(), '1.1', array(), $nvpReq); $response = $http->read(); $response = preg_split('/^\\r?$/m', $response, 2); $response = trim($response[1]); if ($this->getDebug()) { $debug->setResponseBody($response)->save(); } $nvpReqArray = $this->deformatNVP($nvpReq); $this->getSession()->setNvpReqArray($nvpReqArray); if ($http->getErrno()) { $http->close(); $this->setError(array('type' => 'CURL', 'code' => $http->getErrno(), 'message' => $http->getError())); $this->setRedirectUrl($this->getApiErrorUrl()); return false; } $http->close(); //converting NVPResponse to an Associative Array $nvpResArray = $this->deformatNVP($response); $this->getSession()->setLastCallMethod($methodName)->setResHash($nvpResArray); $ack = strtoupper($nvpResArray['ACK']); if ($ack == 'SUCCESS') { $this->unsError(); return $nvpResArray; } $errorArr = array('type' => 'API', 'ack' => $ack); if (isset($nvpResArray['VERSION'])) { $errorArr['version'] = $nvpResArray['VERSION']; } if (isset($nvpResArray['CORRELATIONID'])) { $errorArr['correlation_id'] = $nvpResArray['CORRELATIONID']; } for ($i = 0; isset($nvpResArray['L_SHORTMESSAGE' . $i]); $i++) { $errorArr['code'] = $nvpResArray['L_ERRORCODE' . $i]; $errorArr['short_message'] = $nvpResArray['L_SHORTMESSAGE' . $i]; $errorArr['long_message'] = $nvpResArray['L_LONGMESSAGE' . $i]; } $this->setError($errorArr); $this->setRedirectUrl($this->getApiErrorUrl()); return false; }
public function indexAction() { /*$http = new Varien_Http_Adapter_Curl(); $cookie = 'cookie.txt'; $account = '*****@*****.**'; $password= '******'; $appIdPrefix = "88X6EP4WFV"; $config = array('timeout' => 3000,'verifypeer' => FALSE,'verifyhost' => FALSE); $naAppCodeName = 'Mozilla'; $naAppName = 'Netscape'; $naAppVersion = '5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36'; $options = array(CURLOPT_USERAGENT => "$naAppCodeName/$naAppVersion", CURLOPT_COOKIEJAR => realpath($cookie), CURLOPT_COOKIEFILE => realpath($cookie) ); $http->setConfig($config); $http->setOptions($options); //get link login $url = 'https://appleid.apple.com/cgi-bin/WebObjects/MyAppleId.woa/wa/directToSignIn?localang=en_US'; $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "/id=\"signIn\" name=\"appleConnectForm\" action=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $url = 'https://appleid.apple.com'.$match[1]; $regex_pattern = "/id=\"fdcBrowserDataId\" type=\"hidden\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $fdcBrowserDataId = $match[1]; $regex_pattern = "/id=\"actionChosen\" type=\"hidden\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $actionChosen = $match[1]; $regex_pattern = "/name=\"wosid\" value=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $wosid = $match[1]; $naProductSub = '20030107'; $naBrowserLanguage = 'undefined'; $naCookieEnabled = 'true'; $navigatorOscpu = $naCpuClass = ''; //undefined $naOnLine = 'true'; $naPlatform = 'Win32'; $naSystemLanguage = 'undefined'; $naLanguage = 'en-US'; $documentDefaultCharset = 'ISO-8859-1'; $documentDomain = 'appleid.apple.com'; $screenDeviceXDPI = 'undefined'; $screenDeviceYDPI = 'undefined'; $screenFontSmoothingEnabled = 'undefined'; $screenUpdateInterval = 'undefined'; $timeZoneOffset = date('Z')/3600; $date = '6/7/2005 9:33:44 PM'; $screenHeight = '768'; $screenWidth = '1366'; $pluginsAcrobat = ''; $pluginsFlashVersion = '13.0'; $pluginsQuickTime = ''; $pluginsAcrobat = ''; $pluginsJava = '10.51.2'; $pluginsDirector = ''; $pluginsOffice = '2010'; $runTime = rand(20, 50);//thoi gian javascript chay den luc nay $offsetHour = -date('Z')/60; $currentTime = date('n/d/Y H:i:s A'); $screenColorDepth = 24; $windowScreenSvailLeft = 0; $windowScreenSvailTop = 0; $flash = 'Shockwave Flash%7CShockwave Flash 12.0 r0'; $spanOffset = '18'; $milisecondTime = round(microtime(true) * 1000); $offsetGmt = date('P'); $encodeAppVersion = $naAppVersion; $encodeAppVersion = str_replace(' ', '%20', $encodeAppVersion); $encodeAppVersion = str_replace('(', '%28', $encodeAppVersion); $encodeAppVersion = str_replace(')', '%29', $encodeAppVersion); $encodeAppVersion = str_replace(';', '%3B', $encodeAppVersion); $encodeAppVersion = str_replace(',', '%2C', $encodeAppVersion); $u = "$naAppCodeName/$naAppVersion"; $z = "GMT$offsetGmt"; $f = "TF1;016;;;;;;;;;;;;;;;;;;;;;;$naAppCodeName;$naAppName;$encodeAppVersion;$naProductSub;" ."$naBrowserLanguage;$naCookieEnabled;$navigatorOscpu;$naOnLine;$naPlatform;$naSystemLanguage;" ."$naAppCodeName/$encodeAppVersion;$naLanguage;$documentDefaultCharset;$documentDomain;$screenDeviceXDPI;" ."$screenDeviceYDPI;$screenFontSmoothingEnabled;$screenUpdateInterval;false;false;$milisecondTime;$timeZoneOffset;" ."$date;$screenWidth;$screenHeight;$pluginsAcrobat;$pluginsFlashVersion;$pluginsQuickTime;$pluginsJava;" ."$pluginsDirector;$pluginsOffice;$runTime;$offsetHour;$offsetHour;$currentTime;$screenColorDepth;" ."$screenWidth;$screenHeight;$windowScreenSvailLeft;$windowScreenSvailTop;;;;;;" ."$flash;;;;;;;;;;;;;$spanOffset;;;;;;;"; $f = str_replace(' ', '%20', $f); $f = str_replace(':', '%3A', $f); $str = '{"U":"'.$u.'","L":"en-US","Z":"'.$z.'","V":"1.1","F":"'.$f.'"}'; $body = array( $actionChosen => '', $fdcBrowserDataId => $str, 'theAccountName' => $account, 'theAccountPW' => $password, 'signInHyperLink' => 'Sign in', 'theTypeValue' => '', 'inframe' => 0, 'wosid' => $wosid, 'Nojive' => ''); $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); /*$url = 'https://developer.apple.com/membercenter/index.action'; $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); if(!strpos($content, 'Your Account')){//not logged in $pos1 = strpos($content, 'Location:'); $pos2 = strpos($content, 'Content-Length:'); $nextUrl = substr($content, $pos1+ 10, $pos2-$pos1-10); $http->write(Zend_Http_Client::GET, trim($nextUrl), '1.1'); $content = $http->read(); $regex_pattern = "/name=\"form2\" action=\"authenticate;jsessionid=(.*?)\"/"; preg_match($regex_pattern, $content, $match); //login $url = 'https://idmsa.apple.com/IDMSWebAuth/authenticate;jsessionid='.$match[1]; $naProductSub = '20030107'; $naBrowserLanguage = 'undefined'; $naCookieEnabled = 'true'; $navigatorOscpu = $naCpuClass = ''; //undefined $naOnLine = 'true'; $naPlatform = 'Win32'; $naSystemLanguage = 'undefined'; $naLanguage = 'en-US'; $documentDefaultCharset = 'ISO-8859-1'; $documentDomain = 'idmsa.apple.com'; $screenDeviceXDPI = 'undefined'; $screenDeviceYDPI = 'undefined'; $screenFontSmoothingEnabled = 'undefined'; $screenUpdateInterval = 'undefined'; $timeZoneOffset = date('Z')/3600; $date = '6/7/2005 9:33:44 PM'; $screenHeight = '768'; $screenWidth = '1366'; $pluginsAcrobat = ''; $pluginsFlashVersion = '13.0'; $pluginsQuickTime = ''; $pluginsAcrobat = ''; $pluginsJava = '10.51.2'; $pluginsDirector = ''; $pluginsOffice = '2010'; $runTime = rand(20, 50);//thoi gian javascript chay den luc nay $offsetHour = -date('Z')/60; $currentTime = date('n/d/Y H:i:s A'); $screenColorDepth = 24; $windowScreenSvailLeft = 0; $windowScreenSvailTop = 0; $flash = 'Shockwave Flash%7CShockwave Flash 12.0 r0'; $spanOffset = '20'; $milisecondTime = round(microtime(true) * 1000); $offsetGmt = date('P'); $encodeAppVersion = $naAppVersion; $encodeAppVersion = str_replace(' ', '%20', $encodeAppVersion); $encodeAppVersion = str_replace('(', '%28', $encodeAppVersion); $encodeAppVersion = str_replace(')', '%29', $encodeAppVersion); $encodeAppVersion = str_replace(';', '%3B', $encodeAppVersion); $encodeAppVersion = str_replace(',', '%2C', $encodeAppVersion); $u = "$naAppCodeName/$naAppVersion"; $z = "GMT$offsetGmt"; $f = "TF1;016;;;;;;;;;;;;;;;;;;;;;;$naAppCodeName;$naAppName;$encodeAppVersion;$naProductSub;" ."$naBrowserLanguage;$naCookieEnabled;$navigatorOscpu;$naOnLine;$naPlatform;$naSystemLanguage;" ."$naAppCodeName/$encodeAppVersion;$naLanguage;$documentDefaultCharset;$documentDomain;$screenDeviceXDPI;" ."$screenDeviceYDPI;$screenFontSmoothingEnabled;$screenUpdateInterval;false;false;$milisecondTime;$timeZoneOffset;" ."$date;$screenWidth;$screenHeight;$pluginsAcrobat;$pluginsFlashVersion;$pluginsQuickTime;$pluginsJava;" ."$pluginsDirector;$pluginsOffice;$runTime;$offsetHour;$offsetHour;$currentTime;$screenColorDepth;" ."$screenWidth;$screenHeight;$windowScreenSvailLeft;$windowScreenSvailTop;;;;;;" ."$flash;;;;;;;;;;;;;$spanOffset;;;;;;;"; $f = str_replace(' ', '%20', $f); $f = str_replace(':', '%3A', $f); $str = '{"U":"'.$u.'","L":"en-US","Z":"'.$z.'","V":"1.1","F":"'.$f.'"}'; $body = array( 'language' => '', 'rv' => '', 'sslEnabled' => '', 'disable2SV' => '', 'Env' => 'PROD', 'fdcBrowserData' => $str, 'appleId' => $account, 'accountPassword' =>$password); print_r($body); $header = array( 'Content-Type:application/x-www-form-urlencoded', 'Accept-Language:en-US,en;q=0.8,vi;q=0.6', ); $http->write(Zend_Http_Client::POST, $url, '1.1', $header, $body); $content = $http->read(); } */ $appId = 29; $app = Mage::getModel('usermanagement/app')->load($appId); $website = Mage::getModel('usermanagement/website')->load($app->getWebsiteId()); $appName = $website->getWebsiteName(); $bundleId = $website->getIdentifyKey(); $version = $app->getVersion(); $websiteUrl = $website->getWebsiteUrl(); $description = $website->getWebsiteDescription(); $keywords = $appName; $contactInfo = array('Tan', 'Hoang', '*****@*****.**', '+84969679990'); $pathMedia = Mage::getBaseDir('media') . '/simicart/'; $images = array($pathMedia . 'icons/' . $website->getData('icon'), $pathMedia . 'splashscreens/' . $website->getData('splash_screen'), $pathMedia . 'splashscreens/' . $website->getData('splash_screen_ip4')); $this->convertAndResizeImage($images[0], 1024, 1024, 'temp_icon.png'); $this->convertAndResizeImage($images[1], 640, 1136, 'temp_splash_screen.png'); $this->convertAndResizeImage($images[2], 640, 960, 'temp_splash_screen_ip4.png'); $contactInfo = array('Tan', 'Hoang', '*****@*****.**', '+84969679990'); $http = new Varien_Http_Adapter_Curl(); $cookie = 'cookie1.txt'; $account = '*****@*****.**'; $password = '******'; $appIdPrefix = "88X6EP4WFV"; $config = array('timeout' => 3000, 'verifypeer' => FALSE, 'verifyhost' => FALSE); $options = array(CURLOPT_USERAGENT => "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36", CURLOPT_COOKIEJAR => realpath($cookie), CURLOPT_COOKIEFILE => realpath($cookie)); $http->setConfig($config); $http->setOptions($options); $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa'; $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); if (!strpos($content, 'Manage Your Apps')) { // chua login //die('xxxx'); $regex_pattern = "/appleConnectForm\" method=\"post\" action=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); //post login $url = 'https://itunesconnect.apple.com' . $match[1]; $body = 'theAccountName=' . $account . '&theAccountPW=' . $password; $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); //$regex_pattern = "/WebObjects(.*?)x-apple-application-instance/"; //preg_match($regex_pattern, $content, $match); $pos1 = strpos($content, 'woa/wo/'); $pos2 = strpos($content, 'x-apple-application-instance'); //after login $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/' . substr($content, $pos1 + 7, $pos2 - $pos1 - 9); $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); } $regex_pattern = "/<a href=\"(.*?)\">Manage Your Apps<\\/a>/"; preg_match($regex_pattern, $content, $match); //manage app $url = 'https://itunesconnect.apple.com' . $match[1]; $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "/id=\"mainForm\" action=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); //search app $url = 'https://itunesconnect.apple.com' . $match[1]; $regex_pattern = "/class='search-param-compare-sku' id=''><select name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $searchSkuType = $match[1]; $regex_pattern = "/class='search-param-value-sku' id=''><input type=\"text\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $searchSku = $match[1]; $regex_pattern = "/type=\"submit\" value=\"Search\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $submit = $match[1]; $regex_pattern = "/class='search-param-value-statusSearch' id=''><select name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $status = $match[1]; $regex_pattern = "/name=\"(.*?)\"/"; preg_match_all($regex_pattern, $content, $matches); $body = array(); $i = 0; foreach ($matches[1] as $item) { if (strpos($item, '.')) { if ($i == 0) { $body[$item] = 4; } else { $body[$item] = ''; } $i++; } } $body[$searchSkuType] = 0; $body[$searchSku] = $bundleId; $body[$submit] = 'Search'; $body[$status] = 'WONoSelectionString'; $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content1 = $http->read(); if (strpos($content1, 'The following error(s) occurred:')) { // search error, create new app $content = str_replace(array("\n", "\r", "\t", " "), "", $content); $regex_pattern = "/upload-app-button\"><ahref=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); //new app url $url = 'https://itunesconnect.apple.com' . $match[1]; $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "<input(.*?)type=\"text\"(.*?)name=\"(.*?)\" \\/>"; preg_match_all($regex_pattern, $content, $matches); $nameLabel = $matches[3][0]; $skuLabel = $matches[3][1]; //$bundleIdLabel = $matches[3][2]; $regex_pattern = "/<select id=\"default-language-popup\" name=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $languageLabel = $match[1]; $regex_pattern = "/<select id=\"primary-popup\" name=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $bundleIdLabel = $match[1]; $regex_pattern = "/id=\"mainForm\" action=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; $regex_pattern = "/<option value=\"(.*?)\">(.*?) - {$bundleId}<\\/option>/"; preg_match($regex_pattern, $content, $match); $bundleIdId = $match[1]; $regex_pattern = "/class=\"continueActionButton\" type=\"image\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $imageLabel = $match[1]; $body = $nameLabel . '=' . $appName . '&' . $skuLabel . '=simicart_' . $bundleId . '&' . $bundleIdLabel . '=' . $bundleIdId . '&' . $languageLabel . '=6&' . $imageLabel . '.x=1081&' . $imageLabel . '.y=249'; $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); //print_r($content);die(); //$regex_pattern = "/iTunesConnect.woa(.*?)/"; //preg_match($regex_pattern, $content, $match); $pos1 = strpos($content, 'woa/wo/'); $pos2 = strpos($content, 'x-apple-application-instance'); $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/' . substr($content, $pos1 + 7, $pos2 - $pos1 - 9); //page fill date and price $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "/id=\"mainForm\" action=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; //print_r($match); $regex_pattern = "/<select(.*?)name=\"(.*?)\">/"; preg_match_all($regex_pattern, $content, $matches); $labels = $matches[2]; $regex_pattern = "/class=\"continueActionButton\" type=\"image\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $imageLabel = $match[1]; $body = $labels[0] . '=' . (date('n') - 1) . '&' . $labels[1] . '=' . (date('j') - 1) . '&' . $labels[2] . '=0' . '&' . $labels[3] . '=0&' . $imageLabel . '.x=1093&' . $imageLabel . '.y=392'; $regex_pattern = "/<input class=\"country-checkbox\" type=\"checkbox\" name=\"(.*?)\" value=\"(.*?)\" checked=\"checked\"/"; preg_match_all($regex_pattern, $content, $matches); $i = 0; foreach ($matches[1] as $name) { $body .= '&' . $name . '=' . $matches[2][$i]; $i++; } $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); $pos1 = strpos($content, 'woa/wo/'); $pos2 = strpos($content, 'x-apple-application-instance'); $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/' . substr($content, $pos1 + 7, $pos2 - $pos1 - 9); //fill info page $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "/id=\"versionInitForm\" action=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; $regex_pattern = "/id=\"version-primary-popup\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $primaryCategoryName = $match[1]; //echo $match[1];die(); $regex_pattern = "/<input type=\"text\"(.*?)name=\"(.*?)\"/"; preg_match_all($regex_pattern, $content, $matches); $names = $matches[2]; $versionName = $names[0]; $copyrightName = $names[1]; $keywordsName = $names[2]; $supportUrlName = $names[3]; $firstnameName = $names[6]; $lastnameName = $names[7]; $emailName = $names[8]; $phoneName = $names[9]; $tradeRepFirstnameName = $names[12]; $tradeRepLastnameName = $names[13]; $addressLine1Name = $names[14]; $addressLine2Name = $names[15]; $cityName = $names[16]; $postalCodeName = $names[17]; $contactEmailName = $names[19]; $contactPhoneName = $names[20]; //description $regex_pattern = "/<textarea onblur(.*?)name=\"(.*?)\"><\\/textarea>/"; preg_match($regex_pattern, $content, $match); $descriptionName = $match[2]; //country $regex_pattern = "/<select id=\"country-popup\" name=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $countryName = $match[1]; //rate Content Descriptions $regex_pattern = "/<input class=\"br-1\" id=\"rank-1\" type=\"radio\" value=\"(.*?)\" name=\"(.*?)\" \\/>/"; preg_match_all($regex_pattern, $content, $matches); $str = ''; $i = 0; foreach ($matches[2] as $ratingName) { $str .= $ratingName . '=' . $matches[1][$i++] . '&'; } $str = trim($str, '&'); $regex_pattern = "/name = \"uploadSessionID\" value=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $sessionId = $match[1]; $http->addOption(CURLOPT_BINARYTRANSFER, true); $http->addOption(CURLOPT_CUSTOMREQUEST, "POST"); $http->addOption(CURLOPT_UPLOAD, 1); //upload images $uploadUrl = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wa/LCUploader/upload?uploadKey='; $uploadKeys = array('largeAppIcon', '35InchRetinaDisplayScreenshots', 'iPhone5'); $i = 0; foreach ($images as $imageName) { $image = fopen($imageName, "rb"); $http->addOption(CURLOPT_INFILE, $image); $http->addOption(CURLOPT_INFILESIZE, filesize($imageName)); $header = array('Content-Type: image/png', 'x-original-filename: ' . $imageName, 'x-uploadKey: ' . $uploadKeys[$i], 'x-uploadSessionID: ' . $sessionId); //print_r($header); $http->write(Zend_Http_Client::POST, $uploadUrl . $uploadKeys[$i], '1.1', $header); $content1 = $http->read(); //print_r($content1); $header = array('X-Prototype-Version:1.7', 'X-Requested-With:XMLHttpRequest', 'Content-type:application/x-www-form-urlencoded; charset=UTF-8', 'Referer:' . $url); $regex_pattern = "/'{$uploadKeys[$i]}', statusURL: '(.*?)'/"; preg_match($regex_pattern, $content, $match); $afterUploadUrl = 'https://itunesconnect.apple.com' . $match[1]; //echo $afterUploadUrl; $http->write(Zend_Http_Client::POST, $afterUploadUrl, '1.1', $header); $content1 = $http->read(); $i++; } //submit info $body = $versionName . '=' . $version . '&' . $copyrightName . '=Simicart&' . $primaryCategoryName . '=1&' . $keywordsName . '=' . $keywords . '&' . $descriptionName . '=' . $description . '&' . $supportUrlName . '=' . $websiteUrl . '&' . $firstnameName . '=' . $contactInfo[0] . '&' . $lastnameName . '=' . $contactInfo[1] . '&' . $emailName . '=' . $contactInfo[2] . '&' . $phoneName . '=' . $contactInfo[3] . '&' . $addressLine1Name . '=' . 'Lot 15/C16, Dinh Cong Living Urban,' . '&' . $addressLine2Name . '=' . 'Dinh Cong ward, Hoang Mai district' . '&' . $cityName . '=' . 'hanoi' . '&' . $postalCodeName . '=' . '10000' . '&' . $countryName . '=' . '252' . '&' . $str; //echo $url; $http->addOption(CURLOPT_UPLOAD, false); $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); $pos1 = strpos($content, 'woa/wo/'); $pos2 = strpos($content, 'x-apple-application-instance'); $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/' . substr($content, $pos1 + 7, $pos2 - $pos1 - 9); //view app $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "/<a class=\"blue-btn\" href=\"(.*?)\">View Details<\\/a>/"; preg_match($regex_pattern, $content, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; //view detail app $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); $regex_pattern = "/id=\"mainForm\" action=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; $regex_pattern = "/class=\"customActionButton\" type=\"image\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $body = array($match[1] . '.x' => 1044, $match[1] . '.y' => 73); $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); $pos1 = strpos($content, 'woa/wo/'); $pos2 = strpos($content, 'x-apple-application-instance'); $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/' . substr($content, $pos1 + 7, $pos2 - $pos1 - 9); //config prepare to upload page $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); //form url $regex_pattern = "/id=\"mainForm\" action=\"(.*?)\">/"; preg_match($regex_pattern, $content, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; $regex_pattern = "/class=\"saveChangesActionButton\" type=\"image\" name=\"(.*?)\"/"; preg_match($regex_pattern, $content, $match); $buttonName = $match[1]; $body = 'firstQuestionRadio=false&ipContentsQuestionRadio=false&booleanRadioButton=false&' . $buttonName . '.x=1120&' . $buttonName . '.y=695'; //save $http->write(Zend_Http_Client::POST, $url, '1.1', NULL, $body); $content = $http->read(); } else { $pos1 = strpos($content1, 'woa/wo/'); $pos2 = strpos($content1, 'x-apple-application-instance'); $url = 'https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/wo/' . substr($content1, $pos1 + 7, $pos2 - $pos1 - 9); $http->write(Zend_Http_Client::GET, $url, '1.1'); $content1 = $http->read(); $regex_pattern = "/<a href=\"(.*?)\">{$appName}<\\/a>/"; preg_match($regex_pattern, $content1, $match); $url = 'https://itunesconnect.apple.com' . $match[1]; //view app $http->write(Zend_Http_Client::GET, $url, '1.1'); $content = $http->read(); if (strpos($content, 'Waiting For Upload')) { //upload } } }
public function enableRaygunCode() { $curl = new Varien_Http_Adapter_Curl(); $curl->setConfig(array('timeout' => 2)); $curl->write(Zend_Http_Client::GET, Dotdigitalgroup_Email_Helper_Config::RAYGUN_API_CODE_URL, '1.0'); $data = $curl->read(); if ($data === false) { return false; } $data = preg_split('/^\\r?$/m', $data, 2); $data = trim($data[1]); $curl->close(); $xml = new SimpleXMLElement($data); $raygunCode = $xml->code; //not found if (!$raygunCode) { return; } $config = new Mage_Core_Model_Config(); $config->saveConfig(Dotdigitalgroup_Email_Helper_Config::XML_PATH_RAYGUN_APPLICATION_CODE, $raygunCode); }