Пример #1
0
        private void SynchronizeGroups()
        {
            List <WeChatGroup> allGroups = new List <WeChatGroup>();

            var allAccounts = AccountInfoAdapter.Instance.LoadAll();

            foreach (var account in allAccounts)
            {
                WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                Thread.Sleep(1000);

                WeChatGroupCollection groups = WeChatHelper.GetAllGroups(WeChatRequestContext.Current.LoginInfo);
                Thread.Sleep(1000);

                foreach (var group in groups)
                {
                    group.AccountID = account.AccountID;
                    allGroups.Add(group);
                }
            }

            foreach (var group in allGroups)
            {
                WeChatGroupAdapter.Instance.Update(group);
            }
        }
Пример #2
0
        private void SynchronizeGroupsAndMembersToWeChat()
        {
            var allGroups = ConditionalGroupAdapter.Instance.LoadAll();
            var accounts  = AccountInfoAdapter.Instance.LoadAll();

            WeChatGroupCollection weChatGroups = WeChatGroupAdapter.Instance.LoadAll();

            foreach (var account in accounts)
            {
                WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                Thread.Sleep(1000);

                foreach (var group in allGroups)
                {
                    var fakeIDs = WeChatFriendAdapter.Instance.GetFakeIDsByLocalGroupID(group.GroupID).ToArray(); //找到本组里成员的fakeID

                    var matchedGroup = weChatGroups.Find(p => p.Name == group.Name && p.AccountID == WeChatRequestContext.Current.LoginInfo.AccountID);

                    int groupID = 0;
                    if (matchedGroup == null)
                    {
                        var modifiedGroup = WeChatHelper.AddGroup(group.Name, WeChatRequestContext.Current.LoginInfo);
                        Thread.Sleep(1000);

                        var newGroup = new WeChatGroup()
                        {
                            AccountID = account.AccountID,
                            GroupID   = modifiedGroup.GroupId,
                            Name      = group.Name,
                            Count     = modifiedGroup.MemberCnt
                        };

                        WeChatGroupAdapter.Instance.Update(newGroup);

                        groupID = modifiedGroup.GroupId;
                    }
                    else
                    {
                        groupID = matchedGroup.GroupID;
                    }

                    if (fakeIDs.Length > 0)
                    {
                        WeChatHelper.ChangeFriendsGroup(groupID, fakeIDs, WeChatRequestContext.Current.LoginInfo);
                        Thread.Sleep(1000);
                    }
                }
            }
        }
Пример #3
0
        private void SynchronizeRecentMessages()
        {
            List <WeChatRecentMessage> allMessages = new List <WeChatRecentMessage>();

            var allAccounts = AccountInfoAdapter.Instance.LoadAll();

            foreach (var account in allAccounts)
            {
                WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                Thread.Sleep(1000);

                var flag     = true;
                var curIndex = 0;
                while (flag)
                {
                    WeChatRecentMessageCollection messages = WeChatHelper.GetRecentMessages(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                    Thread.Sleep(1000);

                    foreach (var message in messages)
                    {
                        message.AccountID = account.AccountID;
                        allMessages.Add(message);
                    }

                    if (messages.Count == 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        curIndex++;
                    }
                }
            }

            foreach (var message in allMessages)
            {
                WeChatRecentMessageAdapter.Instance.Update(message);
            }
        }
Пример #4
0
        private void SynchronizeFriends()
        {
            List <WeChatFriend> allFriends = new List <WeChatFriend>();

            var allAccounts = AccountInfoAdapter.Instance.LoadAll();

            foreach (var account in allAccounts)
            {
                WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                Thread.Sleep(1000);

                var flag     = true;
                var curIndex = 0;
                while (flag)
                {
                    WeChatFriendCollection friends = WeChatHelper.GetAllMembers(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                    Thread.Sleep(1000);

                    foreach (var friend in friends)
                    {
                        friend.AccountID = account.AccountID;
                        allFriends.Add(friend);
                    }

                    if (friends.Count == 0)
                    {
                        flag = false;
                    }
                    else
                    {
                        curIndex++;
                    }
                }
            }

            foreach (var friend in allFriends)
            {
                WeChatFriendAdapter.Instance.Update(friend);
            }
        }
Пример #5
0
        private void Synchronize()
        {
            try
            {
                ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);
                List <WeChatRecentMessage> allMessages = new List <WeChatRecentMessage>();

                if (ddlAccount.SelectedIndex == 0)
                {
                    var allAccounts = AccountInfoAdapter.Instance.LoadAll();

                    foreach (var account in allAccounts)
                    {
                        WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                        ProcessProgress.Current.StatusText     = string.Format("正在准备帐号\"{0}\"的数据...", account.UserID);
                        ProcessProgress.Current.Response();
                        Thread.Sleep(1000);

                        var flag     = true;
                        var curIndex = 0;
                        while (flag)
                        {
                            WeChatRecentMessageCollection messages = WeChatHelper.GetRecentMessages(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                            Thread.Sleep(1000);

                            foreach (var message in messages)
                            {
                                message.AccountID = account.AccountID;
                                allMessages.Add(message);
                            }

                            if (messages.Count == 0)
                            {
                                flag = false;
                            }
                            else
                            {
                                curIndex++;
                            }

                            ProcessProgress.Current.Response();
                        }
                    }
                }
                else
                {
                    var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", ddlAccount.SelectedValue)).FirstOrDefault();
                    WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                    ProcessProgress.Current.StatusText     = string.Format("正在准备帐号\"{0}\"的数据...", account.UserID);
                    ProcessProgress.Current.Response();
                    Thread.Sleep(1000);

                    var flag     = true;
                    var curIndex = 0;
                    while (flag)
                    {
                        WeChatRecentMessageCollection messages = WeChatHelper.GetRecentMessages(curIndex, 200, WeChatRequestContext.Current.LoginInfo);
                        Thread.Sleep(1000);

                        foreach (var message in messages)
                        {
                            message.AccountID = account.AccountID;
                            allMessages.Add(message);
                        }

                        if (messages.Count == 0)
                        {
                            flag = false;
                        }
                        else
                        {
                            curIndex++;
                        }

                        ProcessProgress.Current.Response();
                    }
                }

                ProcessProgress.Current.MaxStep    = allMessages.Count;
                ProcessProgress.Current.StatusText = "开始同步...";
                ProcessProgress.Current.Response();

                foreach (var message in allMessages)
                {
                    WeChatRecentMessageAdapter.Instance.Update(message);
                    ProcessProgress.Current.Increment();
                    ProcessProgress.Current.Response();
                }

                ProcessProgress.Current.CurrentStep = 0;
                ProcessProgress.Current.StatusText  = "";
                ProcessProgress.Current.Response();
            }
            catch (System.Exception ex)
            {
                WebUtility.ResponseShowClientErrorScriptBlock(ex);
            }
            finally
            {
                this.Response.Write(MCS.Web.WebControls.SubmitButton.GetResetAllParentButtonsScript(true));
                this.Response.End();
            }
        }
Пример #6
0
        private WeChatAppMessage SendOne(string accountID, ListItem item)
        {
            WeChatAppMessage result = null;

            if (item.Value == "-1")
            {
                var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", accountID)).FirstOrDefault();

                var loginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                Thread.Sleep(1000);

                var uploadedImg = WeChatHelper.UploadFile(imgUploader.ImgProp.FilePath.Decrypt(), loginInfo); //上传图片
                Thread.Sleep(1000);

                WeChatAppMessage message = new WeChatAppMessage();
                message.Title     = txtTitle.Text;
                message.Author    = txtAuthor.Text;
                message.Digest    = txtDigest.Value;
                message.FileID    = uploadedImg.Content;
                message.ShowCover = chkShowInContent.Checked;
                message.Content   = editor.InitialData;
                message.SourceUrl = txtSourceUrl.Text;

                result = WeChatHelper.UpdateAppMessage(message, loginInfo); //新增图文消息

                Thread.Sleep(1000);

                WeChatHelper.MassSendAppMessage(-1, result.AppMessageID.ToString(), loginInfo); //发送,一天一个帐号只能发送一次

                result.Title     = message.Title;
                result.Author    = message.Author;
                result.Digest    = message.Digest;
                result.FileID    = message.FileID;
                result.ShowCover = message.ShowCover;
                result.Content   = message.Content;
                result.SourceUrl = message.SourceUrl;
            }
            else
            {
                var weChatGroup = WeChatGroupAdapter.Instance.Load(p =>
                {
                    p.AppendItem("AccountID", accountID);
                    p.AppendItem("Name", item.Text);
                }).FirstOrDefault();

                if (weChatGroup != null)
                {
                    var account = AccountInfoAdapter.Instance.Load(p => p.AppendItem("AccountID", accountID)).FirstOrDefault();

                    var loginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);
                    Thread.Sleep(1000);

                    var uploadedImg = WeChatHelper.UploadFile(imgUploader.ImgProp.FilePath.Decrypt(), loginInfo); //上传图片
                    Thread.Sleep(1000);

                    WeChatAppMessage message = new WeChatAppMessage();
                    message.Title     = txtTitle.Text;
                    message.Author    = txtAuthor.Text;
                    message.Digest    = txtDigest.Value;
                    message.FileID    = uploadedImg.Content;
                    message.ShowCover = chkShowInContent.Checked;
                    message.Content   = editor.InitialData;
                    message.SourceUrl = txtSourceUrl.Text;

                    result = WeChatHelper.UpdateAppMessage(message, loginInfo); //新增图文消息

                    Thread.Sleep(1000);

                    WeChatHelper.MassSendAppMessage(weChatGroup.GroupID, result.AppMessageID.ToString(), loginInfo); //发送,一天一个帐号只能发送一次

                    result.Title     = message.Title;
                    result.Author    = message.Author;
                    result.Digest    = message.Digest;
                    result.FileID    = message.FileID;
                    result.ShowCover = message.ShowCover;
                    result.Content   = message.Content;
                    result.SourceUrl = message.SourceUrl;
                }
            }

            return(result);
        }
Пример #7
0
        private void SynchronizeToWeChat()
        {
            try
            {
                ProcessProgress.Current.RegisterResponser(SubmitButtonProgressResponser.Instance);

                var allGroups = ConditionalGroupAdapter.Instance.LoadAll();
                var accounts  = AccountInfoAdapter.Instance.LoadAll();

                WeChatGroupCollection weChatGroups = WeChatGroupAdapter.Instance.LoadAll();

                ProcessProgress.Current.MaxStep     = allGroups.Count * accounts.Count;
                ProcessProgress.Current.CurrentStep = 0;
                ProcessProgress.Current.StatusText  = "开始同步...";
                ProcessProgress.Current.Response();

                foreach (var account in accounts)
                {
                    WeChatRequestContext.Current.LoginInfo = WeChatHelper.ExecLogin(account.UserID, account.Password);

                    Thread.Sleep(1000);

                    foreach (var group in allGroups)
                    {
                        var fakeIDs = WeChatFriendAdapter.Instance.GetFakeIDsByLocalGroupID(group.GroupID).ToArray(); //找到本组里成员的fakeID

                        var matchedGroup = weChatGroups.Find(p => p.Name == group.Name && p.AccountID == WeChatRequestContext.Current.LoginInfo.AccountID);

                        int groupID = 0;
                        if (matchedGroup == null)
                        {
                            var modifiedGroup = WeChatHelper.AddGroup(group.Name, WeChatRequestContext.Current.LoginInfo);
                            var newGroup      = new WeChatGroup()
                            {
                                AccountID = account.AccountID,
                                GroupID   = modifiedGroup.GroupId,
                                Name      = group.Name,
                                Count     = modifiedGroup.MemberCnt
                            };

                            WeChatGroupAdapter.Instance.Update(newGroup);
                            Thread.Sleep(1000);
                            groupID = modifiedGroup.GroupId;
                        }
                        else
                        {
                            groupID = matchedGroup.GroupID;
                        }

                        if (fakeIDs.Length > 0)
                        {
                            WeChatHelper.ChangeFriendsGroup(groupID, fakeIDs, WeChatRequestContext.Current.LoginInfo);
                        }

                        ProcessProgress.Current.Increment();
                        ProcessProgress.Current.StatusText = string.Format("帐号\"{0}\",同步组\"{1}\"完成", account.UserID, group.Name);
                        ProcessProgress.Current.Response();
                        Thread.Sleep(1000);
                    }
                }

                ProcessProgress.Current.StatusText = string.Format("同步完成");
                ProcessProgress.Current.Response();
                Thread.Sleep(1000);
            }
            catch (Exception ex)
            {
                WebUtility.ResponseShowClientErrorScriptBlock(ex);
            }
            finally
            {
                this.Response.Write(SubmitButton.GetResetAllParentButtonsScript(true));
                this.Response.End();
            }
        }