|
|
@@ -0,0 +1,55 @@
|
|
|
+<?php
|
|
|
+require_once '../vendor/autoload.php';
|
|
|
+
|
|
|
+putenv('GOOGLE_APPLICATION_CREDENTIALS=/home/axel/configs/narkampen-firebase-adminsdk-k42j5-d3d0354e37.json');
|
|
|
+
|
|
|
+$client = new Google_Client();
|
|
|
+$client->useApplicationDefaultCredentials();
|
|
|
+$client->addScope('https://www.googleapis.com/auth/firebase.messaging');
|
|
|
+$httpClient = $client->authorize();
|
|
|
+
|
|
|
+/*
|
|
|
+$token = "eMvkzPwkTheSeFLFAE5fho:APA91bE-pb5_0xoMn_Bza6-HrgpI5ufKPZ7zhF4NM_leYdfgYTk4MZJdfpfiKDkijUuQAiK7iaT7rXJucF20uh1GvmgjiomiuQehnDHcjUkGjaSvkQtVfj_s0AtLSP>
|
|
|
+*/
|
|
|
+$hostname = 'localhost';
|
|
|
+$username = 'narKampen';
|
|
|
+$pass = 'IfRLzj2HJBXA9eei';
|
|
|
+$database = 'narKampen';
|
|
|
+
|
|
|
+$conn = new mysqli($hostname, $username, $pass, $database);
|
|
|
+if (!$conn) {
|
|
|
+ die("Connection Failed. ". mysqli_connect_error());
|
|
|
+}
|
|
|
+mysqli_set_charset($conn,'utf8');
|
|
|
+
|
|
|
+$gameId = $conn->real_escape_string($_POST['gameId']);
|
|
|
+$playerName = $conn->real_escape_string($_POST['playerName']);
|
|
|
+
|
|
|
+$sql = "SELECT messageToken FROM `gamePlayers` INNER JOIN users ON users.id = playerId WHERE gameId = $gameId and users.username = '$playerName'";
|
|
|
+
|
|
|
+$result = $conn->query($sql);
|
|
|
+if ($result->num_rows == 1) {
|
|
|
+ $returnArray = array();
|
|
|
+ $data = $result->fetch_assoc();
|
|
|
+ $token = $data['messageToken'];
|
|
|
+} else {
|
|
|
+ echo "No games found for user";
|
|
|
+}
|
|
|
+
|
|
|
+if ($token != null && $token != "") {
|
|
|
+// Your Firebase project ID
|
|
|
+$project = "narkampen";
|
|
|
+// Creates a notification for subscribers to the debug topic
|
|
|
+$message = [
|
|
|
+ "message" => [
|
|
|
+ "token" => $token,
|
|
|
+ "notification" => [
|
|
|
+ "body" => "This is an FCM notification message!",
|
|
|
+ "title" => "FCM Message",
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+];
|
|
|
+// Send the Push Notification - use $response to inspect success or errors
|
|
|
+$response = $httpClient->post("https://fcm.googleapis.com/v1/projects/{$project}/messages:send", ['json' => $message]);
|
|
|
+
|
|
|
+}
|