Php Android向所有用户发送通知GCM

Php Android向所有用户发送通知GCM,php,android,Php,Android,我想向我的所有用户发送通知,比如使用GCM的5个用户。这就是我迄今为止所尝试的: <?php include 'db.php'; $sql = "SELECT gcm_regid FROM gcm_users"; $stmt = $conn->prepare($sql); $stmt->execute(); $results = array(); while ($row = $stmt->fe

我想向我的所有用户发送通知,比如使用GCM的5个用户。这就是我迄今为止所尝试的:

    <?php

    include 'db.php';

    $sql = "SELECT gcm_regid
        FROM gcm_users";
    $stmt = $conn->prepare($sql);
    $stmt->execute();

    $results = array();

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
        $results[] = $row;
    }


    $message = "This is a multicast message sent to all users!";

    // Set POST variables
    $url = 'https://android.googleapis.com/gcm/send';

    foreach($results as $value) {
      $fields = array(
            'registration_ids' => $value,
            'data' => $message,
        );
    }

    $headers = array(
            'Authorization: key=' . GOOGLE_API_KEY,
            '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);

        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }

        // Close connection
        curl_close($ch);
        echo $result;



?>

但我没有取得任何成功。有什么想法吗?非常感谢你的帮助