Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#极光推送Python API V2


```
callback_url = ''
app_key = 'cd4f398315d09bxxxxxxxxxx'
app_secret = 'ad59ef62403130xxxxxxxxxx'

imei = '353918059xxxxxx'

#唯一编号
sendno = 222
desc = '测试薇密jpush推送'
title = '薇密安卓测试'
content = '薇密安卓推送测试 python api'

jp = jpush.JpushClient(app_key, app_secret, callback_url)
jp.send_notification_with_imei(imei, app_key, sendno, desc, title, content, 'android')

```

www.weimi.com

By Henter
38 changes: 18 additions & 20 deletions jpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def __init__(self, username, password, callback_url=""):
self.username = username
self.password = password
self.callback_url = callback_url
self.url = "http://api.jpush.cn:8800/sendmsg/sendmsg"
self.url = "http://api.jpush.cn:8800/sendmsg/v2/sendmsg"

def build_params(self, kargs):
params = {}
params["username"] = self.username
params["callback_url"] = self.callback_url
params["sendno"] = kargs["sendno"]
params["appkeys"] = kargs["appkeys"]
params["app_key"] = kargs["app_key"]
params["receiver_type"] = kargs["receiver_type"]
params["receiver_value"] = kargs["receiver_value"]
params["verification_code"] = kargs["verification_code"]
Expand All @@ -41,14 +41,13 @@ def build_content(self, title, content, type):

def generate_verification_code(self, sendno, receiver_type, receiver_value):
m = hashlib.md5()
m2 = hashlib.md5()
m.update(self.password)
input = "%s%d%d%s%s" % (self.username, sendno, receiver_type, receiver_value, m.hexdigest().upper())
m2.update(input)
return m2.hexdigest().upper()
str = "%d%s%s%s" % (sendno, receiver_type, receiver_value, self.password)
m.update(str)
return m.hexdigest().upper()


def send_notification_with_imei(self, imei, appkeys, sendno,

def send_notification_with_imei(self, imei, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send notification with imei id'''
Expand All @@ -61,7 +60,7 @@ def send_notification_with_imei(self, imei, appkeys, sendno,
self.send_msg(params)


def send_custom_msg_with_imei(self, imei, appkeys, sendno,
def send_custom_msg_with_imei(self, imei, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send custom message with imei id'''
Expand All @@ -74,7 +73,7 @@ def send_custom_msg_with_imei(self, imei, appkeys, sendno,
self.send_msg(params)


def send_notification_with_tag(self, tag, appkeys, sendno,
def send_notification_with_tag(self, tag, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send notification with tag'''
Expand All @@ -87,7 +86,7 @@ def send_notification_with_tag(self, tag, appkeys, sendno,
self.send_msg(params)


def send_custom_msg_with_tag(self, tag, appkeys, sendno,
def send_custom_msg_with_tag(self, tag, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send custom message with tag'''
Expand All @@ -100,7 +99,7 @@ def send_custom_msg_with_tag(self, tag, appkeys, sendno,
self.send_msg(params)


def send_notification_with_alias(self, alias, appkeys, sendno,
def send_notification_with_alias(self, alias, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send notification with alias'''
Expand All @@ -113,7 +112,7 @@ def send_notification_with_alias(self, alias, appkeys, sendno,
self.send_msg(params)


def send_custom_msg_with_alias(self, alias, appkeys, sendno,
def send_custom_msg_with_alias(self, alias, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send custom message with alias'''
Expand All @@ -126,7 +125,7 @@ def send_custom_msg_with_alias(self, alias, appkeys, sendno,
self.send_msg(params)


def send_notification_with_appkey(self, appkeys, sendno,
def send_notification_with_appkey(self, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send notification with appkey'''
Expand All @@ -139,7 +138,7 @@ def send_notification_with_appkey(self, appkeys, sendno,
self.send_msg(params)


def send_custom_msg_with_appkey(self, appkeys, sendno,
def send_custom_msg_with_appkey(self, app_key, sendno,
senddes, msgtitle,
msg_content, device):
'''Send custom message with appkey'''
Expand All @@ -159,13 +158,12 @@ def send_msg(self, params):
data = urllib.urlencode(params),
url = self.url
)
except:
print "网络无法访问"
else:
result = json.loads(f.read())
f.close()

if result.get("errcode") == 0:
print u"发送成功, sendNo=%s" % result.get("sendno")
else:
print u"发送失败,错误代码=%s, 错误消息=%s" % (result.get("errcode"), result.get("errmsg"))
finally:
f.close()
except:
print "网络无法访问"
21 changes: 15 additions & 6 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
#coding=utf-8
import jpush

SENDNO = 111
DES="description"
TITLE="Python API"
CONTENT="Testing Python API"
callback_url = ''
app_key = 'cd4f398315d09bxxxxxxxxxx'
app_secret = 'ad59ef62403130xxxxxxxxxx'

imei = '353918059xxxxxx'

#唯一编号
sendno = 222
desc = '测试薇密jpush推送'
title = '薇密安卓测试'
content = '薇密安卓推送测试 python api'

jp = jpush.JpushClient(app_key, app_secret, callback_url)
jp.send_notification_with_imei(imei, app_key, sendno, desc, title, content, 'android')

jp = jpush.JpushClient('username', 'password', 'url')
jp.send_notification_with_tag('tags', 'appkeys', SENDNO, DES, TITLE, CONTENT, 'android')