定制 stevetauber/php-gcm-queue 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

stevetauber/php-gcm-queue

最新稳定版本:1.0.2

Composer 安装命令:

composer require stevetauber/php-gcm-queue

包简介

PHP Google Cloud Messaging (GCM) Queue Library

README 文档

README

A PHP library for sending messages to devices registered through Google Cloud Messaging.

Requirements:

  • PHP >=5.6
  • Redis database

Libraries used:

  • chrisboulton/php-resque 1.2.x (MIT)
  • php-curl-class/php-curl-class 2.1.x (No License)

See: http://developer.android.com/guide/google/gcm/index.html

Example usage

<?php
use \PhpGcmQueue as GCM;

class YourClass {

    public function someFunction() {
        /* The second param is our class that extends DefaultSendJob.php */
        GCM\Client::configure("YOUR GOOGLE API KEY", 'MyQueueJob');

        $message = GCM\Message::fromArray(array(
            'registration_ids' => array('device_registration_id1', 'device_registration_id2'),
            'data' => array('data1' => 123, 'data2' => 'string'),
        ));

        /* This can all be set in the original fromArray call. */
        $message
            ->setCollapseKey('collapse_key')
            ->setDelayWhileIdle(true)
            ->setTimeToLive(123)
            ->setRestrictedPackageName("com.example.trololo")
            ->setDryRun(true);
        
        /* Enqueues the message. php-resque will process via a worker. */
        GCM\Client::send($message);
    }

}

MyQueueJob.php

<?php
class MyQueueJob extends \PhpGcmQueue\DefaultSendJob {

    /* See DefaultSendJob for all the possible statuses */
    public function tearDown() {
        if($this->response) {
            $failed = $this->response->getFailedIds();
            if(!empty($failed['InvalidRegistration'])) {
                foreach($failed['InvalidRegistration'] as $f) {
                    //remove from DB records
                }
            }
            if(!empty($failed['NotRegistered'])) {
                foreach($failed['NotRegistered'] as $f) {
                    //remove from DB records
                }
            }

            $newIds = $this->response->getNewRegistrationIds();
            if(!empty($newIds)) {
                foreach($newIds as $n) {
                    //Update DB records
                }
            }
        }
    }
}

job_app_include.php

<?php
require_once "vendor/autoload.php"
require_once "MyQueueJob.php"

Command line:

$ QUEUE=gcmDefault LOGGING=2 APP_INCLUDE=job_app_include.php php vendor/chrisboulton/php-resque/resque.php

ChangeLog

  • v0.1 - Initial release
  • v1 - Upgraded to support all new commands, iOS, php 5.6 required

Licensed under MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固