我已成功使用Google C2DM实现了Android推送通知。我总是为设备发送一个POST请求,而且一个设备需要延迟1-2秒。所以,如果我有1000个设备,我的脚本将需要超过1000秒才能完成对所有设备的推送。
我想知道的事情是,我们能否向Google C2DM发送所有设备的POST请求?如果可以,应该如何操作?
我正在使用PHP脚本。
以下是我向设备推送消息的代码:
我想知道的事情是,我们能否向Google C2DM发送所有设备的POST请求?如果可以,应该如何操作?
我正在使用PHP脚本。
以下是我向设备推送消息的代码:
function sendMessageToPhone($authCode, $deviceRegistrationId, $msgType, $messageText, $infoType, $messageInfo) {
$headers = array('Authorization: GoogleLogin auth=' . $authCode);
$data = array(
'registration_id' => $deviceRegistrationId,
'collapse_key' => $msgType,
'data.message' => $messageText,
'data.type' => $infoType,
'data.data' => $messageInfo
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/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);
curl_close($ch);
return $response;
}
如果我有更多的设备,我会像这样循环它:
while($row = mysql_fetch_assoc($result)) {
sendMessageToPhone($authCode, $row['deviceRegistrationId'], GOOGLE_MSG_TYPE, $messageText, $infoType, $messageInfo);
}
感谢您的帮助。