简体   繁体   English

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

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

im sending notifications to my clients with PHP. 我用PHP向我的客户发送通知。 Here is my PHP Code for this 这是我的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;

When i execute the script with my registration id there is notification like this, Notification 当我用我的注册ID执行脚本时,会出现这样的通知, 通知

Title is Push message Body is The Message 标题是 推送消息,正文 消息

As you can see, Notification title and message body is not equal with mines. 如您所见,通知标题和消息正文与地雷不相等。 How i can fix this ? 我怎么解决这个问题? Thank you. 谢谢。

$msg should be a JSON object, as indicated in the Messaging Concepts and Options $msg应该是JSON对象,如“ 消息传递概念和选项”中所述

{ "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "data" : { "Nick" : "Mario", "body" : "great match!", "Room" : "PortugalVSDenmark" }, } {“to”:“bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1 ......”,“data”:{“Nick”:“Mario”,“body”:“great match!”,“Room”:“PortugalVSDenmark”},}

For a more detailed discussion regarding Downstream Messaging, you can refer to its documentation page were it discusses various aspects of sending messages. 有关下游消息的更详细讨论,可以参考其文档页面 ,其中讨论了发送消息的各个方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM