有没有办法将 FCM 推送通知发送到我在本地数据库中的所有电子邮件地址

Is there a way to send FCM push notification to all the email address i have in my local database

好吧,我正在建立一个数据库,其中将使用 ionic 作为前端和 lumen 来存储用户详细信息以进行 API 调用。我担心的是,我能否使用数据库中的电子邮件信息向所有使用我的应用程序的人发送推送通知。可以吗

以下是我正在尝试执行的代码:

public function send_notification_all(Request $request){

    $this->validate($request, [
        'title' => 'required|max:30|min:20',
        'message' => 'required'
        ]);

    $noti_title = $request->input('title');
    $noti_body = $request->input('message');

    $optionBuilder = new OptionsBuilder();
    $optionBuilder->setTimeToLive(60*20);

    $notificationBuilder = new PayloadNotificationBuilder($noti_title);
    $notificationBuilder->setBody($noti_body)
                        ->setSound('default');

    $dataBuilder = new PayloadDataBuilder();
    $dataBuilder->addData(['a_data' => 'my_data']);

    $option = $optionBuilder->build();
    $notification = $notificationBuilder->build();
    $data = $dataBuilder->build();
    $email = User::pluck('email')->toArray();
    $downstreamResponse = FCM::sendTo($email, $option, $notification, $data);

    $downstreamResponse->numberSuccess();
    $downstreamResponse->numberFailure();
    $downstreamResponse->numberModification();

    if($downstreamResponse->numberSuccess() == 0 ){
        return $this->errorResponse("unable to send notificaton to all",401);
    }else {
        return $this->successResponse(['msg' => 'message send successfully','successfull' => $downstreamResponse->numberSuccess(),'failures' => $downstreamResponse->numberFailure()]);
    }
}

只需要这样的意见,如果有任何错误或我必须在我的代码中进行更改,请告诉我。等待正面回应和指导

不能使用他们的电子邮件地址发送通知。

您应该在您的数据库中保存每个注册用户的 fcm_token。我建议使用以下包并阅读其中的文档:Laravel-FCM

如果设备请求,您还应该注意刷新令牌。