zoukankan      html  css  js  c++  java
  • 公众号基本配置 token 验证失败,成功解决

    官网提供代码适用于python2.7+版本。

    当你用python3+版本运行,验证token肯定失败。

    需要修改handle.py源代码,才可以。

    # -*- 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 = "12345678"
                
           # 以下5行是官网提供适用于 python 2.7+ 版本的代码 #list = [token, timestamp, nonce] #list.sort() #sha1 = hashlib.sha1() #map(sha1.update, list) #hashcode = sha1.hexdigest()
           # 以下7行是python3+能验证通过的代码  list
    = [token, timestamp, nonce] list.sort() sha1 = hashlib.sha1() sha1.update(list[0].encode('utf-8')) sha1.update(list[1].encode('utf-8')) sha1.update(list[2].encode('utf-8')) hashcode = sha1.hexdigest() print("handle/GET func: hashcode, signature: ", hashcode, signature) if hashcode == signature: return echostr else: return "" except (Exception, Argument): return Argument
  • 相关阅读:
    人生的意义:
    instancetype和id的区别,objective-c
    iOS多线程系统整理 swift
    系统整理 精讲 swift 泛型
    swift学习笔记7
    swift学习笔记6
    swift学习笔记5
    [iOS开发日记]简易计算器
    [ocUI日记]UIImage和UIImageview
    [ocUI日记]UIwindow和UIview
  • 原文地址:https://www.cnblogs.com/maoyan/p/14684395.html
Copyright © 2011-2022 走看看