Commit b49693a5 authored by hupantingxue's avatar hupantingxue

JPush API Client 3.0:

    1. Optimize test case;
	2. Param check;
parent 77f980fc
......@@ -21,14 +21,16 @@ class JPushClient:
'''Push API for all kinds of message and notification,
dict params restore all parameters'''
try:
send_param=json.loads(params)
send_param=json.dumps(params)
except Exception as e:
print 'params should be json object ', e
try:
base64string = base64.encodestring('%s:%s' % (self.app_key, self.master_secret))[:-1]
req = urllib2.Request(API_URL)
req.add_header("Authorization", "Basic %s" % base64string)
api_post = urllib2.urlopen(req, urllib.urlencode(send_param), timeout=5)
api_post = urllib2.urlopen(req, urllib.urlencode(params), timeout=5)
print api_post.read()
except ValueError as e:
print 'params should be json format ', e
except Exception as e:
print 'send message fail ', e
......
......@@ -8,7 +8,7 @@ from jpush import JPushClient
sendno = int(time.time())
app_key = 'dd1066407b044738b6479275'
master_secret = '2b38ce69b1de2a7fa95706ea'
msg_json = '''{"platform":"all","audience":"all", "notification":{"android":{"alert":"Pall Nandroid alert"}},"options":{"time_to_live":60, "sendno":%d}}''' %(sendno)
msg_json = {"platform":"all","audience":"all", "notification":{"android":{"alert":"Pall Nandroid alert"}},"options":{"time_to_live":60, "sendno":sendno, "apns_production":True}}
jpush_client = JPushClient(app_key, master_secret)
jpush_client.send_msg(msg_json)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment