b3da/pusher-bundle

适用于Android和iOS推送通知的Symfony扩展包

安装次数: 642

依赖项: 0

建议者: 0

安全性: 0

星标: 2

关注者: 2

分支: 1

公开问题: 2

类型:symfony-bundle

1.0.0 2018-07-20 18:52 UTC

This package is not auto-updated.

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


README

b3da\PusherBundle

适用于Android和iOS推送通知的Symfony扩展包

安装

  • 将包添加到您的项目中
$ composer require b3da/pusher-bundle "dev-master"
  • 将扩展包添加到 AppKernel
new b3da\PusherBundle\b3daPusherBundle(),
  • config.yml 中添加所需服务的配置
b3da_pusher:
    fcm:  # Firebase Cloud Messaging
        server_key: 'foobarbaz'
    gcm:  # Google Cloud Messaging (deprecated)
        server_key: 'foobarbaz'
    apn:  # Apple Push Notification Service
        passphrase: 'foobarbaz'
        cert_path: 'cert.pem'  # relative to app root dir
  • 可选 - 在 routing.yml 中导入路由,并访问 /pusher/api/doc/ 以获取更多信息
b3da_pusher:
    resource: "@b3daPusherBundle/Controller/"
    type:     annotation
    prefix:   "/pusher/"

使用方法

  • Android - Firebase Cloud Messaging
$msgSound = 'default';  # optional - can be 'default', 'none', or notification sound name
$msgNotoficationId = 1;  # optional - increment for display multiple notification simultaneously
$fcm = $this->get('b3da_pusher.android.fcm');
$message = new b3da\PusherBundle\Model\Message('title', 'message body', $msgSound, $msgNotificationId);
$fcm->notify($recipient, $message->composeAndroidFcmMessage());
# result:
dump($fcm->getOutputAsObject());
  • Android - Google Cloud Messaging (已弃用)
$msgSound = 'default';  # optional - can be 'default', 'none', or notification sound name
$msgNotoficationId = 1;  # optional - increment for display multiple notification simultaneously
$gcm = $this->get('b3da_pusher.android.gcm');
$message = new b3da\PusherBundle\Model\Message('title', 'message body', $msgSound, $msgNotificationId);
$gcm->notify($recipient, $message->composeAndroidGcmMessage());
# result:
dump($gcm->getOutputAsObject());
  • IOS - Apple Push Notification Service
$msgSound = 'default';  # optional - can be 'default', 'none', or notification sound name
$gcm = $this->get('b3da_pusher.ios.apn');
$message = new b3da\PusherBundle\Model\Message('title', 'message body', $msgSound);
$apn->notify($recipient, $message->composeIosMessage());
# result:
dump($apn->getOutputAsObject());

使用默认值的全配置

b3da_pusher:
    fcm:
        server_url: 'https://fcm.googleapis.com/fcm/send'
        server_key: null   # must be defined to use FCM
        proxy: null
    gcm:
        server_url: 'https://android.googleapis.com/gcm/send'
        server_key: null   # must be defined to use GCM
        proxy: null
    apn:
        server_url: 'ssl://gateway.sandbox.push.apple.com:2195'
        passphrase: null   # must be defined to use APN
        cert_path: 'cert.pem'   # must be defined to use APN