59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
# encoding:utf-8
|
|
|
|
from fastapi import FastAPI
|
|
from pydantic import BaseModel
|
|
import uvicorn
|
|
|
|
from lib.service.baidu import check_baidu
|
|
from lib.service.local import check_local
|
|
from lib.service.wechat import msg_sec_check
|
|
|
|
app = FastAPI()
|
|
|
|
|
|
class Item(BaseModel):
|
|
content: str
|
|
|
|
|
|
@app.post("/check_wx")
|
|
async def check_with_wx(item: Item):
|
|
res_wechat = await msg_sec_check(item.content)
|
|
return res_wechat
|
|
|
|
|
|
@app.post("/check_bd")
|
|
async def check_with_bd(item: Item):
|
|
res_baidu = await check_baidu(item.content)
|
|
return res_baidu
|
|
|
|
|
|
@app.post("/check_local")
|
|
async def check_with_local(item: Item):
|
|
res_local = check_local(item.content)
|
|
return res_local
|
|
|
|
|
|
@app.post("/check_all")
|
|
async def check_content(item: Item):
|
|
res_wechat = await msg_sec_check(item.content)
|
|
result = {'errcode': 1}
|
|
if res_wechat['errcode'] == 0:
|
|
result['errcode'] = 0
|
|
result['wx'] = res_wechat['risk']
|
|
result['reason_wx'] = res_wechat['reason']
|
|
res_baidu = await check_baidu(item.content)
|
|
if res_baidu['errcode'] == 0:
|
|
result['errcode'] = 0
|
|
result['bd'] = res_baidu['risk']
|
|
result['reason_bd'] = res_baidu['reason']
|
|
res_local = check_local(item.content)
|
|
if res_local['errcode'] == 0:
|
|
result['errcode'] = 0
|
|
result['local'] = res_local['risk']
|
|
result['reason_local'] = res_local['reason']
|
|
return result
|
|
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="0.0.0.0", port=8009)
|