如何使用Gp为Android发送使用Php的多个通知和多个设备?帮助我向多个设备发送多个消息
问题描述:
$var = select * from table;
foreach($var as $varliable)
{
$to_device_id = $varliable['id']
$message = array("unread"=>$msg); // storing multiple messages
$device_id = array($to_device_id); // storing multiple device ids
$gcmObj->send_notification($device_id, $message); // this function is called in another page test.php
}
test.php
========
test.php
========
function send_notification($device_id, $message="")
{
$curl = 'https://android.googleapis.com/gcm/send';
// how to replace the device id and messages here.
$field= array(
'registration_ids' => $device_id,
'field' => $message,
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $curl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($field));
$result = curl_exec($ch);
curl_close($ch);
echo $result;
}
答
var = select * 来自 table;
foreach(
var = select * from table; foreach(
var as
varliable)
{
varliable) {