我正在嘗試爲使用php的android創建推送通知。但我堅持在某個地方。我正在使用一個例子。這是我的PHP代碼使用PHP獲取無效的GCM註冊錯誤
Web配置
<?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>
這其中我的代碼使用但每次它告訴我信息 {「multicast_id」:4677806556758130005,「成功」:0,「失敗」:1,「ca nonical_ids 「:0,」 結果 「:[{」 錯誤 「:」 InvalidRegistration「}]}
我DONOT知道我做錯了什麼
我越來越有GCM註冊ID,我必須通過混淆。誰能告訴我這是什麼,並在那裏我發現它
我想我的項目ID和項目數量爲,但我再次得到這個錯誤,並再次
任何幫助表示讚賞
感謝
您的API密鑰無效,這就是爲什麼它會給您錯誤 –
但我從我的谷歌控制檯複製它,然後粘貼它。 –
請genrate新的一個。並檢查它。 –