public function indexAction() { $client = new Zend_Http_Client('https://ws.pagseguro.uol.com.br/v2/sessions/'); $client->setMethod(Zend_Http_Client::POST); $client->setParameterGet('email', '*****@*****.**'); $client->setParameterGet('token', '9F79900A9B454CE6B18613D7224C0621'); $client->request(); var_dump($client->getLastResponse()->getBody()); }
private static function getTimeStamp() { //May be used soon for encrypting forwardlinks if (isset($_REQUEST['action'], $_REQUEST['hash']) && $_REQUEST['action'] == 'timestamp') { $client = new Zend_Http_Client(TikiLib::tikiUrl() . 'tiki-timestamp.php', array('timeout' => 60)); $client->setParameterGet('hash', $_REQUEST['hash']); $client->setParameterGet('clienttime', time()); $response = $client->request(); echo $response->getBody(); exit; } }
public function isValid() { if (!$this->getAddresses()) { return true; } $userId = $this->getConfigData('userid'); $request = "<AddressValidateRequest USERID='{$userId}'>"; foreach ($this->getAddresses() as $id => $address) { $regionCode = Mage::getModel('directory/region')->load($address['region_id'])->getCode(); $request .= '<Address ID="' . $id . '">'; if (isset($address['street'][1])) { $address1 = $address['street'][0]; $address2 = $address['street'][1]; } else { $address1 = ''; $address2 = $address['street'][0]; } $request .= '<Address1>' . $address1 . '</Address1>'; $request .= '<Address2>' . $address2 . '</Address2>'; $request .= '<City>' . $address['city'] . '</City>'; $request .= '<State>' . $regionCode . '</State>'; $request .= '<Zip5>' . $address['postcode'] . '</Zip5>'; $request .= '<Zip4></Zip4>'; $request .= '</Address>'; } $request .= "</AddressValidateRequest>"; $responseBody = $this->_getCachedQuotes($request); if ($responseBody === null) { $debugData = array('request' => $request); try { $url = $this->getConfigData('gateway_url'); if (!$url) { $url = $this->_defaultGatewayUrl; } $client = new Zend_Http_Client(); $client->setUri($url); $client->setConfig(array('maxredirects' => 0, 'timeout' => 30)); $client->setParameterGet('API', 'Verify'); $client->setParameterGet('XML', $request); $response = $client->request(); $responseBody = $response->getBody(); $debugData['result'] = $responseBody; $this->_setCachedQuotes($request, $responseBody); } catch (Exception $e) { $debugData['result'] = array('error' => $e->getMessage(), 'code' => $e->getCode()); $responseBody = ''; } $this->_debug($debugData); } $this->_result = $this->_parseXmlResponse($responseBody); return !$this->getError() && $this->isVerified(); }
/** Get analytics for a URL * @access public * @param string $shortUrl * @return object $response */ public function analytics($shortUrl) { $url = $this->checkShortUrl($shortUrl); $client = new Zend_Http_Client(); $client->setUri($this->_api); $client->setMethod(Zend_Http_Client::GET); $client->setParameterGet('shortUrl', $shortUrl); $client->setParameterGet('projection', 'FULL'); $response = $client->request(); if ($response->isSuccessful()) { return $this->getDecode($response); } else { return false; } }
protected function _shortenUrl($url) { $http = new \Zend_Http_Client(); $http->setUri('http://api.bitly.com/v3/shorten'); $http->setParameterGet('login', $this->_config->bitLyLogin); $http->setParameterGet('apiKey', $this->_config->bitLyApiKey); $http->setParameterGet('longUrl', $url); $http->setParameterGet('format', 'json'); $res = $http->request('GET'); $body = json_decode($res->getBody()); if (!isset($body->data) || !isset($body->data->url)) { throw new \Exception('Bit.ly url not returned'); } return $body->data->url; }
public function executeRequest(TingClientHttpRequest $request) { //Transfer request configuration to Zend Client $method = $request->getMethod(); $class = new ReflectionClass(get_class($this->client)); $this->client->setMethod($class->getConstant($method)); $this->client->setUri($request->getBaseUrl()); $this->client->setParameterGet($request->getParameters(TingClientHttpRequest::GET)); $this->client->setParameterPost($request->getParameters(TingClientHttpRequest::POST)); //Check for errors $response = $this->client->request(); if ($response->isError()) { throw new TingClientException('Unable to excecute Zend Framework HTTP request: ' . $response->getMessage(), $response->getStatus()); } return $response->getBody(); }
public function send($phone, $text) { if ($this->_validatePhone($phone)) { $reqest = array('phone' => $phone, 'text' => $text); /** * * Запрос формируется мержем массивом с параметрами, причем настройки указанные в конфиге * в критичных местах могут перехзаписаться * @var array */ $reqest = array_merge($this->_config, $reqest, $this->_defaultRequest); $client = new Zend_Http_Client($this->_apiUrl); $client->setParameterGet($reqest); $result = $client->request('POST'); $jsonResponse = $result->getBody(); $json = Zend_Json::decode($jsonResponse); if (0 == $json['response']['msg']['err_code']) { return true; } else { $this->_log($json['response']['msg']['text'] . ' ' . var_export($reqest, true), Zend_Log::CRIT); return false; } } else { $this->_log('Номер телефона не корректный: ' . var_export($reqest, true), Zend_Log::ERR); return false; } }
function send() { global $tikilib; $entry = array(); $lastModif = 0; $feed = $this->feed(); foreach ($feed->feed->entry as $item) { if (empty($item->forwardlink->href)) { continue; } $client = new Zend_Http_Client($item->forwardlink->href, array('timeout' => 60)); $info = $tikilib->get_page_info($item->page); if ($info['lastModif'] > $lastModif) { $lastModif = $info['lastModif']; } } if (!empty($feed->feed->entry)) { $client->setParameterGet(array('protocol' => 'forwardlink', 'contribution' => json_encode($feed))); try { $response = $client->request(Zend_Http_Client::POST); $request = $client->getLastResponse(); return $response->getBody(); } catch (Exception $e) { return ""; } } }
public function photosAction() { require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Http_Client'); $CLIENT_ID = 'fa2641332bca4ce6bd8f71bd4345cc0f'; $CLIENT_SECRET = 'c44e29e7449444e3bc1f58ff499f5e8e'; $user = '******'; $tag = 'coreprojectua'; try { $client = new Zend_Http_Client('https://api.instagram.com/v1/users/' . $user . '/media/recent'); $client->setParameterGet('client_id', $CLIENT_ID); $response = $client->request(); $result = json_decode($response->getBody()); $data = $result->data; if (count($data) > 0) { $this->view->user = $data; } } catch (Exception $e) { echo 'ERROR: ' . $e->getMessage() . print_r($client); exit; } try { $client = new Zend_Http_Client('https://api.instagram.com/v1/tags/' . $tag . '/media/recent'); $client->setParameterGet('client_id', $CLIENT_ID); $response = $client->request(); $result = json_decode($response->getBody()); $data = $result->data; if (count($data) > 0) { $this->view->tag = $data; } } catch (Exception $e) { echo 'ERROR: ' . $e->getMessage() . print_r($client); exit; } }
/** * */ protected function _request($url, $params, $method = Zend_Http_Client::GET) { $this->_client->setUri($url)->resetParameters(); if (count($params['header'])) { foreach ($params['header'] as $name => $value) { $this->_client->setHeaders($name, $value); } } if (count($params['post'])) { foreach ($params['post'] as $name => $value) { $this->_client->setParameterPost($name, $value); } } if (count($params['get'])) { foreach ($params['get'] as $name => $value) { $this->_client->setParameterGet($name, $value); } } if (count($params['json'])) { //$this->_client->setHeaders('Content-type','application/json'); $rawJson = json_encode($params['json']); //$this->_client->setRawData($rawJson); $this->_client->setRawData($rawJson, 'application/json'); } $response = $this->_client->request($method); $result = $response->getBody(); #echo $result . "\n\n <br>"; return json_decode($result); }
/** * Validate a ticket for a service. * * @param string $ticket Ticket to validate given by CAS Server * @param string $service URL to the service requesting authentication * @uses Zend_Http_Client * * @return false|string Returns false on failure, CAS user on success. */ protected function validateTicket($ticket, $service) { /** * @see Zend_Http_Client */ require_once 'Zend/Http/Client.php'; try { if (!$this->_clientAdapter instanceof Zend_Http_Client_Adapter_Interface) { $this->setClientAdapter(); } $this->setClient(); // Pass parameters ticket and service to client $this->_client->setParameterGet($this->getValidationParams($ticket, $service)); // Get the client response $response = $this->_client->request(); if ($response->getStatus() == 200) { $result = $this->getResponseBody($response->getBody()); if ($result === false) { return false; } else { return $result; } } return false; } catch (Exception $e) { // Set error messages for failure $this->_errors[] = 'Authentication failed: Failed to connect to server'; $this->_errors[] = $e->getMessage(); return false; } }
/** * Post a comment. * * @param string $code * @param string $message * @param array $options * @param string $format */ public function postComment($code, $message, $options = array(), $format = self::FORMAT_XML) { $defaults = array('name' => '', 'email' => '', 'tweet' => 0); $options = array_merge($defaults, $options); if (!strlen($options['name']) && !strlen($options['email'])) { if (null == $this->_username && null == $this->_password) { throw new HausDesign_Service_Mobypicture_Exception('name and email or username and password should by defined'); } } $this->_localHttpClient->resetParameters(); $this->_localHttpClient->setUri(self::MOBYPICTURE_API); $this->_localHttpClient->setParameterGet('action', 'postComment'); if (!strlen($options['name']) && !strlen($options['email'])) { $this->_localHttpClient->setParameterGet('u', $this->_username); $this->_localHttpClient->setParameterGet('p', $this->_password); } $this->_localHttpClient->setParameterGet('k', $this->_apiKey); $this->_localHttpClient->setParameterGet('tinyurl_code ', $code); $this->_localHttpClient->setParameterGet('message', $code); $this->_localHttpClient->setParameterGet('format', $format); foreach ($options as $option => $value) { $this->_localHttpClient->setParameterGet($option, $value); } return $this->_parseContent($this->_localHttpClient->request('GET')->getBody(), $format); }
/** * Gibt die Geokoordinaten anhand einer Adresse zurück * * @param string $address Die Adresse die geocodet werden woll * @return array|null $geocode Ein Array mit key 'lat' und 'lng' */ public static function getCoordinates($address) { $q = $address; $q = str_replace(array('ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü', 'ß'), array('ae', 'oe', 'ue', 'Ae', 'Oe', 'Ue', 'ss'), $q); $getParams = array('address' => $q, 'sensor' => 'false'); $httpClientConfig = array('timeout' => 20, 'persistent' => false); $config = Kwf_Registry::get('config'); if ($config->http && $config->http->proxy && $config->http->proxy->host && $config->http->proxy->port) { $httpClientConfig['adapter'] = 'Zend_Http_Client_Adapter_Proxy'; $httpClientConfig['proxy_host'] = $config->http->proxy->host; $httpClientConfig['proxy_port'] = $config->http->proxy->port; } $client = new Zend_Http_Client("http://maps.googleapis.com/maps/api/geocode/json", $httpClientConfig); $client->setMethod(Zend_Http_Client::GET); $client->setParameterGet($getParams); $body = utf8_encode($client->request()->getBody()); try { $result = Zend_Json::decode($body); } catch (Zend_Json_Exception $e) { $e = new Kwf_Exception_Other($e); $e->logOrThrow(); } if (isset($result['results'][0]['geometry']['location']['lat']) && isset($result['results'][0]['geometry']['location']['lng'])) { return array('lat' => $result['results'][0]['geometry']['location']['lat'], 'lng' => $result['results'][0]['geometry']['location']['lng']); } return null; }
/** * */ public function run() { $_job = new Tools_DataView_Job_MapperView(); $_job->setId($this->jobId)->retrieve(); try { $start = ZendT_Type_Date::nowDateTime(); $config = array('useragent' => 'Mozilla/5.0 (Windows NT 6.1; rv:22.0) Gecko/20100101 Firefox/44.0', 'encodecookies' => false, 'timeout' => 60 * 60); $params = Tools_Interface_Job::prepareParams($_job->getParametro()->toPhp()); $_client = new Zend_Http_Client($_job->getProcedimento()->toPhp(), $config); if (count($params) > 0) { foreach ($params as $name => $value) { $_client->setParameterGet($name, $value); } } $response = $_client->request(); $message = $response->getBody(); if ($message == '' || $message == 'OK') { } else { Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message); } $finish = ZendT_Type_Date::nowDateTime(); $diff = $start->diff($finish); $_job->setTempoUlExec($diff->i); } catch (Exception $ex) { $message = 'Mensagem: ' . $ex->getMessage() . "\n"; $message .= 'Erro: ' . $ex->getTraceAsString() . "\n"; Tools_Model_LogErro_Mapper::log($_job->getProcedimento()->toPhp(), $message); $_job->setTempoUlExec(0); } $_job->setDhUltExec(ZendT_Type_Date::nowDateTime()); $_job->setStatus('A'); $_job->update(); return true; }
public function mailgunRequest($type, $domain, $apiKey, $data, $method = Zend_Http_Client::GET, $uriOveride = false) { $client = new Zend_Http_Client(); $client->setAuth("api", $apiKey); $client->setMethod($method); if ($uriOveride) { $client->setUri($uriOveride); } else { $client->setUri($this->apiUrl . $domain . "/" . $type); } if ($method == Zend_Http_Client::POST) { foreach ($data as $key => $value) { $client->setParameterPost($key, $value); } } else { foreach ($data as $key => $value) { $client->setParameterGet($key, $value); } } try { $response = $client->request(); if ($response->getStatus() == 200) { return json_decode($response->getBody()); } else { throw new Zend_Http_Exception("Error connecting to MailGun API. Returned error code: " . $response->getStatus() . " --- " . $response->getBody()); } } catch (Exception $e) { Mage::logException($e); return false; } }
public function testQuery($queryFields, $format = 'xml') { $client = new \Zend_Http_Client(REST_URL_QUERY . '?format=' . $format); $client->setParameterGet(queryFields); $response = $client->request('GET'); print $response->getBody(); }
/** * Send a GET request to the specified URL with the specified query string. * @param string $url * @param string $data * @return string Remote data **/ public function sendGET($url, $data = array()) { $data['_fake_status'] = '200'; // Zend makes it easier than the others... $this->instance->setConfig(array('useragent' => sprintf(Imgur::$user_agent, Imgur::$key))); $this->instance->setMethod(Zend_Http_Client::GET); $this->instance->setUri($url); $this->instance->setParameterGet($data); try { /** @var Zend_Http_Response */ $response = $this->instance->request(); return $response->getBody(); } catch (Exception $e) { throw new Imgur_Exception("Unknown Failure during HTTP Request", null, $e); } }
/** * Provede dotaz do obchodu na zadanou kartu a rozparsuje vysledek * @param string $cardName * @return bool */ public function doCardRequest($cardName) { if (Zend_Http_Client::POST === $this->_method) { $this->_client->setParameterPost($this->_getParams($cardName)); } else { $this->_client->setParameterGet($this->_getParams($cardName)); } //TODO check result state //get body $rawData = $this->_client->request()->getBody(); //apply iconv if needed if ($this->_encodeFrom && $this->_encodeFrom !== 'utf-8') { $rawData = iconv($this->_encodeFrom, 'utf-8', $rawData); } //process data return $this->_processData($rawData); }
protected function _request($captchaResponse, $secret) { try { $client = new Zend_Http_Client(Mage::getStoreConfig(self::XML_PATH_VALIDATION_ENDPOINT_URI)); $client->setParameterGet('response', $captchaResponse); $client->setParameterGet('secret', $secret); $client->setParameterGet('remoteip', Mage::helper('core/http')->getRemoteAddr(true)); $response = $client->request(); } catch (Zend_Http_Exception $e) { Mage::logException($e); Mage::getSingleton('customer/session')->addError(Mage::helper('grecaptcha')->__('Unable to validate the reCAPTCHA with Google. Please, retry later.')); } catch (Exception $e) { Mage::logException($e); Mage::getSingleton('customer/session')->addError(Mage::helper('grecaptcha')->__('Unable to validate the reCAPTCHA.')); } return $this->_parseResponse($response); }
/** Get the coordinates from an address string * @access public * @param string $address */ public function _getGeocodedLatitudeAndLongitude($address) { $client = new Zend_Http_Client(); $client->setUri(self::GEOCODEURI); $client->setParameterGet('address', $address)->setParameterGet('sensor', 'false'); $result = $client->request('GET'); $response = Zend_Json_Decoder::decode($result->getBody(), Zend_Json::TYPE_OBJECT); return $response; }
/** Get the coordinates from an address string * @param string $address */ public function _getGeocodedLatitudeAndLongitude($address) { $client = new Zend_Http_Client(); $client->setUri(self::GEOCODEURI); $client->setParameterGet('q', urlencode($address))->setParameterGet('output', 'json')->setParameterGet('sensor', 'false')->setParameterGet('key', (string) $this->_key); $result = $client->request('GET'); $response = Zend_Json_Decoder::decode($result->getBody(), Zend_Json::TYPE_OBJECT); return $response; }
/** Get the coordinates from an address string * @access public * @param float $lat * @param float $lon * @access public */ public function _getElevationApiCall($lat, $lon) { $client = new Zend_Http_Client(); $client->setUri(self::ELEVATIONURI); $client->setParameterGet('locations', (string) $lon . ',' . (string) $lat)->setParameterGet('sensor', 'false'); $result = $client->request('GET'); $response = Zend_Json_Decoder::decode($result->getBody(), Zend_Json::TYPE_OBJECT); return $response; }
/** * Index Of Deals * * @param string $name * @param string $email * @param integer $offset * @param integer $limit * @return array */ public function indexOfDeals($status = null, $assignedToEmail = null) { $httpClient = new Zend_Http_Client('https://' . $this->_accountName . '.batchbook.com/service/deals.xml'); if (null !== $status) { $httpClient->setParameterGet('status', $status); } if (null !== $assignedToEmail) { $httpClient->setParameterGet('assigned_to', $assignedToEmail); } $httpClient->setAuth($this->_token, 'x'); $response = $httpClient->request(Zend_Http_Client::GET); $xmlResponse = simplexml_load_string($response->getBody()); $deals = array(); foreach ($xmlResponse->deal as $dealElement) { $deals[] = $this->_populateDealFromXmlElement($dealElement); } return $deals; }
/** * Performs an HTTP GET request to the $path. * * @param string $path * @param array $query Array of GET parameters * @param boolean $addApiEntryPath Defaults to true. Is needed to make outlier Network API part work * @throws Zend_Http_Client_Exception * @return Zend_Http_Response * @see GitHub::_prepare */ protected function _get($path, array $query = null, $addApiEntryPath = true) { $this->_prepare($path, $addApiEntryPath); $this->_localHttpClient->setParameterGet($query); if ($this->_authorizationCredentials) { $this->_localHttpClient->setAuth($this->getLogin() . "/token", $this->getToken()); } return $this->_localHttpClient->request('GET'); }
/** * Sends a request and returns a response * * @param CartRecover_Request $request * @return Cart_Recover_Response */ public function sendRequest(CartRecover_Request $request) { $this->client->setUri($request->getUri()); $this->client->setParameterGet($request->getParams()); $this->client->setMethod($request->getMethod()); $this->client->setHeaders('Accept', 'application/json'); $this->response = $this->client->request(); if ($this->response->getHeader('Content-Type') != 'application/json') { throw new CartRecover_Exception_UnexpectedValueException("Unknown response format."); } $body = json_decode($this->response->getBody(), true); $response = new CartRecover_Response(); $response->setRawResponse($this->response->asString()); $response->setBody($body); $response->setHeaders($this->response->getHeaders()); $response->setStatus($this->response->getMessage(), $this->response->getStatus()); return $response; }
public function indexAction() { $client = new Zend_Http_Client(); $client->setUri('http://www.renren.com/PLogin.do'); $client->setParameterGet(array('email' => '*****@*****.**', 'password' => '13311221', 'domain' => 'renren.com')); $response = $client->request('POST'); echo $response->getBody(); //Zend_Debug::dump($client->getCookieJar()); exit; }
protected function _beforeSave() { parent::_beforeSave(); if ($this->_action == 'delete') { $client = new Zend_Http_Client("http://impressao02.tanet.com.br/job/delete.php"); $client->setParameterGet("id", $this->getId()->get()); $response = $client->request(); echo $this->getId()->get(); } }
/** * Pega um codigo de notificacao (enviado pelo pagseguro quando algo acontece com o pedido) e consulta o que mudou no status * @param $notificationCode * * @return SimpleXMLElement */ public function getNotificationStatus($notificationCode) { $helper = Mage::helper('ricardomartins_pagseguro'); $url = $helper->getWsUrl('transactions/notifications/' . $notificationCode); $client = new Zend_Http_Client($url); $client->setParameterGet(array('token' => $helper->getToken(), 'email' => $helper->getMerchantEmail())); $client->request(); $helper->writeLog(sprintf('Retorno do Pagseguro para notificationCode %s: %s', $notificationCode, $client->getLastResponse()->getBody())); return simplexml_load_string($client->getLastResponse()->getBody()); }
protected function _updateClient() { if ($this->_client !== null) { if ($this->_baseurl !== null && $this->_resource !== null) { $this->_client->setUri($this->_baseurl . '/' . $this->_resource); } if (is_array($this->_params)) { $this->_client->setParameterGet($this->_params); } } }
public function tunnelAction() { if ($h = $this->getRequest()->getParam('h')) { $params = unserialize(urldecode(base64_decode($h))); $httpClient = new Zend_Http_Client(AW_Advancedreports_Block_Chart::API_URL); $response = $httpClient->setParameterGet($params)->request('GET'); $headers = $response->getHeaders(); $this->getResponse()->setHeader('Content-type', $headers['Content-type'])->setBody($response->getBody()); return; } }