Skip to content

Instantly share code, notes, and snippets.

@Kingson
Created April 7, 2014 15:34

Revisions

  1. Kingson revised this gist Apr 7, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pyAPNS.py
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@
    import binascii

    # 请替换为自己的设备的deviceToken
    deviceToken = binascii.unhexlify("7e7786bcfc56a8dd2ca212f0e1c5ae5bffd25220e1d2eaaee651ddf46d780532")
    deviceToken = binascii.unhexlify("********")

    #创建通知对象
    notification = APNSNotification()
  2. Kingson created this gist Apr 7, 2014.
    28 changes: 28 additions & 0 deletions pyAPNS.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #! /usr/bin/env python
    # coding=utf-8
    """
    1. 这是一段使用APNSWrapper[https://code.google.com/p/apns-python-wrapper/]实现的发送Apple Push的代码,
    其中的deviceToken需要替换为自己设备的deviceToken,pem_cert也需要替换为自己应用的P12证书;
    2. 具体的获取设备的deviceToken的方法和导出P12证书的方法,
    请参考这篇文章[http://www.cnblogs.com/sunnyxx/archive/2012/12/01/2796461.html]
    """
    __author__ = 'jszhou'

    from APNSWrapper import *
    import binascii

    # 请替换为自己的设备的deviceToken
    deviceToken = binascii.unhexlify("7e7786bcfc56a8dd2ca212f0e1c5ae5bffd25220e1d2eaaee651ddf46d780532")

    #创建通知对象
    notification = APNSNotification()
    notification.token(deviceToken)
    notification.alert("土豪,我们做朋友吧")
    notification.badge(5)
    notification.sound()

    #创建发送通知的这个wrapper
    pem_cert_name = "production.p12" # 需要使用自己应用的P12证书
    wrapper = APNSNotificationWrapper(pem_cert_name, False)
    wrapper.append(notification)
    wrapper.notify()