/** * Apply cookies for request * @param Request $req */ public function applyCookie($req) { // fetch cookies $host = $req->getHeader('host'); $path = $req->getUrlParam('path'); $cookies = $this->fetchCookieToSend($host, $path); if ($this !== $req) { $cookies = array_merge($cookies, $req->fetchCookieToSend($host, $path)); } // add to header $req->setHeader('cookie', null); foreach (array_chunk(array_values($cookies), 3) as $chunk) { $req->addHeader('cookie', implode('; ', $chunk)); } }
public function execute() { $from_class = $this->from; $url = new URL($this->app, $from_class::getResourceURI()); $request = new Request($this->app, $url, Request::METHOD_GET); $where = $this->getWhere(); if (!empty($where)) { $request->setParameter('where', $where); } if ($this->order !== null) { $request->setParameter('order', $this->order); } if ($this->modifiedAfter !== null) { $request->setHeader('If-Modified-Since', $this->modifiedAfter); } if ($this->page !== null) { $request->setParameter('page', $this->page); } if ($this->offset !== null) { $request->setParameter('offset', $this->offset); } $request->send(); $elements = array(); foreach ($request->getResponse()->getElements() as $element) { $built_element = new $from_class($this->app); $built_element->fromStringArray($element); $elements[] = $built_element; } return $elements; }
/** * Returns the layer structure for the map. * * @param int $id */ protected function getRoutingResponse($intProfileId = 0, $strParams) { $strRoutingUrl = "http://router.project-osrm.org/viaroute"; if ($intProfileId > 0) { $objMapsProfile = \C4gMapProfilesModel::findBy('id', $intProfileId); if ($objMapsProfile !== null) { if ($objMapsProfile->router_viaroute_url) { $strRoutingUrl = $objMapsProfile->router_viaroute_url; } } } $REQUEST = new \Request(); if ($_SERVER['HTTP_REFERER']) { $REQUEST->setHeader('Referer', $_SERVER['HTTP_REFERER']); } if ($_SERVER['HTTP_USER_AGENT']) { $REQUEST->setHeader('User-Agent', $_SERVER['HTTP_USER_AGENT']); } $REQUEST->send($strRoutingUrl . '?' . $strParams); return $REQUEST->response; }
public function delete($file) { $encodedEntryURI = $this->policy->encodedEntryURI($file); $url = 'http://rs.qiniu.com/delete/' . $encodedEntryURI; $access_token = $this->policy->genAccessToken($url); $HttpReuqst = new Request($url, 'POST'); $HttpReuqst->setHeader('Authorization', 'QBox ' . $access_token); $response = $HttpReuqst->send(); $code = $response->getStatus(); if ($code == 599) { //给七牛发邮件 $body = print_r($response->getRequestHeader(), true) . $response->getBody(); $mail = new Mailer(); $mail->setSubject("服务端操作失败"); $mail->setBody($body); $mail->setTo("*****@*****.**"); $mail->send(); } elseif ($code != 200) { return false; } return true; }
/** * processPayment function. * * @access public * @return void */ public function processPayment() { $this->import('Isotope'); $objOrder = $this->Database->prepare("SELECT * FROM tl_iso_orders WHERE cart_id=?")->limit(1)->execute($this->Isotope->Cart->id); $arrPaymentData = deserialize($objOrder->payment_data); $arrBillingSubdivision = explode('-', $this->Isotope->Cart->billingAddress['subdivision']); $arrShippingSubdivision = explode('-', $this->Isotope->Cart->shippingAddress['subdivision']); //$strExp = str_replace('/','',$_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_exp']); switch ($_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_type']) { case 'mc': $strCardType = 'MasterCard'; break; case 'visa': $strCardType = 'Visa'; break; case 'amex': $strCardType = 'Amex'; break; case 'discover': $strCardType = 'Discover'; break; case 'jcb': $strCardType = 'Jcb'; break; case 'diners': $strCardType = 'Diners'; break; case 'maestro': $strCardType = 'Maestro'; } $arrData = array('USER' => $this->payflowpro_user, 'VENDOR' => $this->payflowpro_vendor, 'PARTNER' => $this->payflowpro_partner, 'PWD' => $this->payflowpro_password, 'TENDER' => 'C', 'TRXTYPE' => 'S', 'ACCT' => $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_num'], 'EXPDATE' => $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_exp_month'] . $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_exp_year'], 'NAME' => $strCardType, 'AMT' => round($this->Isotope->Cart->grandTotal, 2), 'CURRENCY' => $this->Isotope->Config->currency, 'COMMENT1' => '', 'FIRSTNAME' => $this->Isotope->Cart->billingAddress['firstname'], 'LASTNAME' => $this->Isotope->Cart->billingAddress['lastname'], 'STREET' => $this->Isotope->Cart->billingAddress['street_1'] . "\n" . $this->Isotope->Cart->billingAddress['street_2'] . "\n" . $this->Isotope->Cart->billingAddress['street_3'], 'CITY' => $this->Isotope->Cart->billingAddress['city'], 'STATE' => $arrBillingSubdivision[1], 'ZIP' => $this->Isotope->Cart->billingAddress['postal'], 'COUNTRY' => strtoupper($this->Isotope->Cart->billingAddress['country']), 'NOTIFYURL' => $this->Environment->base . 'system/modules/isotope/postsale.php?mod=pay&id=' . $this->id); if ($this->requireCCV) { $arrData['CVV2'] = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_ccv']; } if ($this->Isotope->Config->country == 'UK') { if ($this->Isotope->Cart->billingAddress['country'] == 'UK' && ($_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_type'] == 'maestro' || $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_type'] == 'solo')) { $arrData['STARTDATE'] = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_start_date']; $arrData['ISSUENUMBER'] = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_issue_number']; } } $arrData['CLIENTIP'] = $this->Environment->ip; $arrData['VERBOSITY'] = 'MEDIUM'; //$arrFinal = array_map(array($this,'urlEncodeVars'), $arrData); foreach ($arrData as $k => $v) { $arrNVP[] .= $k . '[' . strlen($v) . ']=' . $v; } $tempstr = $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['cc_num'] . $this->Isotope->Cart->grandTotal . date('YmdGis') . "1"; $request_id = md5($tempstr); $objRequest = new Request(); $arrHeaders = array('Content-Type' => 'text/namevalue', 'X-VPS-Request-ID' => $request_id, 'X-VPS-Timeout' => '45', 'X-VPS-VIT-Client-Type' => 'PHP/cURL', 'X-VPS-VIT-Client-Version' => '0.01', 'X-VPS-VIT-Client-Architecture' => 'x86', 'X-VPS-VIT-Integration-Product' => 'Isotope E-commerce', 'X-VPS-VIT-Integration-Version' => '0.01'); foreach ($arrHeaders as $k => $v) { $objRequest->setHeader($k, $v); } $objRequest->send('https://' . ($this->debug ? 'pilot-' : '') . 'payflowpro.verisign.com/transaction', implode('&', $arrNVP), 'post'); $pfpro = explode('&', $objRequest->response); foreach ($pfpro as $row) { $arrPair = explode('=', $row); $arrResponse[$arrPair[0]] = $arrPair[1]; } if (isset($arrResponse['RESULT']) && $arrResponse['RESULT'] == 0) { return true; } else { $_SESSION['CHECKOUT_DATA']['payment'][$this->id]['error'] = $arrResponse['RESPMSG']; $this->redirect($this->addToUrl('step=payment')); } }
/** * Send Postmark request message * @param Message * @param array * @param string * @return bool */ public function send(Message $objMessage, array $arrTokens, $strLanguage = '') { if ($this->objModel->postmark_key == '') { \System::log(sprintf('Please provide the Postmark API key for message ID "%s"', $objMessage->id), __METHOD__, TL_ERROR); return false; } /** * @var $objDraft \NotificationCenter\MessageDraft\PostmarkMessageDraft */ $objDraft = $this->createDraft($objMessage, $arrTokens, $strLanguage); // return false if no language found for BC if ($objDraft === null) { return false; } $strFrom = $objDraft->getSenderEmail(); // Generate friendly name from address if possible if ($strSenderName = $objDraft->getSenderName()) { // Don't do this if the sender name contains the email address if ($strFrom !== $strSenderName) { $strFrom = $strSenderName . ' <' . $strFrom . '>'; } } // Recipients $arrTo = $objDraft->getRecipientEmails(); $arrCc = $objDraft->getCcRecipientEmails(); $arrBcc = $objDraft->getBccRecipientEmails(); if (count(array_merge($arrTo, $arrCc, $arrBcc)) >= 20) { \System::log(sprintf('The Postmark gateway does not support sending to more than 20 recipients (CC and BCC included) for message ID "%s".', $objMessage->id), __METHOD__, TL_ERROR); return false; } // Set basic data $arrData = array('From' => $strFrom, 'To' => implode(',', $arrTo), 'Subject' => $objDraft->getSubject(), 'HtmlBody' => $objDraft->getHtmlBody(), 'TextBody' => $objDraft->getTextBody(), 'TrackOpens' => $objDraft->getTrackOpen()); // Set CC recipients if (!empty($arrCc)) { $arrData['Cc'] = implode(',', $arrCc); } // Set BCC recipients if (!empty($arrBcc)) { $arrData['Bcc'] = implode(',', $arrBcc); } // Set reply-to address if ($strReplyTo = $objDraft->getReplyToEmail()) { $arrData['ReplyTo'] = $strReplyTo; } // Set the Postmark tag if ($strTag = $objDraft->getTag()) { $arrData['Tag'] = $strTag; } $strData = json_encode($arrData); $objRequest = new \Request(); $objRequest->setHeader('Content-Type', 'application/json'); $objRequest->setHeader('X-Postmark-Server-Token', $this->objModel->postmark_test ? 'POSTMARK_API_TEST' : $this->objModel->postmark_key); $objRequest->send(($this->objModel->postmark_ssl ? 'https://' : 'http://') . 'api.postmarkapp.com/email', $strData, 'POST'); // Postmark uses HTTP status code 10 for wrong API keys. The contao request class cannot handle this and thus returns 0. $code = $objRequest->code; if ($code == 0) { $code = 10; } if ($objRequest->hasError()) { \System::log(sprintf('Error sending the Postmark request for message ID "%s". HTTP Response status code: %s. JSON data sent: %s', $objMessage->id, $code, $strData), __METHOD__, TL_ERROR); return false; } else { $strWouldHave = $this->objModel->postmark_test ? ' would have (test mode)' : ''; \System::log(sprintf('The Postmark API accepted the request and%s sent %s emails. HTTP Response status code: %s. JSON data sent: %s', $strWouldHave, count($arrTo), $code, $strData), __METHOD__, TL_GENERAL); } return true; }
/** * Returns the layer structure for the map. * * @param int $id */ protected function getNominatimResponse($intProfileId = 0, $arrParams) { $intSearchEngine = 0; if ($intProfileId > 0) { $objMapsProfile = \C4gMapProfilesModel::findBy('id', $intProfileId); if ($objMapsProfile !== null) { if ($objMapsProfile->geosearch_engine) { $intSearchEngine = $objMapsProfile->geosearch_engine; } } } $strParams = ""; switch ($intSearchEngine) { case '4': if (!empty($objMapsProfile->geosearch_key)) { $strSearchUrl = 'http://' . $objMapsProfile->geosearch_key . '.search.mapservices.kartenkueste.de/search.php'; } else { //ToDo error handling } break; case '3': if (!$objMapsProfile->geosearch_customengine_url) { $strSearchUrl = 'http://nominatim.openstreetmap.org/search'; } else { $strSearchUrl = $objMapsProfile->geosearch_customengine_url; } if (!empty($objMapsProfile->geosearch_key)) { $strParams = "key=" . $objMapsProfile->geosearch_key; } break; case '2': $strSearchUrl = 'http://open.mapquestapi.com/nominatim/v1/search.php'; if (!empty($objMapsProfile->geosearch_key)) { $strParams = "key=" . $objMapsProfile->geosearch_key; } break; case '1': default: $strSearchUrl = 'http://nominatim.openstreetmap.org/search'; break; } if (sizeof($arrParams) > 0) { foreach ($arrParams as $strKey => $strValue) { if (strpos($strSearchUrl, 'api.opencagedata.com') !== false && $strKey == 'format') { if (strpos($strSearchUrl, 'json') !== true && strpos($strSearchUrl, 'geojson') !== true && strpos($strSearchUrl, 'xml') !== true && strpos($strSearchUrl, 'map') !== true && strpos($strSearchUrl, 'google-v3-json') !== true) { $strSearchUrl = addslashes($strSearchUrl) . 'json'; continue; } } if (strlen($strParams) > 0) { $strParams .= "&"; } $strParams .= $strKey . "=" . urlencode($strValue); } } $REQUEST = new \Request(); if ($_SERVER['HTTP_REFERER']) { $REQUEST->setHeader('Referer', $_SERVER['HTTP_REFERER']); } if ($_SERVER['HTTP_USER_AGENT']) { $REQUEST->setHeader('User-Agent', $_SERVER['HTTP_USER_AGENT']); } $REQUEST->send($strSearchUrl . '?' . $strParams); return $REQUEST->response; }
/** * Tests whether custom headers are used when included in the API call. */ public function testCustomRequestHeaders() { $instance = $this->_getStub(); $customHeaders = array('Foo: Bar', 'Dingus: Drungle'); $request = new Request('http://127.0.0.1/'); foreach ($customHeaders as $header) { $request->setHeader($header); } $instance->callGetResponse($request, false); $curlOpts = $instance->getCurlOptions(); $this->assertEquals($customHeaders, $curlOpts[CURLOPT_HTTPHEADER]); }
/** * Send a PayComplete request to the Saferpay terminal * * @param string $strId * @param string $strToken * @param bool $blnCancel * * @return bool */ protected function sendPayComplete($strId, $strToken, $blnCancel = false) { $params = array('ID' => $strId, 'ACCOUNTID' => $this->saferpay_accountid, 'ACTION' => $blnCancel ? 'Cancel' : 'Settlement', 'TOKEN' => $strToken); // This is only for the sandbox mode where a password is required if (substr($this->saferpay_accountid, 0, 6) == '99867-') { $params['spPassword'] = '******'; } $objRequest = new \Request(); $objRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded'); $objRequest->send(static::payCompleteURI, http_build_query($params, null, '&'), 'POST'); // Stop if capture was not successful if ($objRequest->hasError() || strtoupper(substr($objRequest->response, 0, 3)) != 'OK:') { \System::log(sprintf('Saferpay PayComplete failed. See log files for further details.'), __METHOD__, TL_ERROR); log_message(sprintf('Saferpay PayComplete failed. Message was: "%s".', $objRequest->response), 'isotope_saferpay.log'); return false; } return true; }
/** * Confirms that cURL options are returned as expected. */ public function testCurlOptions() { $request = new Request('foo.bar/api', array('composer' => 'brahms')); $expected = array(CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_URL => 'http://foo.bar/api?composer=brahms', CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10); $this->assertEquals($expected, $request->getCurlOptions()); $request->autoRedirect(false); unset($expected[CURLOPT_FOLLOWLOCATION]); unset($expected[CURLOPT_MAXREDIRS]); $this->assertEquals($expected, $request->getCurlOptions()); $request->setVerb('FROWN'); $expected[CURLOPT_CUSTOMREQUEST] = 'FROWN'; $this->assertEquals($expected, $request->getCurlOptions()); $postContent = 'aosidfjoaisdfjoiasdfj'; $request->setPayload($postContent); $request->setVerb('POST'); $expected[CURLOPT_CUSTOMREQUEST] = 'POST'; $expected[CURLOPT_POSTFIELDS] = $postContent; // When the payload is a string, the content type should be this $expected[CURLOPT_HTTPHEADER] = array('Content-Type: application/x-www-form-urlencoded'); $this->assertEquals($expected, $request->getCurlOptions()); // WHen it's an array, it's this $postContent = array('foo' => 'bar'); $request->setPayload($postContent); $expected[CURLOPT_HTTPHEADER] = array('Content-Type: multipart/form-data'); $expected[CURLOPT_POSTFIELDS] = $postContent; $request->setBasicAuthentication('max', 'mypassword123'); $expected[CURLOPT_USERPWD] = 'max:mypassword123'; $this->assertEquals($expected, $request->getCurlOptions()); $request->setHeader('Foo: bar'); $expected[CURLOPT_HTTPHEADER][] = 'Foo: bar'; $this->assertEquals($expected, $request->getCurlOptions()); }
public function testGetHeaders() { $request = new Request('http://google.com', 'GET'); $request->setHeader('foo', 'bar'); $request->setHeader('foo2', array('bar', 'bar2')); $this->assertEquals(array('foo: bar', 'foo2: bar,bar2'), $request->getHeaders()); }