Files
KJD_WebService/TEMUKJD/ChatForms/ChatForm.cs
T

1259 lines
57 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using AllBase.Helper;
using AllBase.Model.Result;
using CefSharp;
using CefSharp.WinForms;
using TemuKJD.ChatForms.ChatHelper;
using TemuKJD.ChatForms.ChatModel;
using TemuKJD.Helper;
using TemuKJD.KJDForms.BaseForms;
using TemuKJD.KJDForms.ShopForms;
using TemuKJD.KJDForms.ToolForms;
using NaiBa.CefHelper;
using NaiBa.CefHelper.Handler;
using NaiBa.Util.Extension;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Work;
namespace TemuKJD.ChatForms
{
public partial class ChatForm : BaseForm
{
public delegate void SearchResultReceivedHandler(ShopLoginInfo shop);
/// <summary>
/// 查询结果事件通知
/// </summary>
public event SearchResultReceivedHandler SearchResultReceived;
public delegate void InfomationReceivedHandler(string infomation);
/// <summary>
/// 消息事件通知,比如:异常等通知
/// </summary>
/// <param name="infomation"></param>
public event InfomationReceivedHandler InfomationReceived;
public static ShopLoginInfo currentShop = null;
//ChromiumWebBrowser mainWebBrowser = new ChromiumWebBrowser("https://im.jinritemai.com/pc_seller/main/chat?selfId=4292110529608375");
ChromiumWebBrowser mainWebBrowser = null;
/// <summary>
/// 弹出框列表
/// </summary>
public static List<ChatMessageForm> lstChatMessageForm = new List<ChatMessageForm>();
public static Dictionary<DataGridViewRow, Color> dicRowColor = new Dictionary<DataGridViewRow, Color>();
public int LocationXY = 0;
public int LocationSize = 200;
private Point mouseOffset;//记录鼠标指针的坐标
private bool isMouseDown;//记录鼠标左键是否按下
const int Guying_HTLEFT = 10;
const int Guying_HTRIGHT = 11;
const int Guying_HTTOP = 12;
const int Guying_HTTOPLEFT = 13;
const int Guying_HTTOPRIGHT = 14;
const int Guying_HTBOTTOM = 15;
const int Guying_HTBOTTOMLEFT = 0x10;
const int Guying_HTBOTTOMRIGHT = 17;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case 0x0084:
base.WndProc(ref m);
Point vPoint = new Point((int)m.LParam & 0xFFFF,
(int)m.LParam >> 16 & 0xFFFF);
vPoint = PointToClient(vPoint);
if (this.WindowState != FormWindowState.Maximized)
{
if (vPoint.X <= 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)Guying_HTTOPLEFT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)Guying_HTBOTTOMLEFT;
else m.Result = (IntPtr)Guying_HTLEFT;
else if (vPoint.X >= ClientSize.Width - 5)
if (vPoint.Y <= 5)
m.Result = (IntPtr)Guying_HTTOPRIGHT;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)Guying_HTBOTTOMRIGHT;
else m.Result = (IntPtr)Guying_HTRIGHT;
else if (vPoint.Y <= 5)
m.Result = (IntPtr)Guying_HTTOP;
else if (vPoint.Y >= ClientSize.Height - 5)
m.Result = (IntPtr)Guying_HTBOTTOM;
}
break;
case 0x0201: //鼠标左键按下的消息
m.Msg = 0x00A1; //更改消息为非客户区按下鼠标
m.LParam = IntPtr.Zero; //默认值
m.WParam = new IntPtr(2);//鼠标放在标题栏内
base.WndProc(ref m);
break;
default:
base.WndProc(ref m);
break;
}
}
public ChatForm()
{
InitializeComponent();
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
ChatConfig.LoadChatSetting();
this.FormClosed += ChatForm_FormClosed;
}
private void ChatForm_FormClosed(object sender, FormClosedEventArgs e)
{
Process.GetCurrentProcess().Kill();
}
private void ChatForm_Load(object sender, EventArgs e)
{
if (BaseClass.LogoImage != null)
pbLogo.Image = BaseClass.LogoImage;
if (BaseClass.Ico != null)
this.Icon = BaseClass.Ico;
else
this.Icon = BaseClass.Ico = ImageBuild.ConvertToIcon(Properties.Resources.icon);
SetTitle();
this.chkIsAutoReLogin.CheckedChanged -= chkIsAutoReLogin_CheckedChanged;
this.chkIsAutoReply.CheckedChanged -= chkIsAutoReply_CheckedChanged;
this.txtAutoReplyText.TextChanged -= txtAutoReplyText_TextChanged;
this.cmbMessage.SelectedIndexChanged -= cmbMessage_SelectedIndexChanged;
if (this.cmbMessage.Items.Contains(ChatConfig.ChatSettingConfig.MessageSound))
this.cmbMessage.SelectedItem = ChatConfig.ChatSettingConfig.MessageSound;
else
this.cmbMessage.SelectedIndex = 0;
this.chkIsAutoReLogin.Checked = GlobalConfig.DouShopSettingParam.IsAutoDragLogin = ChatConfig.ChatSettingConfig.IsAutoReLogin;
this.chkIsAutoReply.Checked = ChatConfig.ChatSettingConfig.IsAutoReply;
this.txtAutoReplyText.Text = ChatConfig.ChatSettingConfig.AutoReplayText;
this.chkIsAutoReLogin.CheckedChanged += chkIsAutoReLogin_CheckedChanged;
this.chkIsAutoReply.CheckedChanged += chkIsAutoReply_CheckedChanged;
this.txtAutoReplyText.TextChanged += txtAutoReplyText_TextChanged;
this.cmbMessage.SelectedIndexChanged += cmbMessage_SelectedIndexChanged;
SearchResultReceived += Chat_SearchResultReceived;
InfomationReceived += Collect_InfomationReceived;
if (mainWebBrowser == null)
{
mainWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
mainWebBrowser.KeyboardHandler = new KeyboardHandler();
mainWebBrowser.Dock = DockStyle.Fill;
var lifeSpanHandler = new LifeSpanHandlerLocal(PopWindowType.NewTitleWindow);
lifeSpanHandler.parent = mainWebBrowser;
lifeSpanHandler.OnPop += MainLifeHandler_OnPop;
mainWebBrowser.LifeSpanHandler = lifeSpanHandler;
//mainWebBrowser.AddressChanged += mainWebBrowser_UrlChanged;
mainWebBrowser.FrameLoadEnd += cefWebBrowser1_FrameLoadEnd;
mainPanel.Controls.Add(mainWebBrowser);
}
Task.Run(() =>
{
// 直到店铺加载完后再加载客服内容
while (!StartUp.IsShopInit)
Thread.Sleep(100);
SetMainBrowserUrl(GlobalConfig.ShopLoginList.FirstOrDefault());
LoadShop();
InitAutoExecute();
});
}
public void SetTitle()
{
lblVersionInfo.Text = BaseClass.ToolName + " V" + BaseClass.Varsion + " - " + BaseClass.NickName;
lblVersionName.Text = "[" + BaseClass.UserVersionString + "]";
Text = BaseClass.ShopName + "-" + BaseClass.ToolName;
}
private void cefWebBrowser1_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
{
//ChromiumWebBrowser cefWebBrowser1 = (ChromiumWebBrowser)sender;
//string url = cefWebBrowser1.Address;
//if (url.Contains("/mallcenter/info/basic") && cefWebBrowser3.IsBrowserInitialized)
//{
// Thread.Sleep(5000);
// var shop = GetShopLoginInfo.Shops.Find(s => s != null && s.ShopName == ShopName);
// string code = "document.getElementsByClassName('new-part')[1].innerHTML=\"<div>" + shop.Name + "<i class='mui-icon mui-icon-question-circle content_tip-icon__2u2h2'></i><span class='create-new-mall-tips'><span>?</span><p class='create-new-mall-entry'><!-- react-text: 498 -->当前状态不支持修改店铺名,您可<!-- /react-text --><a href='/mallcenter/info/createNewMall'>一键开新店铺</a></p></span></div>\"";
// cefWebBrowser3.GetBrowser().MainFrame.ExecuteJavaScriptAsync(code);
//}
}
private void Chat_SearchResultReceived(ShopLoginInfo shop)
{
var r = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(x => x.Cells["columnShopId"].Value.ToString() == shop.ShopId);
if (r != null)
{
for (int i = 0; i < dgvShop.Rows.Count; i++)
{
var row = dgvShop.Rows[i];
if (row.Cells[0].Value.ToString() == shop.ShopId && shop != currentShop)
{
if (ShopChatCount.ContainsKey(shop.ShopId) && ShopChatCount[shop.ShopId] > 0)
{
Task.Run(() =>
{
for (int j = 0; j < 4; j++)
{
Invoke(new Action(() => { row.DefaultCellStyle.BackColor = Color.White; }));
Thread.Sleep(100);
Invoke(new Action(() => { row.DefaultCellStyle.BackColor = Color.FromArgb(245, 95, 50); }));
Thread.Sleep(100);
Invoke(new Action(() => { row.DefaultCellStyle.BackColor = Color.FromArgb(245, 45, 10); }));
Thread.Sleep(100);
}
});
}
else if (row.DefaultCellStyle.BackColor != Color.White)
{
row.DefaultCellStyle.BackColor = Color.White;
}
break;
}
}
}
}
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData)
{
//{"check_spam_resp":{"decision":"PASS","verify_type":"","check_spam_detail":{}},"code":0,"data":{"reqId":"","action":null,"openStatus":2},"msg":"","request_arrived_time":1634629395771,"server_execution_end_time":1634629395782,"st":0}
//{"check_spam_resp":{"decision":"PASS","verify_type":"","check_spam_detail":{}},"code":0,"data":{"reqId":"","action":null,"openStatus":2},"msg":"","request_arrived_time":1634629395771,"server_execution_end_time":1634629395782,"st":0}
//{"ev_type":"batch","list":[{"ev_type":"http","payload":{"api":"xhr","request":{"url":"https://mssdk.snssdk.com/web/report?msToken=qPvfFS_fmS_qrYGcuc8r7tPrFv1vGGyKXz047DsUQwWwS71nflFsNILpxusx7CqhfcCoQqWRqYcsW3uWf8tDwormkmLX_Om59l2butcdH109&X-Bogus=DFSzswVLpIZCR-r8SzOrXdCr9FuN","protocol":"https","domain":"mssdk.snssdk.com","query":"msToken=qPvfFS_fmS_qrYGcuc8r7tPrFv1vGGyKXz047DsUQwWwS71nflFsNILpxusx7CqhfcCoQqWRqYcsW3uWf8tDwormkmLX_Om59l2butcdH109&X-Bogus=DFSzswVLpIZCR-r8SzOrXdCr9FuN","path":"/web/report","hash":"","method":"post","timestamp":1634629435132},"response":{"status":200,"is_custom_error":false,"timestamp":1634629435231,"headers":{"content-type":"text/plain; charset=utf-8"}},"duration":99},"common":{"bid":"mona_plugin","pid":"/pc_seller/main/chat","view_id":"/pc_seller/main/chat_1634628536182","user_id":"pigeon","device_id":"f24e230e-778c-46e5-a9b5-ed2df437c133","session_id":"f6dd538f-2d9d-4cb7-8c54-c06e238a71c8","release":"","env":"production","url":"https://im.jinritemai.com/pc_seller/main/chat","protocol":"https","domain":"im.jinritemai.com","path":"/pc_seller/main/chat","query":"","timestamp":1634629435132,"sdk_version":"0.3.10","sdk_name":"SDK_SLARDAR_WEB","context":{},"network_type":"4g","sample_rate":1}}]}
//{"check_spam_resp":{"decision":"PASS","verify_type":"","check_spam_detail":{}},"code":0,"data":{"count":8},"msg":"","page":0,"request_arrived_time":1634629460322,"server_execution_end_time":1634629460336,"size":0,"st":0,"total":0}
//{"check_spam_resp":{"decision":"PASS","verify_type":"","check_spam_detail":{}},"code":0,"data":{"count":1},"msg":"","page":0,"request_arrived_time":1634629460415,"server_execution_end_time":1634629460432,"size":0,"st":0,"total":0}
if (responseData.Contains("un_replay_customer_num") || responseData.Contains("你好"))
{
Task.Run(() =>
{
});
}
}
private void Collect_InfomationReceived(string infomation)
{
//try
//{
// this.Invoke(new Action(() =>
// {
// lblMsg.Text = infomation;
// var data = infomation.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries);
// if (data.Length == 2)
// {
// if (data[1] == FastCarCollect.FASTCAR_QUOTA_FINISH)
// {
// var shop = gridShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(x => x.Cells["columnShopName"].Value.ToString() == data[0]);
// if (shop != null)
// {
// shop.Cells["columnMsg"].Value = data[1];
// }
// }
// }
// if (infomation == "修改出价结束")
// this.btnStart.Enabled = true;
// if (infomation == "暂停推广结束")
// this.btnStop.Enabled = true;
// }));
//}
//catch { }
}
void SearchNewMessageNofity(ShopLoginInfo shop)
{
if (SearchResultReceived != null)
{
Task.Run(() =>
{
SearchResultReceived(shop);
Thread.Sleep(1000);
});
}
}
void InfomationNotify(string msg)
{
if (InfomationReceived != null)
{
InfomationReceived(msg);
Thread.Sleep(200);
}
}
public void DgvShopClick(ShopLoginInfo shop)
{
var r = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(x => x.Cells["columnShopId"].Value.ToString() == shop.ShopId);
if (r != null)
{
r.Cells[0].Selected = true;
var sender = this.dgvShop;
DataGridViewCellEventArgs e = new DataGridViewCellEventArgs(0, r.Index);
dgvShop_CellClick(sender, e);
}
}
private void dgvShop_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string shopId = dgvShop.Rows[e.RowIndex].Cells["ColumnShopID"].Value?.ToString();
if (string.IsNullOrEmpty(shopId))
return;
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
if (shop == null)
return;
if (dgvShop.Columns[e.ColumnIndex].HeaderText == "登录状态" && dgvShop.Rows[e.RowIndex].Cells[e.ColumnIndex].Value?.ToString() == "未登录 点击登录")
{
Task.Run(() =>
{
// 如需登录,引导至登录窗口,禁止从聊天窗口登录。
Invoke(new Action(() =>
{
// 登录抖音小店
ShopLoginForm lf = new ShopLoginForm(shop);
lf.ShowDialog();
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
}));
ShopListForm.Instance.CheckShopLogin(new string[] { shop.ShopAccount }, false);
LoadShop(new List<ShopLoginInfo>() { shop });
if (shop.LoginStatus == "登录成功")
{
ShowChat(shop);
while (shop.Chat.IsLoading)
{
Thread.Sleep(50);
}
}
});
}
}
private void dgvShop_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string shopId = dgvShop.Rows[e.RowIndex].Cells[0].Value?.ToString();
if (string.IsNullOrEmpty(shopId))
return;
dgvShop.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
var shop = GlobalConfig.ShopLoginList.Where(s => s.ShopId == shopId).FirstOrDefault();
if (shop == null)
return;
if (shop?.Chat != null)
{
//SetJsReaload(shop);
currentShop = shop;
shop.Chat.Dock = DockStyle.Fill;
shop.Chat.BringToFront();
}
Task.Run(() =>
{
SetMainBrowserUrl(shop);
});
}
/// <summary>
/// 更新店铺后台首页
/// </summary>
/// <param name="shop"></param>
private void SetMainBrowserUrl(ShopLoginInfo shop)
{
if (shop == null)
return;
var cookieManager = mainWebBrowser.RequestContext.GetCookieManager(null);
cookieManager.DeleteCookiesAsync("jinritemai.com", null).Wait();
CEFBrowser.SetCookieAsync("jinritemai.com", shop.Cookies, cookieManager);
mainWebBrowser.Load("https://fxg.jinritemai.com/ffa/mshop/homepage/index");
}
/// <summary>
///
/// </summary>
/// <param name="shop"></param>
/// <returns>false表示已经掉线,需要登录</returns>
public bool AutoCheckShopLoginStatus(ShopLoginInfo shop)
{
if (shop == null)
return false;
var browser = shop.Chat;
if (browser.IsBrowserInitialized)
{
var jsStr = "function getNeedLogin() {\r\n"
+ "var bodyHtml = document.body.innerHTML;\r\n"
+ "return bodyHtml.indexOf('登录即代表同意') >= 0 || bodyHtml.indexOf('请输入密码') >= 0 || bodyHtml.indexOf('登录过期') >= 0 /*|| bodyHtml.indexOf('重新登录') >= 0*//*修改密码后出现*/;\r\n"
+ "}\r\n"
+ "getNeedLogin();\r\n";
var html = "";
if (browser.IsBrowserInitialized)
{
var t1 = browser.GetMainFrame().EvaluateScriptAsync(jsStr);
t1.Wait();
html = t1.Result?.Result?.ToString()?.ToLower();
}
if (html == "true")
{
Invoke(new Action(() => { browser.Load("about:blank"); }));
return true;
}
}
return false;
}
/// <summary>
/// 店铺掉线自动重登
/// </summary>
/// <param name="shop"></param>
public void AutoReLogin(ShopLoginInfo shop)
{
try
{
// 如需登录,引导至登录窗口,禁止从聊天窗口登录。
Invoke(new Action(() =>
{
// 登录抖音小店
ShopLoginForm lf = new ShopLoginForm(shop);
lf.ShowDialog();
if (ShopListForm.Instance == null)
ShopListForm.Instance = new ShopListForm();
}));
ShopListForm.Instance.CheckShopLogin(new string[] { shop.ShopAccount }, false);
LoadShop(new List<ShopLoginInfo>() { shop });
if (shop.LoginStatus == "登录成功")
{
ShowChat(shop);
while (shop.Chat.IsLoading)
{
Thread.Sleep(50);
}
}
}
catch
{
}
}
string GetBrowserHtml(ChromiumWebBrowser browser)
{
try
{
if (browser == null)
return null;
var task = browser.GetBrowser().MainFrame.GetSourceAsync();
bool isflag = task.Wait(5000);
if (!isflag)
return null;
//Thread.Sleep(500);
return task.Result;
}
catch
{
return null;
}
}
public void ShowChat(ShopLoginInfo shop)
{
while (shop.Chat?.IsBrowserInitialized != true)
{
Thread.Sleep(50);
}
// 设置cef cookie
if (shop.Chat != null && shop.Chat.IsBrowserInitialized)
{
var cookieManager = shop.Chat.RequestContext.GetCookieManager(null);
cookieManager.DeleteCookiesAsync("jinritemai.com", null).Wait();
CEFBrowser.SetCookieAsync("jinritemai.com", shop.Cookies, shop.Chat.RequestContext.GetCookieManager(null));
//shop.Chat.Load("https://im.jinritemai.com/pc_seller/main/chat?selfId=4292110529608375");
if (shop.LoginStatus == "登录成功")
shop.Chat.Load("https://im.jinritemai.com/pc_seller/main/chat");
}
}
public void LoadShop(List<ShopLoginInfo> shopList = null)
{
if (shopList == null)
shopList = new List<ShopLoginInfo>();
if (shopList.Count == 0)
shopList.AddRange(GlobalConfig.ShopLoginList);
for (int i = 0; i < shopList.Count; i++)
{
var shop = shopList[i];
ShopLoginInfo result = new ShopLoginInfo();
result.ShopId = shop.ShopId;
result.ShopAccount = shop.ShopAccount;
result.LoginStatus = shop.LoginStatus;
var r = dgvShop.Rows.Cast<DataGridViewRow>().FirstOrDefault(x => x.Cells["columnShopId"].Value.ToString() == shop.ShopId);
this.Invoke(new Action(() =>
{
int iGrid = 0;
if (r == null)
iGrid = dgvShop.Rows.Add();
else
iGrid = r.Index;
dgvShop.Rows[iGrid].Cells["ColumnShopID"].Value = shop.ShopId; // 店铺ID
dgvShop.Rows[iGrid].Cells["ColumnShopName"].Value = shop.ShopAccount; // 店铺名称
dgvShop.Rows[iGrid].Cells["ColumnShopStatus"].Value = shop.LoginStatus == "未登录" ? "未登录 点击登录" : shop.LoginStatus; // 登录状态
dicRowColor[dgvShop.Rows[iGrid]] = dgvShop.Rows[iGrid].DefaultCellStyle.BackColor;
if (shop.Chat == null)
{
LocationXY += 5;
shop.X = LocationXY % LocationSize;
shop.Y = LocationXY / LocationSize;
RequestContextSettings requestContextSettings = new RequestContextSettings();
requestContextSettings.PersistSessionCookies = false;
requestContextSettings.PersistUserPreferences = false;
try
{
var cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
//new ChromiumWebBrowser("https://im.jinritemai.com/pc_seller/main/chat?selfId=4292110529608375");
CustomResourceRequestHandler resourceRequestHandler = new CustomResourceRequestHandler();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
var lifeHandler = new LifeSpanHandlerLocal(PopWindowType.NewTitleWindow);
lifeHandler.OnPop += LifeHandler_OnPop;
lifeHandler.parent = cefWebBrowser;
cefWebBrowser.LifeSpanHandler = lifeHandler;
cefWebBrowser.RequestContext = new RequestContext(requestContextSettings);
cefWebBrowser.Dock = DockStyle.Fill; //DockStyle.None;
cefWebBrowser.Location = new Point(shop.X, shop.Y);
shop.Chat = cefWebBrowser;
panel1.Controls.Add(shop.Chat);
if (i == 0)
currentShop = shop;
Task.Run(() =>
{
ShowChat(shop);
});
}
catch (Exception ex)
{
return;
}
}
}));
}
}
private void MainLifeHandler_OnPop(object sender, PopData e)
{
var targetUrl = e.Url;
var lifeHandler = sender as LifeSpanHandlerLocal;
Task.Run(() =>
{
if (lifeHandler.parent != null)
{
var cookies = CEFBrowser.GetCookieList("", lifeHandler.parent.RequestContext.GetCookieManager(null));
Invoke(new Action(() =>
{
CefForm cefForm = new CefForm(targetUrl, cookies);
cefForm.Show();
}));
}
});
}
private void LifeHandler_OnPop(object sender, PopData e)
{
var targetUrl = e.Url;
var lifeHandler = sender as LifeSpanHandlerLocal;
Task.Run(() =>
{
if (e.Url.StartsWith("https://haohuo.jinritemai.com/views/product/item"))
{
var productId = BaseRegex.GetMatchRegexString(ref targetUrl, "&id=(\\d{5,30})");
if (!string.IsNullOrEmpty(productId))
{
long product_id = productId.ParseToLong();
if (product_id > 0)
{
string urlx = BaseClass.LoginApiUrl + "?obj=upshopid/upid_dd&act=get";
string datax = "&pid=" + product_id + "&table=" + (product_id % 1024);
string htmlx = GetHtml.PostUtf8(urlx, UserLogin.GetSignaturex("", "") + datax);
string id = BaseRegex.GetMatchRegexString(htmlx, @"([\d]+)");
if (htmlx.StartsWith("tb"))
targetUrl = "https://item.taobao.com/item.htm?id=" + id;
if (htmlx.StartsWith("pd"))
targetUrl = "https://mobile.yangkeduo.com/goods.html?goods_id=" + id;
if (htmlx.StartsWith("al"))
targetUrl = "https://detail.1688.com/offer/" + id + ".html";
if (htmlx.StartsWith("dy"))
targetUrl = "https://weidian.com/item.html?itemID=" + id;
}
}
}
if (lifeHandler.parent != null)
{
var cookies = CEFBrowser.GetCookieList("", lifeHandler.parent.RequestContext.GetCookieManager(null));
Invoke(new Action(() =>
{
CefForm cefForm = new CefForm(targetUrl, cookies);
cefForm.Show();
}));
}
});
}
public Dictionary<string, int> ShopChatCount = new Dictionary<string, int>();
/// <summary>
/// 获取店铺是否有信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, EventArgs e)
{
//string url = " https://fxg.jinritemai.com/byteshop/broadcast/getIMUnReplyCustomerNum?appid=1&__token=cbaf9d55f488de9de759c2e9de4f9152&_lid=246050185023&_signature=_02B4Z6wo00901prG3SwAAIDBKjcx559pBB6awtmAAMZ2InLzVWKpqWJnptmwhx6Axo5nVtr92zD-a2wI1GAiNviGKrpRnJTAL.hhmniDgXMMnFfzXb7nVj4tluChrVjjRQtlDCcwZSSPWy.13f";
//string refere = "https://fxg.jinritemai.com/ffa/mshop/homepage/index";
//string cookies = "ttcid=e377739c28ce4d18874fa6254b5aae0725; d_ticket=fd4f4a000273570e1b0a578f3c4b63e9c94fb; n_mh=7LrrRmeUceh3vjPZWa4C3h7B_APxodsUr7zuYy75V90; passport_csrf_token_default=b4ef061103fdd818fe8746ec1fae1aef; passport_csrf_token=b4ef061103fdd818fe8746ec1fae1aef; gfpart_1.0.0.94_74391=1; gfpart_1.0.0.695_75006=0; SHOP_ID=9050819; PIGEON_CID=4292110529608375; uidpasaddaehruigqreajf=0; s_v_web_id=verify_kqc1ijuf_5YXfMRjv_Moz5_4gr6_8XNu_0p8ukrjQchfx; ttwid=1%7CQ2FXDv1XIHPVZa_hjjk6pZMPJKpmh59Y9QK9SmHGygE%7C1624866462%7Cba22e39f1164af8fa41006ee4c3be28cc85a33c88bb6c8ac62c67dc10e947420; sso_uid_tt=c365c31887ab82602bc259ea1b07a262; sso_uid_tt_ss=c365c31887ab82602bc259ea1b07a262; toutiao_sso_user=ebe18833115e031bff671e946179e29a; toutiao_sso_user_ss=ebe18833115e031bff671e946179e29a; odin_tt=d28cc07aacedc7065370ef3130a156b0307970e1a25f4cc0771804fad95158f8062f22e2e561a5be77c3ac019926791629bec184551ea5e752dc57925bf8c65a; gfpart_1.0.0.4760_75570=1; ucas_sso_c0_ss=CkEKBTEuMC4wEJ6Ig6Db5d_sYBjmJiC9k9DP4oyUBCiwITC39dDb7fTPB0C1_uWGBki1sqKJBlCOvKLE77ansWBYbhIUidlOg6VtyUt7SIO_Fb0g2QfJAPc; ucas_sso_c0=CkEKBTEuMC4wEJ6Ig6Db5d_sYBjmJiC9k9DP4oyUBCiwITC39dDb7fTPB0C1_uWGBki1sqKJBlCOvKLE77ansWBYbhIUidlOg6VtyUt7SIO_Fb0g2QfJAPc; ucas_c0_ss=CkEKBTEuMC4wEI6Ij_7O5d_sYBjmJiC9k9DP4oyUBCiwITC39dDb7fTPB0C1_uWGBki1sqKJBlCOvKLE77ansWBYbhIU1pl84_FKJDuhWOeYpRoGfYdTYro; sid_guard=6b626ebb4c35cfa047b5336166d9f38f%7C1624866613%7C5184000%7CFri%2C+27-Aug-2021+07%3A50%3A13+GMT; uid_tt=124a8219f77a85f9a7440449283ba2af; uid_tt_ss=124a8219f77a85f9a7440449283ba2af; sid_tt=6b626ebb4c35cfa047b5336166d9f38f; sessionid=6b626ebb4c35cfa047b5336166d9f38f; sessionid_ss=6b626ebb4c35cfa047b5336166d9f38f; ucas_c0=CkEKBTEuMC4wEI6Ij_7O5d_sYBjmJiC9k9DP4oyUBCiwITC39dDb7fTPB0C1_uWGBki1sqKJBlCOvKLE77ansWBYbhIU1pl84_FKJDuhWOeYpRoGfYdTYro; PHPSESSID=867244d48bdc5b1e00fcfbfb70b0c755; PHPSESSID_SS=867244d48bdc5b1e00fcfbfb70b0c755; need_choose_shop=0; login_info=%7B%22for_im_reply%22%3A%22867244d48bdc5b1e00fcfbfb70b0c755%22%7D; gftoken=NmI2MjZlYmI0Y3wxNjI0ODY2NjI3NDB8fDAGBgYGBgY; source=seo.baidu; Hm_lvt_b6520b076191ab4b36812da4c90f7a5e=1624517617,1624600241,1624866399,1625023259; Hm_lpvt_b6520b076191ab4b36812da4c90f7a5e=1625023261; tt_scid=IxysFV-v2TAGPLjDxdlg8h-dhjnwZ9NA7Cqz2oaUqu4irVH4n1Yiz3Hu72AeZh4F8425; MONITOR_WEB_ID=4292110529608375";
//string html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, cookies);
//int count = BaseRegex.GetIntJson(ref html, "un_replay_customer_num");
//string shopId = "111111";
//int oldCount = 0;
//if (ShopChatCount.ContainsKey(shopId))
//{
// oldCount = ShopChatCount[shopId];
//}
//if (oldCount == count)
// return;//countinue;
//ShopChatCount[shopId] = count;
//if (count > 0)
//{
// var shop = GlobalConfig.DouShopLoginList.Where(s => s.ShopId == shopId).FirstOrDefault();
// SearchNewMessageNofity(shop);
//}
}
private void min_Click(object sender, EventArgs e)
{
WindowState = FormWindowState.Minimized;
ShowInTaskbar = true;
}
private void max_Click(object sender, EventArgs e)
{
if (WindowState.Equals(FormWindowState.Normal))
{
WindowState = FormWindowState.Maximized;
max.Style.BackgroundImage = Properties.Resources.normal;
max.StyleMouseOver.BackgroundImage = Properties.Resources.normal_hover;
}
else if (WindowState.Equals(FormWindowState.Maximized))
{
WindowState = FormWindowState.Normal;
max.Style.BackgroundImage = Properties.Resources.max;
max.StyleMouseOver.BackgroundImage = Properties.Resources.max_hover;
}
}
private void close_Click(object sender, EventArgs e)
{
if (BaseMsgForm.ShowConfirm("是否关闭客户端?", "系统提示", FormLevel.SMALL).DialogResult.Equals(DialogResult.Cancel))
return;
this.Close();
}
private void panel2_DoubleClick(object sender, EventArgs e)
{
if (WindowState.Equals(FormWindowState.Normal))
{
WindowState = FormWindowState.Maximized;
return;
}
if (WindowState.Equals(FormWindowState.Maximized))
{
WindowState = FormWindowState.Normal;
}
}
public void InitAutoExecute()
{
Task.Run(() =>
{
while (true)
{
foreach (var shop in GlobalConfig.ShopLoginList)
{
try
{
Thread.Sleep(new Random(DateTime.Now.Millisecond).Next(300, 500));
bool needReLogin = AutoCheckShopLoginStatus(shop);
if (ChatConfig.ChatSettingConfig.IsAutoReLogin && needReLogin)
AutoReLogin(shop);
if (shop.LoginStatus != "登录成功")
continue;
Thread.Sleep(new Random(DateTime.Now.Millisecond).Next(300, 500));
AutoReConnect(shop);
Thread.Sleep(new Random(DateTime.Now.Millisecond).Next(300, 500));
AutoCloseMaskWindow(shop);
Thread.Sleep(new Random(DateTime.Now.Millisecond).Next(300, 500));
var isNewMessage = AutoGetNewMessage(shop);
while (isNewMessage && ChatConfig.ChatSettingConfig.IsAutoReply)
{
AutoReplyWithJs(shop);
Thread.Sleep(new Random(DateTime.Now.Millisecond).Next(300, 500));
isNewMessage = AutoGetNewMessage(shop);
}
}
catch (Exception ex)
{
}
}
}
});
Task.Run(() =>
{
var sleepTime = 1000;
while (true)
{
Thread.Sleep(sleepTime);
var jsStr = "function getVideo() {\r\n" +
" var videos = document.getElementsByTagName('video')\r\n" +
" if (videos && videos.length > 0) {\r\n" +
" var src = videos[0].src;\r\n" +
" videos[0].parentElement.parentElement.click();\r\n" +
" return src;\r\n" +
" //return '';\r\n" +
" }\r\n" +
" return '';\r\n" +
"}" +
"getVideo();\r\n";
if (currentShop?.Chat != null && currentShop.Chat.IsBrowserInitialized)
{
var t = currentShop.Chat.GetMainFrame().EvaluateScriptAsync(jsStr);
t.Wait();
if (!string.IsNullOrEmpty(t.Result?.Result?.ToString()))
{
Invoke(new Action(() =>
{
AllBase.GetHtml.OpenUrl(t.Result.Result.ToString());
}));
}
}
}
});
Task.Run(() =>
{
var sleepTime = 2500;
while (true)
{
try
{
Thread.Sleep(sleepTime);
var jsStr1 = "function ClosePopWindow() {\r\n" +
" var result = 'no_pop'\r\n" +
" var item = document.getElementsByClassName('anticon-close-circle');\r\n" +
" for(i = 0; i < item.length; i++) {\r\n" +
" item[i].click();\r\n" +
" result = 'success'\r\n" +
" }\r\n" +
" return result;\r\n" +
"}\r\n" +
"ClosePopWindow();\r\n";
var jsStr2 = "function clickPopWindow() {\r\n"
+ "var child = document.body.firstElementChild;\r\n"
+ "var element1 = null;\r\n"
+ " while (child) {\r\n"
+ " if (child.innerHTML.indexOf('知道了') >= 0) {\r\n"
+ " element1 = child;\r\n"
+ " if (child.firstElementChild) {\r\n"
+ " child = child.firstElementChild; continue;\r\n"
+ " } else break;\r\n"
+ " }\r\n"
+ " child = child.nextElementSibling;\r\n"
+ " }\r\n"
+ " if (element1) {\r\n"
+ " element1.click(); return 'success';\r\n"
+ " } else return 'no_pop';\r\n"
+ "}\r\n"
+ "clickPopWindow();\r\n";
if (mainWebBrowser.IsBrowserInitialized)
{
var t1 = mainWebBrowser.GetMainFrame().EvaluateScriptAsync(jsStr1);
t1.Wait();
var t2 = mainWebBrowser.GetMainFrame().EvaluateScriptAsync(jsStr2);
t2.Wait();
if (t1.Result?.Result?.ToString() == "success" || t2.Result?.Result?.ToString() == "success")
sleepTime = Randomx.GetId(550, 650);
else
sleepTime = Randomx.GetId(2500, 3000);
}
}
catch (Exception ex) { }
}
});
}
private void chkIsAutoReLogin_CheckedChanged(object sender, EventArgs e)
{
ChatConfig.ChatSettingConfig.IsAutoReLogin = chkIsAutoReLogin.Checked;
ChatConfig.SaveChatSettingParam();
GlobalConfig.DouShopSettingParam.IsAutoDragLogin = chkIsAutoReLogin.Checked;
}
private void chkIsAutoReply_CheckedChanged(object sender, EventArgs e)
{
ChatConfig.ChatSettingConfig.IsAutoReply = chkIsAutoReply.Checked;
ChatConfig.SaveChatSettingParam();
}
private void txtAutoReplyText_TextChanged(object sender, EventArgs e)
{
ChatConfig.ChatSettingConfig.AutoReplayText = txtAutoReplyText.Text;
ChatConfig.SaveChatSettingParam();
}
private void cmbMessage_SelectedIndexChanged(object sender, EventArgs e)
{
ChatConfig.ChatSettingConfig.MessageSound = this.cmbMessage.SelectedItem.ToString();
ChatConfig.SaveChatSettingParam();
}
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
mouseOffset = new Point(-e.X, -e.Y);
isMouseDown = true;
}
}
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
var control = sender as Control;
if (control == null)
return;
//获取鼠标的位置
Point mousePos = MousePosition;
var x = mouseOffset.X;
var y = mouseOffset.Y;
while (control.Parent != null && control.Parent != this)
{
x -= control.Location.X;
y -= control.Location.Y;
control = control.Parent;
}
mousePos.Offset(x, y);
Location = mousePos;
}
}
private void panel2_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}
/// <summary>
/// 自动关闭遮罩层
/// </summary>
/// <param name="shop"></param>
public void AutoCloseMaskWindow(ShopLoginInfo shop)
{
if (shop?.Chat != null)
{
var browser = shop.Chat;
var jsStr = "function clickMaskWindow() {\r\n" +
" var masks = document.getElementsByClassName('ant-modal-wrap');\r\n" +
" for (i = 0; i < masks.length; i++) {\r\n" +
" masks[i].click();\r\n" +
" }\r\n" +
"}\r\n" +
"clickMaskWindow();\r\n";
var t = browser.GetMainFrame().EvaluateScriptAsync(jsStr);
t.Wait();
}
}
/// <summary>
/// 自动重连
/// </summary>
/// <param name="shop"></param>
public void AutoReConnect(ShopLoginInfo shop)
{
if (shop?.Chat != null)
{
var browser = shop.Chat;
var jsStr = "function reConnect() {\r\n"
+ "var child = document.body.firstElementChild;\r\n"
+ "var element1 = null;\r\n"
+ " while (child) {\r\n"
+ " if (child.innerHTML.indexOf('重新连接') >= 0) {\r\n"
+ " element1 = child;\r\n"
+ " if (child.firstElementChild) {\r\n"
+ " child = child.firstElementChild; continue;\r\n"
+ " } else break;\r\n"
+ " }\r\n"
+ " child = child.nextElementSibling;\r\n"
+ " }\r\n"
+ " if (element1) {\r\n"
+ " element1.click(); return 'success';\r\n"
+ " } else return 'failed'\r\n"
+ "}\r\n"
+ "reConnect();\r\n";
var t = browser.GetMainFrame().EvaluateScriptAsync(jsStr);
t.Wait();
}
}
/// <summary>
/// 自动回复
/// </summary>
/// <param name="shop"></param>
public void AutoReplyWithJs(ShopLoginInfo shop)
{
#if DEBUG
//if (shop.ShopId != "9050819") // 测试模式只回复开箱小店
// return;
#endif
if (shop?.Chat == null)
return;
var webBrowser = shop.Chat;
var host = webBrowser.GetBrowser().GetHost();
// 获取回复框坐标
int x = 0, y = 0;
string code = "function getPos() { var box = document.getElementsByTagName('textarea');" +
"if (box[0] == null) return '-|-';" +
"var actualLeft = box[0].offsetLeft;" +
"var actualTop = box[0].offsetTop;" +
"var current = box[0].offsetParent;" +
"while (current !== null) { actualLeft += current.offsetLeft; actualTop += current.offsetTop; current = current.offsetParent; }" +
"return '' + actualLeft + '|' + actualTop;}" +
"getPos();";
var task = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(code);
task.Wait();
var result = task.Result?.Result?.ToString();
if (result != null && result != "-|-")
{
var arr = result.Split('|');
if (arr.Length == 2)
{
x = Convert.ToInt32(arr[0]);
y = Convert.ToInt32(arr[1]);
}
Thread.Sleep(new Random(DateTime.Now.Millisecond).Next(500, 1000));
// 输入自动回复内容
string content = ChatConfig.ChatSettingConfig.AutoReplayText;
var jsStr = "var txt1 = document.getElementsByTagName('textarea')[0]; txt1.focus(); txt1.click(); txt1.value='" + content + " '";
var response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
response.Wait(2000);
// 模拟输入退格键
host.SendKeyEvent(new CefSharp.KeyEvent() { WindowsKeyCode = 8, Type = KeyEventType.RawKeyDown, Modifiers = CefEventFlags.None });
Thread.Sleep(250 + new Random(DateTime.Now.Millisecond).Next(250));
jsStr = "function getTextAreaText() { var txtArea = document.getElementsByTagName('textarea')[0]; if (txtArea) return txtArea.value; return ''; } getTextAreaText();";
var response1 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
response1.Wait(2000);
if (response1.Result?.Result?.ToString() != content && response1.Result?.Result?.ToString() != content + " ")
{
LogSave.Add("自动回复失败,尝试使用剪贴板自动回复功能。-----" + response1.Result?.Result?.ToString());
int x1 = x + new Random(DateTime.Now.Millisecond).Next(5, 75);
int y1 = y + new Random(DateTime.Now.Millisecond).Next(5, 25);
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, false, 1, CefEventFlags.None); // 按下鼠标左键
Thread.Sleep(70 + new Random(DateTime.Now.Millisecond).Next(50));
host.SendMouseClickEvent(x1, y1, MouseButtonType.Left, true, 1, CefEventFlags.None); // 松开鼠标左键
Thread.Sleep(500 + new Random(DateTime.Now.Millisecond).Next(500));
Invoke(new Action(() =>
{
Clipboard.Clear();
Clipboard.SetDataObject("" + content); // 获取自动回复文字
}));
// 黏贴 ctrl + v
host.SendKeyEvent(new CefSharp.KeyEvent() { WindowsKeyCode = 86, Type = KeyEventType.RawKeyDown, Modifiers = CefEventFlags.ControlDown });
Thread.Sleep(250 + new Random(DateTime.Now.Millisecond).Next(250));
}
// 回车回复
host.SendKeyEvent(new CefSharp.KeyEvent() { WindowsKeyCode = 13, Type = KeyEventType.RawKeyDown, Modifiers = CefEventFlags.None });
Thread.Sleep(250 + new Random(DateTime.Now.Millisecond).Next(250));
}
}
/// <summary>
/// 判断是否有新留言
/// </summary>
/// <param name="shopId"></param>
/// <returns></returns>
public bool AutoGetNewMessage(ShopLoginInfo shop)
{
bool isNewMessage = false;
if (shop?.Chat != null)
{
var browser = shop.Chat;
var jsStr = "";
jsStr += "function clickCurrentMessage() {\r\n";
jsStr += " var child = document.body.firstElementChild;\r\n";
jsStr += " var element1 = null;\r\n";
jsStr += " while (child) {\r\n";
jsStr += " var bodyHtml = child.innerHTML;\r\n";
jsStr += " if (bodyHtml.indexOf('messageList') >= 0)\r\n";
jsStr += " bodyHtml = bodyHtml.substring(0, bodyHtml.indexOf('messageList'));\r\n";
jsStr += " if (bodyHtml.indexOf('接待人数') >= 0)\r\n";
jsStr += " bodyHtml = bodyHtml.substring(0, bodyHtml.indexOf('接待人数'));\r\n";
jsStr += " if (bodyHtml.indexOf('&lt;30秒<') >= 0 || bodyHtml.indexOf('>30秒<') >= 0 || bodyHtml.indexOf('分30秒<') >= 0 " +
"|| bodyHtml.indexOf('>1分钟<') >= 0 || bodyHtml.indexOf('>2分钟<') >= 0 || bodyHtml.indexOf('>3分钟<') >= 0 " +
"|| bodyHtml.indexOf('>4分钟<') >= 0 || bodyHtml.indexOf('>5分钟<') >= 0 || bodyHtml.indexOf('>6分钟<') >= 0 " +
"|| bodyHtml.indexOf('>7分钟<') >= 0 || bodyHtml.indexOf('>8分钟<') >= 0 || bodyHtml.indexOf('>9分钟<') >= 0 " +
"|| bodyHtml.indexOf('>10分钟<') >= 0) {\r\n";
jsStr += " element1 = child;\r\n";
jsStr += " if (child.firstElementChild) {\r\n";
jsStr += " child = child.firstElementChild; continue;\r\n";
jsStr += " } else break;\r\n";
jsStr += " }\r\n";
jsStr += " child = child.nextElementSibling;\r\n";
jsStr += " }\r\n";
jsStr += " if (element1) {\r\n";
if (ChatConfig.ChatSettingConfig.IsAutoReply) // 如果是自动回复,点击一下稍后要回复的用户名。
jsStr += " element1.click(); ";
jsStr += " return 'success';\r\n";
jsStr += " } else {";
jsStr += " return 'no_message';";
jsStr += " }\r\n";
jsStr += "}\r\n";
jsStr += "clickCurrentMessage();\r\n";
var t = browser.GetMainFrame().EvaluateScriptAsync(jsStr);
t.Wait();
if (t.Result?.Result?.ToString().StartsWith("success") == true)
isNewMessage = true;
//jsStr = "";
//jsStr += "var result='';\r\n";
//jsStr += "var nodes=[];\r\n";
//jsStr += "nodes.push(document.body);\r\n";
//jsStr += "function getItems() {\r\n";
//jsStr += " for (i = 0; i < nodes.length; i++) {\r\n";
//jsStr += " var node1 = nodes[i];\r\n";
//jsStr += " if ((node1.nodeType != 3) && (node1.nodeName != 'SCRIPT') &&\r\n";
//jsStr += " ((node1.innerHTML + '<').indexOf('30秒<') >= 0 || (node1.innerHTML + '<').indexOf('分钟<') >= 0 || (node1.innerHTML + '<').indexOf('小时<') >= 0)) {\r\n";
//jsStr += " if (!node1.firstElementChild || node1.endWith) { result += node1.parentElement.parentElement.innerHTML + '-----'; }\r\n";
//jsStr += " else { for (j = 0; j < node1.childNodes.length; j++) nodes.push(node1.childNodes[j]); }\r\n";
//jsStr += " }\r\n";
//jsStr += " }\r\n";
//jsStr += " return result;\r\n";
//jsStr += "}\r\n";
//jsStr += "getItems();\r\n";
}
if (isNewMessage)
{
ShopChatCount[shop.ShopId] = 1;
SearchNewMessageNofity(shop);
if (!ChatConfig.ChatSettingConfig.IsNotShowMessageWindow)
ShowMessageForm(shop);
ShowFlash();
playSound();
}
else
{
ShopChatCount[shop.ShopId] = 0;
SearchNewMessageNofity(shop);
CloseMessageForm(shop);
}
return isNewMessage;
}
/// <summary>
/// 显示右下角消息弹框
/// </summary>
/// <param name="shop"></param>
private void ShowMessageForm(ShopLoginInfo shop)
{
if (!lstChatMessageForm.Any(f => f.shop == shop))
{
Invoke(new Action(() =>
{
ChatMessageForm cmf = new ChatMessageForm(shop, this);
cmf.Dragable = false;
cmf.ShowMinimizedBox = false;
lstChatMessageForm.Add(cmf);
Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width - cmf.Width, Screen.PrimaryScreen.WorkingArea.Height);
cmf.PointToScreen(p);
cmf.Location = p;
cmf.Show();
}));
}
}
private void CloseMessageForm(ShopLoginInfo shop)
{
var form = lstChatMessageForm.FirstOrDefault(f => f.shop == shop);
if (form != null)
{
Invoke(new Action(() =>
{
lstChatMessageForm.Remove(form);
form.Close();
this.TopMost = false;
}));
}
}
/// <summary>
/// 任务栏闪烁
/// </summary>
public void ShowFlash()
{
Task.Run(() =>
{
for (int i = 0; i < 5; i++)
{
Invoke(new Action(() =>
{
FlashWindow(Handle, true);
}));
Thread.Sleep(1100);
}
});
}
/// <summary>
/// 任务栏闪烁
/// </summary>
/// <param name="hWnd"></param>
/// <param name="bInvert"></param>
/// <returns></returns>
[DllImport("user32.dll")]
public static extern bool FlashWindow(
IntPtr hWnd, // handle to window
bool bInver // flash status
);
private void button1_Click(object sender, EventArgs e)
{
var shop = GlobalConfig.ShopLoginList.FirstOrDefault(s => s.ShopId == "9050819");
Task.Run(() => { AutoReplyWithJs(shop); });
}
private void pnlSet_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
if (mainWebBrowser != null)
{
AllBase.GetHtml.OpenUrl(textBox1.Text);
}
}
[DllImport("winmm.dll")]
public static extern uint mciSendString(string lpstrCommand, string lpstrReturnString, uint uReturnLength, uint hWndCallback);
/// <summary>
/// 播放提示音
/// </summary>
public void playSound()
{
string musicname = "默认提示音";
if (!string.IsNullOrEmpty(ChatConfig.ChatSettingConfig.MessageSound))
musicname = ChatConfig.ChatSettingConfig.MessageSound;
if (musicname == "无")
return;
if (musicname == "默认提示音")
musicname = "9527.wav";
else
musicname = musicname + ".mp3";
if (musicname.Contains("wav"))
{
try
{
SoundPlayer sound = new SoundPlayer("temp/" + musicname);
sound.Play();
}
catch
{
}
}
if (musicname.Contains("mp3"))
{
try
{
mciSendString(@"close ""temp/" + musicname + @"""", null, 0, 0);
mciSendString(@"open ""temp/" + musicname + @"""", null, 0, 0);
mciSendString(@"play ""temp/" + musicname + @"""", null, 0, 0);
}
catch
{ }
}
}
private void pnlRefresh_Click(object sender, EventArgs e)
{
LoadShop();
}
private void chkNotShowMessageWindow_CheckedChanged(object sender, EventArgs e)
{
ChatConfig.ChatSettingConfig.IsNotShowMessageWindow = chkNotShowMessageWindow.Checked;
ChatConfig.SaveChatSettingParam();
}
}
}