dps43378 2016-05-07 11:45 采纳率: 0%
浏览 51
已采纳

通过PHP发送GCM不会显示onMessageReceived数据

I start using GCM on a android device when i send data via CURL and PHP from my server to the GCM on my android app only get a null on the onMessageReceived i think that it was my code on the app but if i call the curl via terminal it shows the data hope you can help me with my php script to see what is wrong with this, by the way the in both i got the petition of GCM but only via terminal it displays the data

<?php
// Message to be sent


// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';

$fields = array(
                'to'  => 'ezgWcLrhacM:APA91bHzxeKdOnK.......gBfmpF3YrqOkjuHii296Ie1TPEmeQi-B-g_DJg0EHq89V0........7DCh3bzuHDOpN1Ksmp1n_EpkZvKrl56rrWB7M5Z8I',
                'data '  => array( 'message' => 'Hello World!' ),
                );

$headers = array( 
                    'Content-Type: application/json',
                    'Authorization: key=AIzaSyBBgVZuc...........DnZeDY4OZr_uyI' 

                );



// 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 );

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
//echo $ch;
//$info = curl_getinfo($ch);



// Execute post
echo json_encode($fields);
$result = curl_exec($ch);

// // Close connection
curl_close($ch);

 echo $result;

?>

and the log from android terminal

05-07 06:34:48.694 14037-14239/mx.com.iubix.iubixmessage D/ListenerService: Datos recibidosBundle[{collapse_key=do_not_collapse}] 
05-07 06:34:48.694 14037-14239/mx.com.iubix.iubixmessage D/ListenerService: From: 1007097169676 
05-07 06:34:48.694 14037-14239/mx.com.iubix.iubixmessage D/ListenerService: Message: null

and where is the code i send from my terminal

curl --header "Authorization: key=AIzaSyBBgVZ........eDY4OZr_uyI" --header "Content-Typ.....e: application/json" https://android.googleapis.com/gcm/send -d "{\"to\":\"ezgWcLrhacM:APA91bHzxeKdOnKgk.......ZxjEchBezgBfmpF3YrqOkjuHii296Ie1TPEmeQi-B-g_DJg0EHq89V0yllLGw9Yji0zv.......Ksmp1n_EpkZvKrl56rrWB7M5Z8I\",\"data\":{\"message\":\"Hello World\"}}"

this one works fine

  • 写回答

2条回答 默认 最新

  • dougaojue8185 2016-05-07 14:58
    关注

    Sorry guys already solve it in data parameter i had an extra space and remove it and works perfectly ! Sorry for the inconvenience ! Thanks all anyway

    'data ' 
    

    Change this for

     'data'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?