12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package ChatRoomMember
- import (
- "context"
- "wechat-api/ent/wx"
- "wechat-api/hook"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type GetChatroomMemberListLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewGetChatroomMemberListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetChatroomMemberListLogic {
- return &GetChatroomMemberListLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *GetChatroomMemberListLogic) GetChatroomMemberList(req *types.ChatroomMemberListReq) (resp *types.ChatroomMemberListResp, err error) {
- // todo: add your logic here and delete this line
- wxInfo, err := l.svcCtx.DB.Wx.Query().Where(wx.Wxid(*req.OwnerWxid)).First(l.ctx)
- if err != nil {
- l.Error("查询微信信息失败", err)
- return
- }
- serverInfo, err := l.svcCtx.DB.Server.Get(l.ctx, wxInfo.ServerID)
- if err != nil {
- l.Error("查询服务器信息失败", err)
- return
- }
- hookClient := hook.NewHook(serverInfo.PrivateIP, serverInfo.AdminPort, wxInfo.Port)
- friendAndChatRoomList, err := hookClient.BatchGetChatRoomMemberWxid(*req.ChatRoom)
- if err != nil {
- l.Error("获取群成员列表失败", err)
- return
- }
- wxlist := make(map[string]hook.BriefInfo)
- var wxidList []string
- for _, v := range friendAndChatRoomList.Data {
- wxidList = append(wxidList, v.Wxid)
- }
- wxinfos, err := hookClient.BatchGetContactBriefInfo(wxidList)
- if err != nil {
- l.Error("获取微信信息失败", err)
- return
- } else {
- for _, v := range wxinfos.Info {
- wxlist[v.Wxid] = v
- }
- l.Info("获取微信信息成功", wxlist)
- }
- resp = &types.ChatroomMemberListResp{
- BaseDataInfo: types.BaseDataInfo{
- Code: 0,
- Msg: errormsg.Success,
- },
- }
- for _, v := range friendAndChatRoomList.Data {
- nickname := ""
- if _, ok := wxlist[v.Wxid]; ok {
- nickname = wxlist[v.Wxid].Nickname
- }
- resp.Data.Data = append(resp.Data.Data, types.ChatroomMemberInfo{
- Wxid: &v.Wxid,
- ChatRoom: req.ChatRoom,
- OwnerWxid: req.OwnerWxid,
- Account: &nickname,
- })
- }
- return resp, nil
- }
|