fcm_notification.py 693 B

123456789101112131415161718192021222324
  1. import requests
  2. url = "https://fcm.googleapis.com/fcm/send"
  3. def send_notification(user_obj,title,body):
  4. try:
  5. if 'token_id' in user_obj:
  6. payload={
  7. "to" : user_obj['token_id'],
  8. "collapse_key" : "type_a",
  9. "notification" : {
  10. "body" : body,
  11. "title": title
  12. }
  13. }
  14. headers = {
  15. 'Content-Type': 'application/json',
  16. 'Authorization': 'key= AIzaSyDPCiE4_KysqE2necy9dokclU9ocINEsSw'
  17. }
  18. response = requests.request("POST", url, headers=headers, data=payload)
  19. except Exception as err:
  20. print(err)