[英]Send notification by firebase cloud messaging on a topic by django
I have implemented a firebase cloud messaging app which sends a notification to an android device based on its device token which works fine.我已经实现了一个 firebase 云消息传递应用程序,它根据工作正常的设备令牌向 android 设备发送通知。 I've used django-fcm module.
我用过 django-fcm 模块。 But, storing device registration code for each user device is a little difficult in the practical application as I've to modify the front end source code which I don't want to.
但是,在实际应用中为每个用户设备存储设备注册码有点困难,因为我必须修改我不想修改的前端源代码。
Therefor I decided to go with topic messaging.因此,我决定使用主题消息传递 go。 I cannot find any useful documentation regarding this.
我找不到任何有用的文档。
view.py视图.py
def send_notification(registration_id,message_title, message_body):
try:
push_service = FCMNotification(api_key=FCM_DJANGO_SETTINGS['FCM_SERVER_KEY'])
result=push_service.notify_single_device(registration_id=registration_id, message_title=message_title,
message_body=message_body)
return result
except:
pass
def send_noti(request):
device_token = "dEMspOwATpiFVumQGi1QOS:APA91bEZsTu7SbRTYRDGJjhNhHRErYd_UHs43rrPY6uN4yXe5_UHnPpepocFP60wnnU2IImCBXcem0rVuEUj7PCPc9EfkC0W4cLrNSmBCoWM5mz8jp9YgYF-VurJ1JyoRH627IH5Ujxn"
send_notification(device_token,"title","body")
return JsonResponse({"status": "success"}, safe=False)
urls.py网址.py
urlpatterns = [
path('noti/', views.send_noti, name='send_noti'),
]
Can anyone help to send notification on topic using django?任何人都可以帮助使用 django 发送有关主题的通知吗?
Thanks FrankvanPuffelen for your help感谢 FrankvanPuffelen 的帮助
The complete implementation is as follows.完整的实现如下。
views.py视图.py
from fcm_django.fcm import fcm_send_topic_message从 fcm_django.fcm 导入 fcm_send_topic_message
def send_noti_topic(self):
fcm_send_topic_message(topic_name='NEWYORK_WEATHER', message_body='message body', message_title='title')
return JsonResponse({"status": "success"}, safe=False)
urls.py网址.py
urlpatterns = [
path('noti/', views.send_noti_topic, name='send_noti_topic'),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.