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条)

报告相同问题?

悬赏问题

  • ¥15 电脑出问题了,说是usbmom注册表没
  • ¥20 需要步骤截图(标签-服务器|关键词-map)
  • ¥50 gki vendor hook
  • ¥15 灰狼算法和蚁群算法如何结合
  • ¥15 这是一个利用ESP32自带按键和LED控制的录像代码,编译过程出现问题,请解决并且指出错误,指导如何处理 ,协助完成代码并上传代码
  • ¥20 stm32f103,hal库 hal_usart_receive函数接收不到数据。
  • ¥20 求结果和代码,sas利用OPTEX程序和D-efficiency生成正交集
  • ¥50 adb连接不到手机是怎么回事?
  • ¥20 抓取数据时发生错误: get_mooncake_data() missing 1 required positional argument: 'driver'的问题,怎么改出正确的爬虫代码?
  • ¥15 vs2022无法联网