navvygator/pusher

PHP 推送通知到 APNS,由 mxp100/pusher 分支,由 Yuriy Potemkin 维护

1.1 2017-11-18 20:49 UTC

This package is not auto-updated.

Last update: 2024-09-21 15:21:42 UTC


README

兼容性:PHP 7+

安装

Composer

composer require mxp100/pusher

APNS 证书生成

请参阅Wiki: https://github.com/mxp100/Pusher/wiki/Generating-the-Apple-Push-Notification-SSL-certificate-on-Mac

示例

FCM 示例

$serverKey = '[server key]';
$deviceId = '[device token]';

$devices = new DeviceCollection([new Device($deviceId)]);
$message = new Message('This is a test message');

$adapter = new Fcm($serverKey);

$pusher = new Pusher([new Push($adapter, $devices, $message)]);
$pusher->push();

GCM 示例

$serverKey = '[path to certification]';
$deviceId = '[device token]';

$devices = new DeviceCollection([new Device($deviceId)]);
$message = new Message('This is a test message');

$adapter = new Gcm($serverKey, AdapterInterface::ENVIRONMENT_DEVELOPMENT);

$pusher = new Pusher([new Push($adapter, $devices, $message)]);
$pusher->push();

APNS 示例

$serverKey = '[path to certification]';
$deviceId = '[device token]';

$devices = new DeviceCollection([new Device($deviceId)]);
$message = new Message('This is a test message');

$adapter = new Apns($serverKey, AdapterInterface::ENVIRONMENT_DEVELOPMENT);

$pusher = new Pusher([new Push($adapter, $devices, $message)]);
$pusher->push();