/** * @covers Aws\Sns\SnsClient::factory */ public function testFactoryInitializesClient() { $client = SnsClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-east-1')); $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV2', $client->getSignature()); $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials()); $this->assertEquals('https://sns.us-east-1.amazonaws.com', $client->getBaseUrl()); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->output = $output; $this->client = $client = SnsClient::factory(array('key' => $this->getContainer()->getParameter('amazon_s3.key'), 'secret' => $this->getContainer()->getParameter('amazon_s3.secret'), 'region' => $this->getContainer()->getParameter('amazon_s3.region'))); if ($input->getOption('list-android')) { $this->showEndpoints($this->getContainer()->getParameter('amazon_sns.android_arn'), 'List of GCM endpoints:'); } if ($input->getOption('list-ios')) { $this->showEndpoints($this->getContainer()->getParameter('amazon_sns.ios_arn'), 'List of APNS endpoints:'); } $endpoint = $input->getArgument('endpoint'); if ($endpoint) { if ($input->getOption('delete')) { $output->writeln('<comment>Delete endpoint</comment>'); $client->deleteEndpoint(array('EndpointArn' => $endpoint)); } else { $testMessage = 'Test notification'; try { $client->publish(array('TargetArn' => $endpoint, 'MessageStructure' => 'json', 'Message' => json_encode(array('APNS' => json_encode(array('aps' => array('alert' => $testMessage))), 'GCM' => json_encode(array('data' => array('message' => $testMessage))))))); } catch (\Aws\Sns\Exception\SnsException $e) { $output->writeln("<error>{$e->getMessage()}</error>"); } } } }
public function __construct($region = false) { if (!$region && !($region = getenv("AWS_DEFAULT_REGION"))) { throw new \Exception("Set 'AWS_DEFAULT_REGION' environment variable!"); } $this->region = $region; $this->sns = SnsClient::factory(['region' => $region]); $this->ddb = DynamoDbClient::factory(['region' => $region]); }
function __construct() { $this->snsARNs = explode(',', $_ENV['snsTopicARNs']); if ('POST' === $_SERVER['REQUEST_METHOD'] && !empty($_POST['text'])) { $this->setText(); $this->setARN(); $this->awsClient = SnsClient::factory(array('region' => $_ENV['awsSNSRegion'])); $this->processForm(); } else { $this->renderForm(); } }
public function testAttributesSerializeCorrectly() { $client = SnsClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-east-1')); // Mock the response so no request is sent to the service $mockPlugin = new MockPlugin(); $mockPlugin->addResponse(new Response(200)); $client->addSubscriber($mockPlugin); // Listener to grab the request body about to be sent $client->getEventDispatcher()->addListener('request.before_send', function ($event) use(&$actualRequestBody) { list(, $actualRequestBody) = explode("\r\n\r\n", $event['request']); }, -255); // Expected serialization; extracted from service API documentation $expectedRequestBody = 'Action=SetPlatformApplicationAttributes&Version=2010-03-31&PlatformApplicationArn=arn%3' . 'Aaws%3Asns%3Aus-west-2%3A123456789012%3Aapp%2FGCM%2Fgcmpushapp&Attributes.entry.1.key=EventEndpointCreat' . 'ed&Attributes.entry.1.value=arn%3Aaws%3Asns%3Aus-west-2%3A123456789012%3Atopicarn'; // Perform the operation $client->setPlatformApplicationAttributes(array('PlatformApplicationArn' => 'arn:aws:sns:us-west-2:123456789012:app/GCM/gcmpushapp', 'Attributes' => array('EventEndpointCreated' => urldecode('arn:aws:sns:us-west-2:123456789012:topicarn')))); $this->assertEquals($expectedRequestBody, $actualRequestBody); }
/** * @param $strAccountUrl * @param $strUserId * @param $strApplication * @param $strEndpoint * @param $arrJsonData * @throws \Exception (on missing parameters) * @throws Aws\Sns\Exception\SnsException (on method failure) */ public function sendMessage($strAccountUrl, $strUserId, $strApplication, $strEndpoint, $arrJsonData) { if (empty($strAccountUrl)) { throw new \Exception('Missing Account URL'); } if (empty($strUserId)) { throw new \Exception('Missing User ID'); } if (empty($strApplication)) { throw new \Exception('Missing Application Name'); } if (empty($strEndpoint)) { throw new \Exception('Missing URL Endpoint'); } $strTarget = $this->_strTarget; $arrMessage = ['accounturl' => $strAccountUrl, 'userid' => $strUserId, 'application' => $strApplication, 'endpoint' => $strEndpoint]; if (isset($arrJsonData)) { $arrJsonData = is_array($arrJsonData) ? json_encode($arrJsonData) : $arrJsonData; $arrMessage['json_data'] = $arrJsonData; } $client = SnsClient::factory($this->_arrCredentials); $arrMessage = json_encode(['default' => json_encode($arrMessage), 'lambda' => json_encode($arrMessage)]); $client->publish(['TargetArn' => $strTarget, 'MessageStructure' => 'json', 'Message' => $arrMessage]); }
function amazonSnsPush($alert, $msg_encoded, $topic_arn) { $message = '{ "default": "{' . $msg_encoded . '}", "APNS": "{\\"aps\\":{\\"alert\\": \\"' . $alert . '\\"}, \\"custom\\":{' . $msg_encoded . '}}", "APNS_SANDBOX":"{\\"aps\\":{\\"alert\\": \\"' . $alert . '\\"}, \\"custom\\":{' . $msg_encoded . '}}" }'; if (is_null($this->client)) { $args = array(); $args = array('region' => $this->get_aws_region(), 'version' => '2010-03-31', 'credentials' => ['key' => $this->get_access_key_id(), 'secret' => $this->get_secret_access_key()]); $args = apply_filters('aws_get_client_args', $args); $this->client = SnsClient::factory($args); } try { $result = $this->client->publish(array('TopicArn' => $topic_arn, 'Message' => $message, 'MessageStructure' => 'json')); } catch (Exception $e) { error_log("===== got the exception from publish call : " . $e->getMessage()); } }
/** * Returns a S3Client instance * @return \Aws\Sns\SnsClient */ private function getClient() { if ($this->_client === null) { $this->_client = SnsClient::factory(['key' => $this->key, 'secret' => $this->secret, 'region' => $this->region]); } return $this->_client; }
$lastfmApi = "http://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user="******"&period=" . $request['period'] . "&api_key=" . $config['api_key'] . "&limit={$limit}&format=json"; $validUser = "******" . $request['user'] . "&api_key=" . $config['api_key'] . "&format=json"; //Check if a valid user $infoJson = json_decode(getJson($validUser)); //If an error is thrown, generate an error image and exit if (isset($infoJson->{"error"})) { header("Content-Type: image/png"); error_log($infoJson->{"message"} . " - " . $request['user']); imagepng(errorImage($infoJson->{"message"})); $sns = SnsClient::factory(array('credentials.cache' => $cache, 'region' => 'eu-west-1')); $sns->publish(array('TopicArn' => 'arn:aws:sns:eu-west-1:346795263809:LastFM-Errors', 'Message' => $infoJson->{"message"} . " - " . $request['user'], 'Subject' => "Lastfm Error: " . $infoJson->{"error"})); return; } //Get User's albums and generate a MD5 hash based on this $json = getJson($lastfmApi); $sns = SnsClient::factory(array('credentials.cache' => $cache, 'region' => 'eu-west-1')); $sns->publish(array('TopicArn' => 'arn:aws:sns:eu-west-1:346795263809:LastFM-API-CAlls', 'Message' => $json, 'Subject' => $user . "s JSON API Call")); $jsonhash = md5($json); //Cache based on user set variables and JSON hash $filename = "images/{$user}.{$period}.{$rows}.{$cols}.{$albumInfo}.{$plays}.{$jsonhash}"; //if a previous file exists - request is cached, serve from cache and exit if (file_exists($filename)) { header("Content-Type: image/jpeg"); error_log("Serving from cache - " . $filename); echo file_get_contents($filename); exit; } //otherwise carry on and getAlbums from LastFM. $albums = getAlbums(json_decode($json)); //Pass the Albums to getArt to download the art into a $covers array $covers = getArt($albums, 3);
public function boot() { $this->app->make('Illuminate\\Broadcasting\\BroadcastManager')->extend('sns', function ($app, $config) { return new SnsBroadcaster(SnsClient::factory(array('credentials' => array('key' => $config['aws_key'], 'secret' => $config['aws_secret']), 'version' => 'latest', 'region' => $config['aws_region']))); }); }
public function connect() { $this->_connection = SnsClient::factory($this->config); $this->connected = true; }
<?php require 'vendor/autoload.php'; use Aws\Sns\SnsClient; $snsclient = SnsClient::factory(array('region' => 'us-east-1')); $snstopicArn = $client->createTopic(array('Name' => 'string')); echo $snstopicArn; $subscriptionArn = $client->subscribe(array('TopicArn' => $snstopicArn, 'Protocol' => 'sms', 'Endpoint' => '1-312-395-0502')); echo $subscriptionArn; //$result = $client->confirmSubscription(array( // TopicArn is required // 'TopicArn' => $snstopicArn, // Token is required //'Token' => 'string', //'AuthenticateOnUnsubscribe' => 'string', //)); //echo $result;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } print_r($_FILES); print "</pre>"; $testimagefilename = $uploadfile . '_magick'; $testimage = new Imagick($uploadfile); $testimage->thumbnailImage(100, 0); $testimage->writeImages($testimagefilename, false); require 'vendor/autoload.php'; require 'resources/library/db.php'; $s3 = new Aws\S3\S3Client(['version' => 'latest', 'region' => 'us-east-1']); use Aws\Sns\SnsClient; $sns = SnsClient::factory(array('version' => 'latest', 'region' => 'us-east-1')); $bucket = uniqid("php-pv-", false); $result = $s3->createBucket(['ACL' => 'public-read', 'Bucket' => $bucket]); $result = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $bucket, 'Expires' => gmdate("D, d M Y H:i:s T", strtotime("+1 day")), 'Key' => $uploadfile, 'SourceFile' => $uploadfile]); $url = $result['ObjectURL']; $resultthumb = $s3->putObject(['ACL' => 'public-read', 'Bucket' => $bucket, 'Expires' => gmdate("D, d M Y H:i:s T", strtotime("+1 day")), 'Key' => $testimagefilename, 'SourceFile' => $testimagefilename]); $urlthumb = $resultthumb['ObjectURL']; $link = getDbConn(); if (!($stmt = $link->prepare("INSERT INTO items (id, email,phone,filename,s3rawurl,s3finishedurl,status,issubscribed) VALUES (NULL,?,?,?,?,?,?,?)"))) { echo "Prepare failed: (" . $link->errno . ") " . $link->error; } $email = $_SESSION["email"]; $phone = $_SESSION['phone']; $s3rawurl = $url; // $result['ObjectURL']; from above $filename = basename($_FILES['userfile']['name']);
<?php use Aws\Sns\SnsClient; require 'vendor/autoload.php'; $sns = SnsClient::factory(['key' => '', 'secret' => '', 'region' => 'ap-northeast-1']);
/** * @return SnsClient */ public function getSnsClient() { return SnsClient::factory($this->awsApiKeyConfig); }
<?php require __DIR__ . "/vendor/autoload.php"; $config = json_decode(file_get_contents(__DIR__ . "/config.json"), true); $client = \Aws\Sns\SnsClient::factory($config); $message = new \stdClass(); $content = array('data' => array('message' => 'little body', 'title' => 'little title')); $message->GCM = json_encode($content); $message = json_encode($message); $results = $client->publish(array('TargetArn' => '<YOUR TARGET>', 'Message' => $message, 'MessageStructure' => 'json')); var_dump($results);
public function init() { parent::init(); $this->_client = SnsClient::factory(array('credentials' => array('key' => $this->key, 'secret' => $this->secret), 'region' => 'ap-southeast-1', 'version' => '2010-03-31')); }