/// <summary> /// 添加群内用户 /// </summary> /// <param name="groupUserName"></param> /// <param name="?"></param> public void Add(string groupUserName, WxGroup group) { WxSerializable s = new WxSerializable(this._uin, EnumContainer.SerializType.curr_group_user); var dic = (Dictionary <string, WxGroup>)s.DeSerializable(); if (dic != null && dic.ContainsKey(groupUserName)) { dic.Remove(groupUserName); } dic.Add(groupUserName, group); s.Serializable(dic); //序列化 }
public WxGroup GetOnLineGroupMember(string gUserName) { var g_array = new List <string>(); g_array.Add(gUserName); var bat_contact_result = wxs.BatGetContact(g_array); if (bat_contact_result != null) { var dic = new Dictionary <string, WxGroup>(); foreach (JObject bat_contact in bat_contact_result["ContactList"]) { //群号 var roomID = bat_contact["EncryChatRoomId"].ToString(); //群用户名 var userName = bat_contact["UserName"].ToString(); var nickName = bat_contact["NickName"].ToString(); var userNameArray = new List <GroupWxUser>(); foreach (JObject c in bat_contact["MemberList"]) { var m_username = c["UserName"].ToString(); var m_displayName = c["DisplayName"].ToString(); var m_nickName = c["NickName"].ToString(); var m_attrStatus = c["AttrStatus"].ToString(); if (string.IsNullOrEmpty(m_displayName)) { m_displayName = m_nickName; } userNameArray.Add(new GroupWxUser() { UserName = m_username, NickName = m_nickName, DisplayName = m_displayName, AttrStatus = m_attrStatus }); } WxGroup g = new WxGroup() { UserName = userName, MemberUserNames = userNameArray, NickName = nickName, RoomID = roomID }; return(g); } } return(null); }
/// <summary> /// 初始化联系人 /// </summary> public void InitContact(List <WXUser> partUsers) { var groupNames = new List <string>(); var contact_result = wxs.GetContact(); var _allUser = new Dictionary <string, WXUser>(); if (partUsers != null) { foreach (var u in partUsers) { if (!_allUser.ContainsKey(u.UserName)) { _allUser.Add(u.UserName, u); } } } if (contact_result != null) { foreach (JObject contact in contact_result["MemberList"]) //完整好友名单 { WXUser user = new WXUser(); user = Convert(contact); if (!_allUser.ContainsKey(user.UserName)) { _allUser.Add(user.UserName, user); } } } foreach (var u in _allUser) { if (u.Key.Contains("@@")) { groupNames.Add(u.Key); } } //获取所有群内联系人信息 var bat_contact_result = wxs.BatGetContact(groupNames); if (bat_contact_result != null) { var dic = new Dictionary <string, WxGroup>(); foreach (JObject bat_contact in bat_contact_result["ContactList"]) { //群号 var roomID = bat_contact["EncryChatRoomId"].ToString(); //群用户名 var userName = bat_contact["UserName"].ToString(); var nickName = bat_contact["NickName"].ToString(); var userNameArray = new List <GroupWxUser>(); foreach (JObject c in bat_contact["MemberList"]) { var m_username = c["UserName"].ToString(); var m_displayName = c["DisplayName"].ToString(); var m_nickName = c["NickName"].ToString(); var m_attrStatus = c["AttrStatus"].ToString(); if (string.IsNullOrEmpty(m_displayName)) { m_displayName = m_nickName; } userNameArray.Add(new GroupWxUser() { UserName = m_username, NickName = m_nickName, DisplayName = m_displayName, AttrStatus = m_attrStatus }); } WxGroup g = new WxGroup() { UserName = userName, MemberUserNames = userNameArray, NickName = nickName, RoomID = roomID }; dic.Add(userName, g); } WxSerializable s_g = new WxSerializable(this._uin, EnumContainer.SerializType.curr_group_user); s_g.Serializable(dic); //序列化 所有群内成员 } WxSerializable s = new WxSerializable(this._uin, EnumContainer.SerializType.contact); s.Serializable(_allUser); //序列化 所有联系人 }