【发布时间】:2013-05-13 12:41:20
【问题描述】:
我正在尝试向多个用户发送推送通知,当我为 1 个用户执行此操作时,它完美地工作,当我尝试将消息发送给多个用户时出现问题。
我收到了响应 200 MissingRegistration(所以我想问题是我没有以正确的方式发送 ID)
两个 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";
}
【问题讨论】:
标签: php android push-notification google-cloud-messaging