File "notification_server.php"

Full Path: /home/analogde/www/filechange/WEBSITE/douche/notification_server.php
File size: 1.93 KB
MIME-type: text/x-php
Charset: utf-8

<?php
  
  function send_notification($token)
  {
		// projetFirebaseMessaging
		$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
	
        $fields = array(
            'to' => $token,
            'notification' => array('title' => 'Working Good', 'body' => 'That is all we want'),
            'data' => array('message' => $message)
        );
  
		// ancien clé serveur
		$api_KEY = "AIzaSyD2d6W9_b3M5ES6c-kpRKOZd4sa6LNZu5g";
   
		// nouvelle clé serveur
		$api_KEY ="AAAA-53wG4I:APA91bGyXIRJl0X-AoWeU57KseVze8aiB1rooMerHZmd83vmwX7Q7kFh9-Ugq2S3h_1X_gubzQZjb28YUzgFLRqeQmkJ7_9gukwUnla6_vugNBrp-PHOtx3fHNKrGgUIJ3GFBwBY9EVt7P5rbt5ZS0RJI9qJfpLBHA";
   
        $headers = array(
            'Authorization:key=' . $api_KEY,
            'Content-Type:application/json'
        );		
		
		
        $ch = curl_init();
 
        curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm); 
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    
        $result = curl_exec($ch);
       
        curl_close($ch);
  
  }

    /************************************************************/ 
  
    $user = $_POST["user"]; 
 
    require_once __DIR__ . '/db_connect.php';
    $db = new DB_CONNECT();
    
    $sql = "SELECT *FROM debug_firebase_token";
    $result = mysql_query($sql);
    
    $tab_contact = array();
    
    // on exclu l'utilisateur
    while($val = mysql_fetch_array($result)) 
    {
            if($user != $val["user"])
            {
                $tab_token[] = $val["token"];
            }            
    }
    
    for ($i = 0; $i < sizeof($tab_token); $i++) 
    {
            send_notification($tab_token[$i]);
    }
                        
?>