本文整理汇总了PHP中Request::send方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::send方法的具体用法?PHP Request::send怎么用?PHP Request::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request::send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getCoordinates
/**
* {@inheritdoc}
*/
public function getCoordinates($street = null, $postal = null, $city = null, $country = null, $fullAddress = null)
{
// Generate a new container.
$objReturn = new Container();
// Set the query string.
$sQuery = $this->getQueryString($street, $postal, $city, $country, $fullAddress);
$objReturn->setSearchParam($sQuery);
$oRequest = null;
$oRequest = new \Request();
$oRequest->send(sprintf($this->strGoogleUrl, rawurlencode($sQuery)));
$objReturn->setUri(sprintf($this->strGoogleUrl, rawurlencode($sQuery)));
if ($oRequest->code == 200) {
$aResponse = json_decode($oRequest->response, 1);
if (!empty($aResponse['status']) && $aResponse['status'] == 'OK') {
$objReturn->setLatitude($aResponse['results'][0]['geometry']['location']['lat']);
$objReturn->setLongitude($aResponse['results'][0]['geometry']['location']['lng']);
} elseif (!empty($aResponse['error_message'])) {
$objReturn->setError(true);
$objReturn->setErrorMsg($aResponse['error_message']);
} else {
$objReturn->setError(true);
$objReturn->setErrorMsg($aResponse['Status']['error_message']);
}
} else {
// Okay nothing work. So set all to Error.
$objReturn->setError(true);
$objReturn->setErrorMsg('Could not find coordinates for address "' . $sQuery . '"');
}
return $objReturn;
}
示例2: downloadProviders
/**
* packages.json & provider-xxx$xxx.json downloader
*/
function downloadProviders($config, $globals)
{
$cachedir = $config->cachedir;
$packagesCache = $cachedir . 'packages.json';
$req = new Request($config->packagistUrl . '/packages.json');
$req->setOption('encoding', 'gzip');
$res = $req->send();
if (200 === $res->getStatusCode()) {
$packages = json_decode($res->getBody());
foreach (explode(' ', 'notify notify-batch search') as $k) {
if (0 === strpos($packages->{$k}, '/')) {
$packages->{$k} = 'https://packagist.org' . $packages->{$k};
}
}
file_put_contents($packagesCache . '.new', json_encode($packages));
} else {
//no changes';
copy($packagesCache, $packagesCache . '.new');
$packages = json_decode(file_get_contents($packagesCache));
}
if (empty($packages->{'provider-includes'})) {
throw new \RuntimeException('packages.json schema changed?');
}
$providers = [];
$numberOfProviders = count((array) $packages->{'provider-includes'});
$progressBar = new ProgressBarManager(0, $numberOfProviders);
$progressBar->setFormat('Downloading Providers: %current%/%max% [%bar%] %percent%%');
foreach ($packages->{'provider-includes'} as $tpl => $version) {
$fileurl = str_replace('%hash%', $version->sha256, $tpl);
$cachename = $cachedir . $fileurl;
$providers[] = $cachename;
if (!file_exists($cachename)) {
$req->setOption('url', $config->packagistUrl . '/' . $fileurl);
$res = $req->send();
if (200 === $res->getStatusCode()) {
$oldcache = $cachedir . str_replace('%hash%', '*', $tpl);
if ($glob = glob($oldcache)) {
foreach ($glob as $old) {
$globals->expiredManager->add($old, time());
}
}
if (!file_exists(dirname($cachename))) {
mkdir(dirname($cachename), 0777, true);
}
file_put_contents($cachename, $res->getBody());
if ($config->generateGz) {
file_put_contents($cachename . '.gz', gzencode($res->getBody()));
}
} else {
$globals->retry = true;
}
}
$progressBar->advance();
}
return $providers;
}
示例3: runLiveUpdate
/**
* Run the Live Update
* @param \BackendTemplate
*/
protected function runLiveUpdate(\BackendTemplate $objTemplate)
{
$archive = 'system/tmp/' . \Input::get('token');
// Download the archive
if (!file_exists(TL_ROOT . '/' . $archive)) {
$objRequest = new \Request();
$objRequest->send(\Config::get('liveUpdateBase') . 'request.php?token=' . \Input::get('token'));
if ($objRequest->hasError()) {
$objTemplate->updateClass = 'tl_error';
$objTemplate->updateMessage = $objRequest->response;
return;
}
\File::putContent($archive, $objRequest->response);
}
$objArchive = new \ZipReader($archive);
// Extract
while ($objArchive->next()) {
if ($objArchive->file_name != 'TOC.txt') {
try {
\File::putContent($objArchive->file_name, $objArchive->unzip());
} catch (\Exception $e) {
$objTemplate->updateClass = 'tl_error';
$objTemplate->updateMessage = 'Error updating ' . $objArchive->file_name . ': ' . $e->getMessage();
return;
}
}
}
// Delete the archive
$this->import('Files');
$this->Files->delete($archive);
// Run once
$this->handleRunOnce();
}
示例4: getCoordinates
/**
* {@inheritdoc}
*/
public function getCoordinates($street = null, $postal = null, $city = null, $country = null, $fullAddress = null)
{
// Generate a new container.
$objReturn = new Container();
// Set the query string.
$sQuery = $this->getQueryString($street, $postal, $city, $country, $fullAddress);
$objReturn->setSearchParam($sQuery);
$oRequest = null;
$oRequest = new \Request();
$oRequest->send(sprintf($this->strUrl, rawurlencode($sQuery)));
$aResponse = json_decode($oRequest->response);
$objResponse = $aResponse[0];
if ($oRequest->code == 200) {
if (!empty($objResponse->place_id)) {
$objReturn->setLatitude($objResponse->lat);
$objReturn->setLongitude($objResponse->lon);
} else {
$objReturn->setError(true);
$objReturn->setErrorMsg('No data from OpenStreetMap for ' . $sQuery);
}
} else {
// Okay nothing work. So set all to Error.
$objReturn->setError(true);
$objReturn->setErrorMsg('No response from OpenStreetMap for address "' . $sQuery . '"');
}
return $objReturn;
}
示例5: getLonLat
/**
* Find the longitute and latitude from a location string
* @param string $strAddress Optimal format: street (+number), postal, city [country]
* @param string
* @return array|bool return an array with logitute, latitude and address or false if error or empty results
* @example https://developers.google.com/maps/documentation/geocoding/?hl=de
*/
public static function getLonLat($strAddress, $strCountry = null)
{
// Google Geocoding API v3
$strUrl = 'https://maps.googleapis.com/maps/api/geocode/json';
$arrParams = array('address' => $strAddress, 'language' => $GLOBALS['TL_LANGUAGE']);
if (\Config::get('anystores_apiKey')) {
$arrParams['key'] = \Config::get('anystores_apiKey');
}
$strQuery = $strUrl . '?' . http_build_query($arrParams, '', '&');
if ($strCountry) {
$strQuery .= '&components=country:' . strtoupper($strCountry);
}
$objRequest = new \Request();
$objRequest->send($strQuery);
if (!$objRequest->hasError()) {
$objResponse = json_decode($objRequest->response);
// check the possible return status
switch ($objResponse->status) {
case 'OK':
return array('address' => $objResponse->results[0]->formatted_address, 'longitude' => $objResponse->results[0]->geometry->location->lng, 'latitude' => $objResponse->results[0]->geometry->location->lat);
case 'ZERO_RESULTS':
case 'OVER_QUERY_LIMIT':
case 'REQUEST_DENIED':
case 'INVALID_REQUEST':
default:
\System::log("Google Maps API return error '{$objResponse->status}' for '{$strAddress}': {$objResponse->error_message}", __METHOD__, TL_ERROR);
return false;
}
}
\System::log("Failed Request '{$strQuery}' with error '{$objRequest->error}'", __METHOD__, TL_ERROR);
return false;
}
示例6: getLonLat
/**
* Find the longitute and latitude from a location string
* @param type $strAddress
* @param type $strCountry
* @example http://wiki.openstreetmap.org/wiki/Nominatim#Examples
*/
public static function getLonLat($strAddress, $strCountry = null)
{
$strQuery = 'https://nominatim.openstreetmap.org/search?' . 'q=' . rawurlencode($strAddress) . '&format=json' . '&accept-language=' . $GLOBALS['TL_LANGUAGE'] . '&limit=1';
if ($strCountry) {
$strQuery .= '&countrycodes=' . $strCountry;
}
$objRequest = new \Request();
$objRequest->send($strQuery);
// Return on error
if ($objRequest->hasError()) {
\System::log("Failed Request '{$strQuery}' with error '{$objRequest->error}'", __METHOD__, TL_ERROR);
return false;
}
$arrResponse = json_decode($objRequest->response);
// Return on empty response
if (!count($arrResponse)) {
\System::log("Empty Request for address '{$strAddress}': '{$strQuery}'", __METHOD__, TL_ERROR);
return false;
}
// Display copyright and licence in backend
if (TL_MODE == 'BE') {
\Message::addInfo($arrResponse[0]->licence);
}
return array('licence' => $arrResponse[0]->licence, 'address' => $arrResponse[0]->display_name, 'latitude' => $arrResponse[0]->lat, 'longitude' => $arrResponse[0]->lon);
}
示例7: getLonLat
/**
* Find the longitute and latitude from a location string
* @param string $strAddress Optimal format: street (+number), postal, city [country]
* @param string
* @return array|bool return an array with logitute, latitude and address or false if error or empty results
* @example https://developers.google.com/maps/documentation/geocoding/?hl=de
*/
public static function getLonLat($strAddress, $strCountry = null)
{
// Google Geocoding API v3
$strQuery = 'https://maps.googleapis.com/maps/api/geocode/json?' . 'address=' . rawurlencode($strAddress) . '&sensor=false' . '&language=' . $GLOBALS['TL_LANGUAGE'];
if ($strCountry) {
$strQuery .= '&components=country:' . $strCountry;
}
$objRequest = new \Request();
$objRequest->send($strQuery);
if (!$objRequest->hasError()) {
$objResponse = json_decode($objRequest->response);
// check the possible return status
switch ($objResponse->status) {
case 'OK':
return array('address' => $objResponse->results[0]->formatted_address, 'longitude' => $objResponse->results[0]->geometry->location->lng, 'latitude' => $objResponse->results[0]->geometry->location->lat);
case 'ZERO_RESULTS':
case 'OVER_QUERY_LIMIT':
case 'REQUEST_DENIED':
case 'INVALID_REQUEST':
default:
\System::log("Google Maps API return error '{$objResponse->status}' for '{$strAddress}'", __METHOD__, TL_ERROR);
return false;
}
}
\System::log("Failed Request '{$strQuery}' with error '{$objRequest->error}'", __METHOD__, TL_ERROR);
return false;
}
示例8: send
public function send()
{
Request::post('http://api.postmarkapp.com/email', $this->parseData());
Request::set(CURLOPT_HTTPHEADER, $this->headers);
$return = Request::send();
return isset($return->data) ? $return->data : $return;
}
示例9: testSend
/**
* @covers AbiosGaming\Request::send
*/
public function testSend()
{
$this->getsData(200, '{"hello":"world"}');
$request = new Request($this->api, 'ping');
$data = $request->send();
$this->assertEquals($this->requestHistory->getLastRequest()->getUrl(), 'https://api.abiosgaming.com/v1/pingjson');
$this->assertObjectHasAttribute('hello', $data);
$this->assertEquals('world', $data->hello);
}
示例10: processPostsale
/**
* Process PayPal Instant Payment Notifications (IPN)
* @param IsotopeProductCollection
*/
public function processPostsale(IsotopeProductCollection $objOrder)
{
$objRequest = new \Request();
$objRequest->send('https://www.' . ($this->debug ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr?cmd=_notify-validate', file_get_contents("php://input"), 'post');
if ($objRequest->hasError()) {
\System::log('Request Error: ' . $objRequest->error, __METHOD__, TL_ERROR);
exit;
} elseif ($objRequest->response == 'VERIFIED' && (\Input::post('receiver_email', true) == $this->paypal_account || $this->debug)) {
// Validate payment data (see #2221)
if ($objOrder->currency != \Input::post('mc_currency') || $objOrder->getTotal() != \Input::post('mc_gross')) {
\System::log('IPN manipulation in payment from "' . \Input::post('payer_email') . '" !', __METHOD__, TL_ERROR);
return;
}
if (!$objOrder->checkout()) {
\System::log('IPN checkout for Order ID "' . \Input::post('invoice') . '" failed', __METHOD__, TL_ERROR);
return;
}
// Store request data in order for future references
$arrPayment = deserialize($objOrder->payment_data, true);
$arrPayment['POSTSALE'][] = $_POST;
$objOrder->payment_data = $arrPayment;
$objOrder->save();
// @see https://www.paypalobjects.com/webstatic/en_US/developer/docs/pdf/ipnguide.pdf
switch (\Input::post('payment_status')) {
case 'Completed':
$objOrder->date_paid = time();
$objOrder->updateOrderStatus($this->new_order_status);
break;
case 'Canceled_Reversal':
case 'Denied':
case 'Expired':
case 'Failed':
case 'Voided':
// PayPal will also send this notification if the order has not been placed.
// What do we do here?
// $objOrder->date_paid = '';
// $objOrder->updateOrderStatus(Isotope::getConfig()->orderstatus_error);
break;
case 'In-Progress':
case 'Partially_Refunded':
case 'Pending':
case 'Processed':
case 'Refunded':
case 'Reversed':
break;
}
$objOrder->payment_data = $arrPayment;
$objOrder->save();
\System::log('PayPal IPN: data accepted', __METHOD__, TL_GENERAL);
} else {
\System::log('PayPal IPN: data rejected (' . $objRequest->response . ')', __METHOD__, TL_ERROR);
}
// 200 OK
$objResponse = new Response();
$objResponse->send();
}
示例11: getCoordinates
/**
* Find coordinates for given adress
* @param string Street
* @param string Postal/ZIP Code
* @param string Name of city
* @param string 2-letter country code
* @param string Adress string without specific format
* @return array
*/
public function getCoordinates($street = NULL, $postal = NULL, $city = NULL, $country = NULL, $fullAdress = NULL)
{
// find coordinates using google maps api
$sQuery = sprintf("%s %s %s %s", $street, $postal, $city, $country);
$sQuery = $fullAdress ? $fullAdress : $sQuery;
$oRequest = NULL;
$oRequest = new Request();
$oRequest->send("http://maps.googleapis.com/maps/api/geocode/json?address=" . rawurlencode($sQuery) . "&sensor=false&language=de");
$hasError = false;
if ($oRequest->code == 200) {
$aResponse = array();
$aResponse = json_decode($oRequest->response, 1);
if (!empty($aResponse['status']) && $aResponse['status'] == 'OK') {
$coords = array();
$coords['latitude'] = $aResponse['results'][0]['geometry']['location']['lat'];
$coords['longitude'] = $aResponse['results'][0]['geometry']['location']['lng'];
return $coords;
} else {
// try alternative api if google blocked us
$oRequest->send("http://maps.google.com/maps/geo?q=" . rawurlencode($sQuery) . "&output=json&oe=utf8&sensor=false&hl=de");
if ($oRequest->code == 200) {
$aResponse = array();
$aResponse = json_decode($oRequest->response, 1);
if (!empty($aResponse['Status']) && $aResponse['Status']['code'] == 200) {
$coords = array();
$coords['latitude'] = $aResponse['Placemark'][0]['Point']['coordinates'][1];
$coords['longitude'] = $aResponse['Placemark'][0]['Point']['coordinates'][0];
return $coords;
} else {
$hasError = true;
}
} else {
$hasError = true;
}
}
} else {
$hasError = true;
}
if ($hasError) {
$this->log('Could not find coordinates for adress "' . $sQuery . '"', 'StoreLocator getCoordinates()', TL_ERROR);
}
return false;
}
示例12: checkLink
public function checkLink($linkliste_id, $linkliste_url = '')
{
if ($linkliste_url == '') {
$objData = $this->Database->prepare("SELECT url FROM tl_link_data WHERE id = ?")->execute($linkliste_id);
$linkliste_url = $objData->url;
}
if ($linkliste_url == '') {
return false;
}
$linkliste_url = html_entity_decode($linkliste_url);
// Anchor
if (strstr($linkliste_url, 'link_url')) {
$linkliste_url = '{{env::url}}/' . $linkliste_url;
$linkliste_url = $this->replaceInsertTags($linkliste_url);
}
$objRequest = new Request();
$objRequest->send($linkliste_url);
if (false) {
echo '<pre>';
print_r($objRequest);
echo '</pre>';
}
$this->Database->prepare("UPDATE tl_link_data SET be_error = 0, be_warning = 0, be_text = '' WHERE id = ?")->execute($linkliste_id);
$error = '';
if ($objRequest->code == 0) {
$this->Database->prepare("UPDATE tl_link_data SET be_error = 1 WHERE id=?")->execute($linkliste_id);
if (strstr($objRequest->error, 'Name or service not known')) {
$error = 'Name or service not known';
} else {
$error = $objRequest->error;
}
} elseif ($objRequest->code >= 400) {
$this->Database->prepare("UPDATE tl_link_data SET be_error = 1 WHERE id=?")->execute($linkliste_id);
$error = $objRequest->error;
} elseif ($objRequest->code >= 300) {
$this->Database->prepare("UPDATE tl_link_data SET be_warning = 1 WHERE id=?")->execute($linkliste_id);
if ($objRequest->code == 301) {
$error = 'Moved Permanently';
} else {
$error = $objRequest->error;
}
}
if ($error != '' || $objRequest->code > 0) {
$this->Database->prepare("UPDATE tl_link_data SET be_text = ? WHERE id=?")->execute($objRequest->code . ' ' . $error, $linkliste_id);
//$objRequest->response
}
/* duplicates */
$objData = $this->Database->prepare("SELECT id,be_text FROM tl_link_data WHERE url LIKE ?")->execute('%%' . $linkliste_url . '%%');
if ($objData->numRows > 1) {
while ($objData->next()) {
$this->Database->prepare("UPDATE tl_link_data SET be_warning = 1 , be_text = ? WHERE id=?")->execute('Duplicate entrys ', $objData->id);
}
}
}
示例13: getGeoCords
/**
* @param string $address
* @param $lang
* @param bool $blnServer
* @return array|mixed
*/
public function getGeoCords($address = '', $lang, $blnServer = false)
{
// default return value
$return = array('lat' => '0', 'lng' => '0');
// check if parameters are set
if (!$lang) {
$lang = 'de';
}
if (!$address) {
return $return;
}
// set id
$keyID = md5(urlencode($address));
// get lat and lng from cache
$cacheReturn = $this->geoCordsCache[$keyID];
if (!is_null($cacheReturn) && is_array($cacheReturn)) {
return $cacheReturn;
}
// check if api key exist
$apiKey = '';
$strServerID = \Config::get('googleServerKey') ? \Config::get('googleServerKey') : '';
$strBrowserID = \Config::get('googleApiKey') ? \Config::get('googleApiKey') : '';
$strGoogleID = !$blnServer ? $strBrowserID : $strServerID;
if ($strGoogleID) {
$apiKey = '&key=' . $strGoogleID . '';
}
// create google map api
$api = 'https://maps.googleapis.com/maps/api/geocode/json?address=%s%s&language=%s®ion=%s';
$strURL = sprintf($api, urlencode($address), $apiKey, urlencode($lang), strlen($lang));
// send request to google maps api
$request = new \Request();
$request->send($strURL);
// check if request is valid
if ($request->hasError()) {
return $return;
}
$response = $request->response ? json_decode($request->response, true) : array();
if (!is_array($response)) {
return $return;
}
if (empty($response)) {
return $return;
}
// set lng and lat
if ($response['results'][0]['geometry']) {
$geometry = $response['results'][0]['geometry'];
$return['lat'] = $geometry['location'] ? $geometry['location']['lat'] : '';
$return['lng'] = $geometry['location'] ? $geometry['location']['lng'] : '';
}
// save cache
$this->geoCordsCache[$keyID] = $return;
// return geoCoding
return $return;
}
示例14: send
public static function send($data)
{
// Get the config information
$pm = Config::get('email.postmark');
$key = $pm['apiKey'];
// Set headers to send to Postmark
$headers = array('Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: ' . $key);
Request::post('http://api.postmarkapp.com/email', json_encode($data));
Request::set(CURLOPT_HTTPHEADER, $headers);
$return = Request::send();
return $return;
}
示例15: _recaptcha_http_post
/**
* Submits an HTTP POST to a reCAPTCHA server
* @param string $host
* @param string $path
* @param array $data
* @param int port
* @return array response
*/
function _recaptcha_http_post($host, $path, $data, $port = 80)
{
$req = _recaptcha_qsencode($data);
$request = new Request($host, $path, $port, true, true, 10);
$request->setData($data);
$request->setUserAgent('reCAPTCHA/PHP');
$request->skiplog(true);
if (!($response = $request->send())) {
trigger_error("Unable to reach reCAPCHA server.");
}
$response = explode("\r\n\r\n", $response, 2);
return $response;
}