1调整拼多多工作台cookie时的cef user-agent,防止掉线

2优化商品删除逻辑,修复bug
3查找pdd版本长时间运行程序卡死原因并尝试修复
4pdd上货记住主要上货选项避免每次都重新选择
This commit is contained in:
wule committed 2025-10-08 18:23:00 +08:00
1 parent 61264a5a99
commit 5e9bdd1700
19 files changed
+612 -557

No files matched your search

@@ -323,7 +323,7 @@ namespace TemuKJD.PDDForms.ShopForms
//OnInfoReceived("选品商品保存成功!" + success_err_msg);
MainForm.instance.Invoke(new Action(() =>
{
BaseMsgForm.ShowError("选品商品保存成功!" + success_err_msg);
BaseMsgForm.ShowInfo("选品商品保存成功!" + success_err_msg);
}));
}
+51 -35
View File
@@ -28,6 +28,7 @@
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle();
this.label1 = new System.Windows.Forms.Label();
@@ -38,6 +39,7 @@
this.btnLoginSelect = new TemuKJD.UserControls.ButtonEx();
this.btnCheck = new TemuKJD.UserControls.ButtonEx();
this.panel4 = new System.Windows.Forms.Panel();
this.chkUsePddWorkbanch = new TemuKJD.UserComponent.UcCheckBox(this.components);
this.cmbNotes = new System.Windows.Forms.ComboBox();
this.pnlEmpty = new DevComponents.DotNetBar.PanelEx();
this.btnSearch = new TemuKJD.UserControls.ButtonEx();
@@ -52,8 +54,6 @@
this.btnRefreshAuth = new TemuKJD.UserControls.ButtonEx();
this.pbLoading = new System.Windows.Forms.PictureBox();
this.dgvShop = new TemuKJD.UserComponent.DataGridViewEx();
this.chkAutoDrag = new System.Windows.Forms.CheckBox();
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
this.colSelect = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.colLoginName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colShopId = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -77,6 +77,8 @@
this.colCopyCookies = new System.Windows.Forms.DataGridViewLinkColumn();
this.colEdit = new System.Windows.Forms.DataGridViewLinkColumn();
this.colDelete = new System.Windows.Forms.DataGridViewLinkColumn();
this.chkAutoDrag = new System.Windows.Forms.CheckBox();
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -197,6 +199,7 @@
//
// panel4
//
this.panel4.Controls.Add(this.chkUsePddWorkbanch);
this.panel4.Controls.Add(this.cmbNotes);
this.panel4.Controls.Add(this.pnlEmpty);
this.panel4.Controls.Add(this.btnSearch);
@@ -213,10 +216,22 @@
this.panel4.Size = new System.Drawing.Size(1023, 40);
this.panel4.TabIndex = 0;
//
// chkUsePddWorkbanch
//
this.chkUsePddWorkbanch.AutoSize = true;
this.chkUsePddWorkbanch.Location = new System.Drawing.Point(897, 11);
this.chkUsePddWorkbanch.Name = "chkUsePddWorkbanch";
this.chkUsePddWorkbanch.Size = new System.Drawing.Size(128, 21);
this.chkUsePddWorkbanch.TabIndex = 417;
this.chkUsePddWorkbanch.Text = "使用工作台Cookie";
this.chkUsePddWorkbanch.UseVisualStyleBackColor = true;
this.chkUsePddWorkbanch.Visible = false;
this.chkUsePddWorkbanch.CheckedChanged += new System.EventHandler(this.chkUsePddWorkbanch_CheckedChanged);
//
// cmbNotes
//
this.cmbNotes.FormattingEnabled = true;
this.cmbNotes.Location = new System.Drawing.Point(597, 10);
this.cmbNotes.Location = new System.Drawing.Point(584, 10);
this.cmbNotes.Name = "cmbNotes";
this.cmbNotes.Size = new System.Drawing.Size(120, 25);
this.cmbNotes.TabIndex = 413;
@@ -227,7 +242,7 @@
this.pnlEmpty.CanvasColor = System.Drawing.SystemColors.Control;
this.pnlEmpty.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.pnlEmpty.DisabledBackColor = System.Drawing.Color.Empty;
this.pnlEmpty.Location = new System.Drawing.Point(799, 9);
this.pnlEmpty.Location = new System.Drawing.Point(786, 9);
this.pnlEmpty.Name = "pnlEmpty";
this.pnlEmpty.Size = new System.Drawing.Size(66, 26);
this.pnlEmpty.Style.Alignment = System.Drawing.StringAlignment.Center;
@@ -253,7 +268,7 @@
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnSearch.ForeColor = System.Drawing.Color.White;
this.btnSearch.Location = new System.Drawing.Point(728, 9);
this.btnSearch.Location = new System.Drawing.Point(715, 9);
this.btnSearch.Margin = new System.Windows.Forms.Padding(2);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(66, 26);
@@ -265,7 +280,7 @@
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(538, 14);
this.label4.Location = new System.Drawing.Point(525, 14);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(68, 17);
this.label4.TabIndex = 377;
@@ -273,7 +288,7 @@
//
// txtShopName
//
this.txtShopName.Location = new System.Drawing.Point(415, 11);
this.txtShopName.Location = new System.Drawing.Point(402, 11);
this.txtShopName.Name = "txtShopName";
this.txtShopName.Size = new System.Drawing.Size(110, 23);
this.txtShopName.TabIndex = 374;
@@ -281,7 +296,7 @@
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(367, 14);
this.label3.Location = new System.Drawing.Point(354, 14);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(56, 17);
this.label3.TabIndex = 375;
@@ -289,7 +304,7 @@
//
// txtShopId
//
this.txtShopId.Location = new System.Drawing.Point(245, 11);
this.txtShopId.Location = new System.Drawing.Point(232, 11);
this.txtShopId.Name = "txtShopId";
this.txtShopId.Size = new System.Drawing.Size(110, 23);
this.txtShopId.TabIndex = 372;
@@ -297,7 +312,7 @@
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(197, 14);
this.label2.Location = new System.Drawing.Point(184, 14);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(55, 17);
this.label2.TabIndex = 373;
@@ -438,31 +453,6 @@
this.dgvShop.TabIndex = 5;
this.dgvShop.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvShop_CellContentClick);
//
// chkAutoDrag
//
this.chkAutoDrag.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.chkAutoDrag.AutoSize = true;
this.chkAutoDrag.BackColor = System.Drawing.Color.White;
this.chkAutoDrag.Location = new System.Drawing.Point(1108, 2);
this.chkAutoDrag.Name = "chkAutoDrag";
this.chkAutoDrag.Size = new System.Drawing.Size(159, 21);
this.chkAutoDrag.TabIndex = 3;
this.chkAutoDrag.Text = "登录时自动滑动拼图验证";
this.chkAutoDrag.UseVisualStyleBackColor = false;
this.chkAutoDrag.Visible = false;
this.chkAutoDrag.Click += new System.EventHandler(this.chkAutoDrag_Click);
//
// statusBar
//
this.statusBar.BackColor = System.Drawing.Color.White;
this.statusBar.Dock = System.Windows.Forms.DockStyle.Bottom;
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, -1);
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1264, 29);
this.statusBar.TabIndex = 1;
//
// colSelect
//
this.colSelect.FillWeight = 26F;
@@ -651,6 +641,31 @@
this.colDelete.Name = "colDelete";
this.colDelete.ReadOnly = true;
//
// chkAutoDrag
//
this.chkAutoDrag.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.chkAutoDrag.AutoSize = true;
this.chkAutoDrag.BackColor = System.Drawing.Color.White;
this.chkAutoDrag.Location = new System.Drawing.Point(1108, 2);
this.chkAutoDrag.Name = "chkAutoDrag";
this.chkAutoDrag.Size = new System.Drawing.Size(159, 21);
this.chkAutoDrag.TabIndex = 3;
this.chkAutoDrag.Text = "登录时自动滑动拼图验证";
this.chkAutoDrag.UseVisualStyleBackColor = false;
this.chkAutoDrag.Visible = false;
this.chkAutoDrag.Click += new System.EventHandler(this.chkAutoDrag_Click);
//
// statusBar
//
this.statusBar.BackColor = System.Drawing.Color.White;
this.statusBar.Dock = System.Windows.Forms.DockStyle.Bottom;
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, -1);
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1264, 29);
this.statusBar.TabIndex = 1;
//
// PDDShopListForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@@ -733,5 +748,6 @@
private System.Windows.Forms.DataGridViewLinkColumn colCopyCookies;
private System.Windows.Forms.DataGridViewLinkColumn colEdit;
private System.Windows.Forms.DataGridViewLinkColumn colDelete;
private UserComponent.UcCheckBox chkUsePddWorkbanch;
}
}
+10 -1
View File
@@ -578,7 +578,7 @@ namespace TemuKJD.PDDForms.ShopForms
if (shop != null)
{
var loginResult = CheckShopLogin(shop);
if (!loginResult.Contains("\"success\":true") || !loginResult.Contains("\"login\":true"))
if (loginResult.Contains("\"success\":true") && !loginResult.Contains("\"login\":true"))
{
shop.Cookies = "empty=true;";
foreach (var sc in campanys)
@@ -661,6 +661,10 @@ namespace TemuKJD.PDDForms.ShopForms
private void ShopListForm_Load(object sender, EventArgs e)
{
chkUsePddWorkbanch.CheckedChanged -= chkUsePddWorkbanch_CheckedChanged;
chkUsePddWorkbanch.Checked = BaseClass.UsePddWorkbanch;
chkUsePddWorkbanch.CheckedChanged += chkUsePddWorkbanch_CheckedChanged;
if (BaseClass.GroupId != 3)
{
this.dgvShop.Columns["ColEdit"].Visible = false;
@@ -1144,5 +1148,10 @@ function setCookie(name, value, daysToLive, path, domain, secure, httpOnly, same
document.cookie = cookie;
}";
private void chkUsePddWorkbanch_CheckedChanged(object sender, EventArgs e)
{
BaseMsgForm.ShowInfo("您已切换Cookie来源,请重启软件生效!");
NaiBa.Util.Helper.ConfigHelper.SaveConfig("use_pdd_workbanch", chkUsePddWorkbanch.Checked);
}
}
}
+32 -27
View File
@@ -59,10 +59,10 @@ namespace TemuKJD.PDDForms.ShopForms
public PDDShopLoginForm(ShopLoginInfo shopInfo)
{
if (shopLoginInstance != null && !shopLoginInstance.IsDisposed)
{
shopLoginInstance.Dispose();
}
//if (shopLoginInstance != null && !shopLoginInstance.IsDisposed)
//{
// shopLoginInstance.Dispose();
//}
shopLoginInstance = this;
InitializeComponent();
@@ -146,7 +146,7 @@ namespace TemuKJD.PDDForms.ShopForms
cookieListNew.Add(cookie);
}
if (cookieListNew.Any(c => c.Name == "PASS_ID" && c.Value.StartsWith("windows")) &&
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), });
@@ -351,9 +351,9 @@ namespace TemuKJD.PDDForms.ShopForms
{
//cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
if (!string.IsNullOrEmpty(InitUrl)) //temu国际版不支持无痕模式多开,此处改为true,每次创建cefwebbrowser时删除cookie
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(InitUrl, true);
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(InitUrl, false);
else
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(shopMainUrl, true);
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(shopMainUrl, false);
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
@@ -408,8 +408,8 @@ namespace TemuKJD.PDDForms.ShopForms
Thread.Sleep(20);
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null));
if (cookieLst.Any(c=>c.Name == "PddBrowser") && cookieLst.Any(c => c.Value.StartsWith ("windows")) && !string.IsNullOrEmpty(shop.pddid))
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'; });");
//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)
@@ -490,7 +490,7 @@ namespace TemuKJD.PDDForms.ShopForms
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
{
if (this.Created && !this.IsDisposed)
if (this.Created && !this.Disposing && !this.IsDisposed)
Invoke(new Action(() =>
{
currentUrl = e.Address;
@@ -552,21 +552,26 @@ namespace TemuKJD.PDDForms.ShopForms
//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 (shop.Cookies.Contains("windows") && shop.Cookies.Contains("PddBrowser") && !string.IsNullOrEmpty(shop.pddid))
if (BaseClass.MainPath == "binxixi" && BaseClass.UsePddWorkbanch && !shop.Cookies.Contains("windows_1"))
{
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";
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);
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;
//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;
}
return false;
@@ -576,18 +581,18 @@ namespace TemuKJD.PDDForms.ShopForms
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
{
var antiContent = request.Headers.AllKeys.Contains("Anti-Content") ? request.Headers["Anti-Content"] : "";
if (shop != null && !url.StartsWith("https://mms.pinduoduo.com/janus/api/userinfo") && !string.IsNullOrEmpty(antiContent))
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.IsDisposed)
if (this.Created && !this.Disposing && !this.IsDisposed)
Invoke(new Action(() =>
{
try { this.TitleText = "店铺登录 - " + GetAntiContentsTimes; } catch { return; }
}));
shop.AntiContents.Add(antiContent);
while (shop.AntiContents.Count > 50)
while (shop.AntiContents.Count > 100)
shop.AntiContents.RemoveAt(0);
if (!string.IsNullOrEmpty(shop.ShopId) && GetAntiContentsTimes > 500)
{
@@ -996,7 +1001,7 @@ function fireKeyEvent(el, evtType, keyCode) {
//OnSaveComplete(shop);
Task.Run(() => {
Thread.Sleep(500);
if (!this.IsDisposed)
if (!this.Disposing && !this.IsDisposed)
{
MainForm.instance.Invoke(new Action(() => { this.Dispose(); }));
}
@@ -179,7 +179,7 @@ namespace TemuKJD.PDDForms.ShopForms
cookieList.Add(new Cookie() { Domain = "mms.pinduoduo.com", Name = "webp", Value = webp, Expires = DateTime.Now.AddDays(14), Path= "/home" });
if (!string.IsNullOrEmpty(x_visit_time))
cookieList.Add(new Cookie() { Domain = "mms.pinduoduo.com", Name = "x-visit-time", Value = x_visit_time, Expires = DateTime.Now.AddDays(100), });
if (PASS_ID.StartsWith("windows") && !cookieList.Any(c => c.Name == "PddBrowser"))
if (PASS_ID.StartsWith("windows_1") && !cookieList.Any(c => c.Name == "PddBrowser"))
cookieList.Add(new Cookie() { Domain = ".pinduoduo.com", Name = "PddBrowser", Value = "1", Expires = DateTime.Now.AddYears(1), });
cookie = JsonHelper.SerializeObject(cookieList);
@@ -45,7 +45,7 @@ namespace TemuKJD.PDDForms.ShopForms
while (true)
{
i++;
string txt = "Cookie获取中,请稍候";
string txt = "店铺 " + shop.ShopAccount + " Cookie获取中,请稍候";
for (int j = 0; j < i % 3 + 1; j++)
{
txt += ".";
@@ -173,7 +173,7 @@ namespace TemuKJD.PDDForms.ShopForms
cookieList.Add(new Cookie() { Domain = "mms.pinduoduo.com", Name = "webp", Value = webp, Expires = DateTime.Now.AddDays(14), Path = "/home" });
if (!string.IsNullOrEmpty(x_visit_time))
cookieList.Add(new Cookie() { Domain = "mms.pinduoduo.com", Name = "x-visit-time", Value = x_visit_time, Expires = DateTime.Now.AddDays(100), });
if (PASS_ID.StartsWith("windows") && !cookieList.Any(c => c.Name == "PddBrowser"))
if (PASS_ID.StartsWith("windows_1") && !cookieList.Any(c => c.Name == "PddBrowser"))
cookieList.Add(new Cookie() { Domain = ".pinduoduo.com", Name = "PddBrowser", Value = "1", Expires = DateTime.Now.AddYears(1), });
headerCookie = JsonHelper.SerializeObject(cookieList);