spnsss.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/1/3 16:46
  9. @Version: python3.6
  10. @MODIFY DECORD:ansjer dev
  11. @file: spnsss.py
  12. @Contact: chanjunkai@163.com
  13. """
  14. from gcm import GCM
  15. gcm = GCM(API_KEY)
  16. data = {'param1': 'value1', 'param2': 'value2'}
  17. # Downstream message using JSON request
  18. reg_ids = ['token1', 'token2', 'token3']
  19. response = gcm.json_request(registration_ids=reg_ids, data=data)
  20. # Downstream message using JSON request with extra arguments
  21. res = gcm.json_request(
  22. registration_ids=reg_ids, data=data,
  23. collapse_key='uptoyou', delay_while_idle=True, time_to_live=3600
  24. )
  25. # Topic Messaging
  26. topic = 'topic name'
  27. gcm.send_topic_message(topic=topic, data=data)
  28. exit()
  29. import time
  30. import apns2
  31. from var_dump import var_dump
  32. daytime = time.strftime("%Y%m%d%H%M", time.localtime(time.time()))
  33. print(daytime)
  34. cli = apns2.APNSClient(mode="dev", client_cert="apns-dev.pem", password='111111')
  35. alert = apns2.PayloadAlert(body="test!", title="title!")
  36. payload = apns2.Payload(alert=alert)
  37. n = apns2.Notification(payload=payload, priority=apns2.PRIORITY_LOW)
  38. response = cli.push(n=n, device_token="34f057ea415333732aa2347af7f3600fab771b3cd924ad1d1e27aa66b9c280e8",
  39. topic='com.ansjer.zsavcloud')
  40. var_dump(response)
  41. assert response.status_code == 200, response.reason
  42. assert response.apns_id