dev-master
9999999-dev https://github.com/ReduGroup/sns-pushAPI Wrapper for Amazon SNS PHP SDK
MIT
The Requires
by Jonathon Henderson
by Michael Forcer
api amazon aws sns
API Wrapper for Amazon SNS PHP SDK
This package provides a bunch of helper methods to aid interacting with the Amazon (AWS) SNS API., (*1)
SNS Push is a simple SNS SDK wrapper with a collection of methods to aid in interacting with the AWS SNS API. It works directly with Laravel or can be used as a standalone PHP package., (*3)
Supports | Version |
---|---|
PHP | 7.0 |
Platforms | ios/android |
You need to use Composer to install SNS Push into your project:, (*4)
composer require redu/sns-push
Now you have to include SNSPushServiceProvider
in your config/app.php
:, (*5)
'providers' => [ /* * Package Service Providers... */ SNSPush\SNSPushServiceProvider::class, ]
Add 'sns' config keys to the config/services.php
, (*6)
'sns' => [ 'account_id' => env('SNS_ACCOUNT_ID', ''), 'access_key' => env('SNS_ACCESS_KEY', ''), 'secret_key' => env('SNS_SECRET_KEY', ''), 'scheme' => env('SNS_SCHEME', 'https'), 'region' => env('SNS_REGION', 'eu-west-1'), 'platform_applications' => [ 'ios' => '<application-endpoint-arn>', 'android' => '<application-endpoint-arn>' ] ],
You should include the Composer autoload.php
file if not already loaded:, (*7)
require __DIR__ . '/vendor/autoload.php'; ``` Instantiate the SNSPush class with the following required config values: - account_id - access_key - secret_key - platform_applications Also configurable: - region [default: eu-west-1] - api_version [default: 2010-03-31] - scheme [default: https] ```php $sns = new SNSPush([ 'account_id' => '<aws-account-id>', // Required 'access_key' => '<aws-iam-user-access-key>', // Required 'secret_key' => '<aws-iam-user-secret-key>', // Required 'scheme' => 'http', // Defaults to https 'platform_applications' => [ // Required 'ios' => '...', 'android' => '...' ] ]);
Add a device to a platform application (ios/android) by passing the device token and application key to addDevice()
., (*8)
$sns->addDevice('<device-token>, 'ios');
Remove a device from AWS SNS by passing the Endpoint ARN to removeDevice()
., (*9)
$sns->removeDevice('<endpoint-arn>');
Subscribe a device to a Topic by passing the Endpoint Arn and Topic Arn to subscribeDeviceToTopic()
., (*10)
$sns->subscribeDeviceToTopic('<endpoint-arn>', '<topic-arn>');
Remove a device from a Topic by passing the Subscription Arn to removeDeviceFromTopic()
., (*11)
$sns->removeDeviceFromTopic('<subscription-arn>');
SNS Push supports sending notifications to both Topic Endpoint or directly to an Endpoint ARN (Device)., (*12)
$message = 'Push notification message.'; $sns->sendPushNotificationToDevice( '<endpoint-arn>', $message );
You can also optionally send a custom payload along with the message., (*13)
$sns->sendPushNotificationToDevice('<endpoint-arn>', $message, [ 'payload' => [ 'id' => 9 ] ]);
The message structure is sent as JSON and will be properly formatted per device. This is a requirement if sending to multiple platforms and/or sending a custom payload., (*14)
If you are only sending a simple message to a single platform and would like to save on bytes you can set the message structure to a string., (*15)
$sns->sendPushNotificationToDevice('<endpoint-arn>', $message, [ 'message_structure' => 'string' ]);
$message = 'Push notification message.'; $sns->send->sendPushNotificationToTopic( '<topic-arn>', $message );
Similarly, you can set the message structure and payload., (*16)
MIT License © Redu Group Ltd, (*17)
API Wrapper for Amazon SNS PHP SDK
MIT
api amazon aws sns