我可以使用php中的GCM推送插件一次向多个设备发送多条消息

时间:2014-09-19 07:38:21

标签: php android cordova push-notification google-cloud-messaging

如何一次向多个设备发送多条消息

$apiKey = "xxxxx";
$registrationIdArray = array('xxx_1','xxx_2'); 
$msg = array('message' => 'message_1','title'=> 'title_1','message' => 'message_2','title'=> 'title_2'); 
$pusher = new Pusher($apiKey); 
$pusher->notify($registrationIdArray, $msg);

1 个答案:

答案 0 :(得分:0)

我已经编辑了我的代码,请使用此

 <?php
 include_once './GCM.php';
$regid = $_POST['regid'];//your registration id array 
$fields1=$_POST['message'];//your message array
$total_message = count($fields1);//count total no of message
$total_records = count($regid);//Count total number of registration id
for($j=0;$j< $total_message;$j++)//loop for sending multiple messgae
{
for($i=0;$i< $total_records;$i++)//loop for sending to multiple device
{
    $registatoin_ids = array($regid[$i]);
    $message = array("price" => $total_message[$j]);
    $result = $gcm->send_notification($registatoin_ids, $message);
}
}
?>