amorvan/aws-sns-push-bundle

一个用于配置和发送AWS SNS推送通知的包

v0.2.1 2019-10-04 22:54 UTC

This package is auto-updated.

Last update: 2024-09-05 09:29:12 UTC


README

本包的目的是使用AWS Sns服务管理移动推送通知。包提供了以下服务

  • 将设备订阅到广播主题
  • 创建临时主题
  • 将设备订阅到特定临时主题
  • 从广播或特定主题中取消设备订阅
  • 发送带有自定义消息和额外参数的移动推送通知

先决条件

此包需要Symfony 3.4+或4.3+。

安装

步骤1 - 下载包

composer require amorvan/aws-sns-push-bundle

步骤2 - 启用包(Amorvan/AWSSnsPushBundle和AWS SDK)

Symfony 3版本

将包注册到app/AppKernel.php

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Aws\Symfony\AwsBundle(),
            new Amorvan\AwsSnsPushBundle\AmorvanAwsSnsPushBundle(),
        );
    }

    // ...
}

Symfony 4版本

将包注册到config/bundles.php

return [
    //...
    Aws\Symfony\AwsBundle::class => ['all' => true],
    Amorvan\AwsSnsPushBundle\AmorvanAwsSnsPushBundle::class => ['all' => true],
];

步骤3 - 创建实体DeviceLogHistoricPush

//Device entity
<?php

namespace YOUR_NAME_SPACE_ENTITY;

use Amorvan\AwsSnsPushBundle\Model\AbstractDeviceModel;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * Class Device
 *
 * @ORM\Table(name="YOUR_TABLE_NAME")
 * @ORM\Entity()
 */
class Device extends AbstractDeviceModel
{
    /**
     * @var string
     *
     * @ORM\Column(type="string")
     * @ORM\Id()
     */
    protected $id;

    /**
     * @var DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $createdAt;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $deviceType;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $deviceId;

    /**
     * @var UserInterface|null
     *
     * @ORM\ManyToOne(targetEntity="FQCN_ENTITY_USER")
     * @ORM\JoinColumn(name="FK_NAME", referencedColumnName="id", nullable=true)
     */
    protected $user;
}
//LogHistoricPush entity
<?php

namespace YOUR_NAME_SPACE_ENTITY;

use Amorvan\AwsSnsPushBundle\Model\AbstractLogHistoricPush;
use DateTime;
use Doctrine\ORM\Mapping as ORM;

/**
 * Class LogHistoricPush
 *
 * @ORM\Table(name="amo_log_historic_push")
 * @ORM\Entity()
 */
class LogHistoricPush extends AbstractLogHistoricPush
{
    /**
     * @var string
     *
     * @ORM\Column(type="string")
     * @ORM\Id()
     */
    protected $id;

    /**
     * @var DateTime
     *
     * @ORM\Column(type="datetime")
     */
    protected $createdAt;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $type;

    /**
     * @var string
     *
     * @ORM\Column(type="text")
     */
    protected $message;

    /**
     * @var int
     *
     * @ORM\Column(type="integer")
     */
    protected $pushsNumber;

    /**
     * @var string
     *
     * @ORM\Column(type="string")
     */
    protected $topicArn;
}

步骤4 - 更新数据库模式

使用Doctrine模式更新

bin/console doctrine:schema:update --force

使用Migrations Doctrine

bin/console doctrine:migrations:diff

bin/console doctrine:migrations:migrate

步骤5 - 配置包