irice/yii2-fcm-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

irice/yii2-fcm-manager

Composer 安装命令:

composer require irice/yii2-fcm-manager

包简介

FCM Notification manager for Yii2

README 文档

README

Installation

Composer Install

composer require irice/yii2-fcm-manager

Database Migration

cofnig/console.php

return [
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => null,
            'migrationNamespaces' => [
                'fcm\manager\migrations',
                ...
            ],
        ],
    ],
    ...
];

And run migrate command

php yii migrate

Configuration

config/web.php

return [
    'modules' => [
        'fcm' => [
            'class' => 'fcm\manager\Module',
            ...
        ],
        ...
    ],
    ...
    'components' => [
        'fcm' => [
            'class' => 'fcm\manager\components\Connection',
            // you can download config file on firebase console 'https://console.firebase.google.com/u/1/project/<your_project>/settings/serviceaccounts/adminsdk'
            'configPath' => __DIR__ . '/<your_project>-firebase-adminsdk.json',
        ],
        ...
    ],
    ...
];

Basic Usage

Register device to database

$result = Yii::$app->fcm->deviceRegisterClass::registerDevice(
    '<registed_device_token>', // or ['<registed_device_token1>', '<registed_device_token2>']
    <user_id> // user identity id
);

Subscribe device to Topic

$result = Yii::$app->fcm->subscribeToTopic(
    '<topic-name>',
    '<registed_device_token>' // or ['<registed_device_token1>', '<registed_device_token2>']
);

Unsubscribe device from Topic

$result = Yii::$app->fcm->unSubscribeFromTopic(
    '<topic-name>',
    '<registed_device_token>' // or ['<registed_device_token1>', '<registed_device_token2>']
);

Send message to Topic

$result = Yii::$app->fcm->sendToTopic(
    '<topic-name>',
    '<message title>',
    '<message content>',
    '<message image url>' // optional
);

Send message to Device

$result = Yii::$app->fcm->sendToTokens(
    '<registed_device_token>' // or ['<registed_device_token1>', '<registed_device_token2>']
    '<message title>',
    '<message content>',
    '<message image url>' // optional
);

Schedule Send Message

The feature implement by Yii2-queue extension.

config/console.php (config/web.php)

'components' => [
    'queue' => [
        'class' => 'yii\queue\db\Queue',
        'serializer' => 'fcm\manager\components\PhpSerializer',
        'deleteReleased' => false,
        'as log' => 'yii\queue\LogBehavior',
    ],
    'mutex' => [
        'class' => 'yii\mutex\PgsqlMutex',
    ],
    'fcm' => [
        'class' => 'fcm\manager\components\Connection',
        'configPath' => __DIR__ . '/<your_project>-firebase-adminsdk.json',
    ],
    ...
]

Schedule a message to Topic

$job = new \fcm\manager\jobs\SendJob([
    'notification' => [
        'title' => '<message-title>',
        'body' => '<message-body>',
        'target' => [
            'type' => \fcm\manager\jobs\SendJob::TYPE_TOPIC,
            'value' => '<topic-name>',
        ],
    ],
]);

$delayTime = strtotime('2019-12-31 00:00:00') - time(); //Send message on specified time.
//$delayTime = strtotime('next Saturday') - time(); //Send message on next weekend.
//$delayTime = 60 * 60 * 24; //Send message after 24 hours.

$queueId = Yii::$app->queue->delay($delayTime)->push($job);

Auto update fcm progress after send

Implement NotificationInterface on custom class

class Notification extends \yii\db\ActiveRecord implements \fcm\manager\models\NotificationInterface
{
    ... 
    public function getSuccessStatus()
    {
        return static::STATUS['SENDED'];
    }

    public function getFailStatus()
    {
        return static::STATUS['FAILED'];
    }

    public function updateStatus($value)
    {
        $this->status = $value;
        return $this->save();
    }
}

TODO

Notification GUI Manager

Requirements

Yii2-queue

统计信息

  • 总下载量: 309
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固