You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.6KB

  1. from fastapi import APIRouter,Request
  2. from pydantic import BaseModel
  3. from fastapi import APIRouter, Depends
  4. from pydantic import BaseModel, ValidationError
  5. from model.models import AgentConfig,validate_wxid,auth_required_time
  6. import threading
  7. import asyncio
  8. groups_router = APIRouter(prefix="/api/groups")
  9. class GetChatroomInfoRequest(BaseModel):
  10. wxid: str
  11. class GetChatroomMenberListRequest(BaseModel):
  12. wxid: str
  13. chatroomId:str
  14. @groups_router.post("/getchatroominfo",response_model=None)
  15. async def get_chatroominfo(request: Request, body: GetChatroomInfoRequest):
  16. wxid = body.wxid
  17. groups= await request.app.state.gewe_service.get_groups_info_from_cache_async(wxid)
  18. return groups
  19. @groups_router.post("/getmenberlist",response_model=None)
  20. async def get_menberlist(request: Request, body: GetChatroomMenberListRequest):
  21. wxid = body.wxid
  22. chatroom_id=body.chatroomId
  23. _,loginfo=await request.app.state.gewe_service.get_login_info_by_wxid_async(wxid)
  24. token_id=loginfo.get('tokenId')
  25. app_id=loginfo.get('appId')
  26. ret, msg, data = await request.app.state.gewe_service.get_group_memberlist_async(token_id, app_id, chatroom_id)
  27. if ret != 200:
  28. return {
  29. 'code': ret,
  30. 'message': msg
  31. }
  32. loop = asyncio.get_event_loop()
  33. future = asyncio.run_coroutine_threadsafe(
  34. request.app.state.gewe_service.save_groups_members_to_cache_async(token_id, app_id, wxid, [chatroom_id]),
  35. loop
  36. )
  37. # Optionally, you can wait for the future to complete if needed
  38. #future.result()
  39. return data