ronte-ltd/push-bundle

用于发送推送通知

安装: 5

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2017-09-13 09:31 UTC

This package is not auto-updated.

Last update: 2024-09-24 23:16:10 UTC


README

提供发送推送通知的功能。

功能包括

  • 发送单个通知
  • 后台发送通知
  • 批量发送通知

注意:目前只支持APNS。

安装

Composer

composer require ronte-ltd/push-bundle

初始化

AppKernel.php

new RonteLtd\PushBundle\RonteLtdPushBundle(),

config.yml

ronte_ltd_push:
    push_env: "%push_env%"
    push_sound: true // bool
    push_expiry: 12000 // message expiry, int value in seconds
    bg_worker_id: "%bg_worker_id%"
    gearman_server: "%gearman_server%"
    gearman_port: "%gearman_port%"

parameters.yml

push_env: "valid values: 'prod', 'dev'"
gearman_server: "Add gearman server here"
gearman_port: "Add gearman port here"
bg_worker_id: test //This will be a prefix for a background function in case multiple projects on a server using this command.

证书

Puth APNS sertificates files to 'var/apns' folder

使用

发送单个通知

/**
 * @param string $deviceId - recipient device token
 * @param string $text - text message
 * @param array $payload - payload array
 */
 $payload = [
     'project' => $id,    // int|string name or id of an app, required
     'pushType' => $type, // int type, required
     'badge' => null,     // int|null, optional
     'headers' => [],     // array of headers, optional
     'extra' => [],       // additional info array, optional
 ];

 $credentials = [
     'certificate' => $fullPathToCertificate, // required
     'passPhrase' => $passPhrase,
     'certificationAuthorityFile' => $fullPathToCertificationAuthorityFile,
 ];
$container->get('push.pusher')->send($deviceId, $text, $payload, $creadentials);

### 在后台发送通知 运行 push:worker:run 命令在后台。

$payload = [
     'project' => $id,    // int|string name or id of an app, required
     'pushType' => $type, // int type, required
     'badge' => null,     // int|null, optional
     'headers' => [],     // array of headers, optional
     'extra' => [],       // additional info array, optional
 ];

$credentials = [
  'certificate' => $fullPathToCertificate, // required
  'passPhrase' => $passPhrase,
  'certificationAuthorityFile' => $fullPathToCertificationAuthorityFile,
];

$pusher = $container->get('push.pusher');
$pusher->addPush($deviceId, $text, $payload, , $creadentials);

### 批量发送通知

$payload = [
     'project' => $id,    // int|string name or id of an app, required
     'pushType' => $type, // int type, required
     'badge' => null,     // int|null, optional
     'headers' => [],     // array of headers, optional
     'extra' => [],       // additional info array, optional
 ];
$pusher = $container->get('push.apns');
$pusher->addMessage(
    $pusher->createMessage($deviceId, $text, $payload)
);
// Use addMessage as much as needed

$credentials = [
  'certificate' => $fullPathToCertificate, // required
  'passPhrase' => $passPhrase,
  'certificationAuthorityFile' => $fullPathToCertificationAuthorityFile,
];

$pusher->runQueue($credentials);