Beispiel #1
0
        private void OnInitGot(HttpWebRequest req, HttpWebResponse res)
        {
            StreamReader sr      = new StreamReader(res.GetResponseStream());
            string       str_ret = sr.ReadToEnd();

            sr.Close();

            m_wx_init = (WXInit)Common.DecodeJson(str_ret, typeof(WXInit));
            if (0 != m_wx_init.m_base_response.m_ret)
            {
                MessageBox.Show("获取初始化信息发生错误:" + m_wx_init.m_base_response.m_ret);
                Logout(false);
                return;
            }

            m_wx_msg            = new Dictionary <string, List <WXMsg> >();
            m_wx_names          = new Dictionary <string, string>();
            m_wx_contacts       = new Dictionary <string, WXContact>();
            m_wx_sync_check_key = m_wx_init.m_sync_key;

            EnableStatusNotify();

            GetContacts(0);

            niTray.Text = m_wx_init.m_user.m_nick_name + "(" + m_wx_init.m_user.m_uin + ") 在线";
            this.Text   = niTray.Text;

            AddLog("已成功初始化微信!");
        }
Beispiel #2
0
        private string GetSyncKey(WXSyncKey sync_key)
        {
            StringBuilder sb_sync_key = new StringBuilder();

            for (int i = 0; i < sync_key.m_count; i++)
            {
                sb_sync_key.Append(sync_key.m_list[i].m_key);
                sb_sync_key.Append("_");
                sb_sync_key.Append(sync_key.m_list[i].m_val);
                sb_sync_key.Append("|");
            }

            return(sb_sync_key.ToString().TrimEnd("|".ToCharArray()));
        }
Beispiel #3
0
        private void OnSync(HttpWebRequest req, HttpWebResponse res)
        {
            SyncCheck();

            StreamReader sr      = new StreamReader(res.GetResponseStream());
            string       str_ret = sr.ReadToEnd();

            sr.Close();

            WXSync wxs = (WXSync)Common.DecodeJson(str_ret, typeof(WXSync));

            if (null == wxs ||
                0 != wxs.m_base_response.m_ret)
            {
                MessageBox.Show("同步消息发生错误:" + wxs.m_base_response.m_ret);
                Logout(false);
                return;
            }

            AddLog("已成功获取消息!");

            m_wx_sync_key       = wxs.m_sync_key;
            m_wx_sync_check_key = wxs.m_sync_check_key;

            // 解析信息内容
            lvwContacts.BeginUpdate();

            if (wxs.m_add_msg_count > 0)
            {
                for (int i = 0; i < wxs.m_add_msg_count; i++)
                {
                    //string to_user = wxs.m_add_msg_list[i].m_to_user_name;
                    string from_user = wxs.m_add_msg_list[i].m_from_user_name;
                    if (!lvwContacts.Items.ContainsKey(from_user))
                    {
                        continue;
                    }

                    if (from_user == m_wx_init.m_user.m_user_name) // 自己在其他设备发给他人的信息,同步过来
                    {
                    }

                    if (!m_wx_msg.ContainsKey(from_user))
                    {
                        m_wx_msg.Add(from_user, new List <WXMsg>());
                    }

                    WXMsg msg = wxs.m_add_msg_list[i];
                    m_wx_msg[from_user].Add(msg);

                    string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ");
                    string from_nick_name = m_wx_names[from_user];
                    string show_title = "", content = "";
                    if (from_user.StartsWith("@@")) // 群组信息
                    {
                        Regex           re_content = new Regex(@"(?<=(@(?:[0-9a-f]{32}|[0-9a-f]{64})):\<br/\>)(.+)", RegexOptions.IgnoreCase | RegexOptions.Singleline);
                        GroupCollection cc         = re_content.Match(msg.m_content).Groups;
                        if (3 != cc.Count)
                        {
                            continue;
                        }

                        string member_user_name = cc[1].Value;
                        string member_name      = m_wx_names[member_user_name];
                        content    = cc[2].Value;
                        show_title = member_name + "(" + from_nick_name + ")" + " 发来";
                    }
                    else
                    {
                        content    = msg.m_content;
                        show_title = from_nick_name + " 发来";
                    }

                    switch (msg.m_msg_type)
                    {
                    case 1:     // 文本信息
                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "文本信息:\r\n");
                        rtbContent.AppendText(content + "\r\n\r\n");
                        break;

                    case 3:     // 图像
                        GetImage(msg.m_msg_id);

                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "图片信息:\r\n");

                        System.Diagnostics.Debug.Print(now + show_title);
                        break;

                    case 34:     // 语音
                        GetVoice(msg.m_msg_id);

                        TimeSpan ts_voice  = new TimeSpan(msg.m_voice_length * TimeSpan.TicksPerMillisecond);
                        string   str_voice = "播放语音(" + msg.m_msg_id + ")";
                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "语音信息:\r\n");
                        rtbContent.AppendText("语音长度:" + ts_voice.ToString(@"mm\:ss\.fff") + "\r\n");
                        rtbContent.AppendText(str_voice + "\r\n\r\n");

                        RichTextBoxLinkCreater.CreateLink(rtbContent, rtbContent.TextLength - str_voice.Length - 2, str_voice.Length);
                        break;

                    case 43:     // 视频
                        GetVideo(msg.m_msg_id);

                        TimeSpan ts_video  = new TimeSpan(msg.m_play_length * TimeSpan.TicksPerSecond);
                        string   str_video = "播放视频(" + msg.m_msg_id + ")";
                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "视频信息:\r\n");
                        rtbContent.AppendText("视频长度:" + ts_video.ToString(@"hh\:mm\:ss") + "\r\n");
                        rtbContent.AppendText(str_video + "\r\n\r\n");

                        RichTextBoxLinkCreater.CreateLink(rtbContent, rtbContent.TextLength - str_video.Length - 2, str_video.Length);
                        break;

                    case 49:     // 超链接
                        string url = WebUtility.UrlDecode(msg.m_url);

                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "超链接:\r\n");
                        rtbContent.AppendText("标题:" + WebUtility.UrlDecode(msg.m_encry_file_name) + "\r\n");
                        rtbContent.AppendText("地址:" + url + "\r\n\r\n");

                        RichTextBoxLinkCreater.CreateLink(rtbContent, rtbContent.TextLength - url.Length - 2, url.Length);
                        break;

                    case 10000:     // 红包!!!
                        if ("收到红包,请在手机上查看" == msg.m_content)
                        {
                            niTray.BalloonTipIcon  = ToolTipIcon.Info;
                            niTray.BalloonTipTitle = "¥¥¥收到红包¥¥¥";
                            niTray.BalloonTipText  = show_title + "红包!!!";
                            niTray.ShowBalloonTip(10000);
                        }

                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "系统信息:\r\n");
                        rtbContent.AppendText(content + "\r\n\r\n");
                        break;

                    default:
                        rtbContent.Select(rtbContent.TextLength, 1);
                        rtbContent.AppendText(now + show_title + "未知信息:\r\n");
                        rtbContent.AppendText(Common.EncodeJson(msg) + "\r\n\r\n");
                        break;
                    }

                    m_sound.Play();
                    rtbContent.Select(rtbContent.TextLength, 0);
                }
            }

            if (wxs.m_mod_contact_count > 0)
            {
                GetContacts(0);
            }

            lvwContacts.EndUpdate();
        }