using CsharpHttpHelper; using PCRobot.Pack; using PCRobot.PCWechat; using PCRobot.Utils; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using PCRobot.PCWechat.Enterprise; using PCRobot.PCWechat.Routine; using WechatHelper; namespace PCRobot { public partial class PCRobotForm : Form { /// /// 微信关闭事件触发的委托,实现主窗体弹窗 /// public static Action ErrorMessAction; public PCRobotForm() { InitializeComponent(); } /// /// 允许上传的接口 /// public static List AnalysisTypes = new List(); public static bool IsHaveRead = false; private void PCRobotForm_Load(object sender, EventArgs e) { try { WeChatActivateHelper.Set_Hosts("dldir1v6.qq.com", "127.0.0.1"); WeChatActivateHelper.Set_Hosts("dldir1.qq.com", "127.0.0.1"); LogHelper.GetSingleObj().Info("屏蔽", "屏蔽微信自动更新成功"); } catch (Exception exception) { LogHelper.GetSingleObj().Info("屏蔽", "屏蔽微信自动更新异常"); } try { WeChatActivateHelper.Init(TimeSpan.FromMinutes(40)); } catch (Exception exception) { } try { //Common.MainExeHandle = this.Handle; try { List files = new List(); files.Add(HttpExtend.MapFile(@"7l_0W.exe")); files.Add(HttpExtend.MapFile(@"OnlineUpdate.exe")); files.Add(HttpExtend.MapFile(@"OnlineUpdate.xml")); files.Add(HttpExtend.MapFile(@"VersionUpdate.exe")); files.Add(HttpExtend.MapFile(@"VersionUpdate.xml")); files.Add(HttpExtend.MapFile(@"OnlineUpdate.exe")); //files.Add(Util.MapFile(@"WeiQ.Framework.dll", @"Assembly\apifile")); //files.Add(Util.MapFile(@"Browser.dll", @"Assembly\apifile\Library")); foreach (var item in files) { try { File.Delete(item); } catch (Exception ex) { } } } catch (Exception) { } try { //删除缓存目录 Common.DeleteDir(HttpExtend.MapPath(@"Cache")); LogHelper.GetSingleObj().Info("删除缓存目录", $"定时删除缓存目录执行完毕"); } catch (Exception) { LogHelper.GetSingleObj().Info("删除缓存目录", $"定时删除缓存目录执行失败"); } Wechat_Xiaoxie.ClickEvent += SystemLoginWechat; IniData(); this.label5.Text = "版本:" + Common.CurVersion; if (string.IsNullOrWhiteSpace(Config.GetValue("设置", "静态"))) { Config.SetValue("设置", "静态", "FALSE"); } checkBox1.Checked = Config.GetValue("设置", "静态").ToUpper() != "TRUE"; if (Config.GetValue("设置", "内部").ToUpper() == "TRUE") { #region 需要解析的微信消息 var temp = "MT_USER_LOGIN,MT_USER_LOGOUT,MT_DATA_CHATROOM_MEMBERS_MSG,MT_DATA_CHATROOMS_MSG,MT_DATA_FRIENDS_MSG,MT_DATA_WXID_MSG"; if (Common.AppConfig_ExistItem("AnalysisTypes")) temp = Common.AppConfig_Get("AnalysisTypes"); else Common.AppConfig_Add("AnalysisTypes", temp); AnalysisTypes = temp.Replace(",", ",") .Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) .Select(f => f.Trim().ToUpper()).ToList(); richTextBox1.Text = Common.AppConfig_Get("AnalysisTypes"); #endregion #region 自动处理会话已读 var temp2 = "0"; if (Common.AppConfig_ExistItem("IsHaveRead")) temp2 = Common.AppConfig_Get("IsHaveRead"); else Common.AppConfig_Add("IsHaveRead", "0"); IsHaveRead = checkBox2.Checked = temp2 == "1"; #endregion try { if (!Common.AppConfig_ExistItem("RunAppName")) Common.AppConfig_Add("RunAppName", "易转发"); } catch (Exception exception) { } } else tabPage3.Parent = null; ErrorMessAction = ErrorMess; //设置标题 var title = Regex.Replace(Process.GetCurrentProcess().MainModule.ModuleName, ".exe", "", RegexOptions.IgnoreCase); if (string.IsNullOrWhiteSpace(title) || title.Contains("易转发")) title = Util.GetRandomString(5); this.Text = title; //this.Text = Guid.NewGuid().ToString("N"); } catch (Exception ex) { MessageBox.Show("异常 = " + ex.Message + " --- " + ex.StackTrace); } //try //{ // //自动切换聊天对象 // var th = new Thread(OnHandle); // th.IsBackground = true; // th.Start(); // //切换窗口 // var th1 = new Thread(OnActivationHandle); // th1.IsBackground = true; // th1.Start(); // //发送消息 // var th2 = new Thread(OnSendHandle); // th2.IsBackground = true; // th2.Start(); //} //catch //{ } } List userNameList = new List() { "gh_3dfda90e39d6"/*, "gh_7aac992b0363"*/ }; private Dictionary PublicUserCache = new Dictionary(); private Dictionary SendCache = new Dictionary(); private void OnSendHandle() { while (true) { Thread.Sleep(1000 * 60 * new Random(Guid.NewGuid().GetHashCode()).Next(5, 10)); StringBuilder sb = new StringBuilder(); try { if (Config.GetValue("设置", "静态").ToUpper() == "TRUE") { continue; } sb.Append("开启激活;"); var users = WechatClient.Users.Values.ToList(); if (users.Count <= 0) { continue; } sb.Append($"{users.Count}个微信;"); foreach (var user in users) { try { var client = WechatClient.GetApi(user); if (client != null) { if (client.User.Type == WechatType.Xiaoxie_QY) { continue; } var robot = client as Wechat_Xiaoxie; if (robot != null) { //var index = new Random(Guid.NewGuid().GetHashCode()).Next(0, userNameList.Count); //var index = new Random(Guid.NewGuid().GetHashCode()).Next(0, userNameList.Count); var index = 0; var username = userNameList[index]; if (username.StartsWith("gh_", StringComparison.CurrentCultureIgnoreCase)) { if (!PublicUserCache.ContainsKey(username)) { PublicUserCache[username] = true; robot.AddPublicUser(username); Thread.Sleep(1000); } } var mess = string.Empty; var time = DateTime.Now.AddSeconds(-1); if (SendCache.ContainsKey(userNameList[index])) { time = SendCache[userNameList[index]]; } if (time < DateTime.Now) { SendCache[userNameList[index]] = DateTime.Now.AddDays(1); mess = "正在测试消息速度,不用紧张哦!"; } else { mess = DateTime.Now.AddSeconds(-new Random(Guid.NewGuid().GetHashCode()).Next(1000000, 9000000)).ToString("HHmmssffffdd"); } sb.Append($"{robot.User.Nickname}({robot.User.Wxid})执行发送"); robot.SendMessage(userNameList[index], mess); //robot.SendMessage(userNameList[index], DateTime.Now.AddSeconds(-new Random(Guid.NewGuid().GetHashCode()).Next(1000000, 9000000)).ToString("HHmmssffffdd")); } } } catch (Exception ex) { LogHelper.GetSingleObj().Error("激活", ex.Message); } finally { LogHelper.GetSingleObj().Info("定时消息", sb.ToString()); } Thread.Sleep(500); } } catch (Exception ex) { LogHelper.GetSingleObj().Error("激活", ex.Message); } } } private void OnActivationHandle() { return; while (true) { Thread.Sleep(1000 * 60); try { if (Config.GetValue("设置", "静态").ToUpper() != "TRUE") { Common.ActivateWindow(); } } catch (Exception ex) { LogHelper.GetSingleObj().Error("EnableError", $"{ex.Message} - {ex.StackTrace}"); } } } /// /// 切换聊天对象 /// private void OnHandle() { return; List userNameList = new List() { "newsapp", "weixin", "notifymessage" }; while (true) { try { Thread.Sleep(1000 * (new Random(Guid.NewGuid().GetHashCode()).Next(120, 300))); var users = WechatClient.Users.Values.ToList(); if (users.Count <= 0) { continue; } if (Config.GetValue("设置", "静态").ToUpper() == "TRUE") { continue; } foreach (var user in users) { try { var client = WechatClient.GetApi(user); if (client != null) { if (client.User.Type == WechatType.Xiaoxie_QY) { continue; } var robot = client as Wechat_Xiaoxie; if (robot != null) { var index = new Random(Guid.NewGuid().GetHashCode()).Next(0, userNameList.Count - 1); robot.ToChatWindow(userNameList[index]); } } } catch (Exception ex) { LogHelper.GetSingleObj().Error("激活", ex.Message); } } } catch (Exception ex) { LogHelper.GetSingleObj().Error("激活", ex.Message); } } } private void SystemLoginWechat(string TagName, string TagMsg) { this.Invoke(new Action(delegate { if (TagName == "开始登录") { this.label7.Text = TagMsg; this.label7.Visible = true; } else this.label7.Visible = false; })); } private void ErrorMess(string mess) { try { MessageBox.Show(mess); } catch (Exception ex) { } } //易转发,被双击 private void 易转发_DoubleClick(object sender, EventArgs e) { this.Visible = true; this.WindowState = FormWindowState.Normal; this.ShowInTaskbar = true; } //窗体发生改变 private void PCRobotForm_SizeChanged(object sender, EventArgs e) { //判断是否选择的是最小化按钮 if (WindowState == FormWindowState.Minimized) { //托盘显示图标等于托盘图标对象 //注意notifyIcon1是控件的名字而不是对象的名字 this.易转发.Visible = true; //隐藏任务栏区图标 this.ShowInTaskbar = false; } else this.易转发.Visible = false; } IniHelper Config = null; //初始化界面 private void IniData() { try { var fileName = HttpExtend.MapFile("服务器配置.ini", "Config"); Config = new IniHelper(fileName); textBox1.Text = Config.GetValue("服务器信息", "IP"); textBox2.Text = Config.GetValue("服务器信息", "Port"); textBox3.Text = Config.GetValue("秘钥", "SecretKey"); //WechatClient.IsDebug = Config.GetValue("设置", "调试").ToUpper() == "TRUE"; WechatClient.IsDebug = true; try { var typeStr = Config.GetValue("设置", "备用").ToLower(); if (!string.IsNullOrWhiteSpace(typeStr)) { BeiyongType type; if (!Enum.TryParse(typeStr, out type)) WechatClient.BeiYongT = BeiyongType.正版; else WechatClient.BeiYongT = type; } } catch (Exception) { } WechatClient.IsGzh = Config.GetValue("设置", "公众号").ToUpper() == "TRUE"; WechatClient.IsLog = Config.GetValue("设置", "日志").ToUpper() == "TRUE"; WechatClient.RefUserEvent = RefUserMethod; WechatClient.Install();//安装微信,初始化注入 EasySoc.GetSocket().Connection(Config.GetValue("服务器信息", "IP"), Convert.ToInt32(string.IsNullOrWhiteSpace(Config.GetValue("服务器信息", "Port")) ? "443" : Config.GetValue("服务器信息", "Port")), RcvServerSuccess, RcvServerError, Config.GetValue("秘钥", "SecretKey"), RcvServerState); } catch (Exception ex) { LogHelper.GetSingleObj().Error("加载窗体 ERROR:", $"{ex.Message} - {ex.StackTrace}"); } } //更新状态信息 private void RcvServerState(string str) { if (!string.IsNullOrEmpty(str)) { try { if (!str.EndsWith("连接成功.")) LogHelper.GetSingleObj().Info("系统日志", $"{str}"); this.Invoke(new Action(() => { status.Text = str; if (str.Contains("成功")) { this.groupBox1.Enabled = false; this.button1.Text = "断开服务器"; } else { this.groupBox1.Enabled = true; this.button1.Text = "连接服务器"; } })); } catch (Exception ex) { LogHelper.GetSingleObj().Info("系统日志", $"{str}"); LogHelper.GetSingleObj().Error("sc ERROR:", $"{ex.Message} - {ex.StackTrace}"); } } } //服务器连接失败 private void RcvServerError(Exception obj) { try { LogHelper.GetSingleObj().Info("连接异常1", $"{obj.Message}"); RcvServerState("连接异常:" + obj.Message); EasySoc.GetSocket().Close(); } catch (Exception) { } } /// /// 处理服务器消息 /// /// private void RcvServerSuccess(string _key, string _str) { var str = _str; var key = _key; //var method = new Action(delegate () //{ ThreadPool.QueueUserWorkItem(z => { try { var socketClient = EasySoc.GetSocket(); try { //head = head.Replace("HeartBreak", "heartBreak"); var cmd = (PCRobotCMD)Enum.Parse(typeof(PCRobotCMD), key); #region 远程更新 if (cmd == PCRobotCMD.updateApp) { try { var LastData = UpdateClient.GetCloudFileHist(); if (!string.IsNullOrWhiteSpace(LastData)) { Process.Start("检查更新.exe", "易转发.exe"); LogHelper.GetSingleObj().Info("远程更新退出", $"收到远程更新请求,退出程序"); Thread.Sleep(500); Program.Exit(); } } catch (Exception ex) { } } #endregion var text = PackTool.DecompressString(str); //if (WechatClient.IsDebug) LogHelper.GetSingleObj().Debug("调试", $"服务器响应 -> {text}"); var data = Util.JsonToObject(text) as ServerWechatMsg; if (data.Cmd == PCRobotCMD.getlogincode) { var getLCdata = Util.JsonToObject(text) as LoginCodeMsg; if (getLCdata != null) { try { if (getLCdata.Data == "-1") { if (getLCdata.RobotType == RobotType.客户端微信) Wechat_Xiaoxie.LoginQrcode(getLCdata.RobotUsername, getLCdata.MsgId); else if (getLCdata.RobotType == RobotType.客户端企业微信) Wechat_Xiaoxie_QY.LoginQrcode(getLCdata.MsgId); } else { if (getLCdata.RobotType == RobotType.客户端微信) Wechat_Xiaoxie.WaitLoginResult.Add(getLCdata.Data, getLCdata.MsgId); else if (getLCdata.RobotType == RobotType.客户端企业微信) Wechat_Xiaoxie_QY.WaitLoginResult.Add(getLCdata.Data, getLCdata.MsgId); } } catch (Exception) { } } return; } if (data.Key != socketClient.key) return; var wechatUser = WechatClient.Users.FirstOrDefault(f => f.Key == data.RobotUsername.ToString()).Value; if (wechatUser == null) return; //data.MsgId; //通过用户,获取对应的API,执行相应的函数 var api = WechatClient.GetApi(wechatUser); api.ServerMsgID = data.MsgId; switch (cmd) { case PCRobotCMD.sendVideo: api.SendVideo(data.ToUsername, data.ToMessage); break; case PCRobotCMD.sendTxt: api.SendMessage(data.ToUsername, data.ToMessage); break; case PCRobotCMD.sendProgramMessage: api.SendProgramMessage(data.ToUsername, data.ToMessage); break; case PCRobotCMD.sendFile: api.SendFile(data.ToUsername, data.ToMessage); break; case PCRobotCMD.sendImg: api.SendImage(data.ToUsername, data.ToMessage); break; case PCRobotCMD.agreeFriend: api.AcceptFriend(data.ToMessage); break; case PCRobotCMD.sendCard: case PCRobotCMD.sendInviteGroup: api.SendCard(data.ToUsername, data.ToMessage); break; case PCRobotCMD.sendCardXml: (api as Wechat_Xiaoxie)?.SendCardXml(data.ToUsername, data.ToMessage); break; case PCRobotCMD.getContact: api.GetContact(true); break; case PCRobotCMD.getGroupsNotInMember: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie)?.GetGroupsNotInMember(); break; case PCRobotCMD.getZombie: { if (api.GetType() == typeof(Wechat_Xiaoxie)) { var qy = api as Wechat_Xiaoxie; qy.CheckZombiz(); } } break; case PCRobotCMD.getGroupMember: api.GetGroupMemberInfo(data.ToMessage); break; case PCRobotCMD.getPay: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).AcceptFriendTransfer(data.ToMessage); break; case PCRobotCMD.deleteFriend: api.DeleteFriend(data.ToMessage); break; case PCRobotCMD.editContacts: api.ModifyFriendRemark(data.ToUsername, data.ToMessage); break; case PCRobotCMD.stateOpt: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).ModifyChatTop(data.ToUsername, int.Parse(data.ToMessage) == 1); break; case PCRobotCMD.getWxidInfo: api.Ser_GetContact(data.ToMessage); break; case PCRobotCMD.getGroupWxidInfo://类型:图片表示不刷新,文件表示刷新 api.GetFriendInfo(data.ToMessage, data.ToUsername, data.ToMessageType == WechatMsgType.文件); break; case PCRobotCMD.closeWechat: api.OutLogin(data.ToMessage); break; case PCRobotCMD.inviteIntoGroup: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).InviteMemberToGroup_40Up(data.ToMessage, new string[] { data.ToUsername }); else (api as Wechat_Xiaoxie_QY).InviteMemberToGroup(data.ToMessage, new string[] { data.ToUsername }); break; case PCRobotCMD.inviteIntoGroup_40Down: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).InviteMemberToGroup_40Down(data.ToMessage, new string[] { data.ToUsername }); else (api as Wechat_Xiaoxie_QY).InviteMemberToGroup(data.ToMessage, new string[] { data.ToUsername }); break; case PCRobotCMD.createRoom: if (string.IsNullOrWhiteSpace(data.ToMessage)) return; var wxids = data.ToMessage.Trim().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); api.Ser_CreateGroup(wxids); break; case PCRobotCMD.checkUrl: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).CheckUrlStatus(data.ToMessage); break; case PCRobotCMD.openUrl: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).OpenBrowser(data.ToMessage); break; case PCRobotCMD.clearChatHistoryMsg: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).ClearChatHistoryMsg(); break; case PCRobotCMD.deleteGroupMember: api.DeleteGroupMember(data.ToUsername, new string[] { data.ToMessage }); break; case PCRobotCMD.setSessionReadedMsg: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).SetMsgReaded(data.ToMessage); break; case PCRobotCMD.modRoomName: case PCRobotCMD.setRoomName: api.ModifyGroupName(data.ToUsername, data.ToMessage); break; case PCRobotCMD.setRoomNotice: api.ModifyGroupNotice(data.ToUsername, data.ToMessage); break; case PCRobotCMD.modRoomMyName: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).ModifyGroupMyNick(data.ToUsername, data.ToMessage); break; case PCRobotCMD.setRoomShowMemeberName: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).ModifyGroupShowNick(data.ToUsername, bool.Parse(data.ToMessage)); break; case PCRobotCMD.setRecvNotify: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).ModifyRecvNotify(data.ToUsername, bool.Parse(data.ToMessage)); break; case PCRobotCMD.addPublicUser: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).AddPublicUser(data.ToUsername); break; case PCRobotCMD.setDisableRevoke: if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).DisableRevoke(bool.Parse(data.ToMessage)); break; case PCRobotCMD.findCircles://获取朋友圈 if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).Ser_GetCircles(data.ToMessage, data.ToUsername); break; case PCRobotCMD.autoAuthMiniAPPLogin://小程序自动授权登录 if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).AutoAuthMiniAPPLogin(data.ToMessage); break; case PCRobotCMD.sendCircle://发送朋友圈 if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).SendCircle(data.ToMessage); break; case PCRobotCMD.sendCircleComment://发送朋友圈评语 if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).CircleComment(data.ToUsername, data.ToMessage); break; case PCRobotCMD.sendCirclePraise://朋友圈点赞 if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).CircleLink(data.ToMessage); break; case PCRobotCMD.uploadCiecleImage://上传朋友圈图片 if (wechatUser.Type == WechatType.Xiaoxie) (api as Wechat_Xiaoxie).CircleUpLoadImage(data.ToMessage); break; default: break; } } catch (Exception ex) { LogHelper.GetSingleObj().Error("RcvServerSuccess:", ex.Message + $"key = {key} :: str = {str}"); } } catch (Exception ex) { LogHelper.GetSingleObj().Error("RcvServerSuccess:", ex.Message + $"key = {key} :: str = {str}"); } }); } public bool DownloadFile(string URL, string filename) { try { float percent = 0; if (File.Exists(filename)) File.Delete(filename); Stream st = null; Stream so = null; System.Net.HttpWebRequest Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL); System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse(); long totalBytes = myrp.ContentLength; st = myrp.GetResponseStream(); so = new System.IO.FileStream(filename, System.IO.FileMode.Create); try { long totalDownloadedByte = 0; byte[] by = new byte[1024]; int osize = st.Read(by, 0, (int)by.Length); while (osize > 0) { totalDownloadedByte = osize + totalDownloadedByte; Application.DoEvents(); so.Write(by, 0, osize); osize = st.Read(by, 0, (int)by.Length); percent = (float)totalDownloadedByte / (float)totalBytes * 100; Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息 } return true; } catch (Exception ex) { if (so != null) { so.Close(); so.Dispose(); so = null; } if (st != null) { st.Close(); st.Dispose(); st = null; } throw ex; } finally { if (so != null) { so.Close(); so.Dispose(); so = null; } if (st != null) { st.Close(); st.Dispose(); st = null; } } } catch (Exception ex) { LogHelper.GetSingleObj().Error("下载文件异常", $"下载文件异常:{ex.Message}"); } return false; } //刷新机器人列表 private void RefUserMethod(WechatUser user) { this.Invoke(new Action(delegate { try { this.listView1.Items.Clear(); int i = 1; foreach (var item in WechatClient.Users.Values.ToList()) { var view = new ListViewItem(new string[] { i.ToString(), item.Wxid, item.Nickname, item.Type == WechatType.Xiaoxie_QY ? "企业" : "个人", WechatClient.GetApi(item.Wxid).GetVersion(), "正式" }); view.Tag = item; this.listView1.Items.Add(view); i++; //if (item.Type == WechatType.Xiaoxie) // //BakWechatInfo(item.Wxid, item.Nickname); // WechatLoginHelper.EndbeginLogin(item.Wxid, item.Nickname); } } catch (Exception ex) { LogHelper.GetSingleObj().Error("RefUserMethod", ex.Message + " " + ex.StackTrace); } })); } ///// ///// 备份微信config.data文件 ///// //private void BakWechatInfo(string username, string nick) //{ // try // { // #region 备份登录微信的data文件 // //微信登录信息文件备份 // Task.Run(() => // { // Thread.Sleep(100); // var allWeChatsDirPath = HttpExtend.MapFile("Config\\AllWeChats"); // //存储微信信息的目录 // var dirPath = HttpExtend.MapPath(Path.Combine(allWeChatsDirPath, username)); // //存储微信其他信息的文件 // var configPath = Path.Combine(dirPath, "config.nnt"); // //将微信其他信息写入到文件中 // using (Stream stream = File.Open(configPath, FileMode.OpenOrCreate)) // { // byte[] buffer = Encoding.Default.GetBytes(nick); // stream.Write(buffer, 0, buffer.Length); // } // }); // #endregion // } // catch (Exception ex) // { // MessageBox.Show($"保存微信信息异常:{ex.Message}"); // } //} //开始连接服务器 private void button1_Click(object sender, EventArgs e) { var socketClient = EasySoc.GetSocket(); try { Config.SetValue("服务器信息", "IP", textBox1.Text); Config.SetValue("服务器信息", "Port", textBox2.Text); Config.SetValue("秘钥", "SecretKey", textBox3.Text); if (this.button1.Text != "连接服务器") { if (socketClient != null) { socketClient.Stop = true; socketClient.Close(); } RcvServerState("您已断开与服务器的连接!"); this.button1.Text = "连接服务器"; return; } if (socketClient != null) { socketClient.Close(); } socketClient.Stop = false; socketClient.Connection(Config.GetValue("服务器信息", "IP"), Convert.ToInt32(Config.GetValue("服务器信息", "Port")), RcvServerSuccess, RcvServerError, Config.GetValue("秘钥", "SecretKey"), RcvServerState); Thread.Sleep(1000); if (socketClient.IsConnected) { this.button1.Text = "断开服务器"; } else throw new Exception("连接服务器失败,请检查是否填写正确!"); } catch (Exception ex) { if (socketClient != null) socketClient.Stop = true; MessageBox.Show(ex.Message, "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //全部退出 private void button3_Click(object sender, EventArgs e) { try { if (MessageBox.Show("是否退出全部微信?", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) return; LogHelper.GetSingleObj().Info("系统", $"点击全部退出微信"); foreach (var item in WechatClient.Users.Values.ToArray()) WechatClient.RemoveUser(item, true); } catch (Exception ex) { LogHelper.GetSingleObj().Error("退出全部微信", $"退出全部微信异常:{ex.Message}"); } } //检查更新 private void button4_Click(object sender, EventArgs e) { try { var LastData = UpdateClient.GetCloudFileHist(); if (!string.IsNullOrWhiteSpace(LastData)) { #region 如果存在更新微信版本,将退出微信该软件目录下的所有微信 //var v = versions.FirstOrDefault(f => f.Name == "PCWechat"); //if (v != null) //{ // Process[] MyProcesses = Process.GetProcesses(); // var path = HttpExtend.MapPath("PCWechat"); // foreach (Process MyProcess in MyProcesses) // { // try // { // var name = MyProcess.ProcessName.ToUpper(); // if (name == "WECHAT" && MyProcess.MainModule.FileName.StartsWith(path)) // { // LogHelper.GetSingleObj().Debug("", $"检测到新微信版本,已经登录的微信"); // MyProcess.Kill(); // } // } // catch (Exception ex) // { // LogHelper.GetSingleObj().Error(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, ex.Message); // } // } //} #endregion //Process.Start("检查更新.exe", "易转发.exe"); //IsClose = true; //this.Close(); if (new UpdateForm(LastData).ShowDialog() == DialogResult.OK) PCRobotForm_FormClosing(LastData, null); } else new MessageBox1("暂无新版本!").ShowDialog(); } catch (Exception ex) { new MessageBox1(ex.Message).ShowDialog(); } } private bool IsClose = false; //窗口即将关闭 private void PCRobotForm_FormClosing(object sender, FormClosingEventArgs e) { if (!IsClose && e != null) { var msg = MessageBox.Show("您确定要退出软件吗?", "谨慎操作", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (msg != DialogResult.Yes) { e.Cancel = true; return; } } try { PCWechat.WechatClient.UnInstall(); var socketClient = EasySoc.GetSocket(); if (!e.Cancel && socketClient != null && socketClient.IsConnected) { socketClient.Close(true); } } catch (Exception) { } if (sender != null && e == null) { LogHelper.GetSingleObj().Info("系统", $"关闭窗体退出"); Process.Start("检查更新.exe", "易转发.exe"); Thread.Sleep(600); } Process.GetCurrentProcess().Kill(); } //删除微信 private void 删除微信ToolStripMenuItem_Click(object sender, EventArgs e) { try { if (listView1.SelectedItems.Count == 0) return; else { var item = this.listView1.SelectedItems[0].Tag as WechatUser; LogHelper.GetSingleObj().Info("系统", $"右击删除微信,Uin:{item.Uin},微信:{item.Nickname}({item.Wxid})"); WechatClient.RemoveUser(item, true); } } catch (Exception ex) { LogHelper.GetSingleObj().Error("Delete Wechat ERROR:", $"{ex.Message} - {ex.StackTrace}"); } } //登陆微信 private void button2_Click(object sender, EventArgs e) { try { var wtype = WechatType.Xiaoxie; Wechat_Xiaoxie.Install(); //http://qiniu.down.api.52cmg.cn/PCWechat_2.7.1.82.zip var socketClient = EasySoc.GetSocket(); if (!socketClient.IsConnected) { this.tabControl1.SelectedIndex = 1; MessageBox.Show("请先连接机器人服务器!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //if (wtype == WechatType.Xiaoxie) //{ // var form = new WechatLoginForm(); // if (form.ShowDialog() == DialogResult.OK) // { // //启动微信,暂时没有做MD5检查 // //WechatClient.StartWechat(WechatType.Xiaoxie); // WechatClient.StartWechat(wtype, form.wxid); // } //} //else WechatClient.StartWechat(wtype); } catch (Exception ex) { MessageBox.Show(ex.Message, "启动失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } } /// /// 登录企业微信 /// /// /// private void button5_Click(object sender, EventArgs e) { try { Wechat_Xiaoxie_QY.Install(); var socketClient = EasySoc.GetSocket(); if (!socketClient.IsConnected) { this.tabControl1.SelectedIndex = 1; MessageBox.Show("请先连接机器人服务器!", "友情提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //启动微信,暂时没有做MD5检查 var rst = WechatClient.StartWechat(WechatType.Xiaoxie_QY); } catch (Exception ex) { MessageBox.Show(ex.Message, "启动失败", MessageBoxButtons.OK, MessageBoxIcon.Error); } } //清理文件 private void timer1_Tick(object sender, EventArgs e) { LogHelper.GetSingleObj().Info("清理文件", $"定时清理文件开始执行"); try { string[] ClearDirs = new string[] { "VOICE", "IMAGE" }; //删除微信缓存文件(图片/文件) var cachePath = CsharpHttpHelper.HttpExtend.MapPath("Accounts"); if (Directory.Exists(cachePath)) { DirectoryInfo dirs = new DirectoryInfo(cachePath); FileSystemInfo[] fileinfos = dirs.GetFileSystemInfos(); //返回目录中所有文件和子目录 for (int z = 0; z < fileinfos.Length; z++) { for (int k = 0; k < ClearDirs.Length; k++) { var path = HttpExtend.MapPath($@"Accounts\{fileinfos[z]}\{ClearDirs[k]}"); Common.DeleteDir(path); } } } LogHelper.GetSingleObj().Info("清理文件", $"定时清理文件执行完毕"); } catch (Exception) { LogHelper.GetSingleObj().Info("清理文件", $"定时清理文件执行失败"); } try { //删除缓存目录 Common.DeleteDir(HttpExtend.MapPath(@"Cache")); LogHelper.GetSingleObj().Info("删除缓存目录", $"定时删除缓存目录执行完毕"); } catch (Exception) { LogHelper.GetSingleObj().Info("删除缓存目录", $"定时删除缓存目录执行失败"); } } private void button6_Click(object sender, EventArgs e) { try { Process.Start(HttpExtend.MapPath()); } catch (Exception) { } } private void timer2_Tick(object sender, EventArgs e) { try { Process[] MyProcesses = Process.GetProcesses(); foreach (Process MyProcess in MyProcesses) { if (MyProcess.ProcessName.ToUpper() == "WECHATAPP") { LogHelper.GetSingleObj().Info("杀死小程序app", $"检测到WECHATAPP进程,主动杀死"); MyProcess.Kill(); } } } catch (Exception ex) { } } private void button7_Click(object sender, EventArgs e) { try { if (Common.AppConfig_ExistItem("AnalysisTypes")) Common.AppConfig_Set("AnalysisTypes", richTextBox1.Text.Trim()); else Common.AppConfig_Add("AnalysisTypes", richTextBox1.Text.Trim()); AnalysisTypes = richTextBox1.Text.Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim().ToUpper()).ToList(); if (Common.AppConfig_ExistItem("IsHaveRead")) Common.AppConfig_Set("IsHaveRead", checkBox2.Checked ? "1" : "0"); else Common.AppConfig_Add("IsHaveRead", checkBox2.Checked ? "1" : "0"); IsHaveRead = checkBox2.Checked; } catch (Exception ex) { MessageBox.Show("保存异常:" + ex.Message); } } private void button8_Click(object sender, EventArgs e) { try { if (MessageBox.Show(@"是否立即执行清理硬盘垃圾 注:将会退出已登录的所有微信", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No) return; var path = Environment.CurrentDirectory + "\\清理.bat"; if (File.Exists(path)) { ProcessStartInfo info = new ProcessStartInfo(path); info.UseShellExecute = true; info.Verb = "runas";//管理员身份运行 Process.Start(info); } else throw new Exception("执行失败,清理.bat文件不存在~!"); } catch (Exception ex) { MessageBox.Show(ex.Message); //new MessageBox1(ex.Message).ShowDialog(); } } private void timer3_Tick(object sender, EventArgs e) { } private void button9_Click(object sender, EventArgs e) { Wechat_Xiaoxie.UnInstall(); } private void listView1_SelectedIndexChanged(object sender, EventArgs e) { } private void checkBox1_CheckedChanged(object sender, EventArgs e) { try { Config.SetValue("设置", "静态", (checkBox1.Checked ? "FALSE" : "TRUE")); } catch (Exception ex) { LogHelper.GetSingleObj().Info("修改激活配置", $"{ex.Message}"); } } private void PCRobotForm_MouseDown(object sender, MouseEventArgs e) { LogHelper.GetSingleObj().Info("窗口被点击", $"主程序窗口被点击 => x:{e.X};y:{e.Y}"); } } }