1. Go to this page and download the library: Download ricwein/push-notifications 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/ */
ricwein / push-notifications example snippets
use ricwein\PushNotification\{PushNotification, Message, Handler};
$message = new Message('message', 'title', ['payload' => 'data']);
$fcm = new Handler\FCM('ExampleGooglePushToken12345678987654321');
$push = new PushNotification(['fcm' => $fcm]);
$push->send($message, ['<device-token>' => 'fcm']);
use ricwein\PushNotification\{PushNotification, Message, Handler, Config};
use Pushok\AuthProvider;
$message = new Message('message', 'title', ['payload' => 'data']);
$apns = new Handler\APNS(AuthProvider\Token::create([
'key_id' => 'AAAABBBBCC', // The Key ID obtained from Apple developer account
'team_id' => 'DDDDEEEEFF', // The Team ID obtained from Apple developer account
'app_bundle_id' => 'com.app.Test', // The bundle ID for app obtained from Apple developer account
'private_key_path' => __DIR__ . '/private_key.p8', // Path to private key
'private_key_secret' => null // Private key secret
]), Config::ENV_PRODUCTION);
$push = new PushNotification(['apns' => $apns]);
$push->send($message, ['<device-token>' => 'apns']);
use ricwein\PushNotification\{PushNotification, Message, Handler, Config};
$message = new Message('message', 'title');
$fcm = new Handler\FCM('ExampleGooglePushToken12345678987654321');
$apns = new Handler\APNS($authToken, Config::ENV_PRODUCTION);
$push = new PushNotification(['apns' => $apns, 'fcm' => $fcm]);
$push->send($message, [
'<ios-device-token1>' => 'apns',
'<ios-device-token2>' => 'apns',
'<android-device-token1>' => 'fcm',
'<android-device-token2>' => 'fcm',
]);
use ricwein\PushNotification\{PushNotification, Message, Handler};
$result = (new PushNotification)->send(new Message($body,$title), [
'<device-token>' => new Handler\<APNS/FCM/etc.>(...$config);
]);
use \ricwein\PushNotification\Exceptions\ResponseReasonException;
foreach($result->getFailed() as $token => $error) {
if ($error instanceof ResponseReasonException) {
if ($error->isInvalidDeviceToken()) {
// $token was invalid
} elseif ($error->isRateLimited()) {
// the $token device got too many notifications and is currently rate-limited => better wait some time before sending again.
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.