opwoco/rms-push-notifications-bundle

此包已被废弃且不再维护。作者建议使用 opwoco/push-notifications-bundle 包。

移动设备的推送通知/消息

安装次数: 6,414

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 5

分支: 156

类型:symfony-bundle

1.1.0 2019-08-15 11:41 UTC

README

允许向移动设备发送推送通知的包。目前支持Android(C2DM、GCM、FCM)、Blackberry和iOS设备。

安装

要在您的Symfony2项目中使用此包,请将以下内容添加到您的 composer.json

{
    "require": {
        // ...
        "opwoco/rms-push-notifications-bundle": "dev-master"
    }
}

并在您的内核中启用它

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new RMS\PushNotificationsBundle\RMSPushNotificationsBundle(),
    );
}

注意:如果您仍在使用Symfony 2.0,请使用 symfony2.0 分支。

配置

可用的配置选项如下。请注意,具体的服务只有在您分别提供配置的情况下才会可用。

rms_push_notifications:
  android:
      timeout: 5 # Seconds to wait for connection timeout, default is 5
      adm:
          client_id: <amazon_device_messaging_client_id>
          client_secret: <amazon_device_messaging_client_secret>
      c2dm:
          username: <string_android_c2dm_username>
          password: <string_android_c2dm_password>
          source: <string_android_c2dm_source>
      gcm:
          api_key: <string_android_gcm_api_key> # This is titled "Server Key" when creating it
          use_multi_curl: <boolean_android_gcm_use_multi_curl> # default is true
          dry_run: <bool_use_gcm_dry_run>
      fcm:
          api_key: <string_android_fcm_api_key> # This is titled "Server Key" when creating it
          use_multi_curl: <boolean_android_fcm_use_multi_curl> # default is true
  ios:
      timeout: 60 # Seconds to wait for connection timeout, default is 60
      sandbox: <bool_use_apns_sandbox>
      pem: <path_apns_certificate> # can be absolute or relative path (from app directory)
      passphrase: <string_apns_certificate_passphrase>
  mac:
      timeout: 60 # Seconds to wait for connection timeout, default is 60
      sandbox: <bool_use_apns_sandbox>
      pem: <path_apns_certificate>
      passphrase: <string_apns_certificate_passphrase>
  blackberry:
      timeout: 5 # Seconds to wait for connection timeout, default is 5
      evaluation: <bool_bb_evaluation_mode>
      app_id: <string_bb_app_id>
      password: <string_bb_password>
  windowsphone:
      timeout: 5 # Seconds to wait for connection timeout, default is 5

注意:如果您使用的是Windows,可能需要将Android GCM/FCM的use_multi_curl标志设置为false,以确保GCM/FCM消息正确发送。

超时默认值是此配置值引入之前的默认值。

用法

以下是一个示例,说明如何将第一条消息推送到iOS设备,我们假设您已正确设置了配置

use RMS\PushNotificationsBundle\Message\iOSMessage;

class PushDemoController extends Controller
{
    public function pushAction()
    {
        $message = new iOSMessage();
        $message->setMessage('Oh my! A push notification!');
        $message->setDeviceIdentifier('test012fasdf482asdfd63f6d7bc6d4293aedd5fb448fe505eb4asdfef8595a7');

        $this->container->get('rms_push_notifications')->send($message);

        return new Response('Push notification send!');
    }
}

发送方法会检测消息类型,如果您传递一个AndroidMessage,它将自动通过C2DM/GCM服务器发送,同样适用于Mac和Blackberry。

Android消息

由于C2DM和GCM都仍然可用,AndroidMessage类上有一个小标志可以切换要发送的服务。使用方法如下

use RMS\PushNotificationsBundle\Message\AndroidMessage;

$message = new AndroidMessage();
$message->setGCM(true);
$message->setFCM(true); // Use to Firebase Cloud Messaging

以FCM消息而不是GCM或C2DM的形式发送。

iOS反馈服务

Apple推送通知服务还公开了一个反馈服务,您可以从中获取有关失败推送通知的信息 - 更多详情请参阅此处

此服务在包中可用。以下代码演示了如何从服务中检索数据

$feedbackService = $container->get("rms_push_notifications.ios.feedback");
$uuids = $feedbackService->getDeviceUUIDs();

在这里,$uuids 包含一个包含时间戳、令牌长度和设备UUID的 Feedback 对象数组。

Apple建议您每天轮询此服务。

Windows Phone - Toast支持

该包对Windows Phone提供beta支持,并支持Toast通知。使用WindowsphoneMessage消息类进行相应发送。

感谢

首先,感谢所有为此包做出贡献的贡献者!

其次,感谢JetBrains为该项目赞助开源PhpStorm许可。