Beispiel #1
0
        private async Task <bool> HeartBeat()
        {
            String uri = "https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck" +
                         "?skey=" + cookie.skey +
                         "&r=" + Time.Now() +
                         "&sid=" + cookie.wxsid +
                         "&uin=" + cookie.wxuin +
                         "&deviceid=" + "e123456789012345" +
                         "&synckey=" + cookie.syncKey.get_urlstring() +
                         "&_=" + Time.Now();

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

            string result = await response.Content.ReadAsStringAsync();

            Debug.WriteLine(result);

            string result_str = result.Split('=')[1];
            string selector   = result_str.Split('"')[3];
            string retcode    = result_str.Split('"')[1];

            //Debug.WriteLine(selector);
            if (retcode.Equals("1101"))
            {
                Frame.Navigate(typeof(Login));
                return(true);
            }

            if (!selector.Equals("0"))
            {
                Get_Message();
            }
            return(false);
        }
Beispiel #2
0
        public void Send(object sender, MouseButtonEventArgs e)
        {
            long   time = Time.Now();
            string url  = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg" +
                          "?sid=" + Data.wxsid +
                          "&skey=" + Data.skey +
                          "&pass_ticket=" + Data.pass_ticket +
                          "&r=" + time;
            WebRequest request = WebRequest.Create(url);

            request.Method = "POST";

            JObject jsonObj = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest));
            SendMsg msg = new SendMsg();

            msg.FromUserName = Data.me.UserName;
            msg.ToUserName   = user.UserName;
            msg.Type         = 1;
            msg.Content      = SendBox.Text.Replace("\r", "");
            msg.ClientMsgId  = time;
            msg.LocalID      = time;
            SendBox.Clear();
            jsonObj.Add("Msg", JObject.FromObject(msg));

            byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", ""));
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader reader    = new StreamReader(dataStream);
            string       ret       = reader.ReadToEnd();
            webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject <webwxsendmsg>(ret);

            reader.Close();
            dataStream.Close();
            response.Close();
            Msg recvmsg = new Msg();

            recvmsg.MsgId        = wxsendmsg.MsgID;
            recvmsg.FromUserName = msg.FromUserName;
            recvmsg.ToUserName   = msg.ToUserName;
            recvmsg.MsgType      = msg.Type;
            recvmsg.Content      = msg.Content;
            recvmsg.CreateTime   = msg.LocalID;

            Trace.WriteLine("发送消息");
            Trace.WriteLine(recvmsg.Content);

            Data.main.记录消息(recvmsg);
        }
Beispiel #3
0
        void 读取消息()
        {
            long   time = Time.Now();
            string url  = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync" +
                          "?pass_ticket=" + Data.pass_ticket +
                          "&sid=" + Data.wxsid +
                          "&skey=" + Data.skey +
                          "&r=" + time;
            WebRequest request = WebRequest.Create(url);

            request.Method = "POST";

            JObject jsonObj = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest));
            jsonObj.Add("SyncKey", JObject.FromObject(Data.synckey));
            jsonObj.Add("rr", time);

            byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", ""));
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            webwxsync    sync   = JsonConvert.DeserializeObject <webwxsync>(reader.ReadToEnd());

            Data.synckey = sync.SyncKey;

            reader.Close();
            dataStream.Close();
            response.Close();

            Trace.WriteLine("读取消息");
            //Trace.WriteLine(url);
            Trace.WriteLine("BaseResponse.Ret:" + sync.BaseResponse.Ret);
            Trace.WriteLine("AddMsgCount:" + sync.AddMsgCount);
            Trace.WriteLine(sync.AddMsgList.ToString());
            Trace.WriteLine("ModContactCount:" + sync.ModContactCount);
            Trace.WriteLine("DelContactCount:" + sync.DelContactCount);
            Trace.WriteLine("ModChatRoomMemberCount:" + sync.ModChatRoomMemberCount);

            if (sync.BaseResponse.Ret != 0)
            {
                MessageBox.Show("读取消息失败,webwxsync.BaseResponse.Ret:" + sync.BaseResponse.Ret, "错误", MessageBoxButton.OK, MessageBoxImage.Information);
                Close();
            }

            foreach (Msg msg in sync.AddMsgList)
            {
                记录消息(msg);
            }
        }
Beispiel #4
0
        void 获取会话()
        {
            string url = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit" +
                         "?pass_ticket=" + Data.pass_ticket +
                         "&skey=" + Data.skey +
                         "&r=" + Time.Now();
            WebRequest request = WebRequest.Create(url);

            request.Method = "POST";

            JObject jsonObj = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest));

            byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", ""));
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            webwxinit    init   = JsonConvert.DeserializeObject <webwxinit>(reader.ReadToEnd());

            Data.me = init.User;
            foreach (User user in init.ContactList)
            {
                if (Data.Chatlist.ContainsKey(user.UserName))
                {
                    continue;
                }
                user.setDisplayName();
                Data.Chatlist.Add(user.UserName, user);
            }

            reader.Close();
            dataStream.Close();
            response.Close();

            Trace.WriteLine("获取会话");
            //Trace.WriteLine(url);
            Trace.WriteLine(jsonObj);
            Trace.WriteLine("BaseResponse.Ret:" + init.BaseResponse.Ret);

            if (init.BaseResponse.Ret != 0)
            {
                MessageBox.Show("初始化失败,webwxinit.BaseResponse.Ret:" + init.BaseResponse.Ret, "错误", MessageBoxButton.OK, MessageBoxImage.Information);
                Close();
            }
            Data.synckey   = init.SyncKey;
            myname.Content = Data.me.NickName;
            myhead.Source  = new ImagePathConverter().getHead(Data.me);
        }
Beispiel #5
0
        private async Task Get_Contact()
        {
            String uri = "http://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact" +
                         "?&r=" + Time.Now();
            var response = await Get.Get_Response_Str(uri, cookie_str);

            string result = await response.Content.ReadAsStringAsync();

            Debug.WriteLine(result);
            contact           = Contact.FromJson(result);
            btnContact.Click += btnContact_Click;
            btnPublic.Click  += btnPublic_Click;
        }
Beispiel #6
0
        void 后台线程(object sender, DoWorkEventArgs e)
        {
            获取二维码();
            backgroundWorker.ReportProgress(0);

            //等待登录
            while (!backgroundWorker.CancellationPending)
            {
                ///cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=YYQaWByPSA==&tip=1&r=-1696543151
                WebRequest request = WebRequest.Create(WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/login" +
                                                       "?loginicon=true&tip=" + tip +
                                                       "&uuid=" + uuid +
                                                       string.Format("&r={0}", 0 - Time.Now()));
                WebResponse  response   = request.GetResponse();
                Stream       dataStream = response.GetResponseStream();
                StreamReader reader     = new StreamReader(dataStream);
                string       ret        = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();
                Trace.WriteLine("等待登录");
                Trace.WriteLine(ret);

                string[] rets = ret.Split(new char[] { '=', ';' });
                string   code = rets[1];
                switch (rets[1])
                {
                case "408":    //超时
                    break;

                case "201":    //已扫描
                    tip = 0;
                    状态报告(1);
                    状态报告(2);
                    backgroundWorker.ReportProgress(201);
                    break;

                case "200":    //已登录
                    状态报告(3);
                    backgroundWorker.ReportProgress(201);
                    redirect_uri = ret.Split('"')[1];
                    backgroundWorker.CancelAsync();
                    break;

                default:    //400,500
                    获取二维码();
                    backgroundWorker.ReportProgress(0);
                    break;
                }
            }
        }
Beispiel #7
0
        void 后台线程(object sender, DoWorkEventArgs e)
        {
            获取二维码();
            backgroundWorker.ReportProgress(0);

            //等待登录
            while (!backgroundWorker.CancellationPending)
            {
                WebRequest request = WebRequest.Create("http://wx.qq.com/cgi-bin/mmwebwx-bin/login" +
                                                       "?tip=" + tip +
                                                       "&uuid=" + uuid +
                                                       "&_=" + Time.Now());
                WebResponse  response   = request.GetResponse();
                Stream       dataStream = response.GetResponseStream();
                StreamReader reader     = new StreamReader(dataStream);
                string       ret        = reader.ReadToEnd();
                reader.Close();
                dataStream.Close();
                response.Close();
                Trace.WriteLine("等待登录");
                Trace.WriteLine(ret);

                string[] rets = ret.Split(new char[] { '=', ';' });
                string   code = rets[1];
                switch (rets[1])
                {
                case "408":    //超时
                    break;

                case "201":    //已扫描
                    tip = 0;
                    //状态报告(1);
                    //状态报告(2);
                    backgroundWorker.ReportProgress(201);
                    break;

                case "200":    //已登录
                    //状态报告(3);
                    backgroundWorker.ReportProgress(201);
                    redirect_uri = ret.Split('"')[1];
                    backgroundWorker.CancelAsync();
                    break;

                default:    //400,500
                    获取二维码();
                    backgroundWorker.ReportProgress(0);
                    break;
                }
            }
        }
Beispiel #8
0
        void 状态提醒()
        {
            long time = Time.Now();
            //string url = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxstatusnotify" +
            //    "?pass_ticket=" + Data.pass_ticket +
            //    "&sid=" + Data.wxsid +
            //    "&skey=" + Data.skey +
            //    "&r=" + time;
            string url = string.Format(WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/webwxstatusnotify?r={0}&pass_ticket={1}&sid={2}&skey={3}",
                                       0 - Time.Now(), Data.pass_ticket, Data.wxsid, Data.skey);

            WebRequest request = WebRequest.Create(url);

            request.Method = "POST";

            JObject jsonObj = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest));
            jsonObj.Add("Code", 3);
            jsonObj.Add("FromUserName", Data.me.UserName);
            jsonObj.Add("ToUserName", Data.me.UserName);
            jsonObj.Add("ClientMsgId", time);

            byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", ""));
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            WebResponse response = request.GetResponse();

            dataStream = response.GetResponseStream();
            StreamReader      reader       = new StreamReader(dataStream);
            webwxstatusnotify statusnotify = JsonConvert.DeserializeObject <webwxstatusnotify>(reader.ReadToEnd());

            reader.Close();
            dataStream.Close();
            response.Close();

            Trace.WriteLine("状态提醒");
            //Trace.WriteLine(url);
            Trace.WriteLine(statusnotify.ToString());
        }
Beispiel #9
0
        void  步消息()
        {
            //string url = "http://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck" +
            //    "?pass_ticket=" + Data.pass_ticket +
            //    "&skey=" + Data.skey +
            //    "&sid=" + Data.wxsid +
            //    "&uin=" + Data.wxuin +
            //    "&deviceid=" + Data.device_id +
            //    "&synckey=" + Data.synckey.get_urlstring() +
            //    "&_=" + Time.Now();

            ///cgi-bin/mmwebwx-bin/synccheck?r=1440585331636&skey=%40crypt_67c13b2d_631cde5822b6fd866704b9045a13d17c&sid=jmTznox8qavfBu7%2F&uin=1547229180&deviceid=e824539813213050&synckey=1_637639781%7C2_637649490%7C3_637649454%7C11_637649450%7C201_1440585302%7C1000_1440581558
            string url = string.Format("https://webpush2.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck?r={0}&pass_ticket={1}&sid={2}&skey={3}&uin={4}&deviceid={5}&synckey={6}&lang=zh_CN",
                                       Time.Now(), Data.pass_ticket, Data.wxsid, Data.skey, Data.wxuin, Data.device_id, Data.synckey.get_urlstring());

            WebRequest   request    = WebRequest.Create(url);
            WebResponse  response   = request.GetResponse();
            Stream       dataStream = response.GetResponseStream();
            StreamReader reader     = new StreamReader(dataStream);
            string       ret_str    = reader.ReadToEnd().Split('=')[1];
            synccheck    ret        = JsonConvert.DeserializeObject <synccheck>(ret_str);

            reader.Close();
            dataStream.Close();
            response.Close();

            Trace.WriteLine("同步消息");
            //Trace.WriteLine(url);
            Trace.WriteLine(ret_str);

            if (!ret.retcode.Equals("0"))
            {
                //MessageBox.Show("同步失败,synccheck.retcode:" + ret.retcode, "错误", MessageBoxButton.OK, MessageBoxImage.Information);
                //Close();
                Trace.WriteLine("同步失败,synccheck.retcode:" + ret.retcode);
            }

            if (!ret.selector.Equals("0"))
            {
                读取消息();
            }
        }
Beispiel #10
0
        private async Task Init()
        {
            BaseRequest baseRequest = new BaseRequest(cookie.wxuin, cookie.wxsid, cookie.skey);
            JObject     jsonObj     = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(baseRequest));
            String json = jsonObj.ToString().Replace("\r\n", "");

            String uri = "https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=" + Time.Now() + "&lang=ch_ZN&pass_ticket=" + cookie.pass_ticket;

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

            //Debug.WriteLine(result);

            wxInit         = weixinInit.Init.FromJson(result);
            cookie.syncKey = wxInit.SyncKey;

            foreach (var member in wxInit.ContactList)
            {
                if (!member.UserName[1].Equals('@') && !member.NickName.Equals("文件传输助手"))
                {
                    FriendList friend = new FriendList();
                    friend.UserName = member.UserName;
                    friend.NickName = member.NickName;
                    friend.dialog   = new List <bubble>();

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

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

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

                    friend.bitmap = await ByteArrayToBitmapImage(r);

                    ContactView.AllItems.Add(friend);
                }
            }
        }
Beispiel #11
0
        void  步消息()
        {
            string url = "http://webpush.weixin.qq.com/cgi-bin/mmwebwx-bin/synccheck" +
                         "?pass_ticket=" + Data.pass_ticket +
                         "&skey=" + Data.skey +
                         "&sid=" + Data.wxsid +
                         "&uin=" + Data.wxuin +
                         "&deviceid=" + Data.device_id +
                         "&synckey=" + Data.synckey.get_urlstring() +
                         "&_=" + Time.Now();

            WebRequest   request    = WebRequest.Create(url);
            WebResponse  response   = request.GetResponse();
            Stream       dataStream = response.GetResponseStream();
            StreamReader reader     = new StreamReader(dataStream);
            string       ret_str    = reader.ReadToEnd().Split('=')[1];
            synccheck    ret        = JsonConvert.DeserializeObject <synccheck>(ret_str);

            reader.Close();
            dataStream.Close();
            response.Close();

            Trace.WriteLine("同步消息");
            //Trace.WriteLine(url);
            Trace.WriteLine(ret_str);

            if (!ret.retcode.Equals("0"))
            {
                MessageBox.Show("同步失败,synccheck.retcode:" + ret.retcode, "错误", MessageBoxButton.OK, MessageBoxImage.Information);
                Close();
            }

            if (!ret.selector.Equals("0"))
            {
                读取消息();
            }
        }
Beispiel #12
0
        void 获取通讯录()
        {
            //string url = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact" +
            //    "?pass_ticket=" + Data.pass_ticket +
            //    "&skey=" + Data.skey +
            //    "&r=" + Time.Now();
            string url = string.Format(WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/webwxgetcontact?r={0}&pass_ticket={1}&skey={2}",
                                       0 - Time.Now(), Data.pass_ticket, Data.skey);
            WebRequest request = WebRequest.Create(url);

            request.Headers.Add(HttpRequestHeader.Cookie, Data.cookie);
            request.ContentType = "application/json; charset=UTF-8";
            WebResponse     response   = request.GetResponse();
            Stream          dataStream = response.GetResponseStream();
            StreamReader    reader     = new StreamReader(dataStream);
            webwxgetcontact getcontact = JsonConvert.DeserializeObject <webwxgetcontact>(reader.ReadToEnd());

            foreach (User user in getcontact.MemberList)
            {
                user.setDisplayName();
                Data.Contactlist.Add(user.UserName, user);
            }

            reader.Close();
            dataStream.Close();
            response.Close();

            Trace.WriteLine("获取通讯录");
            //Trace.WriteLine(url);
            Trace.WriteLine("BaseResponse.Ret:" + getcontact.BaseResponse.Ret);
            Trace.WriteLine("MemberCount:" + getcontact.MemberCount);

            if (getcontact.BaseResponse.Ret != 0)
            {
                MessageBox.Show("获取通讯录失败,webwxgetcontact.BaseResponse.Ret:" + getcontact.BaseResponse.Ret, "错误", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Beispiel #13
0
        void 获取二维码图片()
        {
            Uri uri = new Uri("http://login.weixin.qq.com/qrcode/" + uuid + "?t=webwx&_=" + Time.Now(), UriKind.Absolute);

            qrcode.Source = new BitmapImage(uri);
        }
Beispiel #14
0
        void 获取二维码uuid()
        {
            string         uri        = "http://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&redirect_uri=http%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=" + Time.Now();
            HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(uri);
            WebResponse    response   = request.GetResponse();
            Stream         dataStream = response.GetResponseStream();
            StreamReader   reader     = new StreamReader(dataStream);
            string         ret        = reader.ReadToEnd();

            reader.Close();
            dataStream.Close();
            response.Close();
            uuid = ret.Split('"')[1];
            tip  = 1;
        }
Beispiel #15
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);
        }
Beispiel #16
0
        void 状态报告(int state)
        {
            Trace.WriteLine("状态报告" + state);
            string postData = "";

            switch (state)
            {
            case 1:
                login_time = DateTime.Now;
                postData   = "{\"BaseRequest\":{\"Uin\":0,\"Sid\":0},\"Count\":1,\"List\":[{\"Type\":1,\"Text\":\"/cgi-bin/mmwebwx-bin/login, First Request Success, uuid: " + uuid + "\"}]}";
                break;

            case 2:
                postData = "{\"BaseRequest\":{\"Uin\":0,\"Sid\":0},\"Count\":1,\"List\":[{\"Type\":1,\"Text\":\"/cgi-bin/mmwebwx-bin/login, Second Request Start, uuid: " + uuid + "\"}]}";
                break;

            case 3:
                postData = "{\"BaseRequest\":{\"Uin\":0,\"Sid\":0},\"Count\":1,\"List\":[{\"Type\":1,\"Text\":\"/cgi-bin/mmwebwx-bin/login, Second Request Success, uuid: " + uuid + ", time: " + (DateTime.Now - login_time).Milliseconds + "ms\"}]}";
                break;
            }

            string     url     = WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/webwxstatreport?type=1&skey=&pass_ticket=undefined&r=" + Time.Now();
            WebRequest request = WebRequest.Create(url);

            request.Method = "POST";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();

            response.Close();
        }
Beispiel #17
0
        void 获取二维码图片()
        {
            ///qrcode/YYQaWByPSA==
            Uri uri = new Uri(WeGlobal.WechatHost + "qrcode/" + uuid + "?t=webwx&_=" + Time.Now(), UriKind.Absolute);

            qrcode.Source = new BitmapImage(uri);
        }
Beispiel #18
0
        void 获取二维码uuid()
        {
            // /jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN
            string         uri     = WeGlobal.WechatHost + "jslogin?appid=wx782c26e4c19acffb&redirect_uri=https%3A%2F%2Fwx2.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage&fun=new&lang=zh_CN&_=" + Time.Now();
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            //X509Certificate2 certificate = new X509Certificate2(PATH_TO_CERTIFICATE, PASSWORD, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);
            //request.ClientCertificates.Add(new X509Certificate(@"D:\abc.cer"));
            request.UserAgent       = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36";
            request.ProtocolVersion = HttpVersion.Version10;
            WebResponse  response   = request.GetResponse();
            Stream       dataStream = response.GetResponseStream();
            StreamReader reader     = new StreamReader(dataStream);
            string       ret        = reader.ReadToEnd();

            reader.Close();
            dataStream.Close();
            response.Close();

            uuid = ret.Split('"')[1];
            tip  = 1;
        }
Beispiel #19
0
        private async Task Get_uuid()
        {
            String        uri      = "https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_=" + Time.Now();
            StringBuilder s        = new StringBuilder();
            var           response = await Get.Get_Response_Str(uri, "");

            string result = await response.Content.ReadAsStringAsync();

            uuid = result.Split('"')[1];

            Debug.WriteLine(uuid);
        }
Beispiel #20
0
        private async Task Get_redirect_uri()
        {
            String uri = "https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?uuid=" + uuid + "&tip=1&_=" + Time.Now();

            var response = await Get.Get_Response_Str(uri, "");

            string result = await response.Content.ReadAsStringAsync();

            code = result.Split(new char[] { '=', ';' })[1];
            if (code.Equals("200"))
            {
                redirect_uri = result.Split('"')[1];
            }

            Debug.WriteLine(redirect_uri);
        }
Beispiel #21
0
        private async void Send_Message(object sender, RoutedEventArgs e)
        {
            if (friend != null)
            {
                String uri = "http://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg" +
                             "?sid=" + cookie.wxsid +
                             "&skey=" + cookie.skey +
                             "&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));

                SendMsg msg = new SendMsg();
                msg.FromUserName = wxInit.User.UserName;
                msg.ToUserName   = friend.UserName;
                msg.Type         = 1;
                msg.Content      = send.Text;
                msg.ClientMsgId  = Time.Now();
                msg.LocalID      = Time.Now();
                jsonObj.Add("Msg", JObject.FromObject(msg));


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

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

                for (int i = 0; i < ContactView.AllItems.Count; i++)
                {
                    if (friend.UserName == ContactView.AllItems[i].UserName)
                    {
                        bubble m = new bubble();
                        m.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
                        m.VerticalAlignment   = Windows.UI.Xaml.VerticalAlignment.Top;
                        m.Text = send.Text;

                        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);

                        m.setImg(bit);
                        m.setNickName(wxInit.User.NickName);

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

                        ContactView.AllItems[i].dialog.Add(m);
                        if (i != 0)
                        {
                            var u = ContactView.AllItems[i];
                            ContactView.AllItems.RemoveAt(i);
                            ContactView.AllItems.Insert(0, u);
                        }
                        sp1.Children.Add(m);
                        send.Text = "";
                    }
                }
            }
        }
Beispiel #22
0
        public async void SendMessage(string contact, string message)
        {
            var u = from c in Data.Contactlist where (c.Value.NickName == contact ||
                                                      c.Value.DisplayName == contact || c.Value.Alias == contact) select c.Value;

            if (u.Count() == 0)
            {
                Trace.WriteLine(string.Format("发送消息失败!未找到群:{0}, 消息:{1}。", contact, message));
                return;
            }
            string userKey = u.First().UserName;
            long   time    = Time.Now();

            string url = string.Format(WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/webwxsendmsg?r={0}&pass_ticket={1}&sid={2}&skey={3}",
                                       time, Data.pass_ticket, Data.wxsid, Data.skey);

            WebRequest request = WebRequest.Create(url);

            //HttpWebRequest request = HttpWebRequest.CreateHttp(url);
            request.Method = "POST";

            JObject jsonObj = new JObject();

            jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest));
            SendMsg msg = new SendMsg();

            msg.FromUserName = Data.me.UserName;
            msg.ToUserName   = userKey;
            msg.Type         = 1;
            msg.Content      = message.Replace("\r", "");
            msg.ClientMsgId  = time;
            msg.LocalID      = time;

            jsonObj.Add("Msg", JObject.FromObject(msg));

            byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", ""));
            request.ContentType   = "application/json; charset=UTF-8";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();

            Trace.WriteLine("发送消息...");
            Trace.WriteLine(jsonObj.ToString().Replace("\r\n", ""));

            WebResponse response = await request.GetResponseAsync();

            dataStream = response.GetResponseStream();
            StreamReader reader    = new StreamReader(dataStream);
            string       ret       = reader.ReadToEnd();
            webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject <webwxsendmsg>(ret);

            reader.Close();
            dataStream.Close();
            response.Close();

            //如果发送失败,调用同步消息获取最新synckey, 再重发一次?
            if (wxsendmsg.MsgID == null)
            {
                this.步消息();
                response   = request.GetResponse();
                dataStream = response.GetResponseStream();
                reader     = new StreamReader(dataStream);
                ret        = reader.ReadToEnd();
                wxsendmsg  = JsonConvert.DeserializeObject <webwxsendmsg>(ret);
                reader.Close();
                dataStream.Close();
                response.Close();
            }

            Trace.WriteLine(string.Format("发送消息成功!发送到:{0}, 消息:{1}。", contact, message));
        }