收藏
回答

示例代码有问题

https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Getting_Started_Guide.html

以下代码仅对Python2有效,对于Python3会有问题,请注明以免产生误导,Map函数再不同版本下有歧义,参考以下文章

https://www.cnblogs.com/zhujincheng/p/10075046.html

# -*- coding: utf-8 -*-
# filename: handle.py

import hashlib
import web

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



回答关注问题邀请回答
收藏
登录 后发表内容
问题标签