向 Gcm 发送 1000 多个用户的 Php 函数

标签 php android mysql google-cloud-messaging

我有发送 gcm 的功能代码,它一直有效,直到 token GCM ID 达到 1000 多个用户,它不会发送。

这是我的函数代码。

private static function send_message($title,$url){
    global $wpdb;
    $token = $wpdb->get_results( 'SELECT * FROM '.$wpdb->prefix.'devices', ARRAY_N );
    foreach ($token as $key) {

        $registrationIds[] = $key[1];
    }               
    $msg = array(
    'registrationIds' => $group,
        'message' => $title,
        'url' => $url,
        'title' => 'This is a title. title',
    );
    $fields = array(
        'registration_ids' => $registrationIds,
        'data' => $msg
    );
     $headers = array(
        'Authorization: key=' . FA_API,
        'Content-Type: application/json'
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    $result = curl_exec($ch);                   
    curl_close($ch);   
    return $result;
}

请帮助我如何向超过 1000 个用户发送推送通知。

最佳答案

This parameter specifies a list of devices (registration tokens, or IDs) receiving a multicast message. It must contain at least 1 and at most 1000 registration tokens.

https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json GCM 限制每条消息 1000 个设备。 所以你必须将 $registrationIds 数组拆分成更小的数组。然后循环发送它们。

关于向 Gcm 发送 1000 多个用户的 Php 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40581353/

相关文章:

php - DOMPDF 的自定义字体

c# - Xamarin.Android - 启动画面图像质量低

Android Keystore 的密码保护

android - 如何将 “mapping.txt”文件用于Android版本中的调试和错误异常处理程序

php - PDO 插入不起作用(PHP/MySQL)

php - 仅显示数据库中用户名的字母

php - 数据库查询最终结果显示错误

php - 为什么MAMP不更改php版本

php - 删除带有外键的表

mysql - 仅选择日期/日期时间字段 SQL