使用PHP获取GCM的无效注册错误

使用PHP获取GCM的无效注册错误,php,android,google-cloud-messaging,Php,Android,Google Cloud Messaging,我正在尝试使用php为android创建推送通知。但我在某个地方卡住了。我用了一个来自的例子来说明这一点。这是我的php代码 网络配置 <?php /** * Database config variables */ define("DB_HOST", "localhost"); define("DB_USER", ""); define("DB_PASSWORD", ""); define("DB_DATABASE", ""); /* * Google API Key */ d

我正在尝试使用php为android创建推送通知。但我在某个地方卡住了。我用了一个来自的例子来说明这一点。这是我的php代码

网络配置

<?php
/**
 * Database config variables
 */
define("DB_HOST", "localhost");
define("DB_USER", "");
define("DB_PASSWORD", "");
define("DB_DATABASE", "");

/*
 * Google API Key
 */
define("GOOGLE_API_KEY", "AIzaSyD_PC6UaeTbnSemX0hpY0eyawlE3EufRcA"); // Place your Google API Key
?>

我的GCM.php文件是

<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GCM
 *
 * @author Ravi Tamada
 */
class GCM {

    //put your code here
    // constructor
    function __construct() {

    }

    /**
     * Sending Push Notification
     */
    public function send_notification($registatoin_ids, $message) {
        // include config
        include_once './config.php';

        // Set POST variables
        $url = 'https://android.googleapis.com/gcm/send';

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

        $headers = array(
            'Authorization: key=' . GOOGLE_API_KEY,
            'Content-Type: application/json'
        );
        // 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_IPRESOLVE, CURL_IPRESOLVE_V4);
        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }

        // Close connection
        curl_close($ch);
        echo $result;
    }

}

?>

我的html是这样的

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
            });
        </script>
    </head>
    <body>
        <form name="" method="post" action="register.php">
            <input type="text" name="name"/>
            <input type="text" name="email"/>
            <input type="text" name="regId"/>
            <input type="submit"/>
        </form>
    </body>
</html>

$(文档).ready(函数(){
});
这是我正在使用的代码,但每次它都向我显示 {“多播id”:4677806556758130005,“成功”:0,“失败”:1,“规范id”:0,“结果”:[{“错误”:“无效注册”}]}

我不知道我做错了什么

我对我必须通过的GCM注册Id感到困惑。谁能告诉我这是什么?我在哪里找到的

我尝试了我的项目id和项目编号,但我一次又一次地遇到这个错误

谢谢你的帮助


谢谢

请传递您的gcm帐户的服务器密钥如果未生成,请生成并传递它,它将100%工作

您的API密钥无效,这就是它给您错误的原因,但我从我的谷歌控制台复制并粘贴它。请生成一个新的。你可以试试这里提供的解决方案,你能告诉我什么是注册id吗?我没有得到什么是注册id是您的设备的唯一id,您将发送推送通知,服务器密钥将设置在GOOGLE_API_密钥。这个问题是因为您的服务器密钥。请检查您的GOOGLE帐户中是否有错误,或者您在GOOGLE_API_密钥中定义了不同的服务器密钥