如果超过一定数量的用户,PHP通知功能将不正确

如果超过一定数量的用户,PHP通知功能将不正确,php,android,api,push-notification,Php,Android,Api,Push Notification,以下代码适用于2或3个用户,只要我将查询限制为3人。当我为2000人试用时,它不再发送通知。我还收到成功:0的响应 public function send_notification($registatoin_ids, $message) { // Set POST variables $googleapikey="AIzaSyCeFfqiRt3xFzZH2XDwICJDZkasF7uWBJI"; $url = 'htt

以下代码适用于2或3个用户,只要我将查询限制为3人。当我为2000人试用时,它不再发送通知。我还收到成功:0的响应

public function send_notification($registatoin_ids, $message) {

            // Set POST variables

            $googleapikey="AIzaSyCeFfqiRt3xFzZH2XDwICJDZkasF7uWBJI";
            $url = 'https://android.googleapis.com/gcm/send';



            $fields = array(
                    'registration_ids'  => $registatoin_ids,
                    'data'              =>  $message,
                    );


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

            $result1=json_decode($result);



    }
我还使用上面的函数调用下面的函数来发送通知。我的问题是,当只有2或3个用户时,它可以工作,但当用户的数量超过2000时,它就不能按预期工作(发送通知)


据我所知,我们一次最多可以从GCM发送1000个通知,因此,如果您想发送更多的通知,请将用户数量分成1000个组,并以这种方式发送请求

例如:
如果你想发送2000个通知,那么打2个电话,每个电话的ID为1000个用户。

据我所知,我们一次最多可以从GCM发送1000个通知,因此如果你想发送更多的通知,请将用户数分成1000个组,并以这种方式发送请求

例如:
如果你想发送2000个通知,那么打2个电话,每个电话的ID为1000个用户。

我建议你使用
Firebase云消息
,因为这是
谷歌云消息的演变。
尝试使用以下方法:

    $message = array ("message" => $bodyMail, "to" => $to, "From" => $from);
$id = array($to);
$message_status = sendPushNotification( $message, $id );

echo $message_status;

// Send push notification via Firebase Cloud Messaging


function sendPushNotification( $data, $ids )
{
    // Insert real FCM API key from the Google APIs Console

    $apiKey = "YourApiKey";
    // Set POST request body
    $fields = array(
        'registration_ids'  => $ids,
        'data'              => $data
    );

    // Set CURL request headers
    $headers = array(
        'Authorization: key =' . $apiKey,
        'Content-Type: application/json'
    );

    // Initialize curl handle
    $ch = curl_init();

    // Set URL to GCM push endpoint
    curl_setopt( $ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );

    // Set request method to POST
    curl_setopt( $ch, CURLOPT_POST, true );

    // Set custom request 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( $fields ) );

    // Actually send the request
    $result = curl_exec( $ch );

    // Handle errors
    if ( curl_errno( $ch ) )
    {
        echo 'FCM error: ' . curl_error( $ch );
    }

    // Close curl handle
    curl_close( $ch );

    // Debug GCM response
    return $result;
}

我建议您使用
Firebase云消息
,因为它是
谷歌云消息的演变。
尝试使用以下方法:

    $message = array ("message" => $bodyMail, "to" => $to, "From" => $from);
$id = array($to);
$message_status = sendPushNotification( $message, $id );

echo $message_status;

// Send push notification via Firebase Cloud Messaging


function sendPushNotification( $data, $ids )
{
    // Insert real FCM API key from the Google APIs Console

    $apiKey = "YourApiKey";
    // Set POST request body
    $fields = array(
        'registration_ids'  => $ids,
        'data'              => $data
    );

    // Set CURL request headers
    $headers = array(
        'Authorization: key =' . $apiKey,
        'Content-Type: application/json'
    );

    // Initialize curl handle
    $ch = curl_init();

    // Set URL to GCM push endpoint
    curl_setopt( $ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );

    // Set request method to POST
    curl_setopt( $ch, CURLOPT_POST, true );

    // Set custom request 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( $fields ) );

    // Actually send the request
    $result = curl_exec( $ch );

    // Handle errors
    if ( curl_errno( $ch ) )
    {
        echo 'FCM error: ' . curl_error( $ch );
    }

    // Close curl handle
    curl_close( $ch );

    // Debug GCM response
    return $result;
}

是创建批处理并发送批处理。是创建批处理并发送批处理。