拼多多商品获取逻辑
This commit is contained in:
1 parent
840636d5c9
commit
6639224771
68 files changed
+7132
-692
No files matched your search
@@ -70,12 +70,6 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
{
|
||||
//this.splitContainer1.SplitterDistance = 674;
|
||||
|
||||
if (openType == EnumOpenType.login)
|
||||
{
|
||||
//this.shop.ShopId = "";
|
||||
//this.shop.ShopAccount = "";
|
||||
}
|
||||
|
||||
if (isMultiLogin && shop != null)
|
||||
{
|
||||
this.pnlMultiLogin.Visible = true;
|
||||
@@ -98,7 +92,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
AutoLogin();
|
||||
|
||||
CheckAndSaveShop(); //判断登录是否成功,成功则保存店铺信息和店铺cookie
|
||||
//ClosePopWindow(); //自动关闭弹窗
|
||||
//ClosePopWindow(); //自动关闭弹窗
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -112,7 +106,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
while (this.Created)
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
//continue;
|
||||
|
||||
if (!this.Created)
|
||||
break;
|
||||
|
||||
@@ -129,18 +123,21 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
|
||||
string cookies = "";
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList(shopCookieHead, cefWebBrowser.GetCookieManager(null));
|
||||
List<Cookie> cookieListNew = new List<Cookie>();
|
||||
if (cookieList != null && cookieList.Count > 0)
|
||||
{
|
||||
foreach (var cookie in cookieList)
|
||||
{
|
||||
//SUB_PASS_ID同时出现两个,domain是seller.kuajingmaihuo.com才是能登录店铺后台的
|
||||
//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"))
|
||||
&& 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 = cookies.Trim().TrimEnd(';');
|
||||
cookies = JsonHelper.SerializeObject(cookieListNew);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(cookies)
|
||||
@@ -160,6 +157,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
ShopId = sc.AccountId,
|
||||
SubUserName = shop.SubUserName,
|
||||
Notes = shop.Notes,
|
||||
AntiContents = new List<string> { sc.AntiContent },
|
||||
};
|
||||
|
||||
var oldShop = GlobalConfig.ShopLoginList.FirstOrDefault(l =>
|
||||
@@ -167,7 +165,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
if (oldShop == null)
|
||||
{
|
||||
GlobalConfig.ShopLoginList.Add(newShop);
|
||||
PDDShopListForm.AddServerDouShop(newShop); // 店铺写入到服务端
|
||||
PDDShopListForm.AddServerPddShop(newShop); // 店铺写入到服务端
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -178,6 +176,24 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
oldShop.ShopId = newShop.ShopId;
|
||||
oldShop.SubUserName = newShop.SubUserName;
|
||||
oldShop.Notes = newShop.Notes;
|
||||
oldShop.AntiContents.AddRange(newShop.AntiContents);
|
||||
while (oldShop.AntiContents.Count > 10)
|
||||
oldShop.AntiContents.RemoveAt(0);
|
||||
|
||||
// 店铺更新写入到服务端
|
||||
var url = BaseClass.BuildObjString("shop/mdy_shop");
|
||||
var data = UserLogin.GetSignaturex()
|
||||
+ "&login_name=" + oldShop.LoginName
|
||||
+ "&new_shop_id=" + oldShop.ShopId
|
||||
+ "&shop_account=" + oldShop.ShopAccount;
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
|
||||
var urlAddress = BaseClass.BuildObjString("shop/mdy_anti_content");
|
||||
data = UserLogin.GetSignaturex()
|
||||
+ "&login_name=" + shop.LoginName
|
||||
+ "&shop_id=" + shop.ShopId
|
||||
+ "&anti_contents=" + JsonHelper.SerializeObject(shop.AntiContents);
|
||||
result = GetHtml.PostUtf8(urlAddress, data);
|
||||
}
|
||||
}
|
||||
var lstShop = GlobalConfig.ShopLoginList.Where(l => l.LoginName == shop.LoginName).ToList();
|
||||
@@ -306,10 +322,19 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
if (shop.Cookies2 == null)
|
||||
shop.Cookies2 = "";
|
||||
|
||||
var cookie = shop.Cookies;
|
||||
if (isMultiLogin)
|
||||
cookie = shop.DictMultiCookies.Keys.Contains(MultiLoginCookieName) ? shop.DictMultiCookies[MultiLoginCookieName] : "";
|
||||
|
||||
//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(() =>
|
||||
{
|
||||
@@ -324,8 +349,15 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null));
|
||||
|
||||
//cef 138 如果没有设置RequestContext 可能为空,直接getCookieManager
|
||||
var t = CEFBrowser.SetCookieAsync(shopCookieHead, cookie, cefWebBrowser.GetCookieManager(null));
|
||||
t.Wait(5000);
|
||||
//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)
|
||||
{
|
||||
@@ -346,6 +378,8 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
|
||||
if (!string.IsNullOrEmpty(InitUrl))
|
||||
cefWebBrowser.Load(InitUrl);
|
||||
else
|
||||
cefWebBrowser.Load(shopMainUrl);
|
||||
|
||||
//不是登录的话就此返回
|
||||
if (openType != EnumOpenType.login)
|
||||
@@ -365,27 +399,17 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(1500,2000));
|
||||
|
||||
//设置 local storage
|
||||
//if (GlobalConfig.dicLocalStorage != null)
|
||||
//{
|
||||
// Thread.Sleep(500);
|
||||
// string jsCode = "function setStorage() {";
|
||||
// foreach (var item in GlobalConfig.dicLocalStorage)
|
||||
// {
|
||||
// if (item.Key == "$TCC_CONFIG" || item.Key == "$TCC_CONFIG_operate_config" || item.Key == "menuStyleStr")
|
||||
// continue;
|
||||
|
||||
// jsCode += "window.localStorage.setItem('" + item.Key + "', '" + item.Value + "');\r\n";
|
||||
// }
|
||||
// jsCode += "}";
|
||||
// jsCode += "setStorage();";
|
||||
// if (cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
||||
// cefWebBrowser.GetBrowser().MainFrame.ExecuteJavaScriptAsync(jsCode);
|
||||
//}
|
||||
|
||||
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));
|
||||
});
|
||||
}
|
||||
@@ -436,32 +460,45 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
cefWebBrowser.GetBrowser().MainFrame.EvaluateScriptAsync(sb.ToString());
|
||||
}
|
||||
|
||||
int GetAntiContentsTimes = 0;
|
||||
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))
|
||||
{
|
||||
GetAntiContentsTimes++;
|
||||
shop.AntiContents.Add(antiContent);
|
||||
while (shop.AntiContents.Count > 10)
|
||||
shop.AntiContents.RemoveAt(0);
|
||||
if (!string.IsNullOrEmpty(shop.ShopId) && GetAntiContentsTimes > 5)
|
||||
{
|
||||
GetAntiContentsTimes = 0;
|
||||
var antis = shop.AntiContents;
|
||||
Task.Run(() =>
|
||||
{
|
||||
var urlAddress = BaseClass.BuildObjString("shop/mdy_anti_content");
|
||||
var data = UserLogin.GetSignaturex()
|
||||
+ "&login_name=" + shop.LoginName
|
||||
+ "&shop_id=" + shop.ShopId
|
||||
+ "&anti_contents=" + JsonHelper.SerializeObject(antis);
|
||||
var result = GetHtml.PostUtf8(urlAddress, data);
|
||||
});
|
||||
}
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
var data = responseData;
|
||||
var uri = url;
|
||||
if (data.Contains("球球小小"))
|
||||
{
|
||||
|
||||
}
|
||||
if (data.Contains("supplierId") && data.Contains("\"success\":true"))
|
||||
{
|
||||
var supplierIds = BaseRegex.GetMatchRegex(ref data, "\"supplierId\":\\d{5,20}");
|
||||
if (supplierIds.Count > 0 && supplierIds[0].Groups.Count > 0)
|
||||
{
|
||||
var supplierId = supplierIds[0].Groups[0].Value.Replace("\"supplierId\":", "").ParseToLong();
|
||||
if (supplierId > 0)
|
||||
this.currentSupplierId = supplierId;
|
||||
}
|
||||
}
|
||||
//var data = responseData;
|
||||
//if (data.Contains("supplierId") && data.Contains("\"success\":true"))
|
||||
//{
|
||||
// var supplierIds = BaseRegex.GetMatchRegex(ref data, "\"supplierId\":\\d{5,20}");
|
||||
// if (supplierIds.Count > 0 && supplierIds[0].Groups.Count > 0)
|
||||
// {
|
||||
// var supplierId = supplierIds[0].Groups[0].Value.Replace("\"supplierId\":", "").ParseToLong();
|
||||
// if (supplierId > 0)
|
||||
// this.currentSupplierId = supplierId;
|
||||
// }
|
||||
//}
|
||||
});
|
||||
if (url.StartsWith("https://seller.kuajingmaihuo.com/settle/site-main"))
|
||||
{
|
||||
cefWebBrowser.Load(shopMainUrl);
|
||||
}
|
||||
//if (url == shopMainUrl)
|
||||
if (url == "https://mms.pinduoduo.com/janus/api/userinfo")
|
||||
{
|
||||
Task.Run(() =>
|
||||
@@ -471,7 +508,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
{
|
||||
var maskMobile = BaseRegex.GetStringJson(ref data, "mobile");
|
||||
maskMobile = maskMobile.Split('*').Last();
|
||||
if (shop.LoginName.EndsWith(maskMobile))
|
||||
if (!string.IsNullOrEmpty(maskMobile) && shop.LoginName.EndsWith(maskMobile))
|
||||
{
|
||||
lstShopCompany.Clear();
|
||||
var jObj = JObject.Parse(data);
|
||||
@@ -480,19 +517,6 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
jArr = new JArray();
|
||||
|
||||
Thread.Sleep(500);
|
||||
//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);
|
||||
//}
|
||||
|
||||
ShopCompany sc = new ShopCompany()
|
||||
{
|
||||
@@ -502,35 +526,15 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
LoginName = shop.LoginName,
|
||||
UserName = BaseClass.UserName,
|
||||
LoginStatus = "登录成功",
|
||||
AntiContent = antiContent,
|
||||
};
|
||||
this.lstShopCompany.Add(sc);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
//if (url.Contains("_signature"))
|
||||
//{
|
||||
// var re = request;
|
||||
// if ((re.Headers != null && re.Headers.AllKeys.Contains("x-secsdk-csrf-token")))
|
||||
// {
|
||||
// }
|
||||
// Task.Run(() =>
|
||||
// {
|
||||
// var _url = url;
|
||||
// var data = responseData;
|
||||
// var signature = url.Substring(url.IndexOf("_signature=") + "_signature=".Length).Split('&')[0];
|
||||
// if (shop != null)
|
||||
// {
|
||||
// shop.Signature = signature;
|
||||
// }
|
||||
// if (url.Contains("x-secsdk-csrf-token") || postData.Contains("x-secsdk-csrf-token") || data.Contains("x-secsdk-csrf-token"))
|
||||
// {
|
||||
// }
|
||||
// });
|
||||
//}
|
||||
// 库存上传按钮
|
||||
if (currentUrl.StartsWith("https://seller.kuajingmaihuo.com/goods/product/list") ||
|
||||
currentUrl.StartsWith("https://agentseller.temu.com/goods/list"))
|
||||
if (1 == 1 && currentUrl.StartsWith("https://mms.pinduoduo.com/goods/goods_list"))
|
||||
{
|
||||
Task.Run(() => {
|
||||
string sAddInputJs = @"
|
||||
@@ -556,11 +560,13 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
addGetProdButton();
|
||||
|
||||
function addGetProdButton() {
|
||||
var productLst = document.getElementsByClassName('product-info_idContent__iDukx');
|
||||
var productLst = document.getElementsByClassName('goods-id');
|
||||
for(i=0; i<productLst.length; i++) {
|
||||
if (productLst[i].innerHTML.indexOf('库存上传') < 0 && productLst[i].innerHTML.indexOf('SPU ID') >= 0) {
|
||||
var sSpuId = productLst[i].innerText.replace('\r','').replace('\n','').replace('SPU ID:', '');
|
||||
productLst[i].innerHTML = productLst[i].innerHTML.replace(""></div>"", ""><input type=\""button\"" style=\""margin-left: 50px; width:60px; text-align:center\"" value=\""库存上传\"" onclick=\""shopObj.getThirdProduct('"" + sSpuId + ""'," + this.currentSupplierId + @")\""></div>"");
|
||||
var addBtnItem = productLst[i].parentElement.parentElement;
|
||||
if (addBtnItem.parentElement.innerHTML.indexOf('库存上传') < 0 && addBtnItem.parentElement.innerHTML.indexOf('ID:') >= 0) {
|
||||
var sSpuId = addBtnItem.innerText.replace('\r','').replace('\n','').replace('ID: ', '');
|
||||
addBtnItem.outerHTML = addBtnItem.outerHTML.replace(""<section>"",""<section style=\""display:inline; float:left; \"">"")
|
||||
.replace(""</section>"", ""</section><input type=\""button\"" style=\""display:inline; width:60px; margin-left:10px; margin-top:0px; cursor:pointer; border:1px solid\"" value =\""库存上传\"" onclick=\""shopObj.getThirdProduct('"" + sSpuId + ""','" + this.shop.ShopId + @"')\"">"");
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
Reference in new issue
Block a user