I am a web developer and hired ios developer to create native app for my client. The client wants to have push notifications. We are using firebase but the problem is that i can't send push notifications from my php script, because of the InvalidRegistration error. I've read all over stackoverflow about this error and still dont have a clue how to fix it.
I am saving the device_token in a mysql table CHAR(64).
This is my script:
if (isset($_POST['submit'])) {
// API access key from Google API's Console
define('API_ACCESS_KEY', 'API');
$users = $db->getResults("device_id", "users", "device_id != '' AND travel_stay = '" . $_POST['group'] . "'");
foreach ($users as $user) {
$registrationIds = (string)$user['device_id'];
// prep the bundle
$msg = array(
'message' => $_POST['description'],
'title' => $_POST['title'],
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon');
$fields = array('to' => $registrationIds, 'data' => $msg);
$headers = array('Authorization: key=' . API_ACCESS_KEY, 'Content-Type: application/json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
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_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
} ?>
I have no idea what is wrong with it, is the device_token sent wrong? How can i fix it.