PHP code example of dashi / apns2
1. Go to this page and download the library: Download dashi/apns2 library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dashi / apns2 example snippets
$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);
$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();
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);