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

+21 -155
View File
@@ -145,14 +145,23 @@ namespace TemuKJD
LoginType = loginType;
if (loginType == "Pdd")
{
BaseClass.MainPath = "binxixi";
}
instance = this;
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
CefInit();
}
public static void CefInit()
{
var usePddWorkbanch = NaiBa.Util.Helper.ConfigHelper.LoadConfig<bool?>("use_pdd_workbanch");
if (usePddWorkbanch == null)
usePddWorkbanch = true;
BaseClass.UsePddWorkbanch = usePddWorkbanch.Value;
//CefSharpSettings.LegacyJavascriptBindingEnabled = true;//cef 79 84以后:“CefSharpSettings”未包含“LegacyJavascriptBindingEnabled”的定义
CefSharpSettings.WcfEnabled = false;
@@ -160,7 +169,10 @@ namespace TemuKJD
//settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36";
//settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36";
//settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36";
//settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36";
settings.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
if (BaseClass.MainPath == "binxixi" && BaseClass.UsePddWorkbanch)
settings.UserAgent = "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";
settings.CefCommandLineArgs.Add("disable-gpu", "1"); // 禁止显卡加速
settings.IgnoreCertificateErrors = true;
settings.Locale = "zh-CN";
@@ -169,7 +181,7 @@ namespace TemuKJD
var pName = Process.GetCurrentProcess().ProcessName;
var pCount = Process.GetProcesses().Count(p => p.ProcessName == pName);
//138版cef自己不会分缓存,会因占用导致报错,手动分缓存
settings.CachePath = Path.Combine(Environment.CurrentDirectory, "Cache\\" + pCount);
settings.CachePath = Path.Combine(Environment.CurrentDirectory, "Cache\\" + pCount);
//settings.CachePath = null; //禁止缓存
//settings.CefCommandLineArgs.Add("enable-javascript", "1");
//settings.CefCommandLineArgs.Add("disable-features", "NetworkService,NetworkServiceInProcess");
@@ -234,17 +246,16 @@ namespace TemuKJD
p.BackgroundImage = p.Style.BackgroundImage;
new Thread(Auto).Start();
new Thread(OpenWebBrower).Start();
new Thread(AutoGC).Start();
var backgroundScheduler = TaskScheduler.Default;
var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Task.Run(() => { DelCookies(); })
//Task.Run(() => { DelCookies(); })
//.ContinueWith(delegate { new UploadPinduoduoMain("").LoadStock(); }, backgroundScheduler)
.ContinueWith(delegate { loadToken(); }, backgroundScheduler)
//.ContinueWith(delegate { loadToken(); }, backgroundScheduler)
//.ContinueWith(delegate { LoadUserAgent(); }, backgroundScheduler)
//.ContinueWith(delegate { refreshPassId(); }, backgroundScheduler)
;
//;
// 是否显示联系客服按钮
//if (FileBase.Exists("locales/ig.pak") || FileBase.Exists("locales/wl.pak"))
@@ -252,12 +263,12 @@ namespace TemuKJD
//else
// lblContactSupport.Visible = true;
Task.Run(() =>
{
//Task.Run(() =>
//{
//抖音获取违规信息
//ViolateManageForm.GetAllViolateRuleName();
//GetShopViolation();
});
//});
}
public void SetTitle()
@@ -278,7 +289,8 @@ namespace TemuKJD
DateTime lastClear = DateTime.Now;
while (true)
{
if (lastClear.AddSeconds(30) < DateTime.Now)
//if (lastClear.AddSeconds(30) < DateTime.Now)
if (lastClear.AddSeconds(60) < DateTime.Now)
{
lastClear = DateTime.Now;
ClearMemory();
@@ -444,32 +456,6 @@ namespace TemuKJD
bodyPanel.Visible = true;
}
private void OpenWebBrower()
{
int count = 0;
while (false)
{
Thread.Sleep(30);
if (count == 1000)
{
count = 0;
}
count++;
if (string.IsNullOrEmpty(BaseClass.WebbrowerUrl))
continue;
Invoke(new delegateView(OpenUrl));
}
}
/// <summary>
/// 自动打开IE窗口
/// </summary>
private void OpenUrl()
{
IeForm i = new IeForm(BaseClass.WebbrowerUrl);
i.Show();
BaseClass.WebbrowerUrl = "";
}
private void Auto()
{
Thread.Sleep(200);
@@ -1006,126 +992,6 @@ namespace TemuKJD
cd.GetProduct();
}
#region 隐蔽获取店铺违规信息第一页填充违规库
ChromiumWebBrowser webBrowser = null;
private void GetShopViolation()
{
while (StartUp.IsShopInit == false || this.Visible == false)
{
Thread.Sleep(1000);
}
dicLastGetFullViolateTime = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, DateTime>>("last_get_full_violate_time");
if (dicLastGetFullViolateTime == null)
dicLastGetFullViolateTime = new Dictionary<string, DateTime>();
// 加载最后一次违规记录
vioDic = NaiBa.Util.Helper.ConfigHelper.LoadConfig<Dictionary<string, List<ViolateInfo>>>("dou_violate_info");
if (vioDic == null)
vioDic = new Dictionary<string, List<ViolateInfo>>();
if (webBrowser == null)
{
Invoke(new Action(() =>
{
webBrowser = CEFBrowser.CreateChromiumWebBrowser("about:blank", false);
webBrowser.KeyboardHandler = new KeyboardHandler();
webBrowser.Dock = DockStyle.Fill;
Helper.CustomResourceRequestHandlerLocal resourceRequestHandler = new Helper.CustomResourceRequestHandlerLocal();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadCompleteEvent;
webBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
webBrowser.BringToFront();
//webBrowser.SendToBack();
this.bodyPanel.Controls.Add(webBrowser);
}));
while (!webBrowser.IsBrowserInitialized || webBrowser.IsLoading)
{
Thread.Sleep(500);
}
}
// 加载一个cef以在后台完成某些任务(原后台违规获取现在作废删除)
}
Dictionary<string, DateTime> dicLastGetFullViolateTime = new Dictionary<string, DateTime>();
Dictionary<string, List<ViolateInfo>> vioDic = new Dictionary<string, List<ViolateInfo>>();
private void RequestHandler_ResourceLoadCompleteEvent(object sender, string url, string postData, string responseData, CefSharp.IRequest iRequest)
{
if (url.Contains("https://fxg.jinritemai.com/shopuser/govern/bff/api/query_penalize_tickets?csrf=&&msToken="))
{
var _data = responseData;
var _url = url;
var _postData = postData;
var _request = iRequest;
Task.Run(() =>
{
// biz_id_type 1.订单类违规 2.商品类违规
if (!string.IsNullOrEmpty(_data) && _data.Contains("\"data\"") && _data.Contains("\"biz_id_type\":2") && !_data.Contains("\"data\":[]"))
{
var jObj = JObject.Parse(_data);
var dataStr = JsonHelper.SerializeObject(jObj["data"]);
List<ViolateInfo> violateList = JsonHelper.DeserializeJsonToList<ViolateInfo>(dataStr);
List<ViolateInfo> violateListTemp = new List<ViolateInfo>();
foreach (var violateInfo in violateList)
{
// 如果是同一条违规,则跳过不再去写缓存
if (vioDic.ContainsKey(violateInfo.shop_id) && vioDic[violateInfo.shop_id] != null && vioDic[violateInfo.shop_id].Any(v => v.penalize_id == violateInfo.penalize_id))
{
var violateInfoOld = vioDic[violateInfo.shop_id].FirstOrDefault(v => v.penalize_id == violateInfo.penalize_id);
if (violateInfoOld != null && violateInfo.rule_name == violateInfoOld.rule_name)
{
violateInfo.up_product_id = violateInfoOld.up_product_id;
violateInfo.up_product_id_number = violateInfoOld.up_product_id_number;
continue;
}
}
if (!ViolateRuleParam.LstViolateRuleName.Contains(violateInfo?.rule_name?.Trim()))
{
//ViolateManageForm.UpdateViolateRuleNameList(violateInfo);
}
if (string.IsNullOrEmpty(violateInfo.up_product_id))
{
// 获取违规商品的上家ID
//ViolateManageForm.GetViolateUpId(violateInfo);
}
if (violateInfo.up_product_id_number > 0)
violateListTemp.Add(violateInfo);
}
foreach (var violateInfo in violateListTemp)
{
// 将上家商品违规信息保存到服务端
//ViolateManageForm.AddViolateToServer(violateInfo);
}
if (violateList.Count > 0)
{
vioDic[violateList.FirstOrDefault()?.shop_id] = violateList;
// 保存店铺违规记录第一页
NaiBa.Util.Helper.ConfigHelper.SaveConfig<Dictionary<string, List<ViolateInfo>>>("dou_violate_info", vioDic);
}
}
});
}
}
private void lblVersionName_Click(object sender, EventArgs e)
{
#if DEBUG
if (this.webBrowser != null)
{
if (webBrowser.Tag == null)
{
webBrowser.BringToFront();
webBrowser.Tag = 1;
}
else
{
webBrowser.SendToBack();
webBrowser.Tag = null;
}
}
#endif
}
#endregion
private void lblContactSupport_Click(object sender, EventArgs e)
{
SupportQrCodeForm qrForm = new SupportQrCodeForm();