예제 #1
0
        /// <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); //序列化
        }
예제 #2
0
        /// <summary>
        /// 获取sid uid   结果存放在cookies中
        /// </summary>
        public string GetSidUid(string login_redirect)
        {
            try
            {
                CookieContainer cookieContainer = new CookieContainer();
                byte[]          bytes           = HttpService.SendGetRequest(login_redirect + "&fun=new&version=v2&lang=zh_CN", ref cookieContainer);
                string          pass_ticket     = Encoding.UTF8.GetString(bytes);
                string          url             = login_redirect;
                Uri             uri             = new Uri(url);
                string          WXUser_url      = (uri.Host);
                string          pass_Ticket     = pass_ticket.Split(new string[] { "pass_ticket" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
                string          sKey            = pass_ticket.Split(new string[] { "skey" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
                string          wxSid           = pass_ticket.Split(new string[] { "wxsid" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
                string          wxUin           = pass_ticket.Split(new string[] { "wxuin" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');


                var passticketEntity = new PassTicketEntity()
                {
                    PassTicket = pass_Ticket,
                    SKey       = sKey,
                    WxSid      = wxSid,
                    WxUin      = wxUin,
                    WxHost     = WXUser_url
                };

                LoginCore.PassTicket(wxUin, passticketEntity);
                if (HttpService.CookiesContainerDic.ContainsKey(wxUin))
                {
                    HttpService.CookiesContainerDic.Remove(wxUin);
                }
                WxSerializable s = new WxSerializable(wxUin, EnumContainer.SerializType.cookie);
                HttpService.CookiesContainerDic.Add(wxUin, cookieContainer);
                s.Serializable(HttpService.CookiesContainerDic);
                return(wxUin);
            }
            catch (Exception ex)
            {
                Tools.Tools.WriteLog(ex.ToString());
                return(null);
            }
        }
예제 #3
0
 /// <summary>
 /// 获取联系人昵称
 /// </summary>
 /// <param name="userName"></param>
 /// <returns></returns>
 public string GetNickName(string userName)
 {
     try
     {
         string nickName = string.Empty;
         var    _allUser = getAllUsers();
         if (_allUser.ContainsKey(userName))
         {
             nickName = _allUser[userName].NickName;
         }
         else
         {
             var array = new List <string>();
             array.Add(userName);
             var bat_contact_result = wxs.BatGetContact(array);
             if (bat_contact_result != null)
             {
                 foreach (JObject bat_contact in bat_contact_result["ContactList"])
                 {
                     WXUser user = Convert(bat_contact);
                     _allUser.Add(userName, user);
                     nickName = user.NickName;
                     break;
                 }
                 WxSerializable s = new WxSerializable(this._uin, EnumContainer.SerializType.contact);
                 s.Serializable(_allUser);
             }
         }
         return(nickName);
     }
     catch (Exception ex)
     {
         //Tools.WriteLog(ex.ToString());
         //MessageBox.Show("GetNickName" + ex.Message);
         Tools.Tools.WriteLog(ex.ToString());
         return("");
     }
 }
예제 #4
0
        /// <summary>
        /// 初始化联系人
        /// </summary>
        public void InitContact(List <WXUser> partUsers)
        {
            var groupNames     = new List <string>();
            var contact_result = wx.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 = wx.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);  //序列化 所有联系人
        }