Пример #1
0
    $msg = $_POST['message'];
    $title = $_POST['title'];
    $cluster = $_POST['cluster'];
    $type = $_POST['type'];
    $event = $_POST['event_name'];
    $gcmpin = $_POST['internalgcmpin'];
    if ($gcmpin == $_ENV["INTERNAL_GCM_PIN"]) {
        $chunk_size = 300;
        $result = $db->get_all($_ENV["GCM_TABLE"]);
        $reg_ids = array();
        while ($row = mysql_fetch_assoc($result)) {
            array_push($reg_ids, $row['gcm_id']);
        }
        $size = sizeof($reg_ids);
        $msg_arr = array("text" => $msg, "title" => $title, "cluster" => $cluster, "type" => $type, "event" => $event);
        $reg_id_chunks = array_chunk($reg_ids, $chunk_size);
        $db = new DB();
        $db->insert($_ENV["MESSAGE_TABLE"], array("message" => $msg, "title" => $title, "type" => $type, "cluster" => $cluster, "event" => $event, "sent_to" => $size));
        for ($i = 0; $i < sizeof($reg_id_chunks); $i++) {
            sendPushNotificationToGCM($reg_id_chunks[$i], $msg_arr);
        }
        $response = array("status_code" => 200, "description" => "Success");
        echo json_encode($response);
    } else {
        $response = array("status_code" => 102, "description" => "Incorrect Pin");
        echo json_encode($response);
    }
} else {
    $response = array("status_code" => 101, "description" => "Incorrect parameters");
    echo json_encode($response);
}
Пример #2
0
    }
    curl_close($ch);
    return $result;
}
//this block is to post message to GCM on-click
$pushStatus = "";
if (!empty($_GET["push"])) {
    $gcmRegIDs = file("GCMRegId.txt");
    for ($i = 0; $i < count($gcmRegIDs); $i++) {
        $gcmRegIDs[$i] = trim($gcmRegIDs[$i]);
    }
    $pushMessage = $_POST["message"];
    $pushTitle = $_POST["title"];
    if (isset($gcmRegIDs)) {
        //$pushStatus = sendPushNotificationToGCM($gcmRegIds, $message);
        $pushStatus = sendPushNotificationToGCM($gcmRegIDs, $pushMessage, $pushTitle);
    }
}
//this block is to receive the GCM regId from external (mobile apps)
if (!empty($_GET["shareRegId"])) {
    $gcmRegID = $_POST["shareRegId"];
    file_put_contents("GCMRegId.txt", $gcmRegID);
    echo "Ok!";
    exit;
}
?>
<html>
    <head>
        <title>Google Cloud Messaging (GCM)</title>
    </head>
 <body>
Пример #3
0
    $result = curl_exec($ch);
    if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }
    curl_close($ch);
    return $result;
}
include_once 'db_functions.php';
$db = new DB_Functions();
$selUsers = $_POST['sendmsg'];
if (empty($selUsers)) {
    echo "You didn't select any users.";
} else {
    $resp = "<tr id='header'><td>GCM Response [" . date("h:i:sa") . "]</td></tr>";
    $userCount = count($selUsers);
    $greetMsg = $_POST['message'];
    $respJson = '{"greetMsg":"' . $greetMsg . '"}';
    $registation_ids = array();
    for ($i = 0; $i < $userCount; $i++) {
        $gcmRegId = $db->getGCMRegID($selUsers[$i]);
        $row = mysql_fetch_assoc($gcmRegId);
        //Add RegIds retrieved from DB to $registration_ids
        /* ummmm, maybe need to update */
        array_push($registation_ids, $row['push_id']);
    }
    // JSON Msg to be transmitted to selected Users
    $message = array("m" => $respJson);
    $pushsts = sendPushNotificationToGCM($registation_ids, $message);
    $resp = $resp . "<tr><td>" . $pushsts . "</td></tr>";
    echo "<table>" . $resp . "</table>";
}
        return $result;
    }
?>
<?php
	
	//this block is to post message to GCM on-click
	$pushStatus = "";	
	if(!empty($_GET["push"])) 
		{	

		$gcmRegID  = file_get_contents("GCMRegId.txt");
		$pushMessage = $_POST["message"];	
		if (isset($gcmRegID) && isset($pushMessage)) {		
			$gcmRegIds = array($gcmRegID);
			$message = array("m" => $pushMessage);	
			$pushStatus = sendPushNotificationToGCM($gcmRegIds, $message);		
		}		
	}
	
	//this block is to receive the GCM regId from external (mobile apps)
	if(!empty($_GET["shareRegId"])) {
		$gcmRegID  = $_POST["regId"]; 
		$gcmRegID = “\r\n”;
		file_put_contents("GCMRegId.txt",$gcmRegID,FILE_APPEND);
		echo "Ok!";
		exit;
	}	
?>
<html>
    <head>
        <title>Google Cloud Messaging (GCM) Server in PHP</title>
Пример #5
0
                notification_type_fr, 
                comment_en, 
                comment_fr) VALUES (' . checkEmpty($deeper[0]) . ', ' . checkEmpty($deeper[1]) . ', "' . checkEmpty($deeper[2]) . '", "' . checkEmpty($deeper[3]) . '", "' . checkEmpty($deeper[4]) . '", "' . checkEmpty($deeper[5]) . '", "' . checkEmpty($deeper[6]) . '", ' . checkEmpty($deeper[7]) . ', "' . checkEmpty($deeper[8]) . '", "' . checkEmpty($deeper[9]) . '", "' . checkEmpty($deeper[10]) . '", "' . checkEmpty($deeper[11]) . '", "' . checkEmpty($deeper[12]) . '", "' . checkEmpty($deeper[13]) . '");';
        // mysqli_query($db, $query);
        //check if any users have new vehicles added and send them a notification
        $query = 'SELECT * FROM users INNER JOIN user_vehicles ON users.id = user_vehicles.user_id WHERE user_vehicles.deleted = 0;';
        $result = mysqli_query($db, $query);
        while ($row = mysqli_fetch_assoc($result)) {
            if (strtolower($row['year']) == strtolower($deeper[1]) && strtolower($row['make']) == strtolower($deeper[5]) && strtolower($row['model']) == strtolower($deeper[6])) {
                $msg = 'Hello ' . $row['username'] . ', your ' . $row['year'] . ' ' . $row['make'] . ' ' . $row['model'] . ' has been associated with a recall';
                echo 'trying to send: ' . $msg;
                $message = array();
                $reg_id = array();
                $message['m'] = '{"greetMsg":"' . $msg . '"}';
                $reg_id[0] = $row['push_id'];
                sendPushNotificationToGCM($reg_id, $message);
                // In case any of our lines are larger than 70 characters, we should use wordwrap()
                $msg = wordwrap($msg, 70, "\r\n");
                $headers = array();
                $headers[] = "MIME-Version: 1.0";
                $headers[] = "Content-type: text/plain; charset=iso-8859-1";
                $headers[] = "From: LemonAide <*****@*****.**>";
                $headers[] = "Reply-To: You <" . $row['email'] . ">";
                $headers[] = "Subject: Recall Notice";
                $headers[] = "X-Mailer: PHP/" . phpversion();
                // Send
                mail($row['email'], 'Recall Alert', $msg, implode("\r\n", $headers));
            }
        }
    }
}