Beispiel #1
0
        /// <summary>
        /// Get the QQ Group Name list
        /// </summary>
        /// <param name="isLoadGroupAccountDetailedInfo">The flag whether or not to load the group member profile</param>
        /// <returns></returns>
        public List <GroupAccount> GetGroupList(bool isLoadGroupAccountDetailedInfo = true)
        {
            string url      = "http://s.web2.qq.com/api/get_group_name_list_mask2";
            string sendData = string.Format("r={{\"vfwebqq\":\"{0}\",\"hash\":\"{1}\"}}", smartQQ.VFWebQQ, smartQQ.Hash);
            string dat      = HTTP.Post(url, sendData, "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2");

            Groups groups = (Groups)JsonConvert.DeserializeObject(dat, typeof(Groups));

            if (groups.result == null)
            {
                return(null);
            }

            smartQQ.GroupAccounts = new List <GroupAccount>();
            foreach (var group in groups.result.gnamelist)
            {
                GroupAccount groupAccount = new GroupAccount();
                groupAccount.Code = group.code;
                groupAccount.Flag = group.flag;
                groupAccount.Gid  = group.gid;
                groupAccount.Name = group.name;

                smartQQ.GroupAccounts.Add(groupAccount);
            }

            if (isLoadGroupAccountDetailedInfo)
            {
                foreach (GroupAccount groupAccount in smartQQ.GroupAccounts)
                {
                    LoadGroupAccountDetailedInfo(groupAccount);
                }
            }

            return(smartQQ.GroupAccounts);
        }
Beispiel #2
0
        public void GetOnlineAccounts()
        {
            string url = "http://d1.web2.qq.com/channel/get_online_buddies2?vfwebqq=#{vfwebqq}&clientid=53999199&psessionid=#{psessionid}&t=#{t}".Replace("#{vfwebqq}", smartQQ.VFWebQQ).Replace("#{psessionid}", smartQQ.PSessionId).Replace("#{t}", HTTP.AID_TimeStamp());

            HTTP.Get(url, "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2");

            url = "http://d1.web2.qq.com/channel/get_recent_list2";
            string        url1          = "{\"vfwebqq\":\"#{vfwebqq}\",\"clientid\":53999199,\"psessionid\":\"#{psessionid}\"}".Replace("#{vfwebqq}", smartQQ.VFWebQQ).Replace("#{psessionid}", smartQQ.PSessionId);
            string        dat           = HTTP.Post(url, "r=" + HttpUtility.UrlEncode(url1), "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2");
            OnlineFirends onlineFirends = (OnlineFirends)JsonConvert.DeserializeObject(dat, typeof(OnlineFirends));

            if (onlineFirends.result == null)
            {
                return;
            }

            Dictionary <string, int> OnlineUserStatusMap = new Dictionary <string, int>();

            foreach (var onlineFirend in onlineFirends.result)
            {
                OnlineUserStatusMap.Add(onlineFirend.uin, onlineFirend.type);
            }

            foreach (var firend in smartQQ.FriendAccounts)
            {
                if (OnlineUserStatusMap.ContainsKey(firend.Uin))
                {
                    firend.OnlineType = OnlineUserStatusMap[firend.Uin];
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="type">接受者类型:0,用户;1,群;2,讨论组</param>
        /// <param name="id">用户:uid;群:qid;讨论组:did</param>
        /// <param name="messageToSend">要发送的消息</param>
        /// <returns></returns>
        public bool SendMessage(int type, string id, string messageToSend)
        {
            if (messageToSend.Equals("") || id.Equals(""))
            {
                return(false);
            }

            string[] tmp = messageToSend.Split("{}".ToCharArray());
            messageToSend = "";
            for (int i = 0; i < tmp.Length; i++)
            {
                if (!tmp[i].Trim().StartsWith("..[face") || !tmp[i].Trim().EndsWith("].."))
                {
                    messageToSend += "\\\"" + tmp[i] + "\\\",";
                }
                else
                {
                    messageToSend += tmp[i].Replace("..[face", "[\\\"face\\\",").Replace("]..", "],");
                }
            }

            messageToSend = messageToSend.Remove(messageToSend.LastIndexOf(','));
            messageToSend = messageToSend.Replace("\r\n", "\n").Replace("\n\r", "\n").Replace("\r", "\n").Replace("\n", Environment.NewLine);

            try
            {
                string to_groupuin_did, url;
                switch (type)
                {
                case 0:
                    to_groupuin_did = "to";
                    url             = "http://d1.web2.qq.com/channel/send_buddy_msg2";
                    break;

                case 1:
                    to_groupuin_did = "group_uin";
                    url             = "http://d1.web2.qq.com/channel/send_qun_msg2";
                    break;

                case 2:
                    to_groupuin_did = "did";
                    url             = "http://d1.web2.qq.com/channel/send_discu_msg2";
                    break;

                default:
                    return(false);
                }

                string postData = "{\"#{type}\":#{id},\"content\":\"[#{msg},[\\\"font\\\",{\\\"name\\\":\\\"宋体\\\",\\\"size\\\":10,\\\"style\\\":[0,0,0],\\\"color\\\":\\\"000000\\\"}]]\",\"face\":#{face},\"clientid\":53999199,\"msg_id\":#{msg_id},\"psessionid\":\"#{psessionid}\"}";
                postData = "r=" + HttpUtility.UrlEncode(postData.Replace("#{type}", to_groupuin_did).Replace("#{id}", id).Replace("#{msg}", messageToSend).Replace("#{face}", this.smartQQ.Face.ToString()).Replace("#{msg_id}", rand.Next(10000000, 99999999).ToString()).Replace("#{psessionid}", this.smartQQ.PSessionId));

                string dat = HTTP.Post(url, postData, "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2");

                return(dat.Equals("{\"errCode\":0,\"msg\":\"send ok\"}"));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Process login request
        /// </summary>
        /// <param name="redirectUrl"></param>
        /// <returns></returns>
        public SmartQQWrapper ProcessLoginRequest(string redirectUrl)
        {
            string url = "";
            string dat = "";

            // 1.
            string ptwebqq = "";

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    dat = HTTP.Get(redirectUrl, "http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1");
                    Uri uri = new Uri("http://web2.qq.com/");
                    ptwebqq = HTTP.cookies.GetCookies(uri)["ptwebqq"].Value;
                    break;
                }
                catch (Exception ex)
                {
                }
            }

            // 2.
            string vfwebqq = "";

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    url     = String.Format("http://s.web2.qq.com/api/getvfwebqq?ptwebqq={0}&clientid=53999199&psessionid=&t={1}", ptwebqq, HTTP.AID_TimeStamp());
                    dat     = HTTP.Get(url, "http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1");
                    vfwebqq = dat.Substring(dat.IndexOf("\"vfwebqq\":") + "\"vfwebqq\":".Length + 1);
                    vfwebqq = vfwebqq.Substring(0, vfwebqq.IndexOf("\""));
                    break;
                }
                catch (Exception ex)
                {
                }
            }

            // 3.
            string psessionid = "";
            string qqNbr      = "";

            for (int i = 0; i < 3; i++)
            {
                try
                {
                    url = "http://d1.web2.qq.com/channel/login2";
                    string url1 = "{\"ptwebqq\":\"#{ptwebqq}\",\"clientid\":53999199,\"psessionid\":\"\",\"status\":\"online\"}".Replace("#{ptwebqq}", ptwebqq);
                    url1       = "r=" + HttpUtility.UrlEncode(url1);
                    dat        = HTTP.Post(url, url1, "http://d1.web2.qq.com/proxy.html?v=20151105001&callback=1&id=2");
                    psessionid = dat.Substring(dat.IndexOf("\"psessionid\":") + "\"psessionid\":".Length + 1);
                    psessionid = psessionid.Substring(0, psessionid.IndexOf("\""));

                    qqNbr = dat.Substring(dat.IndexOf("\"uin\":") + "\"uin\":".Length);
                    qqNbr = qqNbr.Substring(0, qqNbr.IndexOf(","));
                    break;
                }
                catch (Exception ex)
                {
                }
            }

            string hash = "";

            hash = HTTP.AID_Hash(qqNbr, ptwebqq);

            SmartQQWrapper smartQQ = new SmartQQWrapper();

            smartQQ.PTWebQQ    = ptwebqq;
            smartQQ.VFWebQQ    = vfwebqq;
            smartQQ.PSessionId = psessionid;
            smartQQ.QQAccount  = qqNbr;
            smartQQ.Hash       = hash;

            return(smartQQ);
        }
Beispiel #5
0
        /// <summary>
        /// Get QQ Friend List
        /// </summary>
        /// <param name="isLoadAccountDetailedInfo">The flag whether or not to load the friend profile</param>
        /// <returns></returns>
        public List <QQFriendAccount> GetFriendList(bool isLoadAccountDetailedInfo = false)
        {
            string url      = "http://s.web2.qq.com/api/get_user_friends2";
            string sendData = string.Format("r={{\"vfwebqq\":\"{0}\",\"hash\":\"{1}\"}}", smartQQ.VFWebQQ, smartQQ.Hash);
            string dat      = HTTP.Post(url, sendData, "http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1");

            Friends friend = (Friends)JsonConvert.DeserializeObject(dat, typeof(Friends));

            if (friend.result == null)
            {
                return(null);
            }

            Dictionary <string, string> MarkNameList = new Dictionary <string, string>();

            if (friend.result.markNames != null)
            {
                for (int i = 0; i < friend.result.markNames.Count; i++)
                {
                    MarkNameList.Add(friend.result.markNames[i].uin, friend.result.markNames[i].markname);
                }
            }

            Dictionary <int, string> CategoryList = new Dictionary <int, string>();

            if (friend.result.categories != null)
            {
                for (int i = 0; i < friend.result.categories.Count; i++)
                {
                    CategoryList.Add(friend.result.categories[i].index, friend.result.categories[i].name);
                }
            }

            Dictionary <string, QQFriendAccount> accounts = new Dictionary <string, QQFriendAccount>();
            string uin           = String.Empty;
            int    categoryIndex = -1;
            string categoryName  = String.Empty;

            if (friend.result.friends != null)
            {
                for (int i = 0; i < friend.result.friends.Count; i++)
                {
                    uin = friend.result.friends[i].uin;


                    QQFriendAccount account = null;
                    if (accounts.ContainsKey(uin))
                    {
                        account = accounts[uin];
                    }
                    else
                    {
                        account = new QQFriendAccount();
                        accounts.Add(uin, account);
                    }

                    account.Uin      = uin;
                    account.MarkName = MarkNameList.ContainsKey(uin) ? MarkNameList[uin] : "";

                    categoryIndex         = friend.result.friends[i].categories;
                    account.CategotyIndex = categoryIndex;
                    account.CategotyName  = CategoryList.ContainsKey(categoryIndex) ? CategoryList[categoryIndex] : "";

                    accounts[uin] = account;
                }
            }

            if (friend.result.info != null)
            {
                for (int i = 0; i < friend.result.info.Count; i++)
                {
                    uin = friend.result.info[i].uin;

                    QQFriendAccount account = null;
                    if (accounts.ContainsKey(uin))
                    {
                        account = accounts[uin];
                    }
                    else
                    {
                        account = new QQFriendAccount();
                        accounts.Add(uin, account);
                    }

                    account.Nick = friend.result.info[i].nick;

                    accounts[uin] = account;
                }
            }

            smartQQ.FriendAccounts = accounts.Values.ToList <QQFriendAccount>();
            if (isLoadAccountDetailedInfo)
            {
                foreach (QQFriendAccount account in smartQQ.FriendAccounts)
                {
                    LoadAccountDetailedInfo(account);
                }
            }

            return(smartQQ.FriendAccounts);
        }