dongzao3923 2016-02-23 01:44
浏览 37

gcm注册错误无效

i pass to the server a nickname and then i get registration id by nickname from my database.

GOOGLE_API_KEY is a server key generated by google gcm api.

this is the php code of the server:

<?php

require_once("db_config.php");


$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD) or      
die(mysqli_error());

$db = mysqli_select_db($con, DB_DATABASE) or die(mysqli_error()) or die(mysqli_error());


$nicknames = $_POST['nicknames'];
$message = $_POST['message'];




$registration_ids = mysqli_query($con, "SELECT regId FROM Users WHERE nickname = '$nicknames'");
$numOfRows = mysqli_num_rows($registration_ids);

$row=mysqli_fetch_assoc($registration_ids );
printf ("%s
",$row["regId"]);


if($numOfRows > 0) {

$url = 'https://gcm-http.googleapis.com/gcm/send';
//$url = 'https://android.googleapis.com/gcm/send';
$fields = array('registration_ids' => array($registration_ids), 'data' => array("message" => $message),);
$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);

    // Disabling SSL Certificate support temporarly
    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);
    echo $result;
}
else {
    echo 'false';
}     

?>

after i send the message, i recieve:

{"multicast_id":4772095405461687926,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}]

i also printed to my self the registartion id that i get from my database and it is matched to the device`s registration id.

ty for your help.

  • 写回答

2条回答 默认 最新

  • dora12345678 2016-02-23 08:20
    关注

    You should check the registration token that you are passing to the server. See Downstream message error response codes.

    You may also look at this documentation which suggests to check the validity of the registration token.

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程