$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 }
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; }
$fields = array( 'registration_ids' => $device_id, 'data' => $message ); // other code curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)