So i have this test application that i'm using to learn how to send push notifications from an external server hosted in my desktop to a virtual device or smartphone.
Then I use a simple form and input title and message and click the submit button to send the notification.
I have triple checked, the encoding of the notification is fine, and I'm able to pass the firebase token from the android app to the server, which stores it in the MySQL database.
Also the app is correctly sending the token and the server_key is also correct (used the built in copy function at firebase website)
Why isn't my notification showing? this is the source code of the script in php to send the notification to firebase:
<?php
require "init.php";
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "AAAA0Tedu0Y:APA91bGF1k9LAVw90LVM9IdWludKeG1ueVo2V7HesN4CVz2KFvcwGvLkDymuHjm0IvfRvZ6wOEu5Q33pBgYDUXopvTOBSDKQJf2zFFp_22gTCrg6zxNxKyw8_0M9ciPLt3YyJOwkmNYR";
$sql = "select fcm_token from fcm_info";
$result = mysqli_query($con,$sql);
//these lines get the key that has been store (i only store one key from one app, so it takes the first value of the result
$row = mysqli_fetch_row($result);
$key = $row[0];
$header = array(
'Authorization:key=' .$server_key,
'Content-Type:application/json'
);
$field = array( 'to'=>$key,
'notification'=>array('title'=>$title,'body'=>$message)
);
$payload = json_encode($field);
//If echo $payload, It print the following:
/*
{
"to":"esM8_IMRWrw:APA91bEVOTjpC5kkqAWqWwEs7gNq5-4iUvL6fC947cfWkg1G0VhKDiuibSOr_xSNcIJ8rb4VewjNJ2Jd_0AXBdQgTbOO0FO-stmP3ymOCLGQlka3s2RQ3854UiPr_puc274hXSlQMLen",
"notification":{
"title":"asdasd",
"body":"asdasd"
}
}
So the json is properly formatted
*/
/*this generates the http url connection from my server to firebase push notification sending url. I think the error is somewhere in these lines, but i dont know where*/
$curl_session = curl_init();
curl_setopt($curl_session,CURLOPT_URL,$path_to_fcm);
curl_setopt($curl_session,CURLOPT_POST,TRUE);
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($curl_session,CURLOPT_POSTFIELDS,$payload);
$result = curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
?>
Any help is appreciated, thanks in advance!