davibr/apn-push

apn-push 的分支

v3.0.0 2016-12-26 14:37 UTC

README

SensioLabsInsight Scrutinizer Code Quality Build Status

向苹果设备(iPhone、iPad、iPod)发送推送通知。

要求

现在库只支持 HTTP/2 协议,以下库是必需的

  • cURL
  • 协议 HTTP/2 必须在 cURL 中受支持。

安装

在您的 composer.json 中添加 AppleApnPush

{
    "require": {
        "apple/apn-push": "~3.0.0"
    }
}

现在运行以下命令让 composer 下载库

$ php composer.phar update apple/apn-push

简单使用

您可以使用构建器创建发送者以发送推送通知到设备

<?php

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Protocol\Http\Authenticator\CertificateAuthenticator;
use Apple\ApnPush\Sender\Builder\Http20Builder;
use Apple\ApnPush\Model\Alert;
use Apple\ApnPush\Model\Aps;
use Apple\ApnPush\Model\Payload;
use Apple\ApnPush\Model\Notification;
use Apple\ApnPush\Model\DeviceToken;
use Apple\ApnPush\Model\Receiver;
use Apple\ApnPush\Exception\SendNotification\SendNotificationException;

// Create certificate and authenticator
$certificate = new Certificate(__DIR__.'/cert.pem', '');
$authenticator = new CertificateAuthenticator($certificate);

// Build sender
$builder = new Http20Builder($authenticator);
$builder->addDefaultVisitors();

$sender = $builder->build();

// Create payload
$alert = new Alert('hello ;)');
$aps = new Aps($alert);
$payload = new Payload($aps);

// Create notification
$notification = new Notification($payload);

$receiver = new Receiver(
    new DeviceToken('6b4d687c1292f1ff05b5653951be4e5f838ce6d39d6b1be1801fe8dcc35713c9'),
    'you.app.id'
);

try {
    $sender->send($receiver, $notification);
} catch (SendNotificationException $e) {
    print 'Fail send message: '.$e->getMessage()."\n";
}

许可证

此库采用 MIT 许可证。请参阅库中的完整许可证。

LICENSE

报告问题或功能请求

问题和功能请求在 Github 问题跟踪器 中跟踪。

贡献者

感谢 [所有参与者] (https://github.com/ZhukV/AppleApnPush/graphs/contributors) 为 AppleApnPush 库的开发做出贡献!