gcmm.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. @Copyright (C) ansjer cop Video Technology Co.,Ltd.All rights reserved.
  5. @AUTHOR: ASJRD018
  6. @NAME: AnsjerFormal
  7. @software: PyCharm
  8. @DATE: 2019/3/7 10:50
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: gcmm.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. from gcm import GCM
  15. API_KEY = 'AAAAb9YP3rk:APA91bHu8u-CTpcd0g6lKPo0WNVqCi8jZub1cPPbSAY9AucT1HxlF65ZDUko9iG8q2ch17bwu9YWHpK1xI1gHSRXCslLvZlXEmHZC0AG3JKg15XuUvlFKACIajUFV-pOeGRT8tM6-31I'
  16. gcm = GCM(API_KEY)
  17. data = {'param1': 'value1', 'param2': 'value2'}
  18. # Downstream message using JSON request
  19. reg_ids = ['eSooD4fAARg:APA91bEPenBPnSn5aXIQk56QdLOQ1Mu3hevHsekP_0eDpg458y2ZMBP6By2rVsGYIoxZrXxvkkptPKUE9CmUygBxaZXABddUWB9FyLlznRFerC7RG9X5PsEOH58xK9_aTUdkT7p6Ocld']
  20. response = gcm.json_request(registration_ids=reg_ids, data=data)
  21. # Downstream message using JSON request with extra arguments
  22. res = gcm.json_request(
  23. registration_ids=reg_ids, data=data,
  24. collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600
  25. )
  26. # Topic Messaging
  27. topic = 'topic name'
  28. res = gcm.send_topic_message(topic=topic, data=data)
  29. print(res)