我正在尝试向多个用户发送推送通知,当我为 1 个用户执行此操作时,它可以完美地工作,当我尝试将消息发送给多个用户时问题就来了。
我收到了响应 200 MissingRegistration (所以我想问题是我没有以正确的方式发送 ID)
两个 id 都是正确的,因为如果我将消息分别发送给两者,它就可以工作
这是我的代码
$gcmcodes=array("one user key","the other user key");
if(isset($_GET['mensaje'])) $message = $_GET['mensaje'];
$message2 = new gcm();
$message2->sendMessageToPhone(2, $message,$gcmcodes);
function sendMessageToPhone($collapseKey, $messageText, $gcmcodes)
{
$apiKey = 'My apikey';
$headers = array('Authorization:key=' . $apiKey);
$data = array(
'registration_ids' => $gcmcodes,
'collapse_key' => $collapseKey,
'data.message' => $messageText);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
if ($headers)
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo"<pre>";
var_dump($gcmcode,$response);
echo"</pre>";
if (curl_errno($ch)) {
return 'fail';
}
if ($httpCode != 200) {
return 'status code 200';
}
curl_close($ch);
return "mensaje mandado con exito";
}