如何从php firebase通知发送String到android中的通知服务?

时间:2017-07-24 05:03:10

标签: php android firebase push-notification firebase-cloud-messaging

我想从php发送带有“room”字符串的通知。这是我的代码:

define( 'API_ACCESS_KEY', '--------------------------' );
#prep the bundle
$msg = array (
    'body'  => $_GET['isi'],
    'title' => $nama." mengirim pesan",
    'icon'  => 'myicon',/*Default Icon*/
    'sound' => 'mySound',/*Default sound*/
    'room' => $room //This is String I want to send
);
$fields = array (
    'to'            => $registrationIds,
    'notification'  => $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 );

我想在这里收到一串“房间”:

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    private static final String TAG = "MyFirebaseMessagingService";

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        sendNotification(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
    }
}

如何获得“房间”字符串? 感谢..

1 个答案:

答案 0 :(得分:0)

notification消息有效负载仅具有可供使用的特定参数(请参阅here)。

您必须使用data消息有效负载添加自定义键值对,然后相应地添加handle the messages