0

我开发了一个使用 Django rest 框架作为后端的移动应用程序的 api。现在我想为用户创建通知。每当管理员添加新课程时,登录用户都会收到通知。

这是一个课程模型

class Lesson(models.Model):
    course = models.ForeignKey(Course, related_name='lcourse', on_delete=models.CASCADE, 
  null=True, blank=True)
    name = models.CharField(max_length=200)
    description = models.TextField(null=True, blank=True)
    image = models.ImageField(upload_to='lesson/', null=True, blank=True)


    def __str__(self):
        return self.name 
4

1 回答 1

0

尝试这个:

pip install pyfcm

OR

pip install git+git://github.com/olucurious/PyFCM.git

例子:

# Send to single device.
from pyfcm import FCMNotification

push_service = FCMNotification(api_key="<api-key>")

registration_id = "<device registration_id>"
message_title = "Uber update"
message_body = "Hi john, your customized news for today is ready"
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body)

# Send to multiple devices by passing a list of ids.
registration_ids = ["<device registration_id 1>", "<device registration_id 2>", ...]
message_title = "Uber update"
message_body = "Hope you're having fun this weekend, don't forget to check today's news"
result = push_service.notify_multiple_devices(registration_ids=registration_ids, message_title=message_title, message_body=message_body)

print result

你只需要使用firebase。从他们和您的 device_registration_id 或 device_token 获取 api 密钥,您就完成了。

更多您可以点击以下链接

于 2021-05-05T04:57:16.213 回答