peal/ios-push-notification

使用 AWS SNS (简单通知系统) 的 iOS 推送通知

dev-master 2018-08-11 07:13 UTC

This package is auto-updated.

Last update: 2024-09-14 19:09:34 UTC


README

使用 AWS SNS 在 Laravel 中实现 iOS 推送通知

亚马逊简单通知服务 (SNS) 是一种灵活的、完全管理的发布/订阅消息和移动通知服务,用于协调将消息传递到订阅的端点和客户端。使用 SNS,您可以将消息分发到大量订阅者,包括分布式系统和移动设备。它易于设置、操作,并可靠地向所有端点发送通知——无论规模大小。您可以通过 AWS 管理控制台、AWS 命令行界面或使用 AWS SDK 仅通过三个简单的 API 在几分钟内开始使用 SNS。SNS 消除了与管理和操作专用消息软件和基础设施相关的复杂性和开销。

安装

在您的项目根目录下,打开终端

composer require peal/ios-push-notification

Composer 将自动下载所有依赖项。

对于 Laravel

安装完成后,打开配置文件夹中的 app.php,在 providers 数组中粘贴以下行

peal\iosnotification\IosServiceProvider::class,

为了支持 Facade,在 aliases 数组中粘贴以下行

'IosPush' => peal\iosnotification\IosPush::class,

然后运行此命令

php artisan vendor:publish --provider="peal\iosnotification\IosServiceProvider"

在 vendor 发布后,检查您的配置文件夹中是否已创建 aws-config.php。

/*
 * AWS config file
 * 
 */

return [
    'SNS_ACCESS_KEY'  => 'YOUR-SNS-ACCESS-KEY',
    'SNS_SECRET_KEY'  => 'YOUR-SNS-SECRET-KEY',
    'SNS_APP_ARN'  => 'YOUR-SNS-APP-APN',
    'pushIos' => peal\iosnotification\IosPush::class,
];

用法

try {
    $ios = \App::make('IosPush');
        $data = [ 
                    'desc' => 'Ios push description',
                    'TargetArn' => "AWS ENPOINT(AFTER INSTALL APP IN YOUR MOBILE AN END POINT NUMBER IS GENERATED)",
                ];


        return $ios->notificationDescription($data['desc'])
                ->awsEndPoint($data['TargetArn'])
                ->customPayLoadData("type", "Ios Push")
                ->customPayLoadData("cityid", "170")
                ->payLoadData()
                ->iosNotifiction();
} catch(\Exception $e) {
    return $e->getMessage();
}

使用 Facade

use IosPush;

try {
    $data = [ 
                'desc' => 'Ios push description',
                'TargetArn' => "AWS ENPOINT(AFTER INSTALL APP IN YOUR MOBILE AN END POINT NUMBER IS GENERATED)",
            ];
                    
        
    return IosPush::notificationDescription($data['desc'])
            ->awsEndPoint($data['TargetArn'])
            ->customPayLoadData("type", "Ios Push")
            ->customPayLoadData("cityid", "170")
            ->payLoadData()
            ->iosNotifiction();
} catch(\Exception $e) {
    return $e->getMessage();
}

对于核心 PHP

    
    use peal\iosnotification\PushHandler\PushHandler;
    use peal\iosnotification\IosPush;
    use Aws\Credentials\Credentials;
    use Aws\Sns\SnsClient;
    try {

    $pios = new PushHandler(new IosPush(
                new SnsClient([
                        'version' => 'latest',
                        'region' => 'us-west-2',
                        'credentials' => new Credentials(
                            config('aws-config.SNS_ACCESS_KEY'), 
                            config('aws-config.SNS_SECRET_KEY')
                        )
                ])
            ));
    $data = [ 
                'desc' => 'Ios push description',
                'TargetArn' => "AWS ENPOINT(AFTER INSTALL APP IN YOUR MOBILE AN END POINT NUMBER IS GENERATED)",
            ];
    return $pios->notificationDescription($data['desc'])
                ->awsEndPoint($data['TargetArn'])
                ->customPayLoadData("type", "Ios Push")
            	->customPayLoadData("cityid", "170")
            	->payLoadData()
                ->iosNotifiction();
} catch(\Exception $e) {
    return $e->getMessage();
}

更多教程请参考

AWS sns

作者

穆罕默德·米努丁(Peal)