【问题标题】:Php function to Send Gcm more than 1000 usersphp函数发送Gcm超过1000个用户
【发布时间】:2016-11-14 03:11:08
【问题描述】:

我有发送gcm的功能代码,直到令牌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 个用户发送推送通知。

【问题讨论】:

  • api有速率限制
  • 您可以拨打的电话数量可能有所限制。如果此代码有效,则不是编程问题。
  • 是的,它必须与每 1000 个用户令牌一起发送。它必须使用循环

标签: php android mysql google-cloud-messaging


【解决方案1】:

此参数指定设备列表(注册令牌或 IDs) 接收多播消息。它必须至少包含 1 并且在 最多 1000 个注册令牌。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多