PHP code example of jwage / php-apns

1. Go to this page and download the library: Download jwage/php-apns 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/ */

    

jwage / php-apns example snippets


use JWage\APNS\Certificate;
use JWage\APNS\Safari\PackageGenerator;

$certificate = new Certificate(file_get_contents('apns.p12'), 'certpassword');
$packageGenerator = new PackageGenerator(
    $certificate, '/base/pushPackage/path', 'yourdomain.com'
);

// returns JWage\APNS\Safari\Package instance
$package = $packageGenerator->createPushPackageForUser('userid');

// send zip file to the browser
echo $package->getZipPath();

use JWage\APNS\Certificate;
use JWage\APNS\Client;
use JWage\APNS\Sender;
use JWage\APNS\SocketClient;

$certificate = new Certificate(file_get_contents('apns.pem'));
$socketClient = new SocketClient($certificate, 'gateway.push.apple.com', 2195);
$client = new Client($socketClient);
$sender = new Sender($client);

$sender->send('devicetoken', 'Title of push', 'Body of push', 'http://deeplink.com');