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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法