首页 技术 正文
技术 2022年11月15日
0 收藏 439 点赞 4,673 浏览 1272 个字

Pyapns 提供了通用的Apple Push Notification Service (APNS)。该解决方案使用了开源的Twisted server,支持原生的Python和Ruby API。 功能:XML-RPC Based, works with any client in any languageNative Python API with Django and Pylons supportNative Ruby API with Rails/Rack supportScalable, fast and easy to distribute behind a proxyBased on TwistedMulti-application and dual environment supportSimplified feedback interface pyapns项目github开源地址:https://github.com/samuraisam/pyapns 安装(使用pip或easy_install安装。会安装Twisted框架)

pip install pyapns或者使用easy_install pyapns

启动twisted

#linux
twistd -r epoll web --class=pyapns.server.APNSServer --port=#mac os
twistd -r kqueue web --class=pyapns.server.APNSServer --port=

新建push.py文件输入下面内容

#!/usr/bin/python
# -*- coding: utf-8 -*
# Filename: push.pyfrom pyapns import configure, provision, notifytokens = ["token1" ,
"token2"]notifications = [
{'aps' :{'alert': 'Hello token 1', 'badge': 0, 'sound': 'flynn.caf'}},
]configure({'HOST': 'http://localhost:7077/'})
provision('myapp', open('developent.pem').read(), 'sandbox')
notify('myapp', tokens, notifications)

pyapns推送消息需要一个pem格式的证书文件,跟Parse里要求一个.p12文件不同啊。我看看怎么搞到这文件。从苹果下载的证书是.cer格式的,在苹果的KeyChain程序中,选择导出,可是,只能选择导出成.cer和.p12文件,.pem的选项被禁用了,好桑心。通过搜索export pem from keychain找到Creating .pem file for APNS?,简单说,就是在KeyChain里导出.p12格式的,再通过下面的命令转换成.pem的。搞定。

openssl pkcs12 -in Development.p12 -out developent.pem -nodes -clcerts

python push.py

推送成功

完成

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900