oxenti/cake_gcm 问题修复 & 功能扩展

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

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

oxenti/cake_gcm

Composer 安装命令:

composer require oxenti/cake_gcm

包简介

CakeGCM is a plugin for CakePHP to send notification to an Android device through Google Cloud Messaging. This project is a fork from ker0x's repo.

README 文档

README

CakeGCM is a plugin for CakePHP to send downstream message to an Android or iOS device through Google Cloud Messaging

Scrutinizer Total Downloads License

Requirements

  • CakePHP >= 3.*
  • PHP >= 5.4

Installation

Run : composer require oxenti/cake_gcm:dev-cake3 Or add it in your composer.json:

"require": {
    "oxenti/cake_gcm": "dev-cake3"
},

Enable plugin

In config/bootstrap.php file add :

Plugin::load('CakeGcm', ['autoload' => true]);

or uncomment :

Plugin::loadAll();

Usage

In src/Controller/AppController.php file, add :

$this->loadComponent('CakeGcm.Gcm', [
    'api' => [
        'key' => '*****'
    ]
]);

in your Controller's initialize() method. Replace ***** by your API Key.

To get an API key, follow the instructions in this link: http://developer.android.com/google/gcm/gs.html#access-key

Then, in an action of your Controller, add the following code:

if ($this->Gcm->send($ids, $data, $parameters)) {
    // do some stuff
} else {
    // do other stuff
}

where:

  • $ids is a string or an array of device ids. (required)
  • $payload is an array containing the notification and/or some datas that will be passed to a device. (optional)
  • $paramaters is an array of parameters for the notification. (optional)

You could have the response of the request by using the function response():

$response = $this->Gcm->response();

Examples

Send an empty notification to a device:

$this->Gcm->send('1');

Send a notification to a device:

$this->Gcm->send('1', [
    'notification' => [
        'title' => 'Hello World',
        'body' => 'My awesome Hellow World!'
    ]
]);

or

$this->Gcm->sendNotification('1', [
    'title' => 'Hello World',
    'body' => 'My awesome Hellow World!'
]);

Send a notification to multiple devices:

$this->Gcm->send(
    ['1', '2', '3', '4'],
    [
        'notification' => [
            'title' => 'Hello World',
            'body' => 'My awesome Hellow World!'
        ]
    ]
);

or

$this->Gcm->sendNotification(
    ['1', '2', '3', '4'],
    [
        'title' => 'Hello World',
        'body' => 'My awesome Hellow World!'
    ]
);

Send a notification with lots of data

$this->Gcm->send(
    ['1', '2', '3', '4'],
    [
        'data-1' => 'Lorem ipsum',
        'data-2' => 1234,
        'data-3' => true
    ]
);

Send datas to a device:

$this->Gcm->send(
    ['1', '2', '3', '4'],
    [
        'data' => [
            'data-1' => 'Lorem ipsum',
            'data-2' => '1234',
            'data-3' => 'true'
        ]
    ]
);

or

$this->Gcm->sendData(
    ['1', '2', '3', '4'],
    [
        'data-1' => 'Lorem ipsum',
        'data-2' => 1234,
        'data-3' => true
    ]
);

Send a notification and some datas to a device at the same time:

$this->Gcm->send(
    ['1', '2', '3', '4'],
    [
        'notification' => [
            'title' => 'Hello World',
            'body' => 'My awesome Hellow World!'
        ],
        'data' => [
            'data-1' => 'Lorem ipsum',
            'data-2' => 1234,
            'data-3' => true
        ]
    ]
);

Send a notification with extra parameters:

$this->Gcm->sendNotification(
    ['1', '2', '3', '4'],
    [
        'notification' => [
            'title' => 'Hello World',
            'body' => 'My awesome Hello World!'
        ]
    ],
    [
        'delay_while_idle' => true,
        'dry_run' => false,
        'time_to_live' => 86400,
        'collapse_key' => 'Gcm',
        'restricted_package_name' => 'my_awesome_package'
    ]
);

License

The MIT License (MIT)

Copyright (c) 2015 Romain Monteil

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固