无效的注册ID与我的gcm php服务器 [英] Invalid Registration Id with my gcm php server

查看:143
本文介绍了无效的注册ID与我的gcm php服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我将POST张贴到我的gcm.php并将用户手机的注册ID发送到我的服务器上的文本文件中(之后将实施数据库)。出于某种原因,当我发布到gcm服务器时,我收到了无效的注册错误。



我检查了我的txt文件,它没有被填充(这是问题)所以我很好奇我在我的android客户端代码中做了什么错误这是不是与我的PHP服务器共享用户的ID。

gcm.php(服务器)

 <?php 


//通用php函数发送GCM推送通知
函数sendPushNotificationToGCM($ registatoin_ids,$ message){
// Google云端消息GCM-API url
$ url ='https://android.googleapis.com/gcm/send';
$ fields = array(
'registration_ids'=> $ registatoin_ids,
'data'=> $ message,
);
// Google Cloud Messaging GCM API键
define(GOOGLE_API_KEY,AIzaSyDA5dlLInMWVsJEUTIHV0u7maB82MCsZbU);
$ headers = array(
'Authorization:key ='。GOOGLE_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_VERIFYHOST,0);
curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ ch,CURLOPT_POSTFIELDS,json_encode($ fields));
$ result = curl_exec($ ch);
if($ result === FALSE){
die('Curl failed:'。curl_error($ ch));
}
curl_close($ ch);
返回$ result;
}
?>
<?php

//这个区块是发送消息给GCM,点击
$ pushStatus =;
if(!empty($ _ GET [push])){
$ gcmRegID = file_get_contents(GCMRegId.txt);
$ pushMessage = $ _POST [message];
if(isset($ gcmRegID)&& isset($ pushMessage)){
$ gcmRegIds = array($ gcmRegID);
$ message = array(m=> $ pushMessage);
$ pushStatus = sendPushNotificationToGCM($ gcmRegIds,$ message);



//这块是从外部(移动应用程序)
接收GCM regId if(!empty($ _ GET [shareRegId] )){
$ gcmRegID = $ _POST [regId];
file_put_contents(GCMRegId.txt,$ gcmRegID);
回声OK!;
出口;
}
?>
< html>
< head>
< title> PHP中的Google Cloud Messaging(GCM)服务器< / title>
< / head>
< body>
< h1> PHP中的Google Cloud Messaging(GCM)服务器< / h1>
< form method =postaction =gcm.php /?push = 1>
< div>