771 lines
35 KiB
C#
771 lines
35 KiB
C#
using System.Collections.Generic;
|
|
using AllBase;
|
|
using Work.CollectClass;
|
|
using System;
|
|
using Work.ManageClass;
|
|
using System.Linq;
|
|
|
|
namespace Work.Api
|
|
{
|
|
public class FromTitleToCat
|
|
{
|
|
public string Cat1 = "", Cat2 = "", Cat3 = "", Cat4 = "", Title = "", MainCatId = "";
|
|
public List<KeyValuesBase> Cats = new List<KeyValuesBase>();
|
|
public List<KeyValuesBase> CatTop = new List<KeyValuesBase>();
|
|
public static List<KeyValuesBase> MainCat = new List<KeyValuesBase>();
|
|
public static Dictionary<long, KeyValuesBase> TempCat = new Dictionary<long, KeyValuesBase>();
|
|
public static Dictionary<int, string> TaobaoCat = new Dictionary<int, string>();
|
|
public bool MainServer = false, AddToStock = false, JustGetCat = false;
|
|
public static bool UserApi = false;
|
|
public bool AgainCat = false;
|
|
public int TaobaoCatId = 0;
|
|
public TaobaoProductBase TaobaoProduct;
|
|
public FromTitleToCat()
|
|
{
|
|
if (MainCat.Count > 0)
|
|
return;
|
|
MainCat.Add(new KeyValuesBase("0", ",0,", "全类目"));//全类目
|
|
//MainCat.Add(new KeyValuesBase("5", ",8583,8439,8538,8634,8508,8509,8669,239,,210,263,270,277,990,1366,3817,", "服饰箱包"));//服饰箱包
|
|
//MainCat.Add(new KeyValuesBase("4", ",17412,16901,17671,16155,16676,17455,16192,16209,16989,17249,17285,17803,16794,16288,16548,15543,17134,,,483,489,282,519,479,1715,259,1166,3202,525,1889,4958,", "家居生活"));//家居生活
|
|
//MainCat.Add(new KeyValuesBase("11", ",5921,6209,5955,2629,5834,2603,5839,6128,5906,6290,2933,8502,5752,5851,7323,6076,", "数码电器"));//数码电器
|
|
//MainCat.Add(new KeyValuesBase("3", ",18482,18574,18601,18637,,,,1464,1432,69,", "美容个护"));//美容个护
|
|
//MainCat.Add(new KeyValuesBase("6", ",14697,14740,14933,14966,15083,15356,,77,", "母婴玩具"));//母婴玩具
|
|
//MainCat.Add(new KeyValuesBase("12", ",9313,9314,9315,9316,9317,9318,9319,9320,9321,9322,9323,9324,,,879,873,2479,1629,4886,1896,", "家纺家具家装"));//家纺家具
|
|
//MainCat.Add(new KeyValuesBase("10", ",11683,11684,11685,11686,11687,11688,11689,,,,4173,281,2351,", "运动户外"));//运动户外
|
|
//MainCat.Add(new KeyValuesBase("2", ",83,8172,", "水果生鲜"));//水果生鲜
|
|
//MainCat.Add(new KeyValuesBase("7", ",6586,6785,6883,6758,6536,6630,6398,,2,", "食品保健"));//食品保健
|
|
//MainCat.Add(new KeyValuesBase("9", ",80,", "虚拟商品"));//虚拟商品
|
|
//MainCat.Add(new KeyValuesBase("13", ",6785,1715,6883,13176,13177,13178,16237,", "医药健康"));//医药健康
|
|
//MainCat.Add(new KeyValuesBase("14", ",7629,7639,", "汽配摩托"));//汽配摩托
|
|
MainCat.Add(new KeyValuesBase("5", ",8583,8439,8538,8634,8508,8509,8669,239,,210,263,270,277,990,1366,3817,", "服饰箱包"));//服饰箱包
|
|
MainCat.Add(new KeyValuesBase("4", ",5217,17412,16901,17671,16155,16676,17455,16192,16209,16989,17249,17285,17803,16794,16288,16548,15543,17134,,,483,489,282,519,479,1715,259,1166,3202,525,1889,4958,", "家居生活"));//家居生活
|
|
MainCat.Add(new KeyValuesBase("11", ",5921,6209,5955,2629,5834,2603,5839,6128,5906,6290,2933,8502,5752,5851,7323,6076,", "数码电器"));//数码电器
|
|
MainCat.Add(new KeyValuesBase("3", ",18482,18574,18601,18637,,,,,1464,1432,69,", "美容个护"));//美容个护
|
|
MainCat.Add(new KeyValuesBase("6", ",14697,19298,14740,14933,14966,15083,15356,,77,", "母婴玩具"));//母婴玩具
|
|
MainCat.Add(new KeyValuesBase("12", ",9313,9314,9315,9316,9317,9318,9319,9320,9321,9322,9323,9324,,,879,873,2479,1629,4886,1896,20340,", "家纺家具家装"));//家纺家具
|
|
MainCat.Add(new KeyValuesBase("10", ",11683,11684,11685,11686,11687,11688,11689,,,,4173,281,2351,", "运动户外"));//运动户外
|
|
MainCat.Add(new KeyValuesBase("2", ",83,8172,", "水果生鲜"));//水果生鲜
|
|
MainCat.Add(new KeyValuesBase("7", ",6586,6785,6883,6758,6536,6630,6398,,2,", "食品保健"));//食品保健
|
|
MainCat.Add(new KeyValuesBase("9", ",80,20078,", "虚拟商品"));//虚拟商品
|
|
MainCat.Add(new KeyValuesBase("13", ",1715,13176,13177,13178,16237,18814,", "医药健康"));//医药健康
|
|
MainCat.Add(new KeyValuesBase("14", ",7629,7639,", "汽配摩托"));//汽配摩托
|
|
MainCat.Add(new KeyValuesBase("8", ",,", "海淘进口"));//海淘进口
|
|
}
|
|
/// <summary>
|
|
/// 是否在当前分类中
|
|
/// </summary>
|
|
/// <param name="cat1"></param>
|
|
/// <returns></returns>
|
|
public bool InMainCatId(int cat1)
|
|
{
|
|
for (int i = 0; i < MainCat.Count; i++)
|
|
{
|
|
if (MainCat[i].Key == BaseClass.MainCatId.ToString() && MainCat[i].Value1.Contains("," + cat1 + ","))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public string MainCatName = "";
|
|
public int GetMainCatId(int cat1)
|
|
{
|
|
for (int i = 0; i < MainCat.Count; i++)
|
|
{
|
|
if (MainCat[i].Value1.Contains("," + cat1 + ","))
|
|
{
|
|
MainCatName = MainCat[i].Value2;
|
|
return int.Parse(MainCat[i].Key);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
public static ShopChatBase inShop = null;
|
|
/// <summary>
|
|
/// 线程级查询分类
|
|
/// </summary>
|
|
public void Get()
|
|
{
|
|
if (TaobaoProduct == null || string.IsNullOrEmpty(TaobaoProduct.Titlte))
|
|
return;
|
|
TaobaoProductBase t = TaobaoProduct;
|
|
if (UserApi)
|
|
{
|
|
ShopChatBase shop = null;
|
|
if (BaseClass.UserVersion == 110) // 特殊版本,只使用API,默认授权成功店铺就是可用
|
|
{
|
|
inShop = GetShopLoginInfo.Shops.FirstOrDefault(s => s.Message == "授权成功");
|
|
}
|
|
if (inShop == null && BaseClass.UserVersion != 110) // 非特殊版本,逻辑
|
|
{
|
|
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
|
|
{
|
|
if (!GetShopLoginInfo.Shops[i].Select)
|
|
continue;
|
|
if (inShop == null)
|
|
{
|
|
string url = "https://mms.pinduoduo.com/hades/oauth/authed/list";
|
|
string refere = "https://mms.pinduoduo.com/service-market/my-auth";
|
|
string data = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + UploadPinduoduoMain.AntiContent + "\"}";
|
|
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, GetShopLoginInfo.Shops[i].Cookies, UploadPinduoduoMain.AntiContent); //GetPostTaobaoHtml.GetJsonPostAnti(url, refere, true, data, GetShopLoginInfo.Shops[i].Cookies, crawlerInfo);
|
|
var mc = BaseRegex.GetMatchRegex(ref html, @"\{[\w\W]+?\}");
|
|
for (int j = 0; mc != null && j < mc.Count; j++)
|
|
{
|
|
string list = mc[j].Groups[0].Value;
|
|
string cxid = BaseRegex.GetStringJson(ref list, "clientId");
|
|
long expiredAt = BaseRegex.GetLongJson(ref list, "refreshTokenExpiredAt");
|
|
DateTime t1 = DateTime.Now;
|
|
DateTime t2 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(expiredAt);
|
|
System.TimeSpan t3 = t2 - t1;
|
|
double getDay = t3.TotalDays;
|
|
if (BaseClass.ClientIdx.Contains(cxid) && getDay > 0)
|
|
{
|
|
inShop = GetShopLoginInfo.Shops[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (inShop==null)
|
|
{
|
|
string urlxs = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
|
string referes = "https://fuwu.pinduoduo.com/service-market/my-service";
|
|
string dataxs = "{\"redirectUrl\":\"https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2Fmy-service\"}";
|
|
string htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, GetShopLoginInfo.Shops[i].Cookies, dataxs, CpsSetAllGoods.getAnti0aon());
|
|
string accessToken = BaseRegex.GetStringJson(ref htmlxs, "accessToken");
|
|
urlxs = "https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2F&accessToken=" + accessToken;
|
|
htmlxs = PinduoduoAuth.GetJsonPostURL(urlxs, referes, true, "", GetShopLoginInfo.Shops[i].Cookies);
|
|
accessToken = BaseRegex.GetMatchRegexString(ref htmlxs, "SUB_PASS_ID=([^;]+?);");
|
|
string cookiesx = "SUB_PASS_ID=" + accessToken;
|
|
string codexs = CpsSetAllGoods.getAnti0aon();
|
|
urlxs = "https://fuwu.pinduoduo.com/columbine/oauth/authed/list";
|
|
referes = "https://fuwu.pinduoduo.com/service-market/my-auth";
|
|
dataxs = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + codexs + "\"}";
|
|
htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, GetShopLoginInfo.Shops[i].Cookies + cookiesx, dataxs, codexs);
|
|
var m = BaseRegex.GetMatchRegex(ref htmlxs, @"\{[\w\W]+?\}");
|
|
for (int j = 0; m != null && j < m.Count; j++)
|
|
{
|
|
string list = m[j].Groups[0].Value;
|
|
string cxid = BaseRegex.GetStringJson(ref list, "clientId");
|
|
if (cxid == "9558f920cf77403bb475243fe44482ad" || cxid == "81fd2bbabbd54ec5bf312e05401a0343"
|
|
|| cxid == "9f7d0ce6460b46e7a3833ac2e8325519" || cxid == "3069c1c325e44e85bcf5b6295694bdae"
|
|
|| cxid == "f23bda7f6d9c4b6c8751268891779660" || cxid == "5d755c0cf97a4cbdb8aa958beea25011" || cxid == "911bd1c0c0a0403da88334e24ca288a2")
|
|
continue;
|
|
long auditAt = BaseRegex.GetLongJson(ref list, "auditAt");
|
|
long refreshTokenExpiredAt = BaseRegex.GetLongJson(ref list, "refreshTokenExpiredAt");
|
|
DateTime t1 = DateTime.Now;// DateTime.Parse(DateTime.Now.ToString("1970-01-01 00:00:00")).AddMilliseconds(auditAt);
|
|
DateTime t2 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(refreshTokenExpiredAt);
|
|
System.TimeSpan t3 = t2 - t1; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
|
|
double getDay = t3.TotalDays;
|
|
if (BaseClass.ClientIdx.Contains(cxid) && getDay > 0)
|
|
{
|
|
inShop = GetShopLoginInfo.Shops[i];
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (inShop == null)
|
|
GetShopLoginInfo.Shops[i].APIMessage = "请先购买API再上传";
|
|
}
|
|
}
|
|
shop = inShop;
|
|
if (shop == null)
|
|
return;
|
|
// shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken) && sp.Select);
|
|
//if (shop == null)
|
|
// shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken));
|
|
if (shop != null)
|
|
{
|
|
var api = new PinduoduoApiGetProduct(shop);
|
|
string taobaoCatName = "0";
|
|
if (TaobaoCat.ContainsKey(TaobaoCatId))
|
|
taobaoCatName = TaobaoCat[TaobaoCatId];
|
|
if (TaobaoCatId == 0)
|
|
TaobaoCatId = 1;
|
|
string html = api.GetCatId(TaobaoCatId, taobaoCatName, t.Titlte);
|
|
if (html.Contains("\"error_msg\":授权失败,请先购买API再上传"))
|
|
{
|
|
inShop = null;
|
|
}
|
|
if (html.Contains("cat_id1"))
|
|
{
|
|
Cat1 = BaseRegex.GetIntJson(ref html, "cat_id1").ToString();
|
|
Cat2 = BaseRegex.GetIntJson(ref html, "cat_id2").ToString();
|
|
Cat3 = BaseRegex.GetIntJson(ref html, "cat_id3").ToString();
|
|
Cat4 = BaseRegex.GetIntJson(ref html, "cat_id4").ToString();
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(Cat1) || Cat1 == "0")//API未执行成功
|
|
{
|
|
bool ok = Get(t.Titlte, t.FromId, t.FromSiteId);
|
|
if (!ok)
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(Cat4))
|
|
Cat4 = "0";
|
|
t.Cat1 = int.Parse(Cat1);
|
|
t.Cat4 = int.Parse(Cat4);
|
|
t.Cat3 = int.Parse(Cat3);
|
|
t.Cat2 = int.Parse(Cat2);
|
|
int id = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
|
int cid = PinduoduoCatList.GetNewCat3(id);
|
|
if (!AgainCat&&cid != id && PinduoduoCatList.CatIds.ContainsKey(cid))
|
|
{
|
|
var ci = PinduoduoCatList.CatIds[cid];
|
|
t.CatId = ci.id;
|
|
t.Cat1 = ci.cat1;
|
|
t.Cat2 = ci.cat2;
|
|
if (ci.cat3 == 0)
|
|
{
|
|
foreach (KeyValuePair<int, CatBase> c3 in PinduoduoCatList.CatIds)
|
|
{
|
|
if (c3.Value.cat2 == ci.cat2 && c3.Value.cat3 > 0)
|
|
{
|
|
ci.cat3 = c3.Value.cat3;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
t.Cat3 = ci.cat3;
|
|
if (ci.cat4 == 0 && ci.cat3 > 0)
|
|
{
|
|
foreach (KeyValuePair<int, CatBase> c4 in PinduoduoCatList.CatIds)
|
|
{
|
|
if (c4.Value.cat3 == ci.cat3 && c4.Value.cat4 > 0)
|
|
{
|
|
ci.cat4 = c4.Value.cat4;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
t.Cat4 = ci.cat4;
|
|
t.MainCatId = ci.main_cat_id;
|
|
}
|
|
t.MainCatId = GetMainCatId(t.Cat1);
|
|
t.MainCatName = MainCatName;
|
|
t.CatId = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
|
if (t.MainCatId == 0 || JustGetCat || CollectKeywordByTaobao.MainCatId > 0 && CollectKeywordByTaobao.MainCatId != t.MainCatId)
|
|
{
|
|
return;
|
|
}
|
|
if (AddToStock)
|
|
{
|
|
if (!string.IsNullOrEmpty(t.ShopName))
|
|
{
|
|
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == t.ShopName);
|
|
if (shop == null || t.MainCatId != shop.MainCatId)
|
|
t.ShopName = "";
|
|
else
|
|
{
|
|
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == t.ShopName);
|
|
if (s != null)
|
|
{
|
|
s.ProductCount++;
|
|
UploadPinduoduoMain.ShopReplaceTemp.Add(s);
|
|
UploadPinduoduoMain.ShopTemp.Add(s);
|
|
}
|
|
}
|
|
}
|
|
UploadPinduoduoMain.ProductStock.Add(t);
|
|
UploadPinduoduoMain.AddToDataBase(t);
|
|
return;
|
|
}
|
|
if (CollectKeywordByTaobao.AutoAdd)
|
|
{
|
|
UploadPinduoduoMain.ProductStock.Add(t);
|
|
UploadPinduoduoMain.AddToDataBase(t);
|
|
}
|
|
CollectKeywordByTaobao.Product.Add(t);
|
|
CollectKeywordByTaobao.ProductTemp.Add(t);
|
|
}
|
|
public bool Get(string title, long fromId)
|
|
{
|
|
if (string.IsNullOrEmpty(title))
|
|
return false;
|
|
if (TempCat.ContainsKey(fromId) && fromId > 0)
|
|
{
|
|
Cat1 = TempCat[fromId].Value1;
|
|
Cat2 = TempCat[fromId].Value2;
|
|
Cat3 = TempCat[fromId].Value3;
|
|
Cat4 = TempCat[fromId].Value4;
|
|
MainCatId = TempCat[fromId].Key;
|
|
return true;
|
|
}
|
|
Title = title;
|
|
Title = BaseRegex.Clear(Title, @"([\d\s]+)");
|
|
GetLen(4);
|
|
bool ok = OutPut(fromId);
|
|
if (ok)
|
|
return true;
|
|
GetLen(6);
|
|
ok = OutPut(fromId);
|
|
if (ok)
|
|
return true;
|
|
GetLen(8);
|
|
ok = OutPut(fromId);
|
|
if (ok)
|
|
return true;
|
|
if (Cats.Count > 0)
|
|
{
|
|
var c = CatTop[0];
|
|
Cat1 = c.Value1;
|
|
Cat2 = c.Value2;
|
|
for (int i = 0; i < Cats.Count; i++)
|
|
{
|
|
if (Cats[i].Value2 == Cat2)
|
|
{
|
|
Cat3 = Cats[i].Value3;
|
|
break;
|
|
}
|
|
}
|
|
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
|
{
|
|
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
|
{
|
|
MainCatId = MainCat[i].Key;
|
|
if (!TempCat.ContainsKey(fromId))
|
|
{
|
|
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3);
|
|
try
|
|
{
|
|
TempCat.Add(fromId, k);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
public void GetLoad()
|
|
{
|
|
if (TaobaoProduct == null || string.IsNullOrEmpty(TaobaoProduct.Titlte))
|
|
return;
|
|
TaobaoProductBase t = TaobaoProduct;
|
|
if (UserApi)
|
|
{
|
|
var shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken) && sp.Select);
|
|
if (shop == null)
|
|
shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken));
|
|
if (shop != null)
|
|
{
|
|
var api = new PinduoduoApiGetProduct(shop);
|
|
string taobaoCatName = "0";
|
|
if (TaobaoCat.ContainsKey(TaobaoCatId))
|
|
taobaoCatName = TaobaoCat[TaobaoCatId];
|
|
if (TaobaoCatId == 0)
|
|
TaobaoCatId = 1;
|
|
string html = api.GetCatId(TaobaoCatId, taobaoCatName, t.Titlte);
|
|
if (html.Contains("cat_id1"))
|
|
{
|
|
Cat1 = BaseRegex.GetIntJson(ref html, "cat_id1").ToString();
|
|
Cat2 = BaseRegex.GetIntJson(ref html, "cat_id2").ToString();
|
|
Cat3 = BaseRegex.GetIntJson(ref html, "cat_id3").ToString();
|
|
Cat4 = BaseRegex.GetIntJson(ref html, "cat_id4").ToString();
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(Cat1) || Cat1 == "0")//API未执行成功
|
|
{
|
|
bool ok = Get(t.Titlte, t.FromId, t.FromSiteId);
|
|
if (!ok)
|
|
return;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(Cat4))
|
|
Cat4 = "0";
|
|
t.Cat1 = int.Parse(Cat1);
|
|
t.Cat4 = int.Parse(Cat4);
|
|
t.Cat3 = int.Parse(Cat3);
|
|
t.Cat2 = int.Parse(Cat2);
|
|
int id = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
|
int cid = PinduoduoCatList.GetNewCat3(id);
|
|
if (cid != id && PinduoduoCatList.CatIds.ContainsKey(cid))
|
|
{
|
|
var ci = PinduoduoCatList.CatIds[cid];
|
|
t.CatId = ci.id;
|
|
t.Cat1 = ci.cat1;
|
|
t.Cat2 = ci.cat2;
|
|
if (ci.cat3 == 0)
|
|
{
|
|
foreach (KeyValuePair<int, CatBase> c3 in PinduoduoCatList.CatIds)
|
|
{
|
|
if (c3.Value.cat2 == ci.cat2 && c3.Value.cat3 > 0)
|
|
{
|
|
ci.cat3 = c3.Value.cat3;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
t.Cat3 = ci.cat3;
|
|
if (ci.cat4 == 0 && ci.cat3 > 0)
|
|
{
|
|
foreach (KeyValuePair<int, CatBase> c4 in PinduoduoCatList.CatIds)
|
|
{
|
|
if (c4.Value.cat3 == ci.cat3 && c4.Value.cat4 > 0)
|
|
{
|
|
ci.cat4 = c4.Value.cat4;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
t.Cat4 = ci.cat4;
|
|
t.MainCatId = ci.main_cat_id;
|
|
}
|
|
t.MainCatId = GetMainCatId(t.Cat1);
|
|
t.MainCatName = MainCatName;
|
|
t.CatId = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
|
if (t.MainCatId == 0 || JustGetCat || CollectKeywordByTaobao.MainCatId > 0 && CollectKeywordByTaobao.MainCatId != t.MainCatId)
|
|
{
|
|
return;
|
|
}
|
|
if (AddToStock)
|
|
{
|
|
if (!string.IsNullOrEmpty(t.ShopName))
|
|
{
|
|
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == t.ShopName);
|
|
if (shop == null || t.MainCatId != shop.MainCatId)
|
|
t.ShopName = "";
|
|
else
|
|
{
|
|
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == t.ShopName);
|
|
if (s != null)
|
|
{
|
|
s.ProductCount++;
|
|
UploadPinduoduoMain.ShopReplaceTemp.Add(s);
|
|
UploadPinduoduoMain.ShopTemp.Add(s);
|
|
}
|
|
}
|
|
}
|
|
try
|
|
{
|
|
var ps = UploadPinduoduoMain.ProductStock.Find(p => p.FromId == t.FromId && p.Titlte == t.Titlte);
|
|
ps = t;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
return;
|
|
}
|
|
if (CollectKeywordByTaobao.AutoAdd)
|
|
{
|
|
try
|
|
{
|
|
var ps = UploadPinduoduoMain.ProductStock.Find(p => p.FromId == t.FromId && p.Titlte == t.Titlte);
|
|
ps = t;
|
|
}
|
|
catch
|
|
{
|
|
|
|
}
|
|
}
|
|
CollectKeywordByTaobao.Product.Add(t);
|
|
CollectKeywordByTaobao.ProductTemp.Add(t);
|
|
}
|
|
|
|
public KeyValuesBase GetServerTempCat(long fromId, int siteId)
|
|
{
|
|
string url = BaseClass.LoginApiUrl + "?obj=product/product&act=get_cat";
|
|
string data = UserLogin.GetSignaturex() + "&site_id=" + siteId + "&id=" + fromId;
|
|
string html = GetHtml.PostUtf8(url, data);
|
|
if (!string.IsNullOrEmpty(html) && html.Contains("cat_id"))
|
|
{
|
|
Cat1 = BaseRegex.GetStringJson(ref html, "cat1");
|
|
Cat2 = BaseRegex.GetStringJson(ref html, "cat2");
|
|
Cat3 = BaseRegex.GetStringJson(ref html, "cat3");
|
|
Cat4 = BaseRegex.GetStringJson(ref html, "cat4");
|
|
if (Cat3 != "0" || Cat4 != "0")
|
|
{
|
|
MainCatId = BaseRegex.GetStringJson(ref html, "main_cid");
|
|
GetMainCatId(int.Parse(Cat1));
|
|
if (!TempCat.ContainsKey(fromId))
|
|
{
|
|
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3, Cat4);
|
|
try
|
|
{
|
|
TempCat.Add(fromId, k);
|
|
return k;
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return TempCat[fromId];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public bool Get(string title, long fromId, int siteId)
|
|
{
|
|
if (string.IsNullOrEmpty(title))
|
|
return false;
|
|
if (TempCat.ContainsKey(fromId) && fromId > 0)
|
|
{
|
|
Cat1 = TempCat[fromId].Value1;
|
|
Cat2 = TempCat[fromId].Value2;
|
|
Cat3 = TempCat[fromId].Value3;
|
|
Cat4 = TempCat[fromId].Value4;
|
|
MainCatId = TempCat[fromId].Key;
|
|
return true;
|
|
}
|
|
var shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed);
|
|
if (shop != null)
|
|
{
|
|
var api = new PinduoduoApiGetProduct(shop);
|
|
string taobaoCatName = "0";
|
|
if (TaobaoCat.ContainsKey(TaobaoCatId))
|
|
taobaoCatName = TaobaoCat[TaobaoCatId];
|
|
if (TaobaoCatId == 0)
|
|
TaobaoCatId = 1;
|
|
string htmlx = api.GetCatId(TaobaoCatId, taobaoCatName, title);
|
|
if (htmlx.Contains("cat_id1"))
|
|
{
|
|
Cat1 = BaseRegex.GetIntJson(ref htmlx, "cat_id1").ToString();
|
|
Cat2 = BaseRegex.GetIntJson(ref htmlx, "cat_id2").ToString();
|
|
Cat3 = BaseRegex.GetIntJson(ref htmlx, "cat_id3").ToString();
|
|
Cat4 = BaseRegex.GetIntJson(ref htmlx, "cat_id4").ToString();
|
|
}
|
|
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
|
{
|
|
if (string.IsNullOrEmpty(Cat1)) break;//主类目为空
|
|
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
|
{
|
|
MainCatId = MainCat[i].Key;
|
|
if (!TempCat.ContainsKey(fromId))
|
|
{
|
|
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3);
|
|
try
|
|
{
|
|
TempCat.Add(fromId, k);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
if ((Cat3 != "0" || Cat4 != "0") && Cat1 != "")
|
|
return true;
|
|
}
|
|
string url = BaseClass.LoginApiUrl + "?obj=product/product&act=get_cat";
|
|
string data = UserLogin.GetSignaturex() + "&site_id=" + siteId + "&id=" + fromId;
|
|
string html = GetHtml.PostUtf8(url, data);
|
|
if (!string.IsNullOrEmpty(html) && html.Contains("cat_id"))
|
|
{
|
|
Cat1 = BaseRegex.GetStringJson(ref html, "cat1");
|
|
Cat2 = BaseRegex.GetStringJson(ref html, "cat2");
|
|
Cat3 = BaseRegex.GetStringJson(ref html, "cat3");
|
|
Cat4 = BaseRegex.GetStringJson(ref html, "cat4");
|
|
if (Cat3 != "0" || Cat4 != "0")
|
|
{
|
|
MainCatId = BaseRegex.GetStringJson(ref html, "main_cid");
|
|
if (!TempCat.ContainsKey(fromId))
|
|
{
|
|
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3, Cat4);
|
|
try
|
|
{
|
|
TempCat.Add(fromId, k);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
Title = title;
|
|
Title = BaseRegex.Clear(Title, @"([\d\s]+)");
|
|
GetLen(4);
|
|
bool ok = OutPut(fromId);
|
|
if (ok)
|
|
return true;
|
|
GetLen(6);
|
|
ok = OutPut(fromId);
|
|
if (ok)
|
|
return true;
|
|
GetLen(8);
|
|
ok = OutPut(fromId);
|
|
if (ok)
|
|
return true;
|
|
if (Cats.Count > 0)
|
|
{
|
|
var c = CatTop[0];
|
|
Cat1 = c.Value1;
|
|
Cat2 = c.Value2;
|
|
for (int i = 0; i < Cats.Count; i++)
|
|
{
|
|
if (Cats[i].Value2 == Cat2)
|
|
{
|
|
Cat3 = Cats[i].Value3;
|
|
break;
|
|
}
|
|
}
|
|
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
|
{
|
|
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
|
{
|
|
MainCatId = MainCat[i].Key;
|
|
if (!TempCat.ContainsKey(fromId))
|
|
{
|
|
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3);
|
|
try
|
|
{
|
|
TempCat.Add(fromId, k);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
/// <summary>
|
|
/// 使用2级分类
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public bool OutPut(long fromId)
|
|
{
|
|
if (CatTop.Count > 3 && CatTop[0].Rank > 1 || CatTop.Count > 0 && CatTop[0].Rank > 5)
|
|
{
|
|
var c = CatTop[0];
|
|
Cat1 = c.Value1;
|
|
Cat2 = c.Value2;
|
|
|
|
for (int i = 0; i < Cats.Count; i++)
|
|
{
|
|
if (Cats[i].Value2 == Cat2)
|
|
{
|
|
Cat3 = Cats[i].Value3;
|
|
Cat4 = Cats[i].Value4;
|
|
break;
|
|
}
|
|
}
|
|
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
|
{
|
|
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
|
{
|
|
MainCatId = MainCat[i].Key;
|
|
if (!TempCat.ContainsKey(fromId))
|
|
{
|
|
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3, Cat4);
|
|
try
|
|
{
|
|
TempCat.Add(fromId, k);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public void GetLen(int len)
|
|
{
|
|
int count = Title.Length / len;
|
|
if (count < 3)
|
|
return;
|
|
for (int i = 0; i < Cats.Count; i++)
|
|
{
|
|
var c = Cats[i];
|
|
c.Rank++;
|
|
}
|
|
for (int i = 0; i < len; i++)
|
|
{
|
|
string word = Title.Substring(i * count, count);
|
|
string url = "http://pcat.qixiaoke.com/taobao/pinduoduo_main.php?keyword=" + GetHtml.UrlEncodeUtf8(word);
|
|
string html = GetHtml.Utf8(url);
|
|
if (string.IsNullOrEmpty(html) || !html.Contains("\n"))
|
|
continue;
|
|
string[] l = html.Split('\n');
|
|
for (int j = 0; j < l.Length; j++)
|
|
{
|
|
bool had = false;
|
|
string[] ll = l[j].Split(',');
|
|
if (ll.Length < 3)
|
|
continue;
|
|
KeyValuesBase k;
|
|
KeyValuesBase kt;
|
|
if (ll.Length == 3)
|
|
{
|
|
k = new KeyValuesBase(ll[2], ll[0], ll[1], ll[2], "0");
|
|
kt = new KeyValuesBase(ll[1], ll[0], ll[1], ll[2], "0");
|
|
}
|
|
else
|
|
{
|
|
k = new KeyValuesBase(ll[2], ll[0], ll[1], ll[2], ll[3]);
|
|
kt = new KeyValuesBase(ll[1], ll[0], ll[1], ll[2], ll[3]);
|
|
}
|
|
|
|
if (k.Value2 == "242" || k.Value2 == "243" || k.Value3 == "3850")
|
|
continue;
|
|
kt.Rank = 1;
|
|
k.Rank = 1;
|
|
for (int m = 0; m < Cats.Count; m++)
|
|
{
|
|
if (Cats[m].Key == ll[2])
|
|
{
|
|
k = Cats[m];
|
|
had = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!had)
|
|
Cats.Add(k);
|
|
else
|
|
k.Rank++;
|
|
had = false;
|
|
for (int m = 0; m < CatTop.Count; m++)
|
|
{
|
|
if (CatTop[m].Key == ll[1])
|
|
{
|
|
k = CatTop[m];
|
|
had = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!had)
|
|
CatTop.Add(k);
|
|
else
|
|
k.Rank++;
|
|
}
|
|
}
|
|
Cats.Sort(delegate (KeyValuesBase x, KeyValuesBase y)
|
|
{
|
|
return y.Rank.CompareTo(x.Rank);
|
|
});
|
|
CatTop.Sort(delegate (KeyValuesBase x, KeyValuesBase y)
|
|
{
|
|
return y.Rank.CompareTo(x.Rank);
|
|
});
|
|
}
|
|
|
|
public static void Ini()
|
|
{
|
|
//string[] l = FileBase.ReadAllLines("taobao_cat.ico");
|
|
//for (int i = 0; l != null && i < l.Length; i++)
|
|
//{
|
|
// if (!l[i].Contains("\t"))
|
|
// continue;
|
|
// string[] s = l[i].Split('\t');
|
|
// TaobaoCat.Add(int.Parse(s[0]), s[1]);
|
|
//}
|
|
}
|
|
}
|
|
}
|