3
我试图向多个用户发送推送通知,当我为1个用户完成工作时,问题就出现在我尝试将消息发送给多个用户时。发送推送通知给多个用户android
我得到的回应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";
}