PHP code example of onsetsoftware / sns-push
1. Go to this page and download the library: Download onsetsoftware/sns-push library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
onsetsoftware / sns-push example snippets
use SNSPush\SNSPush;
$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' => [ // application endpoints - Required
'ios' => '<application-endpoint-arn>',
'android' => '<application-endpoint-arn>'
]
]);
[
//...
'providers' => [
/*
* Package Service Providers...
*/
SNSPush\SNSPushServiceProvider::class,
]
];
[
//...
'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>'
]
]
];
/**
* @param string $token the raw device token
* @param string $platform ( ios | android )
*
* @return ARN the ARN endpoint for the device
*/
$sns->addDevice('<device-token>', '<platform-id>');
$sns->removeDevice('<endpoint-arn>');
/**
* @return SubscriptionARN
*/
$sns->subscribeDeviceToTopic('<device-endpoint-arn>', '<topic-arn>');
$sns->removeDeviceFromTopic('<subscription-arn>');
use SNSPush\Messages\IOsMessage;
$message = new IOsMessage();
$message->setTitle('Message Title')
->setBody('Message body')
->setBadge(5)
->setSound('sound.caf')
->setPayload(
[
'custom-key' => 'value',
]
);
PhoneGapPluginPushIOSMessage::class;
PhoneGapPluginPushAndroidMessage::class;
$sns->sendPushNotificationToDevice(
'<endpoint-arn>',
$message
);
$iosMessage = new IOsMessage();
$androidMessage = new AndroidMessage();
$message = new TopicMessage([$iosMessage, $androidMessage]);
/**
* @param TopicARN $arm
* @param TopicMessage $message
*/
$sns->send->sendPushNotificationToTopic(
'<topic-arn>',
$message
);