在微信公众号帮助文档中 实例代码为
class Handle(object):
def GET(self):
try:
data = web.input()
if len(data) == 0:
return "hello, this is handle view"
signature = data.signature
timestamp = data.timestamp
nonce = data.nonce
echostr = data.echostr
token = "xxxx" #请按照公众平台官网\基本配置中信息填写
list = [token, timestamp, nonce]
list.sort()
sha1 = hashlib.sha1()
map(sha1.update, list)
hashcode = sha1.hexdigest()
print "handle/GET func: hashcode, signature: ", hashcode, signature
if hashcode == signature:
return echostr
else:
return ""
except Exception, Argument:
return Argument
然后我对接的时候是用python3写的 弄了半天发现结果不对 原来是 python2x和3x的写法不同
#2x写法
map(sha1.update, list)
#3x写法
sha1.update("".join(list).encode('utf-8'))
#以上唯一区别