Przeglądaj źródła

Nytt försök med FCM Message

Axel Nordh 5 lat temu
rodzic
commit
4c987a5833
1 zmienionych plików z 16 dodań i 19 usunięć
  1. 16 19
      dbFiles/FCMMessageing.php

+ 16 - 19
dbFiles/FCMMessageing.php

@@ -5,36 +5,33 @@
 // Hämta token från sql användaren
 $token = "eMvkzPwkTheSeFLFAE5fho:APA91bE-pb5_0xoMn_Bza6-HrgpI5ufKPZ7zhF4NM_leYdfgYTk4MZJdfpfiKDkijUuQAiK7iaT7rXJucF20uh1GvmgjiomiuQehnDHcjUkGjaSvkQtVfj_s0AtLSPjIJz8EQ5Aujkfk";
 $message = "TEST MEDDELANDE FRÅN SERVERN";
-$url = "https://fcm.googleapis.com/fcm/send";
+$title = "TEST TITEL";
+$url = "https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send";
 
 $fields = array(
-	"registration_id" => array(
-		$token
-	),
-	"data" => array("message" => $message));
-	
+	"message" => array(
+		"token" => $token,
+		"notification" => 
+			array(
+				"body" => $message,
+				"title" => $title
+			)
+		)
+	);
 $fields = json_encode($fields);
 
 $headers = array(
-            'Authorization: key=' . "108102546370",
-            'Content-Type: application/json'
-			)
-
-$post = [
-	"message" => array("notification" => array(
-		"title" => "FCM Message",
-		"body" => "This is an FCM Message")
-	"token" => $token
-	)
-];
+			'Content-Type: application/json',
+            'Authorization: Bearer ' . "AAAAGStp88I:APA91bERuLuU7DuAyW2yhoLQeiJizGZVsezzEdLhRa9v9Ehy7uYmHFvBTMrQooMDg0oaGNZE3DXd3Tl3E10JP58OCtuL7z1UQWo071tOCR8Ede3YUXDErs6Zkt8z1VxcBAkOxzVInId3"
+			);
 
-$curl = curl_init()
+$curl = curl_init();
 
 curl_setopt($curl, CURLOPT_URL, $url);
 curl_setopt($curl, CURLOPT_POST, true);
 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
-curl_setopt($curl, CURL_POSTFIELDS, $fields);
+curl_setopt($curl, CURLOPT_POSTFIELDS, $fields);
 
 $response = curl_exec($curl);