issetbv/push-notification-bundle

1.2.0 2017-04-05 12:52 UTC

This package is not auto-updated.

Last update: 2024-09-14 20:20:16 UTC


README

用于向苹果/安卓/Windows 发送推送通知的Bundle

安装

Composer

composer require issetbv/push-notification-bundle

AppKernel.php

$bundles[] = new IssetBV\PushNotificationBundle\IssetBVPushNotificationBundle();

配置

要发送消息,请向isset_bv_push_notification配置添加连接

isset_bv_push_notification:
    #connection_handler: //overwrite the connection handler for all notifiers which don't have there own connection handler set
    apple:
        #connection_handler: connection handler for this notifier
        connections:
            live:
                key_location: <path_to_key>
                key_password_phrase: <password_phrase>
                default: true
    android:
        connections:
            live:
                api_key: <api-key>
                default: true
    windows:
        connections:
            live:
                default: true
            live_other:
                default: true

参数

默认日志器是 @logger,要更改日志器,请将isset_bv_push_notification.center.logger.service 设置为不同的日志器服务

isset_bv_push_notification.center.logger.service: logger

代码示例

示例苹果消息

<?php
$deviceToken = ''; //devicetoken
$center = $this->get('isset_bv_push_notification.center');
$message = new AppleMessageAps($deviceToken);
$message->getAps()->setAlert('Test apple');
$envelope = $center->queue($message);
$center->flushQueue();
echo $envelope->getState();

示例安卓消息

<?php
$deviceToken = ''; //devicetoken
$center = $this->get('isset_bv_push_notification.center');
$message = new AndroidMessage($deviceToken);
$message->addToPayload('notification', ['title' => 'Test android']);
$envelope = $center->queue($message);
$center->flushQueue();
echo $envelope->getState();

示例Windows消息

<?php
$center = $this->get('isset_bv_push_notification.center');
$message = new WindowsMessage('https://cloud.notify.windows.com/?token=AQE%bU%2fSjZOCvRjjpILow%3d%3d');
$message->addToPayload('wp:Text1', 'Test windows');
$envelope = $center->queue($message);
$center->flushQueue();
echo $envelope->getState();

示例通过非默认连接发送消息

<?php
$center = $this->get('isset_bv_push_notification.center');
$message = new WindowsMessage('https://cloud.notify.windows.com/?token=AQE%bU%2fSjZOCvRjjpILow%3d%3d');
$message->addToPayload('wp:Text1', 'Test windows');
$envelope = $center->queue($message, 'live_other');
$center->flushQueue(); 
// if you only want to flush the live_other queue
// $center->flushQueue('live_other'); 
echo $envelope->getState();