# -*- coding: utf-8 -*-
# filename: handle.py
import hashlib
import web
class Handle(object):
# get方法,验证token
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 = "weixin" #请按照公众平台官网\基本配置中信息填写
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 as Argument:
return Argument
if __name__=='__main__':
pass
# -*- coding: utf-8 -*-
# filename: main.py
import web
from handle import Handle
urls = (
'/wx', 'Handle',
)
class Handle(object):
def GET(self):
return "hello, this is handle view"
if __name__ == '__main__':
app = web.application(urls, globals())
app.run()
~
~
以上是验证微信公众号token的代码

直接访问 ip:80 显示 not found
基本配置验证token 也是失败
2023.4.11更
ip:80 有返回信息
hello, this is handle view
但是微信公众号一提交基本配置,就是验证token失败
前两条信息是直接访问ip:80,后面404的是提交基本配置、提示验证失败
