Created
April 1, 2014 01:56
-
-
Save zs1621/9906288 to your computer and use it in GitHub Desktop.
test-igetui-coroutine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding:utf-8 -*- | |
# | |
# Author : Rhapsodyzs | |
# E-mail : zs1213yh@gmail.com | |
# Date : 14/03/31 20:39:23 | |
# Desc : test-igetui-corutine | |
# | |
import httplib, urlparse, hashlib, json, datetime, types | |
import urllib | |
from tornado import gen | |
from tornado import escape | |
from tornado.httpclient import AsyncHTTPClient | |
from tornado.ioloop import IOLoop | |
import tornado | |
def sign(mastersecret,args): | |
keys = args.keys() | |
keys.sort() | |
sign = "" | |
for k in keys: | |
if type(args[k]) in (types.UnicodeType,types.StringType,types.IntType,types.LongType): | |
sign+=k+str(args[k]) | |
sign=mastersecret+sign | |
sign = hashlib.md5(sign).hexdigest() | |
return sign | |
@gen.coroutine | |
def test(): | |
api ="http://sdk.open.api.igexin.com/service" | |
notifyMsgIcon = "icon.png" | |
appname = "测试" | |
title= '测试' | |
offline=True | |
offlineTime=72 | |
priority=1 | |
pushType="NotifyMsg" | |
content = "测试内容无卡卡" | |
transmissionType = 1 | |
transmissionContent = "" | |
notifyMsgNoRing = False | |
notifyMsgNoVibrate = False | |
mastersecret = "" | |
appid = "" | |
clientid = "" | |
appkey ="" | |
if type(clientid) != types.ListType: | |
clientid=[clientid,] | |
notifyMsg = { | |
"notifyMsgIcon":notifyMsgIcon, | |
"notifyMsgTitle":title, | |
"notifyMsgContent":content, | |
"transmissionContent":transmissionContent, | |
"transmissionType":transmissionType, | |
"notifyMsgNoRing":notifyMsgNoRing, | |
"notifyMsgNoVibrate":notifyMsgNoVibrate, | |
} | |
args = { | |
"action": "pushSpecifyMessage", | |
"appkey": appkey, | |
"type": 2, | |
"pushTitle":appname, | |
"pushType": pushType, | |
"offline": offline, | |
"offlineTime":offlineTime, | |
"priority": priority, | |
"tokenMD5List": clientid, | |
"msg":notifyMsg, | |
} | |
args["sign"]=sign(mastersecret, args) | |
body = urllib.urlencode(args) | |
print body | |
try: | |
resp = yield AsyncHTTPClient().fetch(api, method="POST", headers={'Content-Type':'text/plain; charset=UTF-8'} ,body=body) | |
print resp.body | |
raise gen.Return(resp.body) | |
except tornado.httpclient.HTTPError as e: | |
raise gen.Return(e) | |
@gen.coroutine | |
def ok(): | |
a = yield test() | |
print a | |
def _future_done(fu): | |
fu.result() | |
if __name__ == '__main__': | |
fu = ok() | |
fu.add_done_callback(_future_done) | |
IOLoop.current().start() | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment