1上传草稿箱接口改用国际版 2配套相关登录、cookie保存、导出、导入等功能

This commit is contained in:
wule committed 2025-07-30 19:22:43 +08:00
1 parent c032747651
commit 096e1a450d
20 files changed
+825 -249

No files matched your search

@@ -25,6 +25,7 @@ using System.Windows.Forms;
using Work;
using Work.BLL.Tools;
using TemuKJD.KJDForms.ShopForms;
using TemuKJD.KJDForms.ToolForms;
namespace TemuKJD.KJDForms.AdminForms
{
@@ -36,8 +37,10 @@ namespace TemuKJD.KJDForms.AdminForms
public string MultiLoginCookieName = "";
public string InitUrl = "";
private string shopCookieHead = "kuajingmaihuo.com";
private string shopCookieHead2 = "temu.com";
private string shopLoginUrl = "http://seller.kuajingmaihuo.com/login";
private string shopMainUrl = "https://seller.kuajingmaihuo.com";
private string shopMainUrl2 = "https://agentseller.temu.com";
private ChromiumWebBrowser cefWebBrowser = null;
private ShopLoginInfo shop = null;
private List<ShopCompany> lstShopCompany = new List<ShopCompany>();
@@ -116,10 +119,15 @@ namespace TemuKJD.KJDForms.AdminForms
string cookies = "";
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.RequestContext.GetCookieManager(null));
var keys = new string[] { "a42", "_bee", "_f77", "_nano_fp", "api_uid", "rckk", "ru1k", "ru2k", "SUB_PASS_ID" };
if (cookieList != null && cookieList.Count > 0)
{
foreach (var cookie in cookieList)
{
if (!keys.Contains(cookie.Name))
continue;
//SUB_PASS_ID同时出现两个,domain是seller.kuajingmaihuo.com才是能登录店铺后台的
if (cookie.Name == "SUB_PASS_ID" && cookie.Domain != "seller.kuajingmaihuo.com"
&& cookieList.Any(c=>c.Name== "SUB_PASS_ID" && c.Domain == "seller.kuajingmaihuo.com"))
@@ -165,7 +173,107 @@ namespace TemuKJD.KJDForms.AdminForms
if (isSuccess)
{
shop.LoginStatus = "登录成功";
ShopListForm.UpdateServerShopCookies(shop, shop.Cookies); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie
ShopListForm.UpdateServerShopCookies(shop); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie
}
//OnSaveComplete(shop);
//if (this.Created && this.chkCloseAfterLogin.Checked)
//{
// Invoke(new Action(() => { this.Close(); }));
//}
//else
// break;
}
//cefWebBrowser.Load(shopMainUrl2);
var shopStatusRst = ShopListForm.GetShopStatus2(shop);
if (!shopStatusRst.Contains("\"success\":true"))
{
//https://agentseller.temu.com/main/authentication?redirectUrl=https%3A%2F%2Fagentseller.temu.com&mallId=634418217169109&asCode=7PaagItuW7ZD1xw2IXNU198596bf60a24327b02d32da6d43f9bcbc40a4b925d0b2ba8c28bd
var codeRst = ShopListForm.GetShopLogin2Code(shop);
if (codeRst.Contains("\"success\":true"))
{
string code = BaseRegex.GetStringJson(ref codeRst, "code");
cefWebBrowser.Load("https://agentseller.temu.com/main/authentication" +
"?redirectUrl=https%3A%2F%2Fagentseller.temu.com&mallId=" + shop.ShopId +
"&asCode=" + code);
}
else
{
cefWebBrowser.Load("https://agentseller.temu.com");
}
}
else
{
cefWebBrowser.Load("https://agentseller.temu.com");
}
}
if (1 == 1 && this.shop != null && currentUrl.TrimEnd('/') == shopMainUrl2)
{
//https://agentseller.temu.com
if (!cefWebBrowser.GetBrowser().MainFrame.IsValid)
continue;
if (openType != EnumOpenType.login)
continue;
if (!lstShopCompany.Any(c => c.LoginName == shop.LoginName))
continue;
string cookies2 = "";
List<Cookie> cookieList2 = CEFBrowser.GetCookieList(shopCookieHead2, cefWebBrowser.RequestContext.GetCookieManager(null));
if (cookieList2 != null && cookieList2.Count > 0)
{
foreach (var cookie in cookieList2)
{
//SUB_PASS_ID同时出现两个,domain是seller.kuajingmaihuo.com才是能登录店铺后台的
//if (cookie.Name == "seller_temp" && cookie.Domain != "agentseller.temu.com")
// continue;
//if (cookie.Name == "mallid" && cookie.Domain != "agentseller.temu.com")
// continue;
//if (cookie.Name != "seller_temp")
// continue;
cookies2 += cookie.Name + "=" + cookie.Value + "; ";
}
cookies2 = cookies2.Trim().TrimEnd(';');
}
if (!string.IsNullOrEmpty(cookies2)
&& lstShopCompany.Any(c => c.LoginName == shop.LoginName))
{
var lstShopCompanyCopy = lstShopCompany.ToList();
lstShopCompanyCopy = lstShopCompanyCopy.Where(l => l.LoginName == shop.LoginName).ToList();
bool isSuccess = true;
foreach (ShopCompany sc in lstShopCompanyCopy)
{
ShopLoginInfo newShop = new ShopLoginInfo()
{
LoginName = shop.LoginName,
Password = shop.Password,
GroupName = shop.GroupName,
ShopAccount = sc.AccountName,
ShopId = sc.AccountId,
SubUserName = shop.SubUserName,
UserName = shop.UserName,
Notes = shop.Notes,
Cookies2 = cookies2,
};
if (string.IsNullOrEmpty(shop.Cookies)) // 有cookie的认为是已登录过的
{
newShop.LoginStatus2 = "国际版在线";
newShop.LastRefreshDate = DateTime.Now.ToString("yyyyMMdd");
var html = AdminShopForm.AdminAddServerShop(newShop); // 店铺写入到服务端
if (!html.Contains("\"code\":200"))
isSuccess = false;
}
}
shop.Cookies2 = cookies2;
if (isSuccess)
{
shop.LoginStatus2 = "国际版在线";
ShopListForm.UpdateServerShopCookies(shop); // 店铺cookie写入服务端,多店共用一个登录账号一组cookie
}
OnSaveComplete(shop);
if (this.Created && this.chkCloseAfterLogin.Checked)
@@ -259,8 +367,11 @@ namespace TemuKJD.KJDForms.AdminForms
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
var lifeSapnHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
cefWebBrowser.LifeSpanHandler = lifeSapnHandler;
//var lifeSpanHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
var lifeSpanHandler = new LifeSpanHandlerLocal(PopWindowType.NewTitleWindow);
lifeSpanHandler.parent = cefWebBrowser;
lifeSpanHandler.OnPop += MainLifeHandler_OnPop;
cefWebBrowser.LifeSpanHandler = lifeSpanHandler;
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
@@ -280,16 +391,21 @@ namespace TemuKJD.KJDForms.AdminForms
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] : "";
var cookie2 = shop.Cookies2;
Task.Run(() =>
{
var t = CEFBrowser.SetCookieAsync(shopCookieHead, cookie, cefWebBrowser.RequestContext.GetCookieManager(null));
t.Wait(5000);
t = CEFBrowser.SetCookieAsync(shopCookieHead2, cookie2, cefWebBrowser.RequestContext.GetCookieManager(null));
t.Wait(5000);
Invoke(new Action(() =>
{
@@ -300,9 +416,14 @@ namespace TemuKJD.KJDForms.AdminForms
//根据登录的具体店铺设置local storage
if (!string.IsNullOrEmpty(shop.ShopId))
{
var storageJsCode = "window.localStorage.setItem('" + "mall-info-id" + "', '" + shop.ShopId + "');\r\n";
while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid)
Thread.Sleep(20);
var storageJsCode = "window.localStorage.setItem('" + "mall-info-id" + "', '" + shop.ShopId + "');\r\n";
cefWebBrowser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(storageJsCode);
//agentseller-mall-info-id
storageJsCode = "window.localStorage.setItem('" + "agentseller-mall-info-id" + "', '" + shop.ShopId + "');\r\n";
cefWebBrowser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(storageJsCode);
}
@@ -322,7 +443,7 @@ namespace TemuKJD.KJDForms.AdminForms
if (cefWebBrowser.IsLoading)
Thread.Sleep(100);
}
Thread.Sleep(Randomx.GetId(1500,2000));
Thread.Sleep(Randomx.GetId(1500, 2000));
//设置 local storage
//if (GlobalConfig.dicLocalStorage != null)
@@ -349,6 +470,24 @@ namespace TemuKJD.KJDForms.AdminForms
});
}
}
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 ShopObj_OnInfoReceived(string information)
{
@@ -470,7 +609,8 @@ namespace TemuKJD.KJDForms.AdminForms
// }
// });
//}
if (currentUrl.StartsWith("https://seller.kuajingmaihuo.com/goods/product/list"))
if (currentUrl.StartsWith("https://seller.kuajingmaihuo.com/goods/product/list") ||
currentUrl.StartsWith("https://agentseller.temu.com/goods/list"))
{
Task.Run(() => {
string sAddInputJs = @"