示例#1
0
/**
 * recipients: the user and possibly every user in the user's groups
 */
function sendSyncMessage($userId, $sendToGroup = false)
{
    $user = User::findOrFail($userId);
    $recipientIds = array($user->gcm_id);
    if ($sendToGroup) {
        $groups = $user->groups()->with('users')->get();
        foreach ($groups as $group) {
            foreach ($group->users as $groupUser) {
                // add user's gcm registration id to recipients
                if ($groupUser->gcm_id) {
                    array_push($recipientIds, $groupUser->gcm_id);
                }
            }
        }
    }
    sendGoogleCloudMessage('refresh', array_unique($recipientIds));
}
function prepareNotificationOneClueOneNotice($clue_id, $notice_id)
{
    $con = mysqli_connect("localhost", "root", "1212312121", "proj4d");
    mysqli_set_charset($con, "utf8");
    $notify_data = array();
    $notify_ids = array();
    $adder_notice = array();
    $query = "SELECT A.adder, A.name, B.token FROM notice_detail AS A, gcm_token_list AS B WHERE A.id = ? AND A.adder = B.username";
    $statement = mysqli_prepare($con, $query);
    mysqli_stmt_bind_param($statement, "s", $notice_id);
    $success = mysqli_stmt_execute($statement);
    mysqli_stmt_store_result($statement);
    mysqli_stmt_bind_result($statement, $adder, $lostName, $token);
    mysqli_stmt_fetch($statement);
    array_push($notify_ids, $token);
    $adder_notice["" . $adder] = "" . $notice_id . "," . $lostName;
    $notify_data["clue_id"] = $clue_id;
    $notify_data["notice_id_data"] = json_encode($adder_notice);
    mysqli_stmt_close($statement);
    mysqli_close($con);
    return sendGoogleCloudMessage($notify_data, $notify_ids);
}
示例#3
0
//------------------------------
<?php 
$data = array('message' => 'Hello World!');
//------------------------------
// The recipient registration IDs
// that will receive the push
// (Should be stored in your DB)
//
// Read about it here:
// http://developer.android.com/google/gcm/
//------------------------------
$ids = array('abc', 'def');
//------------------------------
// Call our custom GCM function
//------------------------------
sendGoogleCloudMessage($data, $ids);
//------------------------------
// Define custom GCM function
//------------------------------
function sendGoogleCloudMessage($data, $ids)
{
    //------------------------------
    // Replace with real GCM API
    // key from Google APIs Console
    //
    // https://code.google.com/apis/console/
    //------------------------------
    $apiKey = 'abc';
    //------------------------------
    // Define URL to GCM endpoint
    //------------------------------
</html>

<?php 
$message = $_POST['message'];
$token_ids = $_POST['token'];
$gl_api_key = $_POST['api_key'];
// Payload data you want to send to Android device(s)
// (it will be accessible via intent extras)
$data = array('message' => $message);
// The recipient registration tokens for this notification
// http://developer.android.com/google/gcm/
$ids = array($token_ids);
// Send a GCM push
// sendGoogleCloudMessage(  $data, $ids );
if (!empty($_POST['token'])) {
    sendGoogleCloudMessage($gl_api_key, $data, $ids);
}
function sendGoogleCloudMessage($gl_api_key, $data, $ids)
{
    // Insert real GCM API key from Google APIs Console
    // https://code.google.com/apis/console/
    $apiKey = $gl_api_key;
    // Define URL to GCM endpoint
    $url = 'https://gcm-http.googleapis.com/gcm/send';
    // Set GCM post variables (device IDs and push payload)
    $post = array('registration_ids' => $ids, 'data' => $data);
    // Set CURL request headers (authentication and type)
    $headers = array('Authorization: key=' . $apiKey, 'Content-Type: application/json');
    // Initialize curl handle
    $ch = curl_init();
    // Set URL to GCM endpoint
 * Time: 2:43 PM
 */
//------------------------------
// The recipient registration IDs
// that will receive the push
// (Should be stored in your DB)
//
// Read about it here:
// http://developer.android.com/google/gcm/
//------------------------------
$sid = (include "config.php");
$ids = array($sid);
//------------------------------
// Call our custom GCM function
//------------------------------
sendGoogleCloudMessage($ids);
//------------------------------
// Define custom GCM function
//------------------------------
function sendGoogleCloudMessage($ids)
{
    //------------------------------
    // Replace with real GCM API
    // key from Google APIs Console
    //
    // https://code.google.com/apis/console/
    //------------------------------
    $apiKey = 'AIzaSyA2mQ2mrDc3p0Jistx1Ts7tBBO3FyqS9Go';
    //------------------------------
    // Define URL to GCM endpoint
    //------------------------------
示例#6
0
 private function enviarNotificacion($json, $nombreFestival)
 {
     $nombreArtista = $json->nombre;
     var_dump($nombreFestival);
     // Payload data you want to send to Android device(s)
     // (it will be accessible via intent extras)
     $data = array('message' => 'Confirmado ' . $nombreArtista . ' para el ' . $nombreFestival);
     // The recipient registration tokens for this notification
     // http://developer.android.com/google/gcm/
     $ids = array('APA91bHaqoyJq7eytgHqNbX-f8VYxqlMKn-TRLeunEdtACejrEgDZSqTcPQCOb9foiOifbw_KgKzsptQ03pIDy9se9F3VKghqcCZJTdsovHqjfdnCec4vkf6Y_A0a9bWIvA7txrpi5e4');
     function sendGoogleCloudMessage($data, $ids)
     {
         // Insert real GCM API key from Google APIs Console
         // https://code.google.com/apis/console/
         $apiKey = 'AIzaSyBqawIq9yiMPaBTQifXddx9JUMTP6I8pwU';
         // Define URL to GCM endpoint
         $url = 'https://gcm-http.googleapis.com/gcm/send';
         // Set GCM post variables (device IDs and push payload)
         $post = array('registration_ids' => $ids, 'data' => $data);
         // Set CURL request headers (authentication and type)
         $headers = array('Authorization: key=' . $apiKey, 'Content-Type: application/json');
         // Initialize curl handle
         $ch = curl_init();
         // Set URL to GCM endpoint
         curl_setopt($ch, CURLOPT_URL, $url);
         // Set request method to POST
         curl_setopt($ch, CURLOPT_POST, true);
         // Set our custom headers
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         // Get the response back as string instead of printing it
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         // Set JSON post data
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));
         // Actually send the push
         $result = curl_exec($ch);
         // Error handling
         if (curl_errno($ch)) {
             echo 'GCM error: ' . curl_error($ch);
         }
         // Close curl handle
         curl_close($ch);
         // Debug GCM response
         echo $result;
     }
     // Send a GCM push
     sendGoogleCloudMessage($data, $ids);
 }