diff --git a/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs b/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs index 7029b45..e200549 100644 --- a/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs +++ b/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs @@ -46,7 +46,6 @@ namespace TemuKJD.WXForms.TalkForms this.line4 = new DevComponents.DotNetBar.Controls.Line(); this.chkIsAutoReply = new System.Windows.Forms.CheckBox(); this.splitContainer4 = new System.Windows.Forms.SplitContainer(); - this.progressBarX1 = new DevComponents.DotNetBar.Controls.ProgressBarX(); this.dgvShop = new TemuKJD.UserComponent.DataGridViewEx(); this.colSelect = new TemuKJD.UserComponent.UcDataGridViewCheckBoxColumn(this.components); this.colShopLoginName = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -103,6 +102,7 @@ namespace TemuKJD.WXForms.TalkForms this.dataGridViewTextBoxColumn3 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewTextBoxColumn4 = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.dataGridViewLinkColumn2 = new System.Windows.Forms.DataGridViewLinkColumn(); + this.lblAutoReplyStatus = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.pbLogo)).BeginInit(); this.panel3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); @@ -136,7 +136,7 @@ namespace TemuKJD.WXForms.TalkForms // lblVersionName // this.lblVersionName.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lblVersionName.Location = new System.Drawing.Point(31161, 33); + this.lblVersionName.Location = new System.Drawing.Point(31695, 33); // // panel3 // @@ -359,7 +359,6 @@ namespace TemuKJD.WXForms.TalkForms // // splitContainer4.Panel1 // - this.splitContainer4.Panel1.Controls.Add(this.progressBarX1); this.splitContainer4.Panel1.Controls.Add(this.dgvShop); // // splitContainer4.Panel2 @@ -385,19 +384,6 @@ namespace TemuKJD.WXForms.TalkForms this.splitContainer4.SplitterDistance = 450; this.splitContainer4.TabIndex = 7; // - // progressBarX1 - // - // - // - // - this.progressBarX1.BackgroundStyle.CornerType = DevComponents.DotNetBar.eCornerType.Square; - this.progressBarX1.Location = new System.Drawing.Point(21, 46); - this.progressBarX1.Name = "progressBarX1"; - this.progressBarX1.Size = new System.Drawing.Size(98, 10); - this.progressBarX1.TabIndex = 224; - this.progressBarX1.Text = "下载中"; - this.progressBarX1.Visible = false; - // // dgvShop // this.dgvShop.AllowUserToAddRows = false; @@ -965,6 +951,7 @@ namespace TemuKJD.WXForms.TalkForms // // pnlTalk // + this.pnlTalk.Controls.Add(this.lblAutoReplyStatus); this.pnlTalk.Controls.Add(this.chkShowAutoReplyNum); this.pnlTalk.Controls.Add(this.chkShowShopStatistics); this.pnlTalk.Controls.Add(this.chkIsAutoReLogin); @@ -1125,6 +1112,17 @@ namespace TemuKJD.WXForms.TalkForms this.dataGridViewLinkColumn2.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic; this.dataGridViewLinkColumn2.Width = 106; // + // label5 + // + this.lblAutoReplyStatus.AutoSize = true; + this.lblAutoReplyStatus.Dock = System.Windows.Forms.DockStyle.Bottom; + this.lblAutoReplyStatus.Location = new System.Drawing.Point(0, 527); + this.lblAutoReplyStatus.Name = "label5"; + this.lblAutoReplyStatus.Size = new System.Drawing.Size(43, 17); + this.lblAutoReplyStatus.TabIndex = 207; + this.lblAutoReplyStatus.Text = "label5"; + this.lblAutoReplyStatus.Visible = false; + // // WxTalkForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; @@ -1241,8 +1239,8 @@ namespace TemuKJD.WXForms.TalkForms private System.Windows.Forms.DataGridViewCheckBoxColumn colCanUse; private DevComponents.DotNetBar.PanelEx btnMultiLogin; private DevComponents.DotNetBar.PanelEx btnChangeAddress; - private DevComponents.DotNetBar.Controls.ProgressBarX progressBarX1; private System.Windows.Forms.Label lblProgress; private System.Windows.Forms.TabPage tabPage3; + private System.Windows.Forms.Label lblAutoReplyStatus; } } \ No newline at end of file diff --git a/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs b/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs index f917fbc..dfe77f4 100644 --- a/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs +++ b/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs @@ -242,16 +242,29 @@ namespace TemuKJD.WXForms.TalkForms if (chkIsAutoReply.Checked && 1==1) { - while (lstAutoReplayParam.Count > 0) - { - AutoReplayParam autoReplayParam = lstAutoReplayParam.FirstOrDefault(); - var autoReplayParamLst = lstAutoReplayParam.Where(r => r.nickName == autoReplayParam.nickName).ToList(); - var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == autoReplayParam.shopId); - if (shop == null) - continue; + Invoke(new Action(() => { lblAutoReplyStatus.Visible = true; lblAutoReplyStatus.Text = "自动回复中... " + DateTime.Now.ToString("HH:mm:ss"); })); - // 选择正确的用户 - var jsStr1 = @"function clickUser() { + if (lstAutoReplayParam.Count > 0) + { + var tmpAutoReplayParamLst = new List(); + foreach (var rp in lstAutoReplayParam) + { + if (!tmpAutoReplayParamLst.Any(r => r.nickName == rp.nickName)) + tmpAutoReplayParamLst.Add(rp); + } + foreach (AutoReplayParam autoReplayParam in tmpAutoReplayParamLst) + { + //AutoReplayParam autoReplayParam = lstAutoReplayParam.FirstOrDefault(); + var autoReplayParamLst = lstAutoReplayParam.Where(r => r.nickName == autoReplayParam.nickName).ToList(); + var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == autoReplayParam.shopId); + if (shop == null) + { + lstAutoReplayParam.RemoveAll(r => r.shopId == autoReplayParam.shopId); + continue; + } + + // 选择正确的用户 + var jsStr1 = @"function clickUser() { var users = document.getElementsByClassName('user-nickname'); for (i=0; i { lblAutoReplyStatus.Text = "当前用户获取失败,尝试获取全部用户 " + DateTime.Now.ToString("HH:mm:ss"); })); + var jsStr2 = @"function clickAllUser() { var users = document.getElementsByClassName('tab-list-item'); for (i=0; i lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent == k))) + .OrderBy(x => Randomx.GetId(100000)).ToList(); + // 分割完整语句匹配(过滤标点符号) + if (replyContentLst.Count == 0) + replyContentLst = LstTalkTemplatePair + .Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent.Trim('?', '?', ',', ',', '.', '。', '!', '!') == k))) + .OrderBy(x => Randomx.GetId(100000)).ToList(); + // 反向包含匹配 + if (replyContentLst.Count == 0) + replyContentLst = LstTalkTemplatePair.Where(t => lstAutoReplayParam.Any(a => a.talkContent.Contains(t.Key))).OrderBy(x => Randomx.GetId(100000)).ToList(); + + // 不能匹配的发默认消息 + if (replyContentLst.Count == 0) + replyContentLst = LstTalkTemplatePair.Where(t => t.Key.IsNullOrEmpty()).OrderBy(x => Randomx.GetId(100000)).ToList(); + if (replyContentLst.Count > 0) + replyContent = replyContentLst.FirstOrDefault().Value; + shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(KJDForms.ShopForms.ShopLoginForm.sInputValueChange2); + jsStr1 = "var txtarea = document.getElementById('input-textarea'); " + + "changeReactInputValue(txtarea,'" + replyContent + "');"; response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1); response1.Wait(2000); - Thread.Sleep(500); + Thread.Sleep(Randomx.GetId(100, 200)); - continue; - } - Thread.Sleep(1500); - - // 输入内容 - // 默认回复 - string replyContent = "亲,客服打包去了,请稍候!"; - // 分割完整语句匹配 - var replyContentLst = LstTalkTemplatePair - .Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent == k))) - .OrderBy(x => Randomx.GetId(100000)).ToList(); - // 分割完整语句匹配(过滤标点符号) - if (replyContentLst.Count == 0) - replyContentLst = LstTalkTemplatePair - .Where(t => lstAutoReplayParam.Any(a => t.Key.Split('|').Any(k => !k.IsNullOrEmpty() && a.talkContent.Trim('?', '?', ',', ',', '.', '。', '!', '!') == k))) - .OrderBy(x => Randomx.GetId(100000)).ToList(); - // 反向包含匹配 - if (replyContentLst.Count == 0) - replyContentLst = LstTalkTemplatePair.Where(t => lstAutoReplayParam.Any(a => a.talkContent.Contains(t.Key))).OrderBy(x => Randomx.GetId(100000)).ToList(); - - // 不能匹配的发默认消息 - if (replyContentLst.Count == 0) - replyContentLst = LstTalkTemplatePair.Where(t => t.Key.IsNullOrEmpty()).OrderBy(x => Randomx.GetId(100000)).ToList(); - if (replyContentLst.Count > 0) - replyContent = replyContentLst.FirstOrDefault().Value; - shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(KJDForms.ShopForms.ShopLoginForm.sInputValueChange2); - jsStr1 = "var txtarea = document.getElementById('input-textarea'); " + - "changeReactInputValue(txtarea,'" + replyContent + "');"; - response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1); - response1.Wait(2000); - Thread.Sleep(Randomx.GetId(100, 200)); - - // 点击回车发送自动回复 - jsStr1 = @"var event = new KeyboardEvent('keydown', { + // 点击回车发送自动回复 + jsStr1 = @"var event = new KeyboardEvent('keydown', { key: 'Enter', keyCode: 13, code: 'Enter', which: 13 }); txtarea.dispatchEvent(event);"; - response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1); - response1.Wait(2000); + response1 = shop.Chat.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1); + response1.Wait(2000); - // 删除队列里的消息 - lstAutoReplayParam.RemoveAll(r => r.nickName == autoReplayParam.nickName); + // 删除队列里的消息 + lstAutoReplayParam.RemoveAll(r => r.nickName == autoReplayParam.nickName); - var row = dgvShop.Rows.Cast().FirstOrDefault(x => x.Cells["colShopId"].Value.ToString() == shop.ShopId); - if (row != null) - { - int AutoReplyCount = dicTalkAutoReplyCount.FirstOrDefault(t => t.Key == shop.ShopId).Value.ParseToInt(); - AutoReplyCount++; - dicTalkAutoReplyCount[shop.ShopId] = AutoReplyCount; - NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_talk_auto_reply_count", dicTalkAutoReplyCount); - Invoke(new Action(() => + var row = dgvShop.Rows.Cast().FirstOrDefault(x => x.Cells["colShopId"].Value.ToString() == shop.ShopId); + if (row != null) { - row.Cells["colAutoReplyCount"].Value = AutoReplyCount; - })); + int AutoReplyCount = dicTalkAutoReplyCount.FirstOrDefault(t => t.Key == shop.ShopId).Value.ParseToInt(); + AutoReplyCount++; + dicTalkAutoReplyCount[shop.ShopId] = AutoReplyCount; + NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_talk_auto_reply_count", dicTalkAutoReplyCount); + Invoke(new Action(() => + { + row.Cells["colAutoReplyCount"].Value = AutoReplyCount; + })); + } + Invoke(new Action(() => { lblAutoReplyStatus.Text = autoReplayParam.shopId + " 已尝试发送自动回复 " + DateTime.Now.ToString("HH:mm:ss"); })); + Thread.Sleep(Randomx.GetId(500, 600)); } - Thread.Sleep(Randomx.GetId(100, 200)); } } + else + { + Invoke(new Action(() => { lblAutoReplyStatus.Visible = false; })); + } Thread.Sleep(1000); } });