call.py 728 B

12345678910111213141516171819202122232425262728293031
  1. import uvicorn
  2. import fastapi
  3. from fastapi.middleware.cors import CORSMiddleware
  4. import models
  5. app = fastapi.FastAPI()
  6. app.add_middleware(
  7. CORSMiddleware,
  8. allow_origins=['*'],
  9. allow_credentials=True,
  10. allow_methods=["*"],
  11. allow_headers=["*"],
  12. )
  13. @app.post("/callevent")
  14. async def callevent(userModel: models.callBack):
  15. """
  16. 事件會用application/json和POST方式打到指定位址, 內容基本包含
  17. {
  18. "type": "xxx", // 事件類型, 字串
  19. "data": {} // 事件內容資料
  20. }
  21. """
  22. str1 = userModel.type
  23. dict1 = userModel.data
  24. result = str1, dict1
  25. return result
  26. if __name__ == '__main__':
  27. uvicorn.run("call:app", host="0.0.0.0", port=5000, reload=True)