我能够获得消息ID的回报,但是通知未显示在Android设备中,但是它可以从Firebase Console中运行正常,我可以从Firebase发送到主题" Nadakko"控制台
<?php
$data = array(
"message" => "sfsdgdgdfg"
);
$final = array(
"condition" => "'nadakko' in topics",
"data" => $data
);
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=AIzaSyAkjY4wwambC7ryNxr-KEjsx4VgSZuh-UY',
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($final));
// Execute post
$result = curl_exec($ch);
if ($result === FALSE) {
// curl failed
echo "Faild";
}
echo $result;
// Close connection
curl_close($ch);
?>
发送消息后,我从Android监视器中收到了此错误,该消息已接收到手机上的消息,但是有一些问题
06-07 18:06:16.139 8802-12118/info.***.*** E/MyFirebaseMessagingService: Data Payload: {message=sfsdgdgdfg}
06-07 18:06:16.139 8802-12118/info.**.**** E/MyFirebaseMessagingService: push json: {"message":"sfsdgdgdfg"}
06-07 18:06:16.139 8802-12118/info.**.*** E/MyFirebaseMessagingService: Json Exception: No value for data
06-07 18:06:16.139 8802-12118/info.**.*** E/MyFirebaseMessagingService: Json Exception: No value for data
这是问题,您需要读取message
而不是data
使用,它将是
String message = json.getString("message");
JSONObject data = json.getJSONObject("data");
String title = data.getString("title");
String message = data.getString("message");