我有功能代码发送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个用户的推送通知。
答案 0 :(得分:1)
此参数指定设备列表(注册令牌,或 ID)接收多播消息。它必须包含至少1和at 大多数1000个注册令牌。
https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json
GCM每封邮件限制1000个设备。
因此,您必须将$registrationIds
数组拆分为较小的数组。然后将它们循环送出。