Exemple #1
0
        private async void btnPublic_Click(object sender, RoutedEventArgs e)
        {
            MyList.Visibility  = Visibility.Collapsed;
            MyList2.Visibility = Visibility.Collapsed;
            MyList3.Visibility = Visibility.Visible;
            MyList4.Visibility = Visibility.Collapsed;
            right.Visibility   = Visibility.Collapsed;
            if (Public_Flag)
            {
                Public_Flag = false;
                foreach (var member in contact.MemberList)
                {
                    if (!member.UserName[1].Equals('@') && !member.NickName.Equals("文件传输助手") && (member.VerifyFlag & 8) != 0)
                    {
                        FriendList friend = new FriendList();
                        friend.UserName = member.UserName;
                        friend.NickName = member.RemarkName;
                        if (member.RemarkName.Equals(""))
                        {
                            friend.NickName = member.NickName;
                        }

                        friend.dialog = new List <bubble>();

                        String uri = "http://wx2.qq.com" + member.HeadImgUrl;

                        var res = await Get.Get_Response_Str(uri, cookie_str);

                        var r = await res.Content.ReadAsByteArrayAsync();

                        friend.bitmap = await ByteArrayToBitmapImage(r);

                        AllPublicView.AllItems.Add(friend);
                    }
                }
            }
        }
Exemple #2
0
        private async void Get_Message()
        {
            String uri = "http://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync" +
                         "?pass_ticket=" + cookie.pass_ticket +
                         "&r=" + Time.Now();

            BaseRequest baseRequest = new BaseRequest(cookie.wxuin, cookie.wxsid, cookie.skey);
            JObject     jsonObj     = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(baseRequest));
            jsonObj.Add("SyncKey", JObject.FromObject(cookie.syncKey));
            jsonObj.Add("rr", Time.Now());

            String json = jsonObj.ToString().Replace("\r\n", "");

            string result = await Post.Get_Response_Str(uri, json);

            Debug.WriteLine(result);

            var message = Message.FromJson(result);

            cookie.syncKey = message.SyncKey;

            foreach (var user in message.AddMsgList)
            {
                if (user.Content.Equals("") || (user.MsgType != 1 && user.MsgType != 3 && user.MsgType != 49) || (user.MsgType == 49 && user.AppMsgType != 5 && user.AppMsgType != 3))
                {
                    continue;
                }
                if (user.FromUserName == wxInit.User.UserName)
                {
                    bool flag = false;
                    for (int i = 0; i < ContactView.AllItems.Count; i++)
                    {
                        if (user.ToUserName == ContactView.AllItems[i].UserName)
                        {
                            BitmapImage bitmap = new BitmapImage();
                            bool        isImg  = false;
                            if (user.MsgType == 3)
                            {
                                String u   = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=" + user.MsgId + "&skey=" + cookie.skey + "&type=slave";
                                var    res = await Get.Get_Response_Str(u, cookie_str);

                                byte[] b = await res.Content.ReadAsByteArrayAsync();

                                bitmap = await ByteArrayToBitmapImage(b);

                                isImg = true;
                            }
                            bubble msg = new bubble();
                            msg.Text = user.Content;
                            msg.setNickName(ContactView.AllItems[i].NickName);
                            if (isImg)
                            {
                                msg.setImg_msg(bitmap);
                            }
                            if (user.MsgType == 49 && user.AppMsgType == 5)
                            {
                                msg.setHyberLink(user.FileName, user.Url);
                            }
                            if (user.MsgType == 49 && user.AppMsgType == 3)
                            {
                                String str;
                                str = user.Content.Replace("&lt;", "<");
                                str = str.Replace("&gt;", ">");
                                str = str.Replace("<br/>", "\n");
                                Debug.WriteLine(str);
                                var music = Music.GetMusic(str);
                                Debug.WriteLine(music.appmsg.dataurl);
                                msg.setMedia(music.appmsg.dataurl);
                                msg.setName(music.appmsg.title);
                            }
                            uri = "http://wx2.qq.com" + wxInit.User.HeadImgUrl;
                            var response = await Get.Get_Response_Str(uri, cookie_str);

                            var r = await response.Content.ReadAsByteArrayAsync();

                            var bit = await ByteArrayToBitmapImage(r);

                            msg.setImg(bit);
                            msg.setNickName(wxInit.User.NickName);
                            Tile.TileManger.Tile(wxInit.User.NickName, ContactView.AllItems[i].NickName);
                            ContactView.AllItems[i].dialog.Add(msg);
                            if (i != 0)
                            {
                                var u = ContactView.AllItems[i];
                                ContactView.AllItems.RemoveAt(i);
                                ContactView.AllItems.Insert(0, u);
                            }
                            if (friend != null && friend.UserName == user.ToUserName)
                            {
                                sp1.Children.Add(msg);
                            }
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        foreach (var member in contact.MemberList)
                        {
                            if (user.ToUserName == member.UserName && !member.UserName[1].Equals('@'))
                            {
                                FriendList friend = new FriendList();
                                friend.UserName = user.ToUserName;
                                friend.NickName = member.NickName;
                                friend.dialog   = new List <bubble>();

                                BitmapImage bitmap = new BitmapImage();
                                bool        isImg  = false;
                                if (user.MsgType == 3)
                                {
                                    String u   = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=" + user.MsgId + "&skey=" + cookie.skey + "&type=slave";
                                    var    res = await Get.Get_Response_Str(u, cookie_str);

                                    byte[] b = await res.Content.ReadAsByteArrayAsync();

                                    bitmap = await ByteArrayToBitmapImage(b);

                                    isImg = true;
                                }

                                uri = "http://wx2.qq.com" + member.HeadImgUrl;
                                var response = await Get.Get_Response_Str(uri, cookie_str);

                                var result_byte = await response.Content.ReadAsByteArrayAsync();

                                friend.bitmap = await ByteArrayToBitmapImage(result_byte);

                                bubble msg = new bubble();
                                // msg.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                                //msg.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
                                msg.Text = user.Content;

                                if (isImg)
                                {
                                    msg.setImg_msg(bitmap);
                                }
                                if (user.MsgType == 49 && user.AppMsgType == 5)
                                {
                                    msg.setHyberLink(user.FileName, user.Url);
                                }
                                if (user.MsgType == 49 && user.AppMsgType == 3)
                                {
                                    String str;
                                    str = user.Content.Replace("&lt;", "<");
                                    str = str.Replace("&gt;", ">");
                                    str = str.Replace("<br/>", "\n");
                                    Debug.WriteLine(str);
                                    var music = Music.GetMusic(str);
                                    Debug.WriteLine(music.appmsg.dataurl);
                                    msg.setMedia(music.appmsg.dataurl);
                                    msg.setName(music.appmsg.title);
                                }
                                uri      = "http://wx2.qq.com" + wxInit.User.HeadImgUrl;
                                response = await Get.Get_Response_Str(uri, cookie_str);

                                var r = await response.Content.ReadAsByteArrayAsync();

                                var bit = await ByteArrayToBitmapImage(r);

                                msg.setImg(bit);
                                msg.setNickName(wxInit.User.NickName);
                                Tile.TileManger.Tile(wxInit.User.NickName, member.NickName);

                                friend.dialog.Add(msg);
                                ContactView.AllItems.Insert(0, friend);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    bool flag = false;
                    for (int i = 0; i < ContactView.AllItems.Count; i++)
                    {
                        if (user.FromUserName == ContactView.AllItems[i].UserName)
                        {
                            Debug.WriteLine(user.MsgType);
                            BitmapImage bit   = new BitmapImage();
                            bool        isImg = false;
                            if (user.MsgType == 3)
                            {
                                String u        = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=" + user.MsgId + "&skey=" + cookie.skey + "&type=slave";
                                var    response = await Get.Get_Response_Str(u, cookie_str);

                                byte[] r = await response.Content.ReadAsByteArrayAsync();

                                bit = await ByteArrayToBitmapImage(r);

                                isImg = true;
                            }
                            bubble msg = new bubble();
                            //msg.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                            //msg.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
                            msg.Text = user.Content;
                            if (isImg)
                            {
                                msg.setImg_msg(bit);
                            }
                            if (user.MsgType == 49 && user.AppMsgType == 5)
                            {
                                msg.setHyberLink(user.FileName, user.Url);
                            }
                            if (user.MsgType == 49 && user.AppMsgType == 3)
                            {
                                String str;
                                str = user.Content.Replace("&lt;", "<");
                                str = str.Replace("&gt;", ">");
                                str = str.Replace("<br/>", "\n");
                                Debug.WriteLine(str);
                                var music = Music.GetMusic(str);
                                Debug.WriteLine(music.appmsg.dataurl);
                                msg.setMedia(music.appmsg.dataurl);
                                msg.setName(music.appmsg.title);
                            }
                            msg.setImg(ContactView.AllItems[i].bitmap);
                            msg.setNickName(ContactView.AllItems[i].NickName);

                            Tile.TileManger.Tile(ContactView.AllItems[i].NickName, wxInit.User.NickName);

                            ContactView.AllItems[i].dialog.Add(msg);

                            if (i != 0)
                            {
                                var u = ContactView.AllItems[i];
                                ContactView.AllItems.RemoveAt(i);
                                ContactView.AllItems.Insert(0, u);
                            }
                            if (friend != null && friend.UserName == user.FromUserName)
                            {
                                sp1.Children.Add(msg);
                            }
                            flag = true;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        foreach (var member in contact.MemberList)
                        {
                            if (user.FromUserName == member.UserName && !member.UserName[1].Equals('@'))
                            {
                                FriendList friend = new FriendList();
                                friend.UserName = user.FromUserName;
                                friend.NickName = member.NickName;
                                friend.dialog   = new List <bubble>();

                                BitmapImage bitmap = new BitmapImage();
                                bool        isImg  = false;
                                if (user.MsgType == 3)
                                {
                                    String u   = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetmsgimg?&MsgID=" + user.MsgId + "&skey=" + cookie.skey + "&type=slave";
                                    var    res = await Get.Get_Response_Str(u, cookie_str);

                                    byte[] b = await res.Content.ReadAsByteArrayAsync();

                                    bitmap = await ByteArrayToBitmapImage(b);

                                    isImg = true;
                                }

                                uri = "http://wx2.qq.com" + member.HeadImgUrl;
                                var response = await Get.Get_Response_Str(uri, cookie_str);

                                var result_byte = await response.Content.ReadAsByteArrayAsync();

                                friend.bitmap = await ByteArrayToBitmapImage(result_byte);

                                bubble msg = new bubble();
                                // msg.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                                //msg.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
                                msg.Text = user.Content;
                                if (isImg)
                                {
                                    msg.setImg_msg(bitmap);
                                }
                                if (user.MsgType == 49 && user.AppMsgType == 5)
                                {
                                    msg.setHyberLink(user.FileName, user.Url);
                                }
                                if (user.MsgType == 49 && user.AppMsgType == 3)
                                {
                                    String str;
                                    str = user.Content.Replace("&lt;", "<");
                                    str = str.Replace("&gt;", ">");
                                    str = str.Replace("<br/>", "\n");
                                    Debug.WriteLine(str);
                                    var music = Music.GetMusic(str);
                                    Debug.WriteLine(music.appmsg.dataurl);
                                    msg.setMedia(music.appmsg.dataurl);
                                    msg.setName(music.appmsg.title);
                                }
                                uri      = "http://wx2.qq.com" + member.HeadImgUrl;
                                response = await Get.Get_Response_Str(uri, cookie_str);

                                var r = await response.Content.ReadAsByteArrayAsync();

                                var bit = await ByteArrayToBitmapImage(r);

                                msg.setImg(bit);
                                msg.setNickName(member.NickName);

                                Tile.TileManger.Tile(member.NickName, wxInit.User.NickName);

                                friend.dialog.Add(msg);
                                ContactView.AllItems.Insert(0, friend);
                                break;
                            }
                        }
                    }
                }
            }

            Debug.WriteLine("读取消息");
            Debug.WriteLine("BaseResponse.Ret:" + message.BaseResponse.Ret);
            Debug.WriteLine("AddMsgCount:" + message.AddMsgCount);
            foreach (var a in message.AddMsgList)
            {
                Debug.WriteLine(a.Content);
            }

            Debug.WriteLine("ModContactCount:" + message.ModContactCount);
            Debug.WriteLine("DelContactCount:" + message.DelContactCount);
            Debug.WriteLine("ModChatRoomMemberCount:" + message.ModChatRoomMemberCount);
        }