from fastapi import FastAPI
import hashlib
app = FastAPI()
@app.get("/hello")
def hello():
return "hello"
@app.get("/verify")
def verify(signature,timestamp,nonce,echostr):
print(signature,timestamp,',',nonce,',',echostr)
token = 'zhangboyi'
li = [token, timestamp, nonce]
li.sort()
sha1 = hashlib.sha1()
sha1.update(li[0].encode('utf-8'))
sha1.update(li[1].encode('utf-8'))
sha1.update(li[2].encode('utf-8'))
hashcode = sha1.hexdigest()
print("handle/GET func: hashcode, signature: ", hashcode, signature)
if hashcode == signature:
return echostr.encode('utf-8')
else:
return ''
import uvicorn
if __name__ == '__main__':
uvicorn.run(app,host='0.0.0.0')