浏览代码

删除接口

develop
H Vs 1 天前
父节点
当前提交
a6fca3c6ac
共有 1 个文件被更改,包括 26 次插入0 次删除
  1. +26
    -0
      app/endpoints/agent_endpoint.py

+ 26
- 0
app/endpoints/agent_endpoint.py 查看文件

@@ -29,6 +29,9 @@ class GetWxQRCodeRequest(BaseModel):
class LogincCaptchCode(BaseModel): class LogincCaptchCode(BaseModel):
tel: str tel: str
captchCode:str captchCode:str
class DeleteAgentRequest(BaseModel):
tel: str


@agent_router.post("/getlogin", response_model=None) @agent_router.post("/getlogin", response_model=None)
async def get_login(request: Request, body: GetAgentLoginRequest, ): async def get_login(request: Request, body: GetAgentLoginRequest, ):
@@ -210,4 +213,27 @@ async def login_captch_code(request: Request, body: LogincCaptchCode, ):
tel = body.tel tel = body.tel
captch_code=body.captchCode captch_code=body.captchCode
res=await request.app.state.gewe_service.save_login_wx_captch_code_to_cache_async(tel,captch_code) res=await request.app.state.gewe_service.save_login_wx_captch_code_to_cache_async(tel,captch_code)
return {'message': '操作成功'}

@agent_router.post("/delete", response_model=None)
async def delete_agent(request: Request, body: DeleteAgentRequest):
tel = body.tel
loginfo = await request.app.state.gewe_service.get_login_info_from_cache_async(tel)
wxid = loginfo.get('wxid', '')
# 获取所有匹配的 Redis 键
ai_ops_wx_keys = [key async for key in await request.app.state.redis_service.client.scan_iter(match='__AI_OPS_WX__:*')]
# 定义正则表达式模式
pattern = re.compile(rf'^__AI_OPS_WX__.*{wxid}.*')
# 过滤掉符合模式的键
filtered_keys = [key for key in ai_ops_wx_keys if not pattern.match(key)]
# 并发删除过滤后的键
await asyncio.gather(*[request.app.state.redis_service.delete_hash(key) for key in filtered_keys])
# 删除登录信息
await request.app.state.gewe_service.delete_hash(f'__AI_OPS_WX__:LOGININFO:{tel}')
return {'message': '操作成功'} return {'message': '操作成功'}

正在加载...
取消
保存