From 6c1bdc15f1d318243c55e2667f771409b392600e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=87=E1=85=A1=E1=86=A8=E1=84=89=E1=85=B3=E1=86=BC?= =?UTF-8?q?=E1=84=92=E1=85=A9?= Date: Thu, 20 Jun 2024 23:51:02 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20fcm=20HTTP=20->=20HTTP=20=20v1=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B2=84=EC=A0=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/fastapi/app/fcm_notification.py | 26 ++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/fastapi/app/fcm_notification.py b/backend/fastapi/app/fcm_notification.py index e9f8384d..a5a072fb 100644 --- a/backend/fastapi/app/fcm_notification.py +++ b/backend/fastapi/app/fcm_notification.py @@ -1,18 +1,34 @@ -from pyfcm import FCMNotification +import firebase_admin +from firebase_admin import credentials +from firebase_admin import messaging + from .config import Config -push_service = FCMNotification(Config.fcm_server_key) +cred_path = Config.cred_path +cred = credentials.Certificate(cred_path) +firebase_admin.initialize_app(cred) + async def send_push_notification(token, title, body, data): - result = push_service.notify_single_device( + '''result = push_service.notify_single_device( registration_id=token, message_title=title, message_body=body, data_message=data + )''' + + message = messaging.Message( + notification=messaging.Notification( + title=title, + body=body + ), + data=data, + token=token ) - print("[INFO] push notification sent") - return result + response = messaging.send(message) + + print('Successfully sent message:', response)