zoukankan      html  css  js  c++  java
  • 微信公众号之Token验证

    说实话,微信公众号给的文档里面的代码不靠谱,我是用django的,浪费了4个小时,经过研究,使用如下代码才得到正确的哈希值:

    def wx(request):
        signature = request.GET['signature']
        timestamp = request.GET['timestamp']
        nonce = request.GET['nonce']
        echostr = request.GET['echostr']
        token = "××××××"  # 请按照公众平台官网基本配置中信息填写
    
        list = [token, timestamp, nonce]
        list.sort()
        hashstr = ''.join([s for s in list])
        sha1 = hashlib.sha1()
        sha1.update(hashstr.encode('utf8'))
        hashcode = sha1.hexdigest()
    
        # 把我们生成的字符串和微信服务器发送过来的字符串比较,
        # 如果相同,就把服务器发过来的echostr字符串返回去
        if hashcode == signature:
            return HttpResponse(echostr)
        else:
            return HttpResponse('')
  • 相关阅读:
    Windows网络编程经验小结
    异步Socket服务器与客户端
    用C#实现C/S模式下软件自动在线升级
    Linux 安装字体
    word 生成目录
    Linux sar使用
    yum 使用说明
    HASH JOIN算法
    row cache lock
    cursor: pin S
  • 原文地址:https://www.cnblogs.com/darknoll/p/8882984.html
Copyright © 2011-2022 走看看