function sendGCM($UserID, $message, $mysqli ) {
if ($stmt = $mysqli->prepare("SELECT id FROM devices WHERE name = ?"))
{
$stmt->bind_param('s', $UserID);
$stmt->execute(); // Execute the prepared query.
$stmt->store_result();
$stmt->bind_result($myid);
$stmt->fetch();
if($stmt->num_rows > 0){
ChromePhp::log("Num Rows ".$stmt->num_rows);
ChromePhp::log("Reg ID ".$myid);
} else {
ChromePhp::log("No Rows ".$stmt->num_rows);
}
}
else {
ChromePhp::log("Could not execute stmt ");
}
// $query = "SELECT id From devices Where name=$UserID"; // this wasn't working.....
// $row = mysql_fetch_object(mysql_query($query));
// Replace with real BROWSER API key from Google APIs
$apiKey = "AIzaSyAwskhHCz7l-my real browser key from Google"; // Browser Key
ChromePhp::log("apikey ".$apiKey);
// Replace with real client registration IDs
$registrationIDs = array( $myid );
ChromePhp::log("User Name ".$UserID);
ChromePhp::log("Message ".$message);
// Set POST variables
$url = "https://android.googleapis.com/gcm/send";
ChromePhp::log("url ".$url);
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "data" => $message ),
);
$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_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
// Execute post
$result = curl_exec($ch);
ChromePhp::log("result: ".$result);
// Close connection
curl_close($ch);
}