Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从GCM获取响应_Php_Android_Push Notification_Google Cloud Messaging - Fatal编程技术网

Php 从GCM获取响应

Php 从GCM获取响应,php,android,push-notification,google-cloud-messaging,Php,Android,Push Notification,Google Cloud Messaging,如果消息已发送或未发送,如何获得响应,使用Php脚本,然后我想使用响应来确定设备是否在线 下面是我发送消息的Php脚本: function send_push_notification($registration_ids, $message) { $regId=$registration_ids; $msg=$message; $message = array("message" => $msg); $regArray[]=$registration_ids; $url =

如果消息已发送或未发送,如何获得响应,使用Php脚本,然后我想使用响应来确定设备是否在线

下面是我发送消息的Php脚本:

function send_push_notification($registration_ids, $message) {

 $regId=$registration_ids;
 $msg=$message;
 $message = array("message" => $msg);

 $regArray[]=$registration_ids;
 $url = 'https://android.googleapis.com/gcm/send';

 $fields = array('registration_ids' => $regArray, 'data' => $message,);
 $headers = array( 'Authorization: key=API_KEY','Content-Type: application/json');

 $ch = curl_init();

 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_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

 $result=curl_exec($ch);
 echo $result; 
 if($result==FALSE)
 {
die('Curl Failed');

}
 curl_close($ch);

 }

谢谢

您没有收到应用程序的响应;您只能从GCM系统本身获得响应。当CURL调用完成时,
$result
包含一个JSON编码的对象;成功后,其
id
属性包含消息id。

您的服务器从GCM服务器得到的响应不会告诉您消息是否已发送。它只告诉您消息是被GCM服务器接受还是被拒绝。如果它被接受,GCM服务器将尝试交付它,但不能保证它会成功。如果被拒绝,您将收到一条错误消息(例如
无效注册
丢失注册
,等等)


如果你想确认发送,你必须在你的Android应用程序中有一个代码,当你收到消息时,它会打电话给你的服务器,确认消息已经收到

好的,谢谢这些信息