Answer the question
In order to leave comments, you need to log in
Why don't I receive Cloud Messaging notifications?
I am writing a server part to send notifications to a specific user on a device. In the response, the message is sent, but in fact it does not arrive. The main thing from the Console - come. What could be the problem?
$tokens = array();
$tokens[0] = '!!!';
$message = array("message" => '12345');
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $massage
);
$headers = array(
'Authorization:key = !!!',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
echo "---".$ch."---";
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
echo $result;
{"multicast_id":6833045560665960461,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1565387661837510%836c9c22f9fd7ecd"}]}
Answer the question
In order to leave comments, you need to log in
I'm a little lazy to figure it out, but, right off the bat, a question. Why not use the official sdk ? m?
Perhaps it's a typo:
$message / $massage
Not familiar with php, does he swear in such cases, or is silent?
UPD:
Judging by the answer fcm, Google accepts the request. And it must be delivered to the mobile. A similar scheme works fine for me, the only difference is that I send not as a list, but to one device.
There may be a problem on the receiving end. How do you process an incoming message? With these parameters (specified "data", but no "notification"), there will be no automatic pop-up notification - the message must be processed programmatically on the mobile.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question