微信接入验证消息python3+tornado

#!/bin/env python3
#-*- coding:utf-8 -*-
import tornado.ioloop
import tornado.locale
import tornado.web

import hashlib

class checkHandler(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')
        token = 'xxxxxxx'
        list1 = [token, timestamp, nonce]
        list1.sort()
        strList =  ''.join(list1)
        sha1 = hashlib.sha1()
        sha1.update(strList.encode('utf-8'))
        if sha1.hexdigest() == signature:
            self.write(echostr)
        else:
            self.write('')

发表评论

电子邮件地址不会被公开。 必填项已用*标注