armen9696/phpush

用于发送推送通知的PHP包

v3.0 2018-12-05 09:14 UTC

This package is not auto-updated.

Last update: 2024-09-20 21:17:09 UTC


README

PHPush是一个PHP包,提供了一个简单的API来向外部平台发送推送通知。

目前,我们支持3个平台 - Android、iOS和Google Chrome。

安装

通过执行以下命令在您的composer.json中添加该包

composer require armen9696/phpush

示例

以下示例演示了如何在不同平台上向2个设备发送文本为"Hello, World!"的推送通知。

// Include composer autoloader
require_once 'vendor/autoload.php';

use PHPush\PHPush;

// Setting environment
PHPush::Environment(PHPush::ENVIRONMENT_PRODUCTION);

// Adding Android key
PHPush::Provider(\PHPush\Provider::PROVIDER_ANDROID)->setAccessKey('test');

// Adding iOS certificate
PHPush::Provider(\PHPush\Provider::PROVIDER_IOS)->setCertificate('ck.pem');

// Creating new queue
$queue = PHPush::Queue();

// Adding some devices
$queue->add(new \PHPush\providers\android\Device('android_registration_id'));
$queue->add(new \PHPush\providers\chrome\Device('chrome_registration_id'));
$queue->add(new \PHPush\providers\ios\Device('ios_device_token'));

// Setting message
$queue->message('Hello World!');

// Send message. You can provide custom fields to this method.
// Also you can pass sound and passphrase with this custom fields
$queue->send(array(
    'custom' => 'field',
    'sound' => 'popup.aif',
    'passphase' => 'phpush',
));

// Creating another queue
$another_queue = PHPush::Queue();

// Adding only one device
$another_queue->add(new \PHPush\providers\ios\Device('another_or_the_same_ios_device_token'));

// Setting message
$another_queue->message('Hello World! I\'m second queue!');

// This will not open a connection to APNS server again.
// It will use the old connection
$another_queue->send();