infi-nl/push-notifier

此包已被废弃且不再维护。未建议替代包。

从PHP向多种设备类型发送推送通知

v1.0-beta.1 2015-07-15 09:39 UTC

This package is not auto-updated.

Last update: 2021-04-02 23:08:51 UTC


README

PHP库,用于向多种设备类型发送推送通知。

Apple Push Notification 示例

准备 PushNotifier 以发送 Apple Push Notifications。请注意,您可以提供自己的 Pusher-strategies,例如发送 Android 和 Windows Phone 的通知。

$pushNotifier = new PushNotifier(
  new PusherStrategyCollection(array(
      new ApnPusher(
          'ssl://gateway.sandbox.push.apple.com:2195',
          '<path-to-pem-file>'
      )
  ))
);

发送 Apple Push Notification

$message              = new ApnMessage();
$message->body        = "<my message>";
$message->badge       = 0;
$message->deviceToken = "<device token>";

$pushNotifier->push($message);

Google Cloud Messaging 示例

准备 PushNotifier 以发送 Google Cloud Messages。

$pushNotifier = new PushNotifier(
  new PusherStrategyCollection(array(
      new GcmPusher(
        'https://android.googleapis.com/gcm/send',
        '<api-key>'
      )
  ))
);

发送 Google Cloud Message

$message                  = new GcmMessage();
$message->message         = "<my message>";
$message->title           = "<my title>";
$message->registrationIds = array("<registrationId 1>", "<registrationId 2>", ... , "<registrationId n>");

$pushNotifier->push($message);