微信token总是验证不正确

doudoushen 2017-08-26 02:09:58
#!/usr/bin/env python
# -*- 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
print("signature=%s timestanmp=%s nonce=%s" %(signature, timestamp, nonce))
token = "wxtoken"
# 字典序排序

list = [token, timestamp, nonce]
list.sort()
sha1 = hashlib.sha1()
map(sha1.update, list)
hashcode = sha1.hexdigest()
print("hashcode=%s signature=%s" %(hashcode, signature))
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):
print("get ok")
self.write(echostr)
else:
self.write('fail')
print("get fa
il")


application = tornado.web.Application([
(r"/", MainHandler),
])

if __name__ == "__main__":
application.listen(80)
tornado.ioloop.IOLoop.instance().start()



代码几乎是抄网上的,但是 签名和hash出来的值总是不正确
微信上的URL配置为http://xxx.cn Token是wxtoken
...全文
150 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧