1151 lines
54 KiB
C#
1151 lines
54 KiB
C#
using AllBase;
|
|
using AllBase.Helper;
|
|
using AllBase.Model.Result;
|
|
using CefSharp;
|
|
using CefSharp.WinForms;
|
|
//using TemuKJD.DashBoardForms;
|
|
using TemuKJD.Helper;
|
|
using TemuKJD.BaseForms;
|
|
using Microsoft.Win32;
|
|
using NaiBa.CefHelper;
|
|
using NaiBa.CefHelper.Handler;
|
|
using NaiBa.Util.Extension;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
//using System.Web.Hosting;
|
|
using System.Windows.Forms;
|
|
using Work;
|
|
using Work.BLL.Tools;
|
|
using TemuKJD.BLL;
|
|
using AllBase.Model.Result.PDDResult;
|
|
using AllBase.Model.Param.PDDProdParam;
|
|
using TemuKJD.BLL.PddApi;
|
|
using TemuKJD.PDDForms.ShopForms;
|
|
|
|
namespace TemuKJD.WXForms.ShopForms
|
|
{
|
|
public partial class WXPDDShopLoginForm : BaseGeneralForm
|
|
{
|
|
public static WXPDDShopLoginForm shopLoginInstance { get; set; } = null;
|
|
|
|
public string pddUploadGoodsData = "";
|
|
public string pddSourceGoodsDetail = "";
|
|
public string pddSourceGoodsDetailTemp = "";
|
|
public string pddSourceGoodsDecorationTemp = "";
|
|
public string pddSourceGoodsChanceId = "";
|
|
public string pddGetChanceGoodsRefere = "";
|
|
public string pddEditChanceGoodsRefereChanceTab = "";
|
|
|
|
public int CloseAfterSecond { get; set; }
|
|
public EnumOpenType openType = EnumOpenType.manage;
|
|
public bool isMultiLogin = false;
|
|
public string MultiLoginCookieName = "";
|
|
public string InitUrl = "";
|
|
private string shopCookieHead = "pinduoduo.com";
|
|
private string shopLoginUrl = "https://mms.pinduoduo.com/login";
|
|
private string shopMainUrl = "https://mms.pinduoduo.com/home";
|
|
public ChromiumWebBrowser cefWebBrowser = null;
|
|
private ShopLoginInfo shop = null;
|
|
private List<ShopCompany> lstShopCompany = new List<ShopCompany>();
|
|
private string currentUrl = "";
|
|
// 绑定授权的时候传进来和回调信息封装好传到数据库端
|
|
public string AuthClientId = "";
|
|
|
|
public WXPDDShopLoginForm(ShopLoginInfo shopInfo)
|
|
{
|
|
shopLoginInstance = this;
|
|
|
|
InitializeComponent();
|
|
|
|
this.shop = shopInfo;
|
|
this.txtUserName.Text = shopInfo.LoginName;
|
|
this.txtPassWord.Text = DataOpenSSL.DecryptString(shopInfo.Password);
|
|
}
|
|
|
|
private void ShopLoginForm_Load(object sender, EventArgs e)
|
|
{
|
|
this.splitContainer1.SplitterDistance = this.splitContainer1.Height - 62;
|
|
pddSourceGoodsDetailTemp = "";
|
|
pddSourceGoodsDecorationTemp = ""; // 详情装修
|
|
pddSourceGoodsChanceId = "";
|
|
pddGetChanceGoodsRefere = "";
|
|
pddEditChanceGoodsRefereChanceTab = "";
|
|
|
|
if (CloseAfterSecond > 0)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(1000 * CloseAfterSecond);
|
|
if (this.Created)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.Close();
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
|
|
if (!isMultiLogin)
|
|
AutoLogin();
|
|
|
|
CheckAndSaveShop(); //判断登录是否成功,成功则保存店铺信息和店铺cookie
|
|
//ClosePopWindow(); //自动关闭弹窗
|
|
}
|
|
|
|
/// <summary>
|
|
/// 判断登录,保存店铺
|
|
/// </summary>
|
|
private void CheckAndSaveShop()
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
// 自动判断是否登录成功,登录成功后记录cookie保存到服务端。
|
|
while (this.Created)
|
|
{
|
|
Thread.Sleep(3000);
|
|
|
|
if (!this.Created)
|
|
break;
|
|
|
|
//if (this.shop != null && currentUrl.TrimEnd('/') == shopMainUrl)
|
|
if (this.shop != null && currentUrl.StartsWith( shopMainUrl))
|
|
{
|
|
if (!cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
|
continue;
|
|
|
|
// 刷新cookie
|
|
if (openType == EnumOpenType.refresh_cookie)
|
|
{
|
|
string cookies = "";
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.GetCookieManager(null));
|
|
foreach (var cookie in cookieList)
|
|
{
|
|
cookie.Domain = cookie.Domain.Replace(".mms.pinduoduo.com", "mms.pinduoduo.com");
|
|
}
|
|
List<Cookie> cookieListNew = new List<Cookie>();
|
|
if (cookieList != null && cookieList.Count > 0)
|
|
{
|
|
foreach (var cookie in cookieList)
|
|
{
|
|
//PASS_ID同时出现两个,domain是mms.pinduoduo.com才是能登录店铺后台的
|
|
if (cookie.Name == "PASS_ID" && cookie.Domain != "mms.pinduoduo.com"
|
|
&& cookieList.Any(c => c.Name == "PASS_ID" && c.Domain == "mms.pinduoduo.com"))
|
|
continue;
|
|
|
|
cookies += cookie.Name + "=" + cookie.Value + "; ";
|
|
cookieListNew.Add(cookie);
|
|
}
|
|
|
|
if (cookieListNew.Any(c => c.Name == "PASS_ID" && c.Value.StartsWith("windows_1")) &&
|
|
!cookieListNew.Any(c => c.Name == "PddBrowser"))
|
|
{
|
|
cookieList.Add(new Cookie() { Domain = ".pinduoduo.com", Name = "PddBrowser", Value = "1", Expires = DateTime.Now.AddYears(1), });
|
|
}
|
|
cookies = JsonHelper.SerializeObject(cookieListNew);
|
|
|
|
if (!string.IsNullOrEmpty(cookies))
|
|
{
|
|
shop.Cookies = cookies;
|
|
shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd");
|
|
//PDDShopListForm.UpdateServerShopCookies(shop); // 店铺cookie写入服务端
|
|
PDDForms.ProductSelectForms._29WxPddShopManage.Update29WxPddShopCookie(shop);
|
|
if (this.Created && this.chkCloseAfterLogin.Checked)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
this.Close();
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (openType!= EnumOpenType.login)
|
|
continue;
|
|
|
|
if (!lstShopCompany.Any(c => c.LoginName == shop.LoginName))
|
|
continue;
|
|
else // 检测到登录成功后
|
|
{
|
|
string cookies = "";
|
|
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.GetCookieManager(null));
|
|
foreach (var cookie in cookieList)
|
|
{
|
|
cookie.Domain = cookie.Domain.Replace(".mms.pinduoduo.com", "mms.pinduoduo.com");
|
|
}
|
|
List<Cookie> cookieListNew = new List<Cookie>();
|
|
if (cookieList != null && cookieList.Count > 0)
|
|
{
|
|
foreach (var cookie in cookieList)
|
|
{
|
|
//PASS_ID同时出现两个,domain是mms.pinduoduo.com才是能登录店铺后台的
|
|
if (cookie.Name == "PASS_ID" && cookie.Domain != "mms.pinduoduo.com"
|
|
&& cookieList.Any(c => c.Name == "PASS_ID" && c.Domain == "mms.pinduoduo.com"))
|
|
continue;
|
|
|
|
cookies += cookie.Name + "=" + cookie.Value + "; ";
|
|
cookieListNew.Add(cookie);
|
|
}
|
|
//cookies = cookies.Trim().TrimEnd(';');
|
|
cookies = JsonHelper.SerializeObject(cookieListNew);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(cookies)
|
|
&& lstShopCompany.Any(c => c.LoginName == shop.LoginName))
|
|
{
|
|
var lstShopCompanyCopy = lstShopCompany.ToList();
|
|
lstShopCompanyCopy = lstShopCompanyCopy.Where(l => l.LoginName == shop.LoginName).ToList();
|
|
|
|
foreach (ShopCompany sc in lstShopCompanyCopy)
|
|
{
|
|
ShopLoginInfo newShop = new ShopLoginInfo()
|
|
{
|
|
LoginName = shop.LoginName,
|
|
Password = shop.Password,
|
|
GroupName = shop.GroupName,
|
|
ShopAccount = sc.AccountName,
|
|
ShopId = sc.AccountId,
|
|
MallId = sc.MallId,
|
|
SubUserName = shop.SubUserName,
|
|
Notes = shop.Notes,
|
|
AntiContents = new NaiBa.Util.ConcurrentList<string> { sc.AntiContent },
|
|
};
|
|
|
|
var oldShop = GlobalConfig._29WxPddShopLoginList.FirstOrDefault(l =>
|
|
l.LoginName == newShop.LoginName);
|
|
if (oldShop == null)
|
|
{
|
|
GlobalConfig._29WxPddShopLoginList.Add(newShop);
|
|
PDDForms.ProductSelectForms._29WxPddShopManage.AddMdf29WxPddShop(shop); //店铺写入到服务端
|
|
}
|
|
else
|
|
{
|
|
oldShop.LoginName = newShop.LoginName;
|
|
oldShop.Password = newShop.Password;
|
|
oldShop.GroupName = newShop.GroupName;
|
|
oldShop.ShopAccount = newShop.ShopAccount;
|
|
oldShop.ShopId = newShop.ShopId;
|
|
oldShop.MallId = newShop.MallId;
|
|
oldShop.SubUserName = newShop.SubUserName;
|
|
oldShop.Notes = newShop.Notes;
|
|
oldShop.AntiContents.AddRange(newShop.AntiContents);
|
|
while (oldShop.AntiContents.Count > 200)
|
|
oldShop.AntiContents.RemoveAt(0);
|
|
|
|
// 店铺更新写入到服务端
|
|
var url = BaseClass.BuildObjString("shop/wx_add_mdy_29wx_pdd_shop");
|
|
var data = UserLogin.GetSignaturex()
|
|
+ "&login_name=" + newShop.LoginName
|
|
+ "&new_shop_id=" + newShop.ShopId
|
|
+ "&shop_account=" + newShop.ShopAccount
|
|
+ "&mall_id=" + newShop.MallId;
|
|
var result = GetHtml.PostUtf8(url, data);
|
|
//PDDForms.ProductSelectForms._29WxPddShopManage.Mdy29WxPddAntiContent(oldShop);
|
|
}
|
|
}
|
|
var lstShop = GlobalConfig._29WxPddShopLoginList.Where(l => l.LoginName == shop.LoginName).ToList();
|
|
foreach (var s in lstShop)
|
|
{
|
|
s.LoginStatus = "登录成功";
|
|
s.Cookies = cookies;
|
|
s.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd");
|
|
s.pddid = ""; // 网页登录无拼多多id(pddid)
|
|
}
|
|
//PDDShopListForm.UpdateServerShopCookies(shop); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie
|
|
PDDForms.ProductSelectForms._29WxPddShopManage.Update29WxPddShopCookie(shop);
|
|
|
|
OnSaveComplete(shop);
|
|
if (this.Created && this.chkCloseAfterLogin.Checked)
|
|
{
|
|
Invoke(new Action(() => { this.Close(); }));
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自动关闭弹窗
|
|
/// </summary>
|
|
private void ClosePopWindow()
|
|
{
|
|
// 关闭弹窗
|
|
Task.Run(() =>
|
|
{
|
|
var sleepTime = 2500;
|
|
int i = 0;
|
|
while (true && i++ < 50)
|
|
{
|
|
try
|
|
{
|
|
Thread.Sleep(sleepTime);
|
|
var jsStr1 = "function ClosePopWindow(txt) {\r\n" +
|
|
" var result = 'no_pop'\r\n" +
|
|
" var item = document.getElementsByClassName(txt);\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('anticon-close-circle');\r\n" +
|
|
"ClosePopWindow('ant-modal-close-x');\r\n";
|
|
var jsStr2 = "function clickPopWindow(txt) {\r\n"
|
|
+ "var child = document.body.firstElementChild;\r\n"
|
|
+ "var element1 = null;\r\n"
|
|
+ " while (child) {\r\n"
|
|
+ " if (child.innerHTML.indexOf(txt) >= 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"
|
|
+ "clickPopWindow('知道了');\r\n";
|
|
if (cefWebBrowser != null && cefWebBrowser.IsBrowserInitialized)
|
|
{
|
|
var t1 = cefWebBrowser.GetMainFrame().EvaluateScriptAsync(jsStr1);
|
|
t1.Wait();
|
|
var t2 = cefWebBrowser.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(1500, 2000);
|
|
}
|
|
}
|
|
catch (Exception ex) { }
|
|
}
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自动登录店铺后台
|
|
/// </summary>
|
|
private void AutoLogin()
|
|
{
|
|
if (shop == null)
|
|
return;
|
|
|
|
if (cefWebBrowser == null)
|
|
{
|
|
//cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
|
|
if (!string.IsNullOrEmpty(InitUrl)) //temu国际版不支持无痕模式多开,此处改为true,每次创建cefwebbrowser时删除cookie
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(InitUrl, false);
|
|
else
|
|
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(shopMainUrl, false);
|
|
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
|
|
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
|
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
|
|
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
|
var lifeSapnHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
|
|
cefWebBrowser.LifeSpanHandler = lifeSapnHandler;
|
|
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
|
|
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
|
|
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
|
|
cefWebBrowser.LoadError += CefWebBrowser_LoadError;
|
|
cefWebBrowser.Dock = DockStyle.Fill;
|
|
|
|
//js绑定C#对象
|
|
PDDShopBrowserObject shopObj = new PDDShopBrowserObject();
|
|
shopObj.OnInfoReceived += ShopObj_OnInfoReceived;
|
|
CefSharpSettings.WcfEnabled = true;
|
|
cefWebBrowser.JavascriptObjectRepository.Register(
|
|
name: "shopObj",
|
|
objectToBind: shopObj,
|
|
isAsync: false,
|
|
options: new BindingOptions { Binder = BindingOptions.DefaultBinder.Binder /*CamelCaseJavascriptNames = false*/ /*cef79*/ }
|
|
);
|
|
|
|
if (shop.Cookies == null)
|
|
shop.Cookies = "";
|
|
if (shop.Cookies2 == null)
|
|
shop.Cookies2 = "";
|
|
|
|
//var cookie = shop.Cookies;
|
|
//if (isMultiLogin)
|
|
// cookie = shop.DictMultiCookies.Keys.Contains(MultiLoginCookieName) ? shop.DictMultiCookies[MultiLoginCookieName] : "";
|
|
List<Cookie> cookieLst = new List<Cookie>();
|
|
try
|
|
{
|
|
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies);
|
|
if (cookieLst == null)
|
|
cookieLst = new List<Cookie>();
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
Task.Run(() =>
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
splitContainer1.Panel1.Controls.Add(cefWebBrowser);
|
|
//cefWebBrowser.Load(shopMainUrl);
|
|
}));
|
|
// cef138必须init后方可设置或删除cookie
|
|
while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
|
Thread.Sleep(20);
|
|
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null));
|
|
|
|
//if (cookieLst.Any(c => c.Value.StartsWith("windows_1")))
|
|
// cefWebBrowser.ExecuteScriptAsync("navigator.__defineGetter__('userAgent', function() { return 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.5.40.8 Safari/537.36 PddWorkbench-Online PddBrowser pdd_windows_version/3.0.3.12'; });");
|
|
|
|
//cef 138 如果没有设置RequestContext 可能为空,直接getCookieManager
|
|
//if (this.openType != EnumOpenType.login)
|
|
{
|
|
//var t = CEFBrowser.SetCookieAsync(JsonHelper.SerializeObject(cookieLst), cefWebBrowser.GetCookieManager(null));
|
|
foreach (var cook in cookieLst)
|
|
{
|
|
var t = CEFBrowser.SetCookieAsync(cook.Domain, cook.Name + "=" + cook.Value + ";", cefWebBrowser.GetCookieManager(null));
|
|
t.Wait(5000);
|
|
}
|
|
}
|
|
|
|
if (this.openType != EnumOpenType.login)
|
|
{
|
|
//var cookie2 = shop.Cookies2;
|
|
//var t2 = CEFBrowser.SetCookieAsync(shopCookieHead2, cookie2, cefWebBrowser.GetCookieManager(null));
|
|
//t2.Wait(5000);
|
|
}
|
|
|
|
//根据登录的具体店铺设置local storage
|
|
if (!string.IsNullOrEmpty(shop.ShopId))
|
|
{
|
|
//var storageJsCode = "window.localStorage.setItem('" + "mall-info-id" + "', '" + shop.ShopId + "');\r\n";
|
|
//storageJsCode += "window.localStorage.setItem('" + "agentseller-mall-info-id" + "', '" + shop.ShopId + "');\r\n";
|
|
//while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
|
// Thread.Sleep(20);
|
|
//cefWebBrowser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(storageJsCode);
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(InitUrl))
|
|
cefWebBrowser.Load(InitUrl);
|
|
else
|
|
cefWebBrowser.Load(shopMainUrl);
|
|
|
|
//不是登录的话就此返回
|
|
if (openType != EnumOpenType.login)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
chkCloseAfterLogin.Visible = false;
|
|
btnLoginAgain.Visible = false;
|
|
}));
|
|
return;
|
|
}
|
|
|
|
for (int i = 0; i < 50; i++)
|
|
{
|
|
if (cefWebBrowser.IsLoading)
|
|
Thread.Sleep(100);
|
|
}
|
|
Thread.Sleep(Randomx.GetId(1500,2000));
|
|
|
|
if (!this.Created)
|
|
return;
|
|
|
|
while (!cefWebBrowser.Address.StartsWith(shopLoginUrl))
|
|
{
|
|
Thread.Sleep(1000);
|
|
if (!this.Created)
|
|
return;
|
|
}
|
|
|
|
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null));
|
|
InputUserNameAndPassword(cefWebBrowser, shop.LoginName, DataOpenSSL.DecryptString(shop.Password));
|
|
});
|
|
}
|
|
}
|
|
private void ShopObj_OnInfoReceived(string information)
|
|
{
|
|
//BaseMsgForm.ShowInfo(information);
|
|
if (!string.IsNullOrEmpty(information))
|
|
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync("alert('" + information + "');");
|
|
}
|
|
|
|
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
|
|
{
|
|
if (this.Created && !this.Disposing && !this.IsDisposed)
|
|
{
|
|
Invoke(new Action(() =>
|
|
{
|
|
currentUrl = e.Address;
|
|
txtAddress.Text = e.Address;
|
|
}));
|
|
}
|
|
if (e.Address == "https://po.e57.cn/login?redirect=%2Findex" && openType == EnumOpenType.manage)
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
Thread.Sleep(2000);
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (this.Created && !this.IsDisposed && !this.Disposing)
|
|
this.Close();
|
|
}));
|
|
});
|
|
}}
|
|
|
|
private void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
|
{
|
|
//js绑定C#对象 html页面内声明绑定的C#对象
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append("(function(){");
|
|
sb.Append("CefSharp.BindObjectAsync('shopObj');");
|
|
sb.Append("})();");
|
|
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
|
|
}
|
|
|
|
//public Func<object, string, string, request, bool> BeforeResourceLoadEvent; // sender, requestUrl, postData, request, true(表示取消执行)
|
|
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
|
{
|
|
if (BaseClass.MainPath == "29pdd" && BaseClass.UsePddWorkbanch && !shop.Cookies.Contains("windows_1"))
|
|
{
|
|
var ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
|
//ua = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.5.40.8 Safari/537.36";
|
|
request.SetHeaderByName("User-Agent", ua, true);
|
|
|
|
//var ua = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.5.40.8 Safari/537.36 PddWorkbench-Online PddBrowser pdd_windows_version/3.0.3.12";
|
|
//request.SetHeaderByName("User-Agent", ua, true);
|
|
////if (request.Method == "POST")
|
|
//request.SetHeaderByName("pddid", shop.pddid, true);
|
|
//request.SetHeaderByName("Accept-Encoding", "gzip, deflate, br", true);
|
|
//var headers = request.Headers;
|
|
//headers.Remove("sec-ch-ua");
|
|
//headers.Remove("sec-ch-ua-mobile");
|
|
//headers.Remove("sec-ch-ua-platform");
|
|
//headers.Remove("Accept-Language");
|
|
//headers.Remove("Origin");
|
|
////headers["User-Agent"] = ua;
|
|
////headers["Accept-Encoding"] = "gzip, deflate, br";
|
|
//request.Headers = headers;
|
|
}
|
|
if (url == "https://mms.pinduoduo.com/glide/mms/goodsCommit/action/edit" && prodParam != null)
|
|
{
|
|
//postData = postData.Replace(
|
|
// "https://img.pddpic.com/mms-goods-image/2025-12-27/e7d145cb-1147-46b5-a673-e3df4b93cd02.jpeg.a.jpeg",
|
|
// "https://img.pddpic.com/mms-material-img/2025-12-26/748ae660-53f4-4806-9e88-2712a7b5114b.jpeg.a.jpeg");
|
|
|
|
//postData = postData.Replace(
|
|
// "https://img.pddpic.com/mms-material-img/2025-12-26/748ae660-53f4-4806-9e88-2712a7b5114b.jpeg.a.jpeg",
|
|
// "https://img.pddpic.com/mms-goods-image/2025-12-26/1a788e0c-468a-4b6d-9389-cc2dab1f69a0.jpeg.a.jpeg?imageView2/2/w/1700/q/85");
|
|
|
|
JObject jObj = JObject.Parse(postData);
|
|
var skuStr = JsonHelper.SerializeObject(jObj["skus"]);
|
|
var skuStrNew = JsonHelper.SerializeObject(prodParam.skus);
|
|
foreach(JObject skuObj in jObj["skus"])
|
|
{
|
|
var skuName = "";
|
|
foreach (JObject specObj in skuObj["spec"])
|
|
{
|
|
skuName += specObj["spec_name"].ParseToString() + ";";
|
|
}
|
|
skuName = skuName.TrimEnd(';');
|
|
var skuBase = prodParam.skus.FirstOrDefault(s => string.Join(";", s.spec.Select(sp => sp.spec_name)) == skuName);
|
|
if (skuBase != null)
|
|
skuObj["thumb_url"] = skuBase.thumb_url;
|
|
|
|
//skuObj["thumb_url"] = "https://img.pddpic.com/mms-material-img/2025-12-27/23e40222-1a08-4ba1-a6a3-65588c75e0cd.jpeg.a.jpeg";
|
|
}
|
|
|
|
//skuStrNew = skuStrNew.Replace("\"thumb_url_file_id\":null,", "");
|
|
//postData = postData.Replace(skuStr, skuStrNew);
|
|
|
|
postData = JsonHelper.SerializeObject(jObj);
|
|
request.PostData.Elements[0].Bytes = System.Text.Encoding.UTF8.GetBytes(postData);
|
|
}
|
|
return false;
|
|
}
|
|
public PDDProductUploadParam prodParam = null;
|
|
|
|
static int GetAntiContentsTimes = 40;
|
|
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
|
{
|
|
var responseDataTmp = responseData;
|
|
if (responseDataTmp.Contains("活动权益失效"))
|
|
{
|
|
|
|
}//修改后恢复活动权益
|
|
if (responseDataTmp.Contains("修改后恢复活动权益"))
|
|
{
|
|
|
|
}//修改后恢复活动权益
|
|
if (responseDataTmp.Contains("结婚男方主卧洞房喜联女方出嫁新婚房门挂联入户门贴婚庆用品批发"))
|
|
{
|
|
|
|
}
|
|
|
|
var antiContent = request.Headers.AllKeys.Contains("Anti-Content") ? request.Headers["Anti-Content"] : "";
|
|
var refere = request.ReferrerUrl;
|
|
if (shop != null && !url.StartsWith("https://mms.pinduoduo.com/janus/api/userinfo") && !string.IsNullOrEmpty(antiContent) && request.Method == "POST")
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
GetAntiContentsTimes++;
|
|
if (this.Created && !this.Disposing && !this.IsDisposed)
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (this.Created && !this.Disposing && !this.IsDisposed)
|
|
try { this.TitleText = "店铺登录 - " + GetAntiContentsTimes; } catch { return; }
|
|
}));
|
|
shop.AntiContents.Add(antiContent);
|
|
while (shop.AntiContents.Count > 200)
|
|
shop.AntiContents.RemoveAt(0);
|
|
if (!string.IsNullOrEmpty(shop.ShopId) && GetAntiContentsTimes > 500)
|
|
{
|
|
GetAntiContentsTimes = 0;
|
|
ShopBLL.MdyAntiContent(shop);
|
|
}
|
|
});
|
|
}
|
|
|
|
if (url.Contains("https://mms.pinduoduo.com/home"))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var data = responseData;
|
|
if (this.shop != null && data.Contains("\"success\":true"))
|
|
{
|
|
var username = BaseRegex.GetStringJson(ref data, "username");
|
|
var maskMobile = BaseRegex.GetStringJson(ref data, "mobile");
|
|
var mall_name = BaseRegex.GetStringJson(ref data, "mall_name");
|
|
|
|
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(maskMobile))
|
|
{
|
|
maskMobile = maskMobile.Split('*').Last();
|
|
if (string.IsNullOrWhiteSpace(maskMobile) || string.IsNullOrWhiteSpace(username))
|
|
return;
|
|
|
|
if (shop.LoginName.EndsWith(maskMobile) || shop.LoginName == username || shop.LoginName == mall_name)
|
|
{
|
|
lstShopCompany.Clear();
|
|
//var jObj = JObject.Parse(data);
|
|
//var jArr = jObj["result"] as JArray;
|
|
//if (jArr == null)
|
|
// jArr = new JArray();
|
|
|
|
Thread.Sleep(500);
|
|
|
|
ShopCompany sc = new ShopCompany()
|
|
{
|
|
MallId = BaseRegex.GetStringJson(ref data, "mall_id"),
|
|
AccountId = BaseRegex.GetStringJson(ref data, "username"),
|
|
AccountName = BaseRegex.GetStringJson(ref data, "mall_name"),
|
|
LoginName = shop.LoginName,
|
|
UserName = BaseClass.UserName,
|
|
LoginStatus = "登录成功",
|
|
AntiContent = antiContent,
|
|
};
|
|
this.lstShopCompany.Add(sc);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (openType == EnumOpenType.manage && string.IsNullOrWhiteSpace(shop.MallId))
|
|
{
|
|
shop.MallId = BaseRegex.GetStringJson(ref data, "mall_id");
|
|
shop.ShopId = BaseRegex.GetStringJson(ref data, "username");
|
|
shop.ShopAccount = BaseRegex.GetStringJson(ref data, "mall_name");
|
|
var mdyShopUrl = BaseClass.BuildObjString("shop/wx_add_mdy_29wx_pdd_shop");
|
|
var mdyShopData = UserLogin.GetSignaturex()
|
|
+ "&login_name=" + shop.LoginName
|
|
+ "&new_shop_id=" + shop.ShopId
|
|
+ "&shop_account=" + shop.ShopAccount
|
|
+ "&mall_id=" + shop.MallId;
|
|
var result = GetHtml.PostUtf8(mdyShopUrl, mdyShopData);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
// 有些店铺mall_id未获取,补救(260401,临时,后面等店铺重新登录后就可以移除)
|
|
if (url.Contains("https://mms.pinduoduo.com/janus/api/new/userinfo") && responseData.Contains("mall_id"))
|
|
{
|
|
if (openType == EnumOpenType.manage && string.IsNullOrWhiteSpace(shop.MallId))
|
|
{
|
|
var data = responseData;
|
|
shop.MallId = BaseRegex.GetStringJson(ref data, "mall_id");
|
|
shop.ShopId = BaseRegex.GetStringJson(ref data, "username");
|
|
var mdyShopUrl = BaseClass.BuildObjString("shop/wx_add_mdy_29wx_pdd_shop");
|
|
var mdyShopData = UserLogin.GetSignaturex()
|
|
+ "&login_name=" + shop.LoginName
|
|
+ "&new_shop_id=" + shop.ShopId
|
|
+ "&shop_account=" + shop.ShopAccount
|
|
+ "&mall_id=" + shop.MallId;
|
|
var result = GetHtml.PostUtf8(mdyShopUrl, mdyShopData);
|
|
}
|
|
}
|
|
|
|
if (url.Contains("https://xtjpd.jiaotian.vip/") && responseData.Contains("access_token"))
|
|
{
|
|
Task.Run(() =>
|
|
{
|
|
var pddClientData = responseData;
|
|
pddClientData = GetHtml.Unicode2String(pddClientData);
|
|
// {"id":"2","cid":"2","company_id":"0","site_id":"2","main_sid":"0","shop_id":"490943134","shop_name":"pdd49094313446","mall_name":"阿杰小铺浦哈哈","mall_desc":"您的小店已开启,为了更方便消费者了解您的店铺,快来补充店铺详情吧~","logo":"http:\/\/t16img.yangkeduo.com\/pdd_ims\/img_check\/v2\/E62F2CFFFFFF0720200112155452281\/7a235545414b40deaa2a90ab8eaebfd3.png","merchant_type":"1","mall_character":"2","access_token":"3f66557920e0481697325b46c73299e76e3d9e7e","refresh_token":"aa163da98e944063abbbe57a5365fad2fa90fe50","expires_at":"1776264848","expires_in":"26259","refresh_token_expires_at":"1776264848","refresh_token_expires_in":"26259","buy_sku_id":"435494","spec_name":"服务版本:专业版,周期:15天","spec_value":"专业版","goods_get_time":null,"order_get_time":null,"addtime":"2026-03-31 22:54:29","add_user_id":"2","add_user_name":"授权","update_time":"2026-04-15 15:36:27","update_user_id":"0","delete_user_id":"0"}
|
|
var access_token = BaseRegex.GetStringJson(ref pddClientData, "access_token");
|
|
var refresh_token = BaseRegex.GetStringJson(ref pddClientData, "refresh_token");
|
|
var mall_id = BaseRegex.GetStringJson(ref pddClientData, "shop_id");
|
|
var shop_id = BaseRegex.GetStringJson(ref pddClientData, "shop_name");
|
|
var mall_name = BaseRegex.GetStringJson(ref pddClientData, "mall_name"); // 阿杰小铺浦哈哈
|
|
var expires_at = BaseRegex.GetStringJson(ref pddClientData, "expires_at");
|
|
if (shop?.MallId == mall_id && !string.IsNullOrWhiteSpace(AuthClientId))
|
|
{
|
|
var auth = shop.ApiAuthInfoList.FirstOrDefault(a => a.AppKey == AuthClientId);
|
|
if (auth == null)
|
|
{
|
|
auth = new AuthInfo();
|
|
shop.ApiAuthInfoList.Add(auth);
|
|
}
|
|
auth.ShopId = shop_id;
|
|
auth.AccessToken = access_token;
|
|
auth.RefreshToken = refresh_token;
|
|
auth.AppKey = AuthClientId;
|
|
auth.ExpiresTime = BaseClass.StampToDateTime(expires_at.ParseToInt());
|
|
auth.UpdateTime = DateTime.Now;
|
|
auth.ApiAuthStatus = "授权成功";
|
|
auth.AppSecret = "";
|
|
|
|
var rst = PddApiHelper.SaveShopClientInfo(auth);
|
|
|
|
Invoke(new Action(() =>
|
|
{
|
|
if (this.Created && !this.IsDisposed && !this.Disposing)
|
|
this.Close();
|
|
}));
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 自动登录
|
|
/// </summary>
|
|
/// <param name="webBrowser"></param>
|
|
/// <param name="_account"></param>
|
|
/// <param name="_password"></param>
|
|
private void InputUserNameAndPassword(ChromiumWebBrowser webBrowser, string _account, string _password)
|
|
{
|
|
webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sGetElementWithText);
|
|
|
|
var jsStr0 = "var clickBox1 = getElementWithText('账号登录'); clickBox1.click()";
|
|
var response0 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr0);
|
|
response0.Wait(1000);
|
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
|
|
|
string jsStr1 = "function getInputItem () {var usernameId = document.getElementById('usernameId'); if (usernameId) return 'true';} getInputItem();";
|
|
Task<JavascriptResponse> response1 = null;
|
|
while (response1?.Result?.Result == null || !response1.Result.Result.ParseToString().Contains("true"))
|
|
{
|
|
Thread.Sleep(250);
|
|
if (!this.Created)
|
|
return;
|
|
|
|
response1 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
|
response1.Wait(5000);
|
|
|
|
if (!this.Created)
|
|
return;
|
|
}
|
|
|
|
webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sInputValueChange2);
|
|
|
|
jsStr1 = "var usernameId = document.getElementById('usernameId'); " +
|
|
"changeReactInputValue(usernameId,'" + _account + "');";
|
|
response1 = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr1);
|
|
response1.Wait(1000);
|
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
|
|
|
string jsStr = "var passwordId = document.getElementById('passwordId'); "+
|
|
"changeReactInputValue(passwordId,'" + _password + "');";
|
|
var response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(1000);
|
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
|
|
|
jsStr = "var clickBox = getElementWithText('我已阅读并同意'); " +
|
|
"clickBox.click()";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(1000);
|
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
|
|
|
jsStr = "var clickBox = getElementWithText('登录'); " +
|
|
"clickBox.click()";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(1000);
|
|
Thread.Sleep(Randomx.GetId(500, 1000));
|
|
return;
|
|
//下面代码原抖音使用,废弃
|
|
|
|
#region 输入用js
|
|
string jsSetValue = @"
|
|
function keyboardInput(dom, st) {
|
|
var evt = new InputEvent('input', {
|
|
//var evt = new Event('input', { // cef57
|
|
inputType: 'insertText',
|
|
data: st,
|
|
dataTransfer: null,
|
|
isComposing: false
|
|
});
|
|
dom.value = st;
|
|
dom.dispatchEvent(evt);
|
|
dom.focus();
|
|
};";
|
|
|
|
string jsInputKey = @"
|
|
function fireKeyEvent(el, evtType, keyCode) {
|
|
var evtObj;
|
|
if (document.createEvent)
|
|
{
|
|
if (window.KeyEvent)
|
|
{
|
|
//firefox 浏览器下模拟事件
|
|
evtObj = document.createEvent('KeyEvents');
|
|
evtObj.initKeyEvent(evtType, true, true, window, true, false, false, false, keyCode, 0);
|
|
}
|
|
else
|
|
{
|
|
//chrome 浏览器下模拟事件
|
|
evtObj = document.createEvent('UIEvents');
|
|
evtObj.initUIEvent(evtType, true, true, window, 1);
|
|
|
|
delete evtObj.keyCode;
|
|
if (typeof evtObj.keyCode === 'undefined')
|
|
{
|
|
//为了模拟keycode
|
|
Object.defineProperty(evtObj, 'keyCode', { value: keyCode });
|
|
}
|
|
else
|
|
{
|
|
evtObj.key = String.fromCharCode(keyCode);
|
|
}
|
|
|
|
if (typeof evtObj.ctrlKey === 'undefined')
|
|
{
|
|
//为了模拟ctrl键
|
|
Object.defineProperty(evtObj, 'ctrlKey', { value: true });
|
|
}
|
|
else
|
|
{
|
|
evtObj.ctrlKey = true;
|
|
}
|
|
}
|
|
el.dispatchEvent(evtObj);
|
|
}
|
|
else if (document.createEventObject)
|
|
{
|
|
//IE 浏览器下模拟事件
|
|
evtObj = document.createEventObject();
|
|
evtObj.keyCode = keyCode
|
|
el.fireEvent('on' + evtType, evtObj);
|
|
}
|
|
}";
|
|
#endregion
|
|
|
|
#region 输入用户名
|
|
jsStr = @"var txt1 = document.getElementsByName('email')[0]; txt1.focus(); txt1.click(); keyboardInput(txt1, '" + _account + "');"
|
|
+ "var uname = '" + _account + "';"
|
|
+ "for(var i = 0; i < uname.length; i++) {"
|
|
+ " cCode = uname.charCodeAt(i);"
|
|
+ " fireKeyEvent(txt1, 'keydown', cCode);"
|
|
+ " fireKeyEvent(txt1, 'keypress', cCode);"
|
|
+ " fireKeyEvent(txt1, 'keyup', cCode);"
|
|
+ "}";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsSetValue + jsInputKey + jsStr);
|
|
response.Wait(2000);
|
|
Thread.Sleep(Randomx.GetId(400, 800));
|
|
#endregion
|
|
|
|
#region 输入密码
|
|
jsStr = @"var txt2 = document.getElementsByName('password')[0]; txt2.focus(); txt2.click(); keyboardInput(txt2, '" + _password + "');"
|
|
+ "var pwd = '" + _password + "';"
|
|
+ "for(var i = 0; i < pwd.length; i++) {"
|
|
+ " cCode = pwd.charCodeAt(i);"
|
|
+ " fireKeyEvent(txt2, 'keydown', cCode);"
|
|
+ " fireKeyEvent(txt2, 'keypress', cCode);"
|
|
+ " fireKeyEvent(txt2, 'keyup', cCode);"
|
|
+ "}";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsInputKey + jsStr);
|
|
response.Wait(2000);
|
|
Thread.Sleep(Randomx.GetId(400, 800));
|
|
#endregion
|
|
|
|
#region 点击登录按钮
|
|
jsStr = "var btn = document.getElementsByClassName('account-center-action-button')[0]; btn.click(); //btn.dispatchEvent(new Event('change'));";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(2000);
|
|
Thread.Sleep(1500 + Randomx.GetId(1000));
|
|
#endregion
|
|
|
|
#region 获取验证码
|
|
int getImageCount = 0;
|
|
getImageAgain:
|
|
if (!this.Created)
|
|
return;
|
|
|
|
jsStr = "function getImg() { return document.getElementsByClassName('captcha_verify_img--wrapper')[0].innerHTML; }";
|
|
jsStr += "getImg();";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(2000);
|
|
if (response.Result?.Result == null)
|
|
{
|
|
if (getImageCount < 50)
|
|
{
|
|
Thread.Sleep(2500);
|
|
getImageCount++;
|
|
goto getImageAgain;
|
|
}
|
|
}
|
|
if (response.Result?.Result != null)
|
|
{
|
|
var imgStr = response.Result.Result.ToString();
|
|
var src = BaseRegex.GetMatchRegexString(ref imgStr, "src=\"([\\s\\S]*?)\"");
|
|
Bitmap bt = (Bitmap)GetHtml.LoadImage(src);
|
|
if (bt != null)
|
|
{
|
|
int Stopxt = 0;
|
|
int dragButtonWidth = 53;
|
|
//Stopxt = new Base64ChangeImgUrl().CalculateNick(bt, dragButtonWidth);
|
|
Thread.Sleep(500 + Randomx.GetId(1000));
|
|
Stopxt = new Base64ChangeImgUrl().CalculateNickNew(bt, dragButtonWidth);
|
|
if (Stopxt > 0)
|
|
{
|
|
jsStr = "function getImgPos() { return document.getElementsByClassName('secsdk-captcha-drag-icon')[0].getBoundingClientRect().left + '|' "
|
|
+ " + document.getElementsByClassName('secsdk-captcha-drag-icon')[0].getBoundingClientRect().top;} getImgPos();";
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(2000);
|
|
if (response.Result?.Result != null)
|
|
{
|
|
var xy = response.Result?.Result.ToString();
|
|
var xyArr = xy.Split('|');
|
|
if (xyArr.Length == 2)
|
|
{
|
|
try
|
|
{
|
|
int x = (int)Convert.ToDecimal(xyArr[0]) + 25;
|
|
int y = (int)Convert.ToDecimal(xyArr[1]) + 25;
|
|
|
|
// 自动滑块图形验证
|
|
if (GlobalConfig.TemuShopSettingParam.IsAutoDragLogin)
|
|
{
|
|
PDDShopLoginForm.CefMouseDragDou(cefWebBrowser, x, y, Convert.ToInt32((x + Stopxt * 340m / 552m) - 15), y);
|
|
for (int i = 0; i < 1; i++)
|
|
Thread.Sleep(2000 + Randomx.GetId(1000));
|
|
response = webBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr);
|
|
response.Wait(2000);
|
|
if (response.Result?.Result != null && getImageCount < 50)
|
|
{
|
|
getImageCount++;
|
|
goto getImageAgain;
|
|
}
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < 1; i++)
|
|
Thread.Sleep(2000 + Randomx.GetId(1000));
|
|
}
|
|
}
|
|
}
|
|
Thread.Sleep(1500 + Randomx.GetId(1000));
|
|
#endregion
|
|
}
|
|
|
|
// 鼠标左键按下,移动,移动...左键抬起。
|
|
public static void CefMouseDrag(ChromiumWebBrowser webBrowser, int x1, int y1, int x2, int y2)
|
|
{
|
|
Thread.Sleep(100);
|
|
var host = webBrowser.GetBrowser().GetHost();
|
|
|
|
var rx = -6 + Randomx.GetId(13);
|
|
x2 = x2 + rx;
|
|
// 随机按下点的位置(正负6像素),提高仿真性
|
|
int x = x1 + rx;
|
|
int y = y1 - 6 + Randomx.GetId(13);
|
|
|
|
// 按下鼠标左键
|
|
host.SendMouseClickEvent(x, y, MouseButtonType.Left, false, 1, CefEventFlags.None);
|
|
Thread.Sleep(100 + Randomx.GetId(300));
|
|
|
|
// 滑动光标
|
|
int times = -20;
|
|
while (x < x2 + 4 - Randomx.GetId(9))
|
|
{
|
|
times++;
|
|
x += (15 + Randomx.GetId(15)) / 8;
|
|
if (times % 5 == 0)
|
|
y = y - 1 + Randomx.GetId(3);
|
|
Thread.Sleep(6 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
}
|
|
if (x < x2 - 1)
|
|
while (x < x2)
|
|
{
|
|
times++;
|
|
x += (8 + Randomx.GetId(8)) / 8;
|
|
if (times % 5 == 0)
|
|
y = y - 1 + Randomx.GetId(3);
|
|
Thread.Sleep(6 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
}
|
|
else if (x > x2 + 1)
|
|
while (x > x2)
|
|
{
|
|
times++;
|
|
x -= (8 + Randomx.GetId(8)) / 8;
|
|
if (times % 5 == 0)
|
|
y = y - 1 + Randomx.GetId(3);
|
|
Thread.Sleep(6 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
}
|
|
|
|
// 如果最后位置偏差较多,再做一次调整
|
|
x = x2 - 1 + Randomx.GetId(3);
|
|
x = x2;
|
|
Thread.Sleep(18 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
Thread.Sleep(18 + Math.Abs(times) / 5 + Randomx.GetId(16));
|
|
host.SendMouseMoveEvent((int)x, (int)y, false, CefEventFlags.LeftMouseButton);
|
|
|
|
// 抬起鼠标左键
|
|
Thread.Sleep(300 + Randomx.GetId(500));
|
|
host.SendMouseClickEvent(x, y, MouseButtonType.Left, true, 1, CefEventFlags.None);
|
|
host.SendMouseClickEvent(x, y, MouseButtonType.Left, true, 1, CefEventFlags.None);
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnCopyUserName_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(txtUserName.Text))
|
|
Clipboard.SetDataObject(txtUserName.Text);
|
|
}
|
|
|
|
private void btnCopyPassword_Click(object sender, EventArgs e)
|
|
{
|
|
if (!string.IsNullOrEmpty(txtPassWord.Text))
|
|
Clipboard.SetDataObject(txtPassWord.Text);
|
|
}
|
|
|
|
private void btnReload_Click(object sender, EventArgs e)
|
|
{
|
|
if (cefWebBrowser != null)
|
|
{
|
|
if (txtAddress.Text != "about:blank")
|
|
cefWebBrowser.Load(txtAddress.Text);
|
|
else
|
|
cefWebBrowser.Load(shopMainUrl);
|
|
}
|
|
}
|
|
|
|
private void ShopLoginForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
//OnSaveComplete(shop);
|
|
Task.Run(() => {
|
|
Thread.Sleep(500);
|
|
if (!this.Disposing && !this.IsDisposed)
|
|
{
|
|
MainForm.instance.Invoke(new Action(() => { this.Dispose(); }));
|
|
}
|
|
});
|
|
}
|
|
|
|
private void txtAddress_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
if (cefWebBrowser != null)
|
|
{
|
|
cefWebBrowser.Load(txtAddress.Text);
|
|
}
|
|
}
|
|
}
|
|
|
|
string sInputValueChange = @"
|
|
let usernameId = document.getElementById('usernameId');
|
|
usernameId.value = '1';
|
|
|
|
var event = document.createEvent('HTMLEvents');
|
|
event.initEvent('input', true, true);
|
|
event.eventType = 'message';
|
|
usernameId.dispatchEvent(event);
|
|
";
|
|
|
|
public static string sInputValueChange2 = @"
|
|
function changeReactInputValue(inputDom,newText){
|
|
let lastValue = inputDom.value;
|
|
inputDom.value = newText;
|
|
let event = new Event('input', { bubbles: true });
|
|
event.simulated = true;
|
|
let tracker = inputDom._valueTracker;
|
|
if (tracker) {
|
|
tracker.setValue(lastValue);
|
|
}
|
|
inputDom.dispatchEvent(event);
|
|
}
|
|
";
|
|
|
|
string sGetElementWithText = @"
|
|
function getElementWithText(sText)
|
|
{
|
|
var elem=null;
|
|
const elements = document.querySelectorAll('*'); // 选择所有元素
|
|
elements.forEach(element => {
|
|
if (element.textContent.includes(sText)) {
|
|
// 对每个匹配的元素执行操作
|
|
//console.log(element);
|
|
elem=element;
|
|
}
|
|
});
|
|
return elem;
|
|
};
|
|
";
|
|
|
|
private void btnLoginAgain_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.currentUrl != shopLoginUrl)
|
|
this.cefWebBrowser.Load(shopLoginUrl);
|
|
|
|
|
|
Task.Run(() =>
|
|
{
|
|
InputUserNameAndPassword(cefWebBrowser, shop.LoginName, DataOpenSSL.DecryptString(shop.Password));
|
|
});
|
|
}
|
|
}
|
|
}
|