From 89eb9ce9d472011065afb729c8f9e602200b2852 Mon Sep 17 00:00:00 2001 From: wule Date: Tue, 1 Jul 2025 09:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=97=E9=93=BA=E7=99=BB=E5=BD=95=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AllBase/Model/Result/DouShopLoginInfo.cs | 10 ++ TEMUKJD/KJDForms/ShopForms/ShopAuthForm.cs | 4 +- TEMUKJD/KJDForms/ShopForms/ShopListForm.cs | 61 +++++---- TEMUKJD/KJDForms/ShopForms/ShopLoginForm.cs | 119 ++++++++++++------ TEMUKJD/KJDForms/UploadForms/Fission.cs | 8 +- .../UploadForms/FissionDataBaseForm.cs | 2 +- .../KJDForms/UploadForms/ShopProductForm.cs | 4 +- TEMUKJD/StartUp.cs | 6 +- 8 files changed, 139 insertions(+), 75 deletions(-) diff --git a/AllBase/Model/Result/DouShopLoginInfo.cs b/AllBase/Model/Result/DouShopLoginInfo.cs index 2cc4b8f..e95e57e 100644 --- a/AllBase/Model/Result/DouShopLoginInfo.cs +++ b/AllBase/Model/Result/DouShopLoginInfo.cs @@ -193,4 +193,14 @@ namespace AllBase.Model.Result public string brand_reg_num { get; set; } public long id { get; set; } } + + // temu 一个登录账号下可以有多个店铺 + public class ShopCompany + { + public string UserName { get; set; } + public string LoginName { get; set; } + public string AccountId { get; set; } + public string AccountName { get; set; } + public string LoginStatus { get; set; } + } } diff --git a/TEMUKJD/KJDForms/ShopForms/ShopAuthForm.cs b/TEMUKJD/KJDForms/ShopForms/ShopAuthForm.cs index 1cba412..95080ed 100644 --- a/TEMUKJD/KJDForms/ShopForms/ShopAuthForm.cs +++ b/TEMUKJD/KJDForms/ShopForms/ShopAuthForm.cs @@ -114,7 +114,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms { //shop.ApiAuthStatus = "授权成功"; ShopListForm.UpdateShopTokens(GlobalConfig.DouShopLoginList.Where(s => s.ShopAccount == shop.ShopAccount).ToList()); - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); OnSaveComplete(shop); if (this.Created && this.chkCloseAfterLogin.Checked) { @@ -134,7 +134,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms if (this.Created && this.chkCloseAfterLogin.Checked) { ShopListForm.UpdateShopTokens(GlobalConfig.DouShopLoginList.Where(s => s.ShopAccount == shop.ShopAccount).ToList()); - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); OnSaveComplete(shop); Thread.Sleep(2000); Invoke(new Action(() => { this.Close(); })); diff --git a/TEMUKJD/KJDForms/ShopForms/ShopListForm.cs b/TEMUKJD/KJDForms/ShopForms/ShopListForm.cs index 6f39a31..5135925 100644 --- a/TEMUKJD/KJDForms/ShopForms/ShopListForm.cs +++ b/TEMUKJD/KJDForms/ShopForms/ShopListForm.cs @@ -37,6 +37,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms + "&login_pass=" + GetHtml.UrlEncodeUtf8(_shop.Password) + "&shop_id=" + _shop.ShopAccountId + "&shop_account=" + _shop.ShopAccount + + "&cookie=" + _shop.Cookies + "&shop_group=" + GetHtml.UrlEncodeUtf8(_shop.Group); var result = GetHtml.PostUtf8(url, data); @@ -218,14 +219,12 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms /// 店铺名称 /// cookies /// 工具名称(可不填写) - public static void AddServerShopCookies(DouShopLoginInfo shop, string shopCookies, string fromTool = null) + public static void UpdateServerShopCookies(DouShopLoginInfo shop, string shopCookies, string fromTool = null) { var fTool = string.IsNullOrEmpty(fromTool) ? "" : "&from_tool=" + fromTool; var url = BaseClass.BuildObjString("shop/mdy_shop"); var data = UserLogin.GetSignaturex() + "&login_name=" + shop.LoginName - + "&shop_id=" + shop.ShopAccountId - + "&shop_account=" + shop.ShopAccount + "&cookie=" + shopCookies.Replace("&", "&").Replace("%", "%").Replace("+", "+") + fTool; var result = GetHtml.PostUtf8(url, data); @@ -236,17 +235,17 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms BaseMsgForm.ShowError("服务端登录状态保存失败!请检查网络连接。"); } } - /// - /// 获取店铺Cookies - /// - /// 店铺名称,逗号隔开 - public static string GetServerShopCookies(string shopNames) - { - var url = BaseClass.BuildObjString("shop&act=get_shop_cookie"); - var data = UserLogin.GetSignaturex() + "&shop_name=" + shopNames.Trim(','); - var result = GetHtml.PostUtf8(url, data); - return result; - } + ///// + ///// 获取店铺Cookies + ///// + ///// 店铺名称,逗号隔开 + //public static string GetServerShopCookies(string shopNames) + //{ + // var url = BaseClass.BuildObjString("shop&act=get_shop_cookie"); + // var data = UserLogin.GetSignaturex() + "&shop_name=" + shopNames.Trim(','); + // var result = GetHtml.PostUtf8(url, data); + // return result; + //} #endregion public static string GetServerShopTokens(string shopLoginNames) @@ -280,13 +279,21 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms { if ((isAdd as bool?) == true) { - ShopLoginForm shopLoginForm = new ShopLoginForm(shopInfo); - shopLoginForm.SaveComplete += shopLoginForm_SaveComplete; - shopLoginForm.Show(); + var shop = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.LoginName == shopInfo.LoginName); + if (shop != null) + { + BaseMsgForm.ShowError("店铺" + shopInfo.LoginName + "已存在!"); + } + else + { + GlobalConfig.DouShopLoginList.Add(shopInfo); + StartUp.SaveLocalShopLoginInfo(); + ShopListForm.AddServerDouShop(shopInfo); + } } else { - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); ShopListForm.AddServerDouShop(shopInfo); shopLoginForm_SaveComplete(shopInfo); } @@ -356,7 +363,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms } else GlobalConfig.DouShopLoginList.Add(shop); - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); ShopListForm.AddServerDouShop(shop); } } @@ -423,7 +430,9 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms return; this.Invoke(new Action(() => { - DataGridViewRow dgvr = dgvShop.Rows.Cast().Where(p => p.Cells.GetCellValueFromColumnName("colLoginName").ParseToString() == param.LoginName).FirstOrDefault(); + DataGridViewRow dgvr = dgvShop.Rows.Cast().Where(p => + p.Cells.GetCellValueFromColumnName("colLoginName").ParseToString() == param.LoginName && + p.Cells.GetCellValueFromColumnName("colShopId").ParseToString() == param.ShopAccountId).FirstOrDefault(); if (dgvr != null) { UpdateDataGridViewRowToken(dgvr, param); @@ -603,7 +612,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms if (!string.IsNullOrEmpty(loginResult)) shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd"); - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); AddDataGridViewRow(shop); } if (this.Created && isShowProgress) @@ -737,7 +746,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms return; DeleteShop(e.RowIndex); DelServerDouShop(shop.LoginName); - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); break; case "编辑": ShopAddEditForm editForm = new ShopAddEditForm(shop); @@ -788,8 +797,12 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms private void DeleteShop(int rowIndex) { string shopLoginName = this.dgvShop.Rows[rowIndex].Cells["colLoginName"].Value.ParseToString(); - dgvShop.Rows.RemoveAt(rowIndex); - GlobalConfig.DouShopLoginList.RemoveAll(v => v.ShopAccount == shopLoginName); + List dgvRows = dgvShop.Rows.Cast().Where(p => + p.Cells.GetCellValueFromColumnName("colLoginName").ParseToString() == shopLoginName).ToList(); + + foreach(var row in dgvRows) + dgvShop.Rows.Remove(row); + GlobalConfig.DouShopLoginList.RemoveAll(v => v.LoginName == shopLoginName); } private void btnCheck_Click(object sender, EventArgs e) diff --git a/TEMUKJD/KJDForms/ShopForms/ShopLoginForm.cs b/TEMUKJD/KJDForms/ShopForms/ShopLoginForm.cs index fb00f1f..73bb6b7 100644 --- a/TEMUKJD/KJDForms/ShopForms/ShopLoginForm.cs +++ b/TEMUKJD/KJDForms/ShopForms/ShopLoginForm.cs @@ -10,6 +10,7 @@ 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; @@ -42,6 +43,7 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms private string shopMainUrl = "https://seller.kuajingmaihuo.com"; private ChromiumWebBrowser cefWebBrowser = null; private DouShopLoginInfo shop = null; + private List lstShopCompany = new List(); private string currentUrl = ""; public ShopLoginForm(DouShopLoginInfo shopInfo) @@ -109,17 +111,10 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms if (openType!= EnumOpenType.login) continue; - if (string.IsNullOrEmpty(shop.ShopAccountId) || string.IsNullOrEmpty(shop.ShopAccount)) + if (!lstShopCompany.Any(c => c.LoginName == shop.LoginName)) continue; - //var jsStr = "function getShopName() { return document.getElementsByClassName('headerShopName')[0].innerHTML; } getShopName();"; - //var response = cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(jsStr); - //response.Wait(5000); - //var res = response.Result.Result?.ToString(); - //if (res != null && res.Contains("")) { - //shop.ShopAccount = res.Substring(res.IndexOf("") + 7); - //shop.ShopAccount = BaseRegex.FliterHtmlTag(shop.ShopAccount); string cookies = ""; List cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.RequestContext.GetCookieManager(null)); if (cookieList != null && cookieList.Count > 0) @@ -133,37 +128,69 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms } cookies = cookies.Trim().TrimEnd(';'); } - shop.Cookies = cookies; - //if (isMultiLogin) - //{ - // shop.DictMultiCookies[MultiLoginCookieName] = cookies; - //} - if (!string.IsNullOrEmpty(shop.Cookies) - && !string.IsNullOrEmpty(shop.ShopAccount) - && !string.IsNullOrEmpty(shop.ShopAccountId) - //&& !string.IsNullOrEmpty(shop.Mobile) - //&& !string.IsNullOrEmpty(shop.ShopToken) - ) + if (!string.IsNullOrEmpty(cookies) + && lstShopCompany.Any(c => c.LoginName == shop.LoginName)) { - shop.LoginStatus = "登录成功"; + var lstShopCompanyCopy = lstShopCompany.ToList(); + //var shopCompany = lstShopCompany.FirstOrDefault(c=>c.LoginName==shop.LoginName); + //if (shopCompany == null) + // shopCompany = new ShopCompany(); - shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd"); - var shopInfo = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.ShopAccountId == shop.ShopAccountId); - if (shopInfo != null) + //shop.LoginStatus = "登录成功"; + //shop.ShopAccountId = shopCompany.AccountId; + //shop.ShopAccount = shopCompany.AccountName; + //shop.Cookies = cookies; + + //shop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd"); + //var shopInfo = GlobalConfig.DouShopLoginList.FirstOrDefault(v => v.ShopAccountId == shop.ShopAccountId); + //if (shopInfo != null) + //{ + // shopInfo.Cookies = shop.Cookies; + // shopInfo.Password = shop.Password; + // shopInfo.ShopAccountId = shop.ShopAccountId; + // shopInfo.ShopAccount = shop.ShopAccount; + //} + //else + // GlobalConfig.DouShopLoginList.Add(shop); + //StartUp.SaveLocalShopLoginInfo(); + ////ShopListForm.AddServerDouShop(shop); // 店铺写入到服务端 + //ShopListForm.UpdateServerShopCookies(shop, shop.Cookies); // cookie写入到服务端 + + foreach (ShopCompany sc in lstShopCompanyCopy) { - //shopInfo.ShopToken = shop.ShopToken; - //shopInfo.Mobile = shop.Mobile; - shopInfo.Cookies = shop.Cookies; - shopInfo.Password = shop.Password; - shopInfo.ShopAccountId = shop.ShopAccountId; - shopInfo.ShopAccount = shop.ShopAccount; + DouShopLoginInfo newShop = new DouShopLoginInfo() + { + LoginName = shop.LoginName, + Password = shop.Password, + Group = shop.Group, + LoginStatus = "登录成功", + ShopAccount = sc.AccountName, + ShopAccountId = sc.AccountId, + Cookies = cookies, + }; + + var oldShop = GlobalConfig.DouShopLoginList.FirstOrDefault(l => + l.LoginName == newShop.LoginName && l.ShopAccountId == newShop.ShopAccountId); + if (oldShop == null) + { + GlobalConfig.DouShopLoginList.Add(newShop); + ShopListForm.AddServerDouShop(newShop); // 店铺写入到服务端 + } + else + { + oldShop.LoginName = shop.LoginName; + oldShop.Password = shop.Password; + oldShop.Group = shop.Group; + oldShop.LoginStatus = "登录成功"; + oldShop.ShopAccount = sc.AccountName; + oldShop.ShopAccountId = sc.AccountId; + oldShop.Cookies = cookies; + } + StartUp.SaveLocalShopLoginInfo(); + ShopListForm.UpdateServerShopCookies(newShop, newShop.Cookies); } - else - GlobalConfig.DouShopLoginList.Add(shop); - StartUp.SaveDouShopLoginInfo(); - //ShopListForm.AddServerDouShop(shop); // 店铺写入到服务端 - ShopListForm.AddServerShopCookies(shop, shop.Cookies); // cookie写入到服务端 + OnSaveComplete(shop); if (this.Created && this.chkCloseAfterLogin.Checked) { @@ -359,10 +386,24 @@ namespace LittleRabbit.LittleRabbitForms.ShopForms var maskMobile = BaseRegex.GetStringJson(ref data, "maskOwnerMobile"); if (shop.LoginName.EndsWith(maskMobile)) { - shop.ShopAccountId = BaseRegex.GetStringJson(ref data, "mallId"); - shop.ShopAccount = BaseRegex.GetStringJson(ref data, "mallName"); - //shop.ShopToken = BaseRegex.GetStringJson(ref data, "token"); - //shop.Mobile = BaseRegex.GetStringJson(ref data, "mobile"); + lstShopCompany.Clear(); + var jObj = JObject.Parse(data); + var jArr = jObj["result"]?["companyList"]?[0]?["malInfoList"] as JArray; + if (jArr == null) + jArr = new JArray(); + foreach (var productObj in jArr) + { + var prod = JsonHelper.SerializeObject(productObj); + ShopCompany sc = new ShopCompany() + { + AccountId = BaseRegex.GetStringJson(ref prod, "mallId"), + AccountName = BaseRegex.GetStringJson(ref prod, "mallName"), + LoginName = shop.LoginName, + UserName = BaseClass.UserName, + LoginStatus = "登录成功", + }; + this.lstShopCompany.Add(sc); + } } } }); @@ -716,7 +757,7 @@ function fireKeyEvent(el, evtType, keyCode) { if (shop != null) { shop.DictMultiCookies.Remove(cmbMultiCookieName.Text); - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); InitMultiLoginCookies(); } diff --git a/TEMUKJD/KJDForms/UploadForms/Fission.cs b/TEMUKJD/KJDForms/UploadForms/Fission.cs index 163c0ce..3838e94 100644 --- a/TEMUKJD/KJDForms/UploadForms/Fission.cs +++ b/TEMUKJD/KJDForms/UploadForms/Fission.cs @@ -689,7 +689,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms break; if (dyShop.LoginStatus == "未登录") { - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); dyShop = GlobalConfig.DouShopLoginList.FirstOrDefault(s => s.LoginStatus == "登录成功"); Thread.Sleep(100); } @@ -2075,7 +2075,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms if (result.Contains("已过期")) { shop.ApiAuthStatus = "未授权"; - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); continue; } @@ -2130,7 +2130,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms BaseMsgForm.ShowInfo("获取类目失败!"); } - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); NaiBa.Util.Helper.ConfigHelper.SaveConfig("cat_dy", list); return list; } @@ -2576,7 +2576,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms while (propResult.Contains("已过期")) { dyShop.ApiAuthStatus = "未授权"; - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); dyShop = GlobalConfig.DouShopLoginList.FirstOrDefault(s => s.ApiAuthStatus == "授权成功"); if (dyShop == null) { diff --git a/TEMUKJD/KJDForms/UploadForms/FissionDataBaseForm.cs b/TEMUKJD/KJDForms/UploadForms/FissionDataBaseForm.cs index 28c5171..abe86d1 100644 --- a/TEMUKJD/KJDForms/UploadForms/FissionDataBaseForm.cs +++ b/TEMUKJD/KJDForms/UploadForms/FissionDataBaseForm.cs @@ -304,7 +304,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms if (result.Contains("已过期")) { shop.ApiAuthStatus = "未授权"; - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); GoodsCategoryModel cat = new GoodsCategoryModel() { enable = true, diff --git a/TEMUKJD/KJDForms/UploadForms/ShopProductForm.cs b/TEMUKJD/KJDForms/UploadForms/ShopProductForm.cs index 65bd67b..6e2cc8b 100644 --- a/TEMUKJD/KJDForms/UploadForms/ShopProductForm.cs +++ b/TEMUKJD/KJDForms/UploadForms/ShopProductForm.cs @@ -98,7 +98,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms Thread.Sleep(Randomx.GetId(50, 150)); } if (shopList.Count() > 0) - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); Invoke(new Action(() => { if (isShowProgress) @@ -1594,7 +1594,7 @@ namespace LittleRabbit.LittleRabbitForms.UploadForms if (shop.PayStatus != 1) { shop.TrialOperateCount++; - StartUp.SaveDouShopLoginInfo(); + StartUp.SaveLocalShopLoginInfo(); } } diff --git a/TEMUKJD/StartUp.cs b/TEMUKJD/StartUp.cs index 97b65c3..053df11 100644 --- a/TEMUKJD/StartUp.cs +++ b/TEMUKJD/StartUp.cs @@ -85,10 +85,10 @@ namespace LittleRabbit localDouShopList.AddRange(serverDouShopList); foreach (var localShop in localDouShopList) { - if (GlobalConfig.DouShopLoginList.Any(s => s.LoginName == localShop.LoginName)) + if (GlobalConfig.DouShopLoginList.Any(s => s.LoginName == localShop.LoginName && s.ShopAccountId == localShop.ShopAccountId)) continue; - var serverShop = serverDouShopList.FirstOrDefault(s => s.LoginName == localShop.LoginName); + var serverShop = serverDouShopList.FirstOrDefault(s => s.LoginName == localShop.LoginName && s.ShopAccountId == localShop.ShopAccountId); if (serverShop != null) { localShop.ShopAccount = serverShop.ShopAccount; @@ -450,7 +450,7 @@ namespace LittleRabbit NaiBa.Util.Helper.ConfigHelper.SaveConfig("fission_setting_param", GlobalConfig.FissionSettingParam); } - public static void SaveDouShopLoginInfo() + public static void SaveLocalShopLoginInfo() { ConcurrentList shopLoginListCopy = JsonHelper.DeserializeJsonToObject>(JsonHelper.SerializeObject(GlobalConfig.DouShopLoginList));