PHP code example of valdeirpsr / firebasemessaging-php
1. Go to this page and download the library: Download valdeirpsr/firebasemessaging-php 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/ */
valdeirpsr / firebasemessaging-php example snippets
use FirebaseMessaging\FirebaseMessaging;
use FirebaseMessaging\FirebaseNotification;
use FirebaseMessaging\FirebaseCondition;
$notification = new FirebaseNotification();
$notification->setTitle("Run!! New video");
$notification->setBody("Duelo de MC's - FINAL - Thaik vs Din");
$messaging = new FirebaseMessaging("serverKey");
$messaging->setTo("/topics/RapHipHop");
$messaging->setOperacionalSystem(FirebaseMessaging::OS_ANDROID);
$messaging->setNotification($notification);
$messaging->send();
use FirebaseMessaging\FirebaseMessaging;
use FirebaseMessaging\FirebaseNotification;
use FirebaseMessaging\FirebaseCondition;
$notification = new FirebaseNotification();
$notification->setTitle("Run!! New video");
$notification->setBody("Duelo de MC's - FINAL - Thaik vs Din");
$notification->setIcon("custom_logo");
$notification->setTag("valdeirpsr_1");
$notification->setColor("#E91E63");
$notification->setClickAction("OPEN_ACTIVITY_VIDEO");
$notification->setSound("sound_notification");
$condition = new FirebaseCondition("RapHipHop");
$condition->openAnd("DouglasDin");
$condition->orInTopics("Thaik");
$condition->closeAnd();
// output: 'RapHipHop' in topics && ('DouglasDin' in Topics || 'Thaik' in Topics)
$messaging = new FirebaseMessaging("serverKey");
$messaging->setCondition($condition);
$messaging->setPriority(FirebaseMessaging::PRIORITY_HIGH);
$messaging->setTimeToLive(2419200);
$messaging->setOperacionalSystem(FirebaseMessaging::OS_BOTH);
$messaging->setNotification($notification);
$messaging->setRestrictedPackageName("br.com.valdeirsantana.test");
$messaging->setCollapseKey("video_new");
$messaging->setDelayWhileIdle(false);
$messaging->setDevelopmentMode(false);
$messaging->setData([
"video_id" => "ZDz-5fQAIo4",
"title" => "Duelo de MC's - FINAL - Thaik vs Din :: Tradicional - 23/11/12",
"channel" => "Indie BH",
"channel_url" => "https://www.youtube.com/channel/UCBkYx1zP0aOaMXsp9As75Tg",
"channel_id" => "UCBkYx1zP0aOaMXsp9As75Tg",
"thumbnail" => [
"default" => [
"url" => "https://i.ytimg.com/vi/ZDz-5fQAIo4/default.jpg",
"width" => "120",
"height" => "90"
],
"high" => [
"url" => "https://i.ytimg.com/vi/ZDz-5fQAIo4/mqdefault.jpg",
"width" => "320",
"height" => "180"
],
"high" => [
"url" => "https://i.ytimg.com/vi/ZDz-5fQAIo4/hqdefault.jpg",
"width" => "480",
"height" => "360"
],
"standard" => [
"url" => "https://i.ytimg.com/vi/ZDz-5fQAIo4/sddefault.jpg",
"width" => "640",
"height" => "480"
],
"maxres" => [
"url" => "https://i.ytimg.com/vi/ZDz-5fQAIo4/maxresdefault.jpg",
"width" => "1920",
"height" => "1080"
]
]
]);
$messaging->send();