我希望有一个人可以帮助我!对不起我的英语;)我有以下 PHP 代码:
//Android - Push Notification Variables
$apiKey = '';
//Android - Push Notification Service
$registrationIDs = array();
$abfrage = "SELECT id, registrationId, active FROM `push-android` WHERE active = 'true'";
$ergebnis = mysql_query($abfrage) or die(mysql_error());
while($row = mysql_fetch_object($ergebnis))
{
$id = $row->id;
$registrationIDs[] = $row->registrationId;
}
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
$headers = array(
'Authorization: key='.$apiKey,
'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_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
$obj = json_decode($result);
$return = $obj->{'failure'};
print_r($obj);
?>
那么,我能做些什么来获得 GCM 的正确响应以从我的数据库中删除无效的 registrationID?我已经在我的 Android 手机上安装了该应用程序,发送了一个通知,一切正常。在我卸载应用程序后,发送通知,回复说:
stdClass 对象 ( [multicast_id] => 8.6408433884968E+18 [success] => 1 [failure] => 0 [canonical_ids] => 0 [results] => 数组 ( [0] => stdClass Object ( [message_id] => 0:13813433954546524%df6f31cff9fd7ecd)))