FCM(Firebase云消息传递)使用唯一的参数发送到多个设备

时间:2019-03-12 14:56:54

标签: php firebase curl firebase-cloud-messaging

我需要使用FCM向成千上万的用户发送推送通知,每个用户都必须标记有唯一的ID,并且我必须知道确切地单击了该消息的人。对于我的目标,我使用PHP和CURL。这里是一个代码示例:

$data = [
                    'title' => $title,
                    'body'=>$body,
                    'priority'=>$priority,
                    'icon' => $icon,
                    'click_action' => "example.com",
                    'requireInteraction'=> true
            ];

            if($image){
                $data['image'] = $image;
            }

            $request_body = [
                'registration_ids' =>$recipients, //Here 999 user tokens
                "content_available"=>false,
                'data' => $data,
            ];
            $fields = json_encode($request_body);

            $request_headers = [
                'Content-Type: application/json',
                'Authorization: key=' . $API_KEY,
            ];

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
            curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            $response = curl_exec($ch);
            curl_close($ch);

我如何才能检测到谁以及使用哪个令牌/用户ID单击邮件? 结果,我需要向每个FCM消息传递一个唯一的参数 预先谢谢你。

0 个答案:

没有答案