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



好吧,我正在建立一个数据库,其中将使用Ionic作为前端和流明进行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

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

相关内容

最新更新