jgpush.py 933 B

123456789101112131415161718192021222324252627
  1. #-*-coding:utf-8 -*-
  2. import jpush
  3. app_key = "6aba55e8e8dacb49a5290b6e"
  4. master_secret = "257f2f6f8aa62add95accd86"
  5. _jpush = jpush.JPush(app_key, master_secret)
  6. _jpush.set_logging("DEBUG")
  7. push = _jpush.create_push()
  8. def send_notification_by_registration_ids(regids=["171976fa8a0d3dd7c0b"],msg="测试",title=None):
  9. """给指定regid发送消息
  10. """
  11. push.platform = jpush.all_
  12. android_msg = jpush.android(alert=msg,title=title)
  13. ios_msg = jpush.ios(alert={"title":title,"body":msg}, badge="+1", sound=None, extras={'k1':'v1'})
  14. push.notification = jpush.notification(alert=msg,android=android_msg,ios=ios_msg)
  15. push.options = {"time_to_live":86400, "sendno":12345,"apns_production":False}
  16. push.audience = jpush.audience(
  17. jpush.registration_id(*regids)
  18. )
  19. response = push.send()
  20. print response
  21. return response
  22. if __name__ == "__main__":
  23. send_notification_by_registration_ids()