20/07
2017
Wallogit.com
2017 © Pedro Peláez
PHP Library Client Firebase Cloud Messaging
Install dulu dari composer:, (*1)
>$ composer require amrikasir/firebasecmclient
baru deh di PHPnya., (*2)
<?php require_once __DIR__ . '/vendor/autoload.php'; use ald\FirebaseCM; use ald\Push;
SET Push Parameter, (*3)
$push = new Push(
"ALD Push Notification", //Title
"dari: " . $_SERVER['HTTP_HOST'] //Message
);
SET Server Key, (*4)
$notification = new FirebaseCM(
//this is key from server Firebase Cloud Messaging Console
//and this is new Server key
"SERVER_KEY_FROM_FCM_CONSOLE"
//old legacy server key
//"OR_LEGACY_SERVER_KEY"
);
Finaly..., (*5)
SET Server Key, (*6)
echo $notification->send(
//This is token from client (Android / iOS)
//You can store this token in mysql server or other dbms
array(
'REGISTRATION_TOKEN',
'OTHER_REGISTRATION_TOKEN'
),
$push->getPush()
);
Dibuat untuk keperluan internal tim., (*7)
jika butuh, dan (kalau bisa) kembangkan menjadi lebih baik., (*8)