Google Cloud Message API 通知数据未显示 - PHP


Google Cloud Message API Notification Data doesn't appear - PHP

>im 使用 PHP 向我的客户端发送通知。这是我的PHP代码

<?php
define( 'API_ACCESS_KEY', 'AIzaSyAYq7KpB5J7x3p3zYyna...' );
$registrationId = array( $_GET['id'] );
$msg = array
(
    'message'   => 'here is a message. message',
    'title'     => 'This is a title. title',
    'subtitle'  => 'This is a subtitle. subtitle'
);
$fields = array
(
    'registration_ids'  => $registrationId,
    'notification'          => $msg
);
$headers = array
(
    'Authorization: key=' . API_ACCESS_KEY,
    'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/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;

当我使用我的注册ID执行脚本时,有这样的通知,通知

标题为推送消息身体是讯息

如您所见,通知标题和消息正文与地雷不相等。我该如何解决这个问题?谢谢。

$msg应该是 JSON 对象,如消息传递概念和选项中所述

{"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...","数据" : {"尼克" : "马里奥","身体" : "伟大的匹配!"房间" : "葡萄牙VS登马克"},}

有关下游消息传递的更详细讨论,您可以参考其文档页面,其中讨论了发送消息的各个方面。