Kan*_*ika 5 php android push-notification android-c2dm
我已经使用google c2dm成功实现了android推送通知.我总是发送一个设备的发布请求,一个设备延迟1-2秒.因此,如果我有1000个设备,我的脚本将需要超过1000秒才能完成对所有设备的推送.
我想知道的是,我们可以将所有设备的发布请求发送到谷歌c2dm吗?如果可以,该怎么办?
我正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
如果我有更多设备,我会像这样循环:
while($row = mysql_fetch_assoc($result)) {
sendMessageToPhone($authCode, $row['deviceRegistrationId'], GOOGLE_MSG_TYPE, $messageText, $infoType, $messageInfo);
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
| 归档时间: |
|
| 查看次数: |
2821 次 |
| 最近记录: |