简体   繁体   中英

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

im sending notifications to my clients with PHP. Here is my PHP Code for this

<?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

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

{ "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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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