Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
J
jpush-api-python-client
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
jpush-api-python-client
Commits
b49693a5
Commit
b49693a5
authored
May 14, 2014
by
hupantingxue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
JPush API Client 3.0:
1. Optimize test case; 2. Param check;
parent
77f980fc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
5 deletions
+7
-5
push.py
jpush/push.py
+6
-4
test_case1.py
tests/test_case1.py
+1
-1
No files found.
jpush/push.py
View file @
b49693a5
...
...
@@ -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
...
...
tests/test_case1.py
View file @
b49693a5
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment