已经是深秋了,森林里那一望无际的林木都已光秃,让褐色的苔掩住它身上的皱纹。无情的秋天剥下了它们美丽的衣裳,它们只好枯秃地站在那里。
本文实例为大家分享了python tornado微信开发的具体代码,供大家参考,具体内容如下
#微信入门代码 #!/usr/bin/env python2.7 # -*- coding: utf-8 -*- import tornado.ioloop import tornado.web import hashlib import xml.etree.ElementTree as ET import time def check_signature(signature, timestamp, nonce): # 微信公众平台里输入的token token="linden" #字典序排序 list = [token,timestamp,nonce] list.sort() sha1=hashlib.sha1() map(sha1.update,list) hashcode=sha1.hexdigest() return hashcode == signature class MainHandler(tornado.web.RequestHandler): def get(self): signature = self.get_argument('signature') timestamp = self.get_argument('timestamp') nonce = self.get_argument('nonce') echostr = self.get_argument('echostr') if check_signature(signature, timestamp, nonce): self.write(echostr) else: self.write('fail') def post(self): body = self.request.body data = ET.fromstring(body) toUser = data.find('ToUserName').text fromUser = data.find('FromUserName').text createTime = int(time.time()) msgType = data.find('MsgType').text content = data.find('Content').text msgId= data.find("MsgId").text # from与to在返回的时候要交换 textTpl = """<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> <MsgId>%s</MsgId> </xml>""" out = textTpl % (fromUser, toUser, createTime, msgType, content, msgId) self.write(out) application = tornado.web.Application([ (r"/", MainHandler), ]) if __name__ == "__main__": application.listen(80) tornado.ioloop.IOLoop.instance().start()
以上就是python tornado微信开发入门代码。也许世间的事,都是那么的千奇百怪,随时随刻都会发生,但你要镇静,可又能镇静得了吗?我们都是俗人,没有什么惊天动地的事情,我们只有这份爱,可又那么的叫人难猜。更多关于python tornado微信开发入门代码请关注haodaima.com其它相关文章!