我正在尝试将推送发送到我的应用并使用该网站进行测试:http://www.pushwatch.com/gcm/
首先尝试收到成功消息,然后收到错误消息:NotRegistered。
与该代码相同的结果:
<html>
<form method="post" action="test.php">
id : <input type="text" name="id"/><br/>
message : <input type="text" name="message"/><br/>
<input type="submit" value="Envoyer"/>
</form>
if (isset($_POST["message"])) {
$message = $_POST["message"];
$registrationIds = $_POST["id"];
echo "CALL<br/>";
echo "message = ".$message." / ids = ".$registrationIds."<br/><br/>";
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'AIza....' );
// prep the bundle
$msg = array
(
'message' => $message,
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'to' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://gcm-http.googleapis.com/gcm/send' );
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<br/>";
echo $result;
}
答案 0 :(得分:0)
根据此forum:
尝试以下变通办法检查这些相关的SO问题: