/** #######################SEND NOTIFICATION ##########################**/
$selUserDeviceTokenQryStr = "SELECT device_token FROM usermst WHERE userid = '$userid'";
$selUserDeviceTokenQry = mysql_query($selUserDeviceTokenQryStr);
$deviceToken = array();
while($selUserDeviceTokenRes = mysql_fetch_array($selUserDeviceTokenQry))
{
$deviceToken[] = $selUserDeviceTokenRes['device_token'];
}
if(!empty($deviceToken))
{
$apiKey = "AIzaSyD3nnefwyCsN22tp3rUga_8mbSEc4mv8eQ";
$notificationMsg = "Hi".$advertrate." How are u friendes ".$advertnm." welcome";
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $deviceToken,
'data' => array("message" => $notificationMsg, "title" => 'Hi Friendes Happy new year',"bedge" => 3, "type" => "1"),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
curl_close($ch); // Close connection
}
/** #######################SEND NOTIFICATION ##########################**/
$selUserDeviceTokenQryStr = "SELECT device_token FROM usermst WHERE userid = '$userid'";
$selUserDeviceTokenQry = mysql_query($selUserDeviceTokenQryStr);
$deviceToken = array();
while($selUserDeviceTokenRes = mysql_fetch_array($selUserDeviceTokenQry))
{
$deviceToken[] = $selUserDeviceTokenRes['device_token'];
}
if(!empty($deviceToken))
{
$apiKey = "AIzaSyD3nnefwyCsN22tp3rUga_8mbSEc4mv8eQ";
$notificationMsg = "Hi".$advertrate." How are u friendes ".$advertnm." welcome";
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $deviceToken,
'data' => array("message" => $notificationMsg, "title" => 'Hi Friendes Happy new year',"bedge" => 3, "type" => "1"),
);
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
curl_close($ch); // Close connection
}
/** #######################SEND NOTIFICATION ##########################**/
0 comments:
Post a Comment