/// <summary> /// 获取群成员列表 /// </summary> /// <param name="groupId">目标群号</param> /// <exception cref="ArgumentOutOfRangeException">参数: groupId 超出范围</exception> /// <exception cref="InvalidDataException">数据流格式错误或为 null</exception> /// <exception cref="EndOfStreamException">无法读取数据, 因为已读取到数据流末尾</exception> /// <returns>获取成功返回 <see cref="GroupMemberInfoCollection"/>, 失败返回 <see langword="null"/></returns> public GroupMemberInfoCollection GetGroupMemberList(long groupId) { if (groupId < Group.MinValue) { throw new ArgumentOutOfRangeException("groupId"); } string data = CQP.CQ_getGroupMemberList(this.AppInfo.AuthCode, groupId).ToString(CQApi.DefaultEncoding); if (string.IsNullOrEmpty(data)) { #if DEBUG throw new InvalidDataException("获取的数据流格式无效"); #else return(null); #endif } try { return(new GroupMemberInfoCollection(this, data)); } catch { #if DEBUG throw; #else return(null); #endif } }
/// <summary> /// 获取群成员列表 /// </summary> /// <param name="groupId">目标群</param> /// <returns>获取成功返回 <see cref="List{GroupMember}"/>, 失败返回 null</returns> public List<GroupMemberInfo> GetMemberList(long groupId) { string result = CQP.CQ_getGroupMemberList(_authCode, groupId).ToString(Encoding.ASCII); if (string.IsNullOrEmpty(result)) { return null; } #region --其他_转换_文本到群成员列表信息a-- using (BinaryReader binary = new BinaryReader(new MemoryStream(Convert.FromBase64String(result)))) { List<GroupMemberInfo> memberInfos = new List<GroupMemberInfo>(); for (int i = 0, len = binary.ReadInt32_Ex(); i < len; i++) { if (binary.Length() <= 0) { return null; } #region --其它_转换_ansihex到群成员信息-- using (BinaryReader tempBinary = new BinaryReader(new MemoryStream(binary.ReadToken_Ex()))) //解析群成员信息 { GroupMemberInfo member = new GroupMemberInfo { GroupId = tempBinary.ReadInt64_Ex(), QQId = tempBinary.ReadInt64_Ex(), Nick = tempBinary.ReadString_Ex(_defaultEncoding), Card = tempBinary.ReadString_Ex(_defaultEncoding), Sex = (Sex)tempBinary.ReadInt32_Ex(), Age = tempBinary.ReadInt32_Ex(), Area = tempBinary.ReadString_Ex(_defaultEncoding), JoiningTime = tempBinary.ReadInt32_Ex().ToDateTime(), LastDateTime = tempBinary.ReadInt32_Ex().ToDateTime(), Level = tempBinary.ReadString_Ex(_defaultEncoding), PermitType = (PermitType)tempBinary.ReadInt32_Ex(), BadRecord = tempBinary.ReadInt32_Ex() == 1, SpecialTitle = tempBinary.ReadString_Ex(_defaultEncoding), SpecialTitleDurationTime = tempBinary.ReadInt32_Ex().ToDateTime(), CanModifiedCard = tempBinary.ReadInt32_Ex() == 1 }; memberInfos.Add(member); } #endregion } return memberInfos; } #endregion }
/// <summary> /// 获取群成员列表 /// </summary> /// <param name="groupId">目标群</param> /// <param name="memberInfos">如果成功,返回群成员列表</param> /// <returns>成功返回 0, 失败返回 负数</returns> public int GetMemberList(long groupId, out List <GroupMember> memberInfos) { string result = CQP.CQ_getGroupMemberList(_authCode, groupId); if (string.IsNullOrEmpty(result)) { memberInfos = null; return(-1000); } #region --其他_转换_文本到群成员列表信息a-- UnPack unpack = new UnPack(Convert.FromBase64String(result)); memberInfos = new List <GroupMember> (); for (int i = 0, len = unpack.GetInt32(); i < len; i++) { if (unpack.OverLength <= 0) { memberInfos = null; return(-1000); } #region --其它_转换_ansihex到群成员信息-- UnPack temp = new UnPack(unpack.GetToken()); //解析群成员信息 GroupMember member = new GroupMember { GroupId = temp.GetInt64(), QQId = temp.GetInt64(), Nick = temp.GetString(Encoding.GetEncoding("GB18030")), Card = temp.GetString(Encoding.GetEncoding("GB18030")), Sex = (Sex)temp.GetInt32(), Age = temp.GetInt32(), Area = temp.GetString(Encoding.GetEncoding("GB18030")), JoiningTime = NativeConvert.FotmatUnixTime(temp.GetInt32().ToString()), LastDateTime = NativeConvert.FotmatUnixTime(temp.GetInt32().ToString()), Level = temp.GetString(Encoding.GetEncoding("GB18030")), PermitType = (PermitType)temp.GetInt32(), BadRecord = temp.GetInt32() == 1, SpecialTitle = temp.GetString(Encoding.GetEncoding("GB18030")), SpecialTitleDurationTime = NativeConvert.FotmatUnixTime(temp.GetInt32().ToString()), CanModifiedCard = temp.GetInt32() == 1 }; #endregion memberInfos.Add(member); } #endregion return(0); }
/// <summary> /// 获取群成员列表 /// </summary> /// <param name="groupId">目标群</param> /// <param name="memberInfos">如果成功,返回群成员列表</param> /// <returns>成功返回 0, 失败返回 负数</returns> public int GetMemberList(long groupId, out List <GroupMember> memberInfos) { string result = CQP.CQ_getGroupMemberList(_authCode, groupId); if (string.IsNullOrEmpty(result)) { memberInfos = null; return(-1000); } #region --其他_转换_文本到群成员列表信息a-- BinaryReader binary = new BinaryReader(new MemoryStream(Convert.FromBase64String(result))); memberInfos = new List <GroupMember> (); for (int i = 0, len = binary.ReadInt32_Ex(); i < len; i++) { if (binary.Length() <= 0) { memberInfos = null; return(-1000); } #region --其它_转换_ansihex到群成员信息-- BinaryReader tempBinary = new BinaryReader(new MemoryStream(binary.ReadToken_Ex())); //解析群成员信息 GroupMember member = new GroupMember(); member.GroupId = tempBinary.ReadInt64_Ex(); member.QQId = tempBinary.ReadInt64_Ex(); member.Nick = tempBinary.ReadString_Ex(_defaultEncoding); member.Card = tempBinary.ReadString_Ex(_defaultEncoding); member.Sex = (Sex)tempBinary.ReadInt32_Ex(); member.Age = tempBinary.ReadInt32_Ex(); member.Area = tempBinary.ReadString_Ex(_defaultEncoding); member.JoiningTime = tempBinary.ReadInt32_Ex().ToDateTime(); member.LastDateTime = tempBinary.ReadInt32_Ex().ToDateTime(); member.Level = tempBinary.ReadString_Ex(_defaultEncoding); member.PermitType = (PermitType)tempBinary.ReadInt32_Ex(); member.BadRecord = tempBinary.ReadInt32_Ex() == 1; member.SpecialTitle = tempBinary.ReadString_Ex(_defaultEncoding); member.SpecialTitleDurationTime = binary.ReadInt32_Ex().ToDateTime(); member.CanModifiedCard = tempBinary.ReadInt32_Ex() == 1; #endregion memberInfos.Add(member); } #endregion return(0); }