GCM卷曲脚本无效注册

时间:2016-01-12 20:49:26

标签: php android curl google-cloud-messaging

我正在尝试通过curl脚本实现gcm。当我预览页面时,我得到的是无效注册,而我提供了我的API密钥。在我下载的脚本中,它的行"registration ids"已经有了一些值。现在我的问题是我在哪里可以获得我的注册ID输入到脚本中。我有点困惑

//request url
$url    = 'https://android.googleapis.com/gcm/send';

//your api key
$apiKey = 'AIzaSyAHb_Mh27PNnNkwj------------tkqKjc';

//registration ids
$registrationIDs = array('APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...');

//payload data
$data   = array('score' => '1-0', 'scorer' => 'Ronaldo', 'time' => '44');

$fields = array('registration_ids' => $registrationIDs,
                'data' => $data);

//http header
$headers = array('Authorization: key=' . $apiKey,
                 'Content-Type: application/json');

//curl connection
$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);

curl_close($ch);

echo $result;

2 个答案:

答案 0 :(得分:0)

您可以查看Downstream message error response codes的文档。

  

无效注册令牌200 +错误:InvalidRegistration

     

检查传递给服务器的注册令牌的格式。确保它与客户端应用程序从GCM注册时收到的注册令牌相匹配。不要截断或添加其他字符。

答案 1 :(得分:0)

客户端(Android / IOS应用程序)生成

registration_id,而不是服务器端。查看GCM guides