定制 mcfedr/awspushbundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

mcfedr/awspushbundle

Composer 安装命令:

composer require mcfedr/awspushbundle

包简介

A set of services to simplify using Aws to send push notifications

README 文档

README

A convenient bundle for registering devices and then pushing to them using amazons SNS service.

Latest Stable Version License Build Status

Install

Composer

php composer.phar require mcfedr/awspushbundle

AppKernel

Include the bundle in your AppKernel

public function registerBundles()
{
    $bundles = array(
        ...
        new Mcfedr\AwsPushBundle\McfedrAwsPushBundle()

Config

Put something like this in your config. The arns in the platforms section should be the preconfigured app arns in SNS.

mcfedr_aws_push:
    platforms:
        ios: 'arn:aws:sns:....'
        android: 'arn:aws:sns:....'
    topic_arn: 'arn:aws:sns:...'
    pushPlatforms: [apns, fcm]
    aws:
        credentials: 
            key: 'my key'
            secret: 'my secret'
        region: 'my region'

You can skip credentials if you have want the Aws SDK to get credentials indirectly, either from environment or ec2 role.

If you don't set the pushPlatforms setting then android messages will sent in a format compatible with GCM, i.e. the notification field will not be set. This is for backwards compatibility of this bundle.

Usage

Basically have a look at how the ApiController does its stuff

  1. Register the device token

     $arn = $this->get('mcfedr_aws_push.devices')->registerDevice($token, $platform)
    
  2. Send message to one device

     $this->get('mcfedr_aws_push.messages')->send($message, $arn)
    
  3. Send message to all devices

     $this->get('mcfedr_aws_push.messages')->broadcast($message)
    

Alternative usage, using topics to send messages to lots of devices

  1. Register the device token

     $arn = $this->get('mcfedr_aws_push.devices')->registerDevice($token, $platform)
    
  2. Register the device on the topic

     $this->get('mcfedr_aws_push.topics')->registerDeviceOnTopic($arn, $topicArn)
    
  3. Send messages

     $this->get('mcfedr_aws_push.topics')->broadcast($message, $topicArn)
    

If you later add a topic_name to the configuration you can run the mcfedr:aws:subscribe command to add your existing devices to the topic.

Text in notifications

For GCM and ADM there is no 'standard' key for text data as there is for Apple pushes, so this bundle send text in a key called message.

If localized text is sent the keys are

  • message-loc-key
  • message-loc-args

'Complicated' data on ADM

ADM only allows strings as values in the push data. This bundle lets you send 'complicated' values and will automatically json encode these values for ADM. When it does this the key has _json added so that its easy to handle this on the app side.

Example

Sending:

$message = new Message();
$message->setCustom(['simple' => 'Hello', 'complicated' => ['inner' => 'value']]);

ADM received data:

{"data": {"simple": "Hello", "complicated_json": "{\"inner\":\"value\"}"}}

To handle this data you should detect keys that end with _json and decode the values

The applies to message-loc-args as well, they will always come as message-loc-args_json via ADM

Commands

There are some commands to help manage the devices

  1. mcfedr:aws:enable

    This will reenable all the devices

  2. mcfedr:aws:remove

    This will remove any disabled devices. Its a good idea to do something like this regularly to remove old devices

  3. mcfedr:aws:subscribe

    This will subscribe all devices to a topic, useful when introducing a topic

Api Controller

Optional.

There is a controller included which makes basic usage of the bundle very easy. You may or may not want to use it, you might find it most useful as an example.

There are some extra dependencies you must add when using the controller

  • sensio/framework-extra-bundle
  • symfony/validator
  • symfony/serializer
  • symfony/property-info
  • symfony/security-bundle
  • symfony/expression-language

They also need enabling in the framework config

framework:
    validation: { enable_annotations: true }
    serializer:
        enabled: true
    property_info:
        enabled: true

Add the routes in your routing.yaml:

mcfedr_aws_push:
    resource: "@McfedrAwsPushBundle/Controller/"
    type:     annotation
    prefix:   /

Usage

The controller provides two urls, both expect a JSON POST body

  1. The first is a way to register a device

     POST /devices
     {
         "device": {
             "deviceId": "a push token",
             "platform": "the platform name in your config file"
         }
     }
    
  2. The second is a way to send a broadcast message. If you are using a topic for all devices then don't send the platform parameter.

     POST /broadcast
     {
         "broadcast": {
             "platform": "ios"
             "message": {
                 "text": "The plain text message to send",
                 "badge": 1
             }
         }
     }
    

More info

mcfedr/awspushbundle 适用场景与选型建议

mcfedr/awspushbundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 384.69k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2013 年 12 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「amazon」 「bundle」 「notification」 「aws」 「push」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 mcfedr/awspushbundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mcfedr/awspushbundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 mcfedr/awspushbundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 384.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 40
  • 点击次数: 40
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 40
  • Watchers: 4
  • Forks: 24
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-12-11