[英]Getting Invalid registration error for GCM using PHP
I am trying to create push notification for android using php. 我正在尝试使用php为Android创建推送通知。 But I stuck somewhere.I am using an example from for that.
但是我停留在某个地方,为此我使用了一个例子。 Here is my php code
这是我的PHP代码
Web config 网页配置
<?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
?>
And my GCM.php File is this 我的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;
}
}
?>
My html is this 我的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>
This the code which I am using but everytime it show me message that {"multicast_id":4677806556758130005,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]} 这是我正在使用的代码,但每次都会向我显示以下消息:{“ multicast_id”:4677806556758130005,“ success”:0,“ failure”:1,“ canonical_ids”:0,“ results”:[{“ error”:“ InvalidRegistration“}]}
I donot know what I am doing wrong 我不知道我在做什么错
I am getting confuse with GCM Registration Id which I have to pass. 我对必须通过的GCM注册ID感到困惑。 Can anybody tell me what is this and where I find it
谁能告诉我这是什么以及在哪里找到它
I tried my project id and project number for that But I got this error again and again 我为此尝试了我的项目ID和项目编号,但是却一次又一次地收到此错误
Any help is appreciated 任何帮助表示赞赏
Thanks 谢谢
请传递您的gcm帐户的服务器密钥 (如果未生成),请生成它并通过它,它将100%有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.