Coder Social home page Coder Social logo

apns2's Introduction

apns2

Simple & expressive PHP HTTP2 API for Apple Push Notification service (APNs) with comprehensive docs/constants.

Guidance

  1. Make Sure CURL Supports HTTP/2 (for php version < 5.5.24, check here)
  2. Creating a Universal Push Notification Client SSL Certificate (.p12)
  3. Converting .p12 to .pem

openssl pkcs12 -in cert.p12 -out cert.pem -nodes -clcerts

  1. Go

composer require dashi/apns2

Usage

using classes

$connection = new Dashi\Apns2\Connection();
$connection->sandbox = false;
$connection->certPath = '/path/to/http2/cert.pem';

$aps = new Dashi\Apns2\MessageAPSBody();
$aps->alert = 'test 1';
$aps->sound = 'default';

$message = new Dashi\Apns2\Message();
$message->aps = $aps;

$options = new Dashi\Apns2\Options();
$options->apnsTopic = 'your.bundle.id';

$responses = $connection->send([
    '81fbf7e296f6c94755832a48476182e4e9586a380116e18a46531b62349504f0',
    'e2d0b464813b6b2371d745dff2b1e5fb6b83b07f7dcd98cc9f1346a7752dcc45',
], $message, $options);
$connection->close();
var_dump($responses);

using arrays

$connection = new \Dashi\Apns2\Connection(['sandbox' => true, 'cert-path' => '/path/to/http2/cert.pem']);

$responses = $connection->send([
    '81fbf7e296f6c94755832a48476182e4e9586a380116e18a46531b62349504f1' // invalid
], [
    'aps' => [
        'alert' => 'test 2',
        'sound' => 'default',
    ]
], [
    'apns-topic' => 'your.bundle.id',
]);
$connection->close();

check response data

echo "check response: {$responses[0]->apnsId} == ${uuid}\n";
assert($responses[0]->apnsId == $uuid);

$reason = \Dashi\Apns2\Response::REASON_BAD_DEVICE_TOKEN;
echo "check response: {$responses[0]->reason} == ${reason}\n";
assert($responses[0]->reason == $reason);

License

MIT

apns2's People

Contributors

huxia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

apns2's Issues

Compatibility of ::class is only with php 5.5

Hi,
You may want to change your compatibility level to 5.5 or fix it for 5.3 because of static::class feature you are using in Message.php. I would really like fixing it to 5.3 if you can though.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.