将百度云推送(Push)服务端的所有 API 封装成一个类 BaiduPush,通过对该类的简单初始化,即可调用其内部的各种方法,使用百度云推送服务。
BaiduPush 提供的方法和服务端 API 对应,是对服务端 REST API 的封装,详细的 REST API 请参考 官网API列表 。
代码构成
baidupush/baidupush.py – SDK 脚本,包含对外提供的所有接口
sample/sample.py – 使用 SDK 的 Demo 文件
依赖库
一般规则
所有函数的参数和返回值中如果有中文,必须是UTF-8编码
不需要对函数参数进行urlencode
错误信息见 错误码定义
安装
pip install baidupush
或者
easy_install baidupush
调用方法
from baidupush import BaiduPush, BaiduPushError
apikey = "76Yi0ZBGGV2HrAziIiYEFtRh"
secretkey = "xxxxxxxxxxxxx"
user_id = "1105115563847474869"
channel_id = 3944730196422489622
message = "{'title':'baidu push','description':'message from python sdk'}"
message_key = "key1"
pusher = BaiduPush(apikey, secretkey)
push_type = BaiduPush.PUSH_TO_USER
optional = dict()
optional[BaiduPush.USER_ID] = user_id
optional[BaiduPush.CHANNEL_ID] = channel_id
optional[BaiduPush.MESSAGE_TYPE] = BaiduPush.PUSH_NOTIFICATION
try:
ret = pusher.push_msg(push_type, message, message_key, optional)
except BaiduPushError:
print 'Exception :', err
print ret
版本更迭
该 Python SDK 主要由 luvchh 完成了大部分的工作
第一版:
由 luvchh 提供
第二版:
由 blacklaw0 修改
第三版:
由 gfreezy 修改
第四版:
由 cheng-shiwen 更新
第五版:
由 sinchb 修改
Metadata
Release files for baidupush 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| baidupush-0.1.1.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| baidupush-0.1.1.macosx-10.10-intel.exe | Details |
Total release size: 78.6 kB
Release files / baidupush-0.1.1.tar.gz
| Download URL | baidupush-0.1.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aed238e626327841fe2ba8ba3d5dd7b2e6e4fce043dae7d49b4e0fc95759c73a
|
|
BLAKE2b-256 checksum How to use checksums |
b4d96e0bd5a84160d53d4dfbaabeb52b0777118b7a0ccc4589f809d2b6b5025b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / baidupush-0.1.1.macosx-10.10-intel.exe
| Download URL | baidupush-0.1.1.macosx-10.10-intel.exe |
|---|---|
| Size | 71.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56fca164bca096ddd493c6f6fb236abecf00058ae3eea42785c2f570ad3d7788
|
|
BLAKE2b-256 checksum How to use checksums |
411878a72fc599f2e89e212a8e53a31fe10a0f31f3ab6e93ecc767e0d017daeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |