|
|
@@ -0,0 +1,54 @@
|
|
|
+<?php
|
|
|
+ require __DIR__ . "/vendor/autoload.php";
|
|
|
+
|
|
|
+ use Kreait\Firebase\Factory;
|
|
|
+ use Kreait\Firebase\Messaging\Notification;
|
|
|
+
|
|
|
+ $factory = (new Factory)->withServiceAccount("narkampen-firebase-adminsdk-k42j5-d3d0354e37.json");
|
|
|
+
|
|
|
+ $messaging = $factory->createMessaging();
|
|
|
+
|
|
|
+ $deviceToken = "ck4OuDu3RweBW5s8ncj7FV:APA91bHo58TUsXVgTB8cLOKHkpVaSydej_TFZLJyuPMrAEhgWNxLRRd83a_6Mz1YnZYtzz5sTjnowlbYVwyp3JudKa-jl3UY1xNGae9FpYU7bn6hSHLzW-OuzM87w149lQg6zYC6PXJg";
|
|
|
+
|
|
|
+ // NOTIFICATION EXAMPLE
|
|
|
+ $title = 'My Notification Title';
|
|
|
+ $body = 'My Notification Body';
|
|
|
+ $imageUrl = 'http://lorempixel.com/400/200/';
|
|
|
+
|
|
|
+ $notification = Notification::fromArray([
|
|
|
+ 'title' => $title,
|
|
|
+ 'body' => $body,
|
|
|
+ 'image' => $imageUrl,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $notification = Notification::create($title, $body);
|
|
|
+
|
|
|
+ $changedNotification = $notification
|
|
|
+ ->withTitle('Changed title')
|
|
|
+ ->withBody('Changed body')
|
|
|
+ ->withImageUrl('http://lorempixel.com/200/400/');
|
|
|
+
|
|
|
+ $message->withNotification($notification);
|
|
|
+ // NOTIFICATION EXAMPLE END
|
|
|
+
|
|
|
+ // DATA Example
|
|
|
+ $data = [
|
|
|
+ 'first key' => "First value",
|
|
|
+ "second key" => "Second value"];
|
|
|
+
|
|
|
+ $message->withData($data);
|
|
|
+ // DATA EXAMPLE END
|
|
|
+
|
|
|
+ $message = CloudMessage::withTarget('token', $deviceToken)
|
|
|
+ ->withNotification($notification) // OPTIONAL
|
|
|
+ ->withData($data); // OPTIONAL
|
|
|
+
|
|
|
+ /*
|
|
|
+ $message = CloudMessage::fromArray([
|
|
|
+ 'token' => $deviceToken,
|
|
|
+ 'notification' => [],
|
|
|
+ 'data' => []
|
|
|
+ ]);
|
|
|
+ */
|
|
|
+
|
|
|
+ $messaging->send($message);
|