Php 从服务器调用Firebase云消息传递不起作用
我刚刚开发了一个firebase web应用服务器。我正在发送通知,似乎一切正常,但在我的android应用程序中没有收到通知。如果我从firebase控制台发送通知,它将进入我的android应用程序。但是我想从我的web应用程序发送它 以下是我的web应用程序php代码:Php 从服务器调用Firebase云消息传递不起作用,php,curl,firebase,firebase-cloud-messaging,Php,Curl,Firebase,Firebase Cloud Messaging,我刚刚开发了一个firebase web应用服务器。我正在发送通知,似乎一切正常,但在我的android应用程序中没有收到通知。如果我从firebase控制台发送通知,它将进入我的android应用程序。但是我想从我的web应用程序发送它 以下是我的web应用程序php代码: public function sendMessage($data,$target=null){ //FCM api URL $url = 'https://fcm.googleapis.c
public function sendMessage($data,$target=null){
//FCM api URL
$url = 'https://fcm.googleapis.com/fcm/send';
//api_key available in Firebase Console -> Project Settings -> CLOUD MESSAGING -> Server key
$server_key = 'S6GzaCUhIbS6GzaCAIzaSyJtkQLzl3FCUhIbUhIbS6Gza8A';
//$fields = array();
//$fields['data'] = $data;
if(is_array($target)){
$fields['registration_ids'] = $target;
}
$fields = array(
'notification' => array('title' => 'Working Good', 'body' => 'That is all we want'),
'data' => array('message' => "melaapa")
);
//header with content_type api key
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
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));
$result = curl_exec($ch);
if ($result === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
var_dump($result);
return $result;
}
产量
变量转储($result)
是
字符串(3)“至”
对于正在工作的firebase服务器,响应应该是什么?或者我如何理解我的firebase服务器工作正常?请参见此处的预期响应格式:谢谢先生,您真的帮助了我:)