Files
KJD/Work/CollectClass/PinduoduoProductCollect.cs
T

2916 lines
150 KiB
C#

using AllBase;
using AllBase.Helper;
using NaiBa.Util.Extension;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using Work.Api;
using Work.ManageClass;
namespace Work.CollectClass
{
public class PinduoduoProductCollect
{
public TaobaoProductBase Product;
public bool IsOverdue = false;
public static List<long> TempIds = new List<long>();
public static List<long> DeleteIds = new List<long>();
public ProductCollectBase pb = new ProductCollectBase();
public static List<KeyValueBase> Mobiles = new List<KeyValueBase>();
public string Name, TempHtml = "";
public bool NoAdd = false, Cloud = false, OnSale = true;
public int MainCatId = 0;
public string message = "";
public static Dictionary<string, string> dic = new Dictionary<string, string>();
public static List<PinDuoDuoTokenInfo> PinDuoDuoTokenList = new List<PinDuoDuoTokenInfo>();
public static bool isProxyAvailable = true;
public bool IsUseProxy = true;
public static string proxymessage = "";
public bool isUseCache = true;
private static int count = 0;
private static bool isCheckProxy = false;
public bool isSearchUp = false;
public bool IsNoToken = false;
public bool IsAdvance = false;
private static Dictionary<string, bool> DicApiUid = new Dictionary<string, bool>();
public PinduoduoProductCollect(string name, TaobaoProductBase product)
{
Name = name;
Product = product;
}
public PinduoduoProductCollect(string name, TaobaoProductBase product, bool isUseProxy)
{
Name = name;
Product = product;
IsUseProxy = isUseProxy;
}
public void Get()
{
try
{
Getx();
}
catch (Exception ex)
{
}
}
public void Getx()
{
message = "";
if (DeleteIds.Contains(Product.FromId) && !isSearchUp)
{
LogSave.Add(Name, "商品已经下架:" + Product.FromId);
message = "商品已经下架:" + Product.FromId;
OnSale = false;
Thread.Sleep(500);
return;
}
string cookies = "", mobile = "";
if (SetCookiesUserInfo.UserCookies.Count > 0)
{
var list = SetCookiesUserInfo.UserCookies.ToList();
var cook = list[Randomx.GetId(list.Count)];
mobile = cook.Key;
foreach (var cookie in cook.Value.Cookies)
cookies += cookie.Name + "=" + cookie.Value + "; ";
}
if (TaobaoMobileCollect.ProductTemp.ContainsKey(Product.FromId))
{
pb = TaobaoMobileCollect.ProductTemp[Product.FromId].Clone();
return;
}
//if (TempIds.Contains(Product.FromId) && string.IsNullOrEmpty(TempHtml) && MainCatId == 0)
// Thread.Sleep(5 * 1000);
if (!TempIds.Contains(Product.FromId))
TempIds.Add(Product.FromId);
if (TaobaoMobileCollect.ProductTemp.ContainsKey(Product.FromId))
{
pb = TaobaoMobileCollect.ProductTemp[Product.FromId].Clone();
return;
}
bool canUse = false;
bool userData = false;
string serverTempHtml = "";
if (UploadPinduoduoMain.isUsePddCache)
{
serverTempHtml = ServerTemp.Get(2, Product.FromId.ToString(), out canUse);
if (canUse)
{
userData = true;
TempHtml = serverTempHtml;
}
}
string url = BaseClass.NewUrl + "/goods.html?goods_id=" + Product.FromId;
string refere = BaseClass.NewUrl + "/";
string html = "";
string api_uid = string.Empty;
if (string.IsNullOrEmpty(TempHtml) || (!TempHtml.Contains("catID1") && !TempHtml.Contains("catId1") && !TempHtml.Contains("cat_id_1")))
{
Thread.Sleep(2000);
if (UploadPinduoduoMain.Running || UploadPinduoduoMain.RunningReplace)
{
int it = UploadPinduoduoMain.ShopThreadCount * UploadPinduoduoMain.SingleThreadCount;
Thread.Sleep(it * 200);
}
if ((string.IsNullOrEmpty(html) || (!html.Contains("catID1") && !html.Contains("catId1") && !TempHtml.Contains("cat_id_1"))))
{
if (!string.IsNullOrEmpty(GetProxyHtml.orderId))
html = GetProxyHtml.RequestUrl_yangkeduo_com(Product.FromId, GetProxyHtml.UserAgentList.ToArray(), out IsOverdue);
if (IsOverdue || string.IsNullOrEmpty(GetProxyHtml.orderId))
{
string purl = BaseClass.LoginApiUrl + "index.php?obj=api/shared_pool&act=get_agent_ip";
string phtml = GetHtml.PostUtf8(purl, UserLogin.GetSignaturex());
string sAgentIpKey = BaseRegex.GetStringJson(ref phtml, "the_key");
GetProxyHtml.orderId = GetProxyHtml.DESDecode(sAgentIpKey, GlobalConfig.cAgentIpCode);
html = GetProxyHtml.RequestUrl_yangkeduo_com(Product.FromId, GetProxyHtml.UserAgentList.ToArray(), out IsOverdue);
}
if (!string.IsNullOrEmpty(html) && (html.Contains("catID1") || html.Contains("catId1") || html.Contains("cat_id_1")))
{
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = Product.FromId.ToString(), SaveHtml = html });
}
}
if ((string.IsNullOrEmpty(html) || (!html.Contains("catID1") && !html.Contains("catId1") && !TempHtml.Contains("cat_id_1"))) && IsUseProxy && GetProxyHtml.txtUrl.Contains("66"))
{
IsOverdue = false;
html = GetProxyHtml.RequestUrl_yangkeduo_com(Product.FromId, GetProxyHtml.UserAgentList.ToArray(), out IsOverdue);
if (IsOverdue)
{
LogSave.Add(Name, "代理IP过期,请重新填写");
message = "代理IP过期,请重新填写";
return;
}
if (!string.IsNullOrEmpty(html) && (html.Contains("catID1") || html.Contains("catId1") || html.Contains("cat_id_1")))
{
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = Product.FromId.ToString(), SaveHtml = html });
}
}
int retryTimes = 0;
while ((string.IsNullOrEmpty(html) || (!html.Contains("catID1") && !html.Contains("catId1") && !html.Contains("cat_id_1"))) && !DeleteAndDown(html) && PinDuoDuoTokenList != null && PinDuoDuoTokenList.Count > 0)
{
retryTimes++;
var lst = PinDuoDuoTokenList.Where(t => t.ProductDetailStatus == 1).ToList();
if (lst.Count == 0 || retryTimes > 10)
{
IsNoToken = false;
LogSave.Add(Name, "可用token不足,请输入token或勾选并设置代理IP" + Product.FromId);
message = "可用token不足,请输入token或勾选并设置代理IP:" + Product.FromId;
return;
}
var token = lst[Randomx.GetId(lst.Count)];
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, "PDDAccessToken=" + token.PDDAccessToken);
if ((string.IsNullOrEmpty(html) || !html.Contains("catID1") && !html.Contains("catId1") && !html.Contains("cat_id_1")) && !DeleteAndDown(html))
token.ProductDetailStatus = 0;
}
TempHtml = html;
}
else
{
html = TempHtml;
}
if (string.IsNullOrEmpty(html))
{
LogSave.Add(Name, "获取商品" + Product.FromId + "信息为空,请检测商品是否存在");
message = "获取商品信息为空,请检测商品是否存在";
}
if (html.Contains("商品已售罄,推荐以下相似商品") && !html.Contains("原商品已售罄,为你推荐相似商品"))
{
LogSave.Add(Name, "商品" + Product.FromId + "商品已售罄");
OnSale = false;
message = "商品已售罄";
return;
}
//if (html.Contains("原商品已售罄,为你推荐相似商品"))
//{
// LogSave.Add(Name, "商品" + Product.FromId + "商品已售罄");
// OnSale = false;
// message = "商品已售罄";
// return;
//}
if (html.Contains("商品不存在"))
{
LogSave.Add(Name, "商品" + Product.FromId + "不存在");
OnSale = false;
message = "商品不存在";
return;
}
//如果缓存的是大麦助手数据则先进行扣取
if (html.Contains("\"cache_time\""))
{
html = BaseRegex.GetMatchRegexString(ref html, "\"data\":([\\w\\W]+?),\"msg\":\"成功\"\\}");
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = Product.FromId.ToString(), SaveHtml = html });
}
if (!string.IsNullOrEmpty(html) && canUse)
{
int index = html.IndexOf(",") + 1;
html = html.Substring(index);
}
#region 最新数据解析
html = html.Replace(" ", "");
if (html.Contains("catId1"))
{
if (!html.Contains(@"""isOnsale"":1") || DeleteAndDown(html))
{
if (!userData)
{
ServerTemp.Set(2, Product.FromId.ToString(), html);
BigDataBuild.Delete(Product.FromId, 2);
}
//LogSave.Add(Name, "商品获取成功:" + Product.FromId + "商品已下架");
message = "商品获取成功:" + Product.FromId + "商品已下架";
OnSale = false;
if (!DeleteIds.Contains(Product.FromId))
DeleteIds.Add(Product.FromId);
return;
}
html = GetHtml.Decode(html);
pb.from = "拼多多";
pb.id = Product.FromId;
pb.from_id = Product.FromId;
LogSave.Add(Name, "获取成功:" + Product.FromId);
pb.name = BaseRegex.GetStringJson(ref html, "goodsName");
pb.name_share = BaseRegex.GetStringJson(ref html, "share_desc");
pb.from_shop_name = BaseRegex.GetStringJson(ref html, "mallName");
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goodsDesc");
string temp = BaseRegex.GetMatchRegexString(ref html, @"""gallery"":\[(.*?)\]");
var m = BaseRegex.GetMatchRegex(ref temp, @"""url"":""([^""]+?)"",""width"":([\d]+),""height"":([\d]+),""priority"":([\d]+),""type"":([\d]+)");
string content = "";
Dictionary<int, string> mainImage = new Dictionary<int, string>();
Dictionary<int, string> contentImage = new Dictionary<int, string>();
for (int i = 0; i < m.Count; i++)
{
string item = m[i].Groups[0].Value;
int type = int.Parse(m[i].Groups[5].Value);
if (type == 6)
continue;
if (type == 1)
{
string img = m[i].Groups[1].Value;
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
//pb.Images.Add(img);
int index = BaseRegex.GetIntJson(ref item, "priority");
mainImage.Add(index, img);
}
else
{
string img = m[i].Groups[1].Value;
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
int width = int.Parse(m[i].Groups[2].Value);
int height = int.Parse(m[i].Groups[3].Value);
//content += "<img src='" + img + "'>";
int index = BaseRegex.GetIntJson(ref item, "priority");
contentImage.Add(index, img);
}
}
var mainlst = mainImage.OrderBy(p => p.Key).ToList();
for (int i = 0; i < mainlst.Count; i++)
{
pb.Images.Add(mainlst[i].Value);
}
var contentlst = contentImage.OrderBy(p => p.Key).ToList();
for (int i = 0; i < contentlst.Count; i++)
{
content += "<img src='" + contentlst[i].Value + "'>";
}
m = BaseRegex.GetMatchRegex(ref html, @"\{""skuId"".*?\}\].*?\}");
for (int i = 0; i < m.Count; i++)
{
string list = m[i].Groups[0].Value;
SkuMapBase s = new SkuMapBase();
s.id = BaseRegex.GetLongJson(ref list, "skuId");
s.price = BaseRegex.GetDecimalJson(ref list, "groupPrice") / 100;
if (s.price < 1)
continue;
int num = BaseRegex.GetIntJson(ref list, "quantity");
s.number = BaseRegex.GetIntJson(ref list, "isOnsale") == 1 ? 99 : 0;
if (num < 3)
num = 0;
if (s.number > num)
s.number = num;
s.sale_count = BaseRegex.GetIntJson(ref list, "soldQuantity");
pb.saleCount += s.sale_count;
s.prop_image = BaseRegex.GetStringJson(ref list, "thumbUrl");
if (!string.IsNullOrEmpty(s.prop_image))
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
if (s.prop_image.Contains("?"))
s.prop_image = s.prop_image.Substring(0, s.prop_image.IndexOf("?"));
UpPinduoduoProductSet.AddImage(s.prop_image, s.prop_image, 0, 0);
s.name = GetNameNew(list, ref pb, s.prop_image);
pb.SkuMaps.Add(s);
}
decimal maxPriceNew = 0;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (maxPriceNew < pb.SkuMaps[i].price)
maxPriceNew = pb.SkuMaps[i].price;
}
string firstSkuImage = pb.SkuMaps[0].prop_image;
if (pb.Props.Count == 1)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
bool ishad = false;
for (int k = 0; k < pb.SkuMaps.Count; k++)
{
if (pb.SkuMaps[k].name.Contains(pb.Props[0].Values[j].name))
{
ishad = true;
break;
}
}
if (!ishad)
{
SkuMapBase sm = new SkuMapBase();
sm.id = BaseClass.GetTime(DateTime.Today);
sm.price = maxPriceNew;
sm.number = 0;
sm.sale_count = 0;
pb.saleCount += sm.sale_count;
sm.prop_image = firstSkuImage;
sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";";
pb.SkuMaps.Add(sm);
}
}
}
if (pb.Props.Count == 2)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
for (int k = 0; k < pb.Props[1].Values.Count; k++)
{
bool ishad = false;
for (int l = 0; l < pb.SkuMaps.Count; l++)
{
string[] li = pb.SkuMaps[l].name.Split(';');
if (li.Length == 2)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1)
{
ishad = true;
break;
}
}
if (li.Length == 3)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
}
if (li.Length == 4)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
string n4 = li[3].Substring(li[3].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
if (pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n3
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
}
}
if (!ishad)
{
SkuMapBase sm = new SkuMapBase();
sm.id = BaseClass.GetTime(DateTime.Today);
sm.price = maxPriceNew;
sm.number = 0;
sm.sale_count = 0;
pb.saleCount += sm.sale_count;
sm.prop_image = firstSkuImage;
sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";" + pb.Props[1].name + ":" + pb.Props[1].Values[k].name + ";";
pb.SkuMaps.Add(sm);
}
}
}
}
pb.cat1 = BaseRegex.GetIntJson(ref html, "catId1");
pb.cat2 = BaseRegex.GetIntJson(ref html, "catId2");
pb.cat3 = BaseRegex.GetIntJson(ref html, "catId3");
pb.cat4 = BaseRegex.GetIntJson(ref html, "catId4");
pb.cat_id = BaseRegex.GetIntJson(ref html, "catId");
if (pb.cat_id != pb.cat3)
pb.cat4 = pb.cat_id;
int cid = PinduoduoCatList.GetNewCat3(pb.cat_id);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
pb.cat_id = ci.id;
pb.cat1 = ci.cat1;
pb.cat2 = ci.cat2;
pb.cat3 = ci.cat3;
pb.cat4 = ci.cat4;
pb.main_cid = ci.main_cat_id;
}
pb.before_price = BaseRegex.GetIntJson(ref html, "linePrice") / 100m;
pb.content = content;
var ft = new FromTitleToCat();
pb.main_cid = ft.GetMainCatId(pb.cat1);
pb.main_cat_name = ft.MainCatName;
Product.Cat1 = pb.cat1;
Product.Cat2 = pb.cat2;
Product.Cat3 = pb.cat3;
Product.Cat4 = pb.cat4;
Product.CatId = pb.cat_id;
Product.MainCatId = pb.main_cid;
Product.MainCatName = pb.main_cat_name;
string sepc = BaseRegex.GetMatchRegexString(ref html, @"(""property"":\[\{([\w\W]+?)\}\])");
m = BaseRegex.GetMatchRegex(ref sepc, @"\{""key"":""([^""]+?)"",""values"":\[([\w\W]+?)\][\w\W]+?\}");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[1].Value;
string val = m[i].Groups[2].Value;
var list = BaseRegex.GetMatchRegex(ref val, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(name, v));
}
pb.mall_id = BaseRegex.GetLongJson(ref html, "mallId");
pb.from_site_id = 2;
pb.price = Product.Price;
if (pb.price == 0 && pb.SkuMaps.Count > 0)
pb.price = pb.SkuMaps[0].price;
string sale = BaseRegex.GetStringJson(ref html, "soldQuantity");
if (string.IsNullOrEmpty(sale))
{
sale = BaseRegex.GetStringJson(ref html, "salesTip");
sale = BaseRegex.GetMatchRegexString(ref sale, @"([\d\.万]+)");
}
if (!string.IsNullOrEmpty(sale))
{
sale = sale.Replace(".", "").Replace("万", "000");
int sa = 0;
int.TryParse(sale, out sa);
pb.saleCount = sa;
}
Product.SaleCount = pb.saleCount;
if (!userData)
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = Product.FromId.ToString(), SaveHtml = html });
//ServerTemp.Set(2, Product.FromId.ToString(), html);
}
#endregion
#region 拼多多平台数据解析
if (html.Contains("catID1"))
{
if (!(html.Contains(@"""isOnSale"":true") || html.Contains(@"""isOnsale"":1")) || DeleteAndDown(html))
{
if (!userData)
{
ServerTemp.Set(2, Product.FromId.ToString(), html);
BigDataBuild.Delete(Product.FromId, 2);
}
//LogSave.Add(Name, "商品获取成功:" + Product.FromId + "商品已下架");
message = "商品获取成功:" + Product.FromId + "商品已下架";
OnSale = false;
if (!DeleteIds.Contains(Product.FromId))
DeleteIds.Add(Product.FromId);
return;
}
html = GetHtml.Decode(html);
pb.from = "拼多多";
pb.id = Product.FromId;
pb.from_id = Product.FromId;
LogSave.Add(Name, "获取成功:" + Product.FromId);
pb.name = BaseRegex.GetStringJson(ref html, "goodsName");
pb.name_share = BaseRegex.GetStringJson(ref html, "shareDesc");
pb.from_shop_name = BaseRegex.GetStringJson(ref html, "mallName");
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goodsDesc");
string temp = BaseRegex.GetMatchRegexString(ref html, @"""topGallery"":\[(.*?)\]");
var m = BaseRegex.GetMatchRegex(ref temp, @"{([^}]+?)}");
if (m == null || m.Count == 0)
m = BaseRegex.GetMatchRegex(ref temp, @"""([^""]+?)""");
for (int i = 0; i < m.Count; i++)
{
string img = m[i].Groups[1].Value.Replace("@750w_1l_50Q", "");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
if (img.Contains("url"))
{
if (img.Contains("\":\"") && img.EndsWith("jpeg"))
img += "\"";
img = BaseRegex.GetStringJson(ref img, "url");
}
if (!(img.Contains("jpeg") || img.Contains("jpg") || img.Contains("png")))
continue;
pb.Images.Add(img);
}
//pb.videoUrl = BaseRegex.GetStringJson(ref html, "videoUrl");
temp = BaseRegex.GetMatchRegexString(ref html, @"""detailGallery"":\[(.*?)\]");
m = BaseRegex.GetMatchRegex(ref temp, @"""url"":""([^""]+?)"",""width"":([\d]+),""height"":([\d]+)");
string content = "";
for (int i = 0; i < m.Count; i++)
{
string img = m[i].Groups[1].Value.Replace("@750w_1l_50Q", "");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
int width = int.Parse(m[i].Groups[2].Value);
int height = int.Parse(m[i].Groups[2].Value);
content += "<img src='" + img + "'>";
}
m = BaseRegex.GetMatchRegex(ref html, @"\{""skuID"".*?\}\].*?\}");
for (int i = 0; i < m.Count; i++)
{
string list = m[i].Groups[0].Value;
SkuMapBase s = new SkuMapBase();
s.id = BaseRegex.GetLongJson(ref list, "skuID");
s.price = BaseRegex.GetDecimalJson(ref list, "groupPrice");
//if (s.price < 1)
// continue;
int num = BaseRegex.GetIntJson(ref list, "quantity");
s.number = BaseRegex.GetIntJson(ref list, "isOnSale") == 1 ? 99 : 0;
//if (num < 3)
// num = 0;
if (s.number > num)
s.number = num;
s.sale_count = BaseRegex.GetIntJson(ref list, "soldQuantity");
pb.saleCount += s.sale_count;
s.prop_image = BaseRegex.GetStringJson(ref list, "thumbUrl");
if (string.IsNullOrEmpty(s.prop_image))//跳过劵后价
continue;
if (!string.IsNullOrEmpty(s.prop_image))
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
if (s.prop_image.Contains("?"))
s.prop_image = s.prop_image.Substring(0, s.prop_image.IndexOf("?"));
s.name = GetName(list, ref pb, s.prop_image);
pb.SkuMaps.Add(s);
}
decimal maxPriceNew = 0;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (maxPriceNew < pb.SkuMaps[i].price)
maxPriceNew = pb.SkuMaps[i].price;
}
string firstSkuImage = pb.SkuMaps[0].prop_image;
if (pb.Props.Count == 1)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
bool ishad = false;
for (int k = 0; k < pb.SkuMaps.Count; k++)
{
if (pb.SkuMaps[k].name.Contains(pb.Props[0].Values[j].name))
{
ishad = true;
break;
}
}
if (!ishad)
{
SkuMapBase sm = new SkuMapBase();
sm.id = BaseClass.GetTime(DateTime.Today);
sm.price = maxPriceNew;
sm.number = 0;
sm.sale_count = 0;
pb.saleCount += sm.sale_count;
sm.prop_image = firstSkuImage;
sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";";
pb.SkuMaps.Add(sm);
}
}
}
if (pb.Props.Count == 2)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
for (int k = 0; k < pb.Props[1].Values.Count; k++)
{
bool ishad = false;
for (int l = 0; l < pb.SkuMaps.Count; l++)
{
string[] li = pb.SkuMaps[l].name.Split(';');
if (li.Length == 2)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1)
{
ishad = true;
break;
}
}
if (li.Length == 3)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
}
if (li.Length == 4)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
string n4 = li[3].Substring(li[3].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
if (pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n3
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
}
}
if (!ishad)
{
SkuMapBase sm = new SkuMapBase();
sm.id = BaseClass.GetTime(DateTime.Today);
sm.price = maxPriceNew;
sm.number = 0;
sm.sale_count = 0;
pb.saleCount += sm.sale_count;
sm.prop_image = firstSkuImage;
sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";" + pb.Props[1].name + ":" + pb.Props[1].Values[k].name + ";";
pb.SkuMaps.Add(sm);
}
}
}
}
pb.cat1 = BaseRegex.GetIntJson(ref html, "catID1");
pb.cat2 = BaseRegex.GetIntJson(ref html, "catID2");
pb.cat3 = BaseRegex.GetIntJson(ref html, "catID3");
pb.cat_id = BaseRegex.GetIntJson(ref html, "catID");
if (pb.cat_id != pb.cat3)
pb.cat4 = pb.cat_id;
int cid = PinduoduoCatList.GetNewCat3(pb.cat_id);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
pb.cat_id = ci.id;
pb.cat1 = ci.cat1;
pb.cat2 = ci.cat2;
pb.cat3 = ci.cat3;
pb.cat4 = ci.cat4;
pb.main_cid = ci.main_cat_id;
}
pb.before_price = BaseRegex.GetIntJson(ref html, "marketPrice") / 100m;
pb.content = content;
var ft = new FromTitleToCat();
pb.main_cid = ft.GetMainCatId(pb.cat1);
pb.main_cat_name = ft.MainCatName;
Product.Cat1 = pb.cat1;
Product.Cat2 = pb.cat2;
Product.Cat3 = pb.cat3;
Product.Cat4 = pb.cat4;
Product.CatId = pb.cat_id;
Product.MainCatId = pb.main_cid;
Product.MainCatName = pb.main_cat_name;
string sepc = BaseRegex.GetMatchRegexString(ref html, @"(""goodsProperty"":\[\{([\w\W]+?)\}\])");
m = BaseRegex.GetMatchRegex(ref sepc, @"\{""key"":""([^""]+?)"",""values"":\[([\w\W]+?)\][\w\W]+?\}");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[1].Value;
string val = m[i].Groups[2].Value;
var list = BaseRegex.GetMatchRegex(ref val, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(name, v));
}
pb.mall_id = BaseRegex.GetLongJson(ref html, "mallID");
pb.from_site_id = 2;
pb.price = Product.Price;
decimal minPrcie = 0M;
if (pb.price == 0 && pb.SkuMaps.Count > 0)
{
minPrcie = pb.SkuMaps[0].price;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (minPrcie > pb.SkuMaps[i].price)
{
minPrcie = pb.SkuMaps[i].price;
}
}
pb.price = minPrcie;
}
string sale = BaseRegex.GetStringJson(ref html, "sideSalesTip");
sale = BaseRegex.GetMatchRegexString(ref sale, @"([\d\.万]+)");
if (!string.IsNullOrEmpty(sale))
{
sale = sale.Replace(".", "").Replace("万", "0000");
int sa = 0;
int.TryParse(sale, out sa);
pb.saleCount = sa;
}
//pb.saleCount = BaseRegex.GetIntJson(ref html, "sales");
Product.SaleCount = pb.saleCount;
if (!userData)
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = Product.FromId.ToString(), SaveHtml = html });
//ServerTemp.Set(2, Product.FromId.ToString(), html);
if (pb.saleCount > 0)
{
//TempHtml = html;
//url = BaseClass.BigDataApiUrl + "?obj=product/product";
// string json = JsonHelper.SerializeObject(pb);
//string data = "&act=update&site_id=2&shop_name=" + GetHtml.UrlEncodeUtf8(pb.from_shop_name) + "&json=" + GetHtml.UrlEncodeUtf8(json);
//if (!userData)
//{
// html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex() + data);
// url = BaseClass.BigDataApiUrl + "?obj=product/image_PinBaoBao&act=add_pinduoduo_content";
// content = BaseRegex.GetMatchRegexString(ref TempHtml, @"window\.rawData([\w\W]+?)</script>");
// data = UserLogin.GetSignaturex() + "&id=" + pb.from_id + "&table=" + table + "&content=" +
// GetHtml.UrlEncodeUtf8(content);
// html = GetHtml.PostUtf8(url, data);
//}
}
}
#endregion
#region 66最新解析 20220207
if (html.Contains("cat_id_1") && pb.SkuMaps.Count == 0)
{
try
{
html = html.Replace("\r\n", "").Replace(" ", "");
if (html.Contains("}}}}pddRouteName"))
{
html = html.Split(new string[] { "}}}}pddRouteName" }, StringSplitOptions.RemoveEmptyEntries)[0] + "}}}}";
}
JObject ja = JObject.Parse(html);
if (!html.Contains(@"""is_onsale"":1") || DeleteAndDown(html))
{
if (!userData)
{
ServerTemp.Set(2, Product.FromId.ToString(), html);
BigDataBuild.Delete(Product.FromId, 2);
}
message = "商品获取成功:" + Product.FromId + "商品已下架";
if (IsAdvance)
{
message = "预售商品" + Product.FromId + ",跳过";
}
OnSale = false;
if (!DeleteIds.Contains(Product.FromId))
DeleteIds.Add(Product.FromId);
return;
}
if (ja["data"]["goods"] != null)
{
string goodStr = ja["data"]["goods"].ToString();
pb.from = "拼多多";
pb.id = BaseRegex.GetLongJson(ref goodStr, "goods_id");
pb.from_id = BaseRegex.GetLongJson(ref goodStr, "goods_id");
pb.name = BaseRegex.GetStringJson(ref goodStr, "goods_name");
pb.from_shop_name = BaseRegex.GetStringJson(ref html, "mall_name");
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goods_desc");
string main_gallery = ja["data"]["goods"]["main_gallery"].ToString();
main_gallery = main_gallery.Replace("\r\n", "").Replace(" ", "");
var m = BaseRegex.GetMatchRegex(ref main_gallery, @"{""url""[^}]+?"",");
string content = "";
for (int i = 0; i < m.Count; i++)
{
var item = m[i].Groups[0].Value;
string img = BaseRegex.GetStringJson(ref item, "url");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
pb.Images.Add(img);
}
string detail_gallery = ja["data"]["goods"]["detail_gallery"].ToString();
detail_gallery = detail_gallery.Replace("\r\n", "").Replace(" ", "");
m = BaseRegex.GetMatchRegex(ref detail_gallery, @"{""url""[^}]+?"",");
for (int i = 0; i < m.Count; i++)
{
var item = m[i].Groups[0].Value;
string img = BaseRegex.GetStringJson(ref item, "url");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
content += "<img src='" + img + "'>";
}
string specmaps = ja["data"]["specs"].ToString();
var vProps = JArray.Parse(specmaps)?.ToObject<List<Object>>();
for (int i = 0; i < vProps.Count; i++)
{
var specStr = vProps[i].ToString();
specStr = specStr.Replace("\r\n", "").Replace(" ", "");
var spec_key = BaseRegex.GetStringJson(ref specStr, "spec_key");
var spec_key_id = BaseRegex.GetStringJson(ref specStr, "spec_key_id");
PropBase p = new PropBase();
p.name = spec_key;
p.pinduoduo_id = spec_key_id;
var spec_values = "[{" + BaseRegex.GetMatchRegexString(ref specStr, @"""spec_values"":\[\{([\w\W]+?)\}\]") + "}]";
if (spec_values == "[{}]")
spec_values = BaseRegex.GetMatchRegexString(ref specStr, @"""spec_values"":\[([\w\W]+?)\]");
var mc = BaseRegex.GetMatchRegex(ref spec_values, @"\{""([^}]+?)"":""([^}]+?)""\}");
if (mc.Count > 0)
{
for (int j = 0; j < mc.Count; j++)
{
PropValueBase pv = new PropValueBase();
pv.id = mc[j].Groups[1].Value;
pv.name = mc[j].Groups[2].Value;
p.Values.Add(pv);
}
}
else
{
try
{
List<Dictionary<string, string>> dicList = JsonHelper.DeserializeJsonToList<Dictionary<string, string>>(spec_values);
if (dicList != null)
{
foreach (var item in dicList)
{
if (item.Keys.Count > 0)
{
PropValueBase pv = new PropValueBase();
pv.id = item.Keys.FirstOrDefault();
pv.name = item.Values.FirstOrDefault();
p.Values.Add(pv);
}
}
}
}
catch (Exception ex) { }
}
pb.Props.Add(p);
}
string skumaps = ja["data"]["sku"].ToString();
var vSkuProps = JArray.Parse(skumaps)?.ToObject<List<Object>>();
for (int i = 0; i < vSkuProps.Count; i++)
{
var list = vSkuProps[i].ToString();
SkuMapBase s = new SkuMapBase();
s.id = BaseRegex.GetLongJson(ref list, "sku_id");
s.price = BaseRegex.GetDecimalJson(ref list, "group_price");
s.number = BaseRegex.GetIntJson(ref list, "quantity");
s.sale_count = BaseRegex.GetIntJson(ref list, "sold_quantity");
pb.saleCount += s.sale_count;
s.prop_image = BaseRegex.GetStringJson(ref list, "thumb_url");
if (!string.IsNullOrEmpty(s.prop_image))
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
if (s.prop_image.Contains("?"))
s.prop_image = s.prop_image.Substring(0, s.prop_image.IndexOf("?"));
s.skuPreSaleTip = BaseRegex.GetStringJson(ref list, "sku_pre_sale_tip");
s.skuPreTime = BaseRegex.GetLongJson(ref list, "sku_pre_sale_time");
s.spec_pinduoduo = BaseRegex.GetStringJson(ref list, "spec");
var pvalue = BaseRegex.GetMatchRegexString(html, @"""skuId"":" + s.id + @",""activityCopyWriting"":""券后¥([\w\W]+?)"",");
if (!string.IsNullOrEmpty(pvalue))
s.quanPrice = decimal.Parse(pvalue);
string specs = BaseRegex.GetStringJson(ref list, "spec");
string[] specItem = specs.Split(',');
string temp = "";
for (int k = 0; k < specItem.Length; k++)
{
var item = specItem[k];
bool ishas = false;
for (int j = 0; j < pb.Props.Count; j++)
{
if (ishas)
break;
for (int q = 0; q < pb.Props[j].Values.Count; q++)
{
if (pb.Props[j].Values[q].id.ToString() == item)
{
temp += pb.Props[j].name + ":" + pb.Props[j].Values[q].name + ";";
ishas = true;
break;
}
}
}
}
s.name = temp;
UpPinduoduoProductSet.AddImage(s.prop_image, s.prop_image, 0, 0);
//s.name = GetNewName(list, ref pb, s.prop_image);
pb.SkuMaps.Add(s);
foreach (var propGroup in pb.Props)
{
foreach (var pv in propGroup.Values)
{
if (pv.id == s.spec_pinduoduo?.Split(',')[0])
{
if (string.IsNullOrEmpty(pv.image))
{
pv.image = pv.image_from_url = s.prop_image;
}
break;
}
}
}
}
decimal maxPriceNew = 0;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (maxPriceNew < pb.SkuMaps[i].price)
maxPriceNew = pb.SkuMaps[i].price;
}
string firstSkuImage = pb.SkuMaps[0].prop_image;
pb.cat1 = BaseRegex.GetIntJson(ref goodStr, "cat_id_1");
pb.cat2 = BaseRegex.GetIntJson(ref goodStr, "cat_id_2");
pb.cat3 = BaseRegex.GetIntJson(ref goodStr, "cat_id_3");
pb.cat_id = BaseRegex.GetIntJson(ref goodStr, "cat_id");
if (pb.cat_id != pb.cat3)
pb.cat4 = pb.cat_id;
int cid = PinduoduoCatList.GetNewCat3(pb.cat_id);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
pb.cat_id = ci.id;
pb.cat1 = ci.cat1;
pb.cat2 = ci.cat2;
pb.cat3 = ci.cat3;
pb.cat4 = ci.cat4;
pb.main_cid = ci.main_cat_id;
}
pb.before_price = BaseRegex.GetIntJson(ref goodStr, "market_price") / 100m;
pb.content = content;
var ft = new FromTitleToCat();
pb.main_cid = ft.GetMainCatId(pb.cat1);
pb.main_cat_name = ft.MainCatName;
string goodPropertyStr = ja["data"]["goods"]["goods_property"]?.ToString();
if (!string.IsNullOrEmpty(goodPropertyStr))
{
goodPropertyStr = goodPropertyStr.Replace("\r\n", "").Replace(" ", "");
m = BaseRegex.GetMatchRegex(ref goodPropertyStr, @"\{""key"":""([^""]+?)"",""values"":\[([\w\W]+?)\]");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[1].Value;
string val = m[i].Groups[2].Value;
var list = BaseRegex.GetMatchRegex(ref val, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(name, v));
}
}
pb.mall_id = BaseRegex.GetLongJson(ref goodStr, "mall_id");
pb.from_site_id = 2;
pb.price = 0;
if (pb.price == 0 && pb.SkuMaps.Count > 0)
pb.price = pb.SkuMaps[0].price;
string sale = BaseRegex.GetStringJson(ref goodStr, "side_sales_tip");
sale = BaseRegex.GetMatchRegexString(ref sale, @"([\d\.万]+)");
if (!string.IsNullOrEmpty(sale))
{
sale = sale.Replace(".", "").Replace("万", "0000");
int sa = 0;
int.TryParse(sale, out sa);
pb.saleCount = sa;
}
if (html.Contains("class=\"RWpliLUr\"") && html.Contains("https://pinduoduoimg.yangkeduo.com/deposit/global_shopping.png"))
{
pb.main_cid = Product.MainCatId = 8;
pb.main_cat_name = Product.MainCatName = "海淘进口";
pb.country = Product.country = BaseRegex.GetStringJson(ref html, "countryDesc").Replace("品牌", "");
}
if (TaobaoMobileCollect.ProductTemp.Count > 100000)
{
TaobaoMobileCollect.ProductTemp.Clear();
}
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(pb.from_id))
{
try
{
TaobaoMobileCollect.ProductTemp.Add(pb.from_id, pb);
}
catch
{
}
}
else
{
TaobaoMobileCollect.ProductTemp[pb.from_id] = pb;
}
}
}
catch (Exception ex)
{
}
}
#endregion
#region 大麦解析
if (html.Contains("cat_id_1") && pb.SkuMaps.Count == 0)
{
try
{
JObject ja = JObject.Parse(html);
html = html.Replace("\r\n", "").Replace(" ", "");
if (!html.Contains(@"""is_onsale"":1") || DeleteAndDown(html))
{
if (!userData)
{
ServerTemp.Set(2, Product.FromId.ToString(), html);
BigDataBuild.Delete(Product.FromId, 2);
}
//LogSave.Add(Name, "商品获取成功:" + Product.FromId + "商品已下架");
message = "商品获取成功:" + Product.FromId + "商品已下架";
if (IsAdvance)
{
message = "预售商品" + Product.FromId + ",跳过";
}
OnSale = false;
pb.message = message;
Product.Message = message;
TaobaoMobileCollect.ProductTemp[pb.from_id] = pb;
return;
}
if (ja["goods"] != null)
{
string goodStr = ja["goods"].ToString();
pb.from = "拼多多";
pb.id = BaseRegex.GetLongJson(ref goodStr, "goods_id");
pb.from_id = BaseRegex.GetLongJson(ref goodStr, "goods_id");
pb.name = BaseRegex.GetStringJson(ref goodStr, "goods_name");
//pb.name_share = BaseRegex.GetStringJson(ref html, "goods_desc");
pb.from_shop_name = BaseRegex.GetStringJson(ref html, "mall_name");
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goods_desc");
string gallerys = ja["goods"]["gallery"].ToString();
gallerys = gallerys.Replace("\r\n", "").Replace(" ", "");
var m = BaseRegex.GetMatchRegex(ref gallerys, @"{[^}]+?""url""[^}]+?}");
string content = "";
for (int i = m.Count - 1; i >= 0; i--)
{
var item = m[i].Groups[0].Value;
int type = BaseRegex.GetIntJson(ref item, "type");
if (type == 1)
{
string img = BaseRegex.GetStringJson(ref item, "url");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
pb.Images.Add(img);
}
else
{
if (type == 6)
continue;
string img = BaseRegex.GetStringJson(ref item, "url");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
int width = BaseRegex.GetIntJson(ref item, "width");
int height = BaseRegex.GetIntJson(ref item, "height");
content += "<img src='" + img + "'>";
}
}
string skumaps = ja["sku"].ToString();
var vSkuProps = JArray.Parse(skumaps)?.ToObject<List<Object>>();
//skumaps = skumaps.Replace("\r\n", "").Replace(" ", "");
//m = BaseRegex.GetMatchRegex(ref skumaps, @"""default_quantity""[^}]+?""sku_id"".*?\}\].*?\}");
//if (m==null||m.Count==0)
// m = BaseRegex.GetMatchRegex(ref skumaps, @"""default_quantity""[^}]+?""sku_id"".*?\}");
//if (m == null || m.Count == 0)
// m = BaseRegex.GetMatchRegex(ref skumaps, @"""sku_id"".*?\}\].*?\}");
for (int i = 0; i < vSkuProps.Count; i++)
{
var list = vSkuProps[i].ToString();
SkuMapBase s = new SkuMapBase();
s.id = BaseRegex.GetLongJson(ref list, "sku_id");
s.price = BaseRegex.GetDecimalJson(ref list, "group_price") / 100;
//if (s.price < 1)
// continue;
int num = BaseRegex.GetIntJson(ref list, "quantity");
s.number = BaseRegex.GetIntJson(ref list, "is_onsale") == 1 ? 99 : 0;
if (num < 3)
num = 0;
if (s.number > num)
s.number = num;
s.sale_count = BaseRegex.GetIntJson(ref list, "sold_quantity");
pb.saleCount += s.sale_count;
s.prop_image = BaseRegex.GetStringJson(ref list, "thumb_url");
if (!string.IsNullOrEmpty(s.prop_image))
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
if (s.prop_image.Contains("?"))
s.prop_image = s.prop_image.Substring(0, s.prop_image.IndexOf("?"));
UpPinduoduoProductSet.AddImage(s.prop_image, s.prop_image, 0, 0);
s.name = GetNewName(list, ref pb, s.prop_image);
pb.SkuMaps.Add(s);
}
decimal maxPriceNew = 0;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (maxPriceNew < pb.SkuMaps[i].price)
maxPriceNew = pb.SkuMaps[i].price;
}
string firstSkuImage = pb.SkuMaps[0].prop_image;
pb.cat1 = BaseRegex.GetIntJson(ref goodStr, "cat_id_1");
pb.cat2 = BaseRegex.GetIntJson(ref goodStr, "cat_id_2");
pb.cat3 = BaseRegex.GetIntJson(ref goodStr, "cat_id_3");
pb.cat_id = BaseRegex.GetIntJson(ref goodStr, "cat_id");
if (pb.cat_id != pb.cat3)
pb.cat4 = pb.cat_id;
int cid = PinduoduoCatList.GetNewCat3(pb.cat_id);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
pb.cat_id = ci.id;
pb.cat1 = ci.cat1;
pb.cat2 = ci.cat2;
pb.cat3 = ci.cat3;
pb.cat4 = ci.cat4;
pb.main_cid = ci.main_cat_id;
}
pb.before_price = BaseRegex.GetIntJson(ref goodStr, "market_price") / 100m;
pb.content = content;
var ft = new FromTitleToCat();
pb.main_cid = ft.GetMainCatId(pb.cat1);
pb.main_cat_name = ft.MainCatName;
string goodPropertyStr = ja["goods"]["goods_property"]?.ToString();
if (!string.IsNullOrEmpty(goodPropertyStr))
{
goodPropertyStr = goodPropertyStr.Replace("\r\n", "").Replace(" ", "");
m = BaseRegex.GetMatchRegex(ref goodPropertyStr, @"\{[^}]+?""values"":\[([\w\W]+?)\],""key"":""([^""]+?)""\}");
if (m == null || m.Count == 0)
{
m = BaseRegex.GetMatchRegex(ref goodPropertyStr, @"\{""key"":""([^""]+?)"",[^}]+?""values"":\[([\w\W]+?)\]\}");
}
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[1].Value;
string val = m[i].Groups[2].Value;
var list = BaseRegex.GetMatchRegex(ref val, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(name, v));
}
if (m == null || m.Count == 0)
{
var prop = JArray.Parse(goodPropertyStr).ToObject<List<Object>>();
for (int i = 0; i < prop.Count; i++)
{
var propStr = prop[i].ToString();
propStr = propStr.Replace("\r\n", "").Replace(" ", "");
var pkey = BaseRegex.GetStringJson(ref propStr, "key");
var pvalue = BaseRegex.GetMatchRegexString(propStr, @"""values"":\[([^<]+)\]");
var list = BaseRegex.GetMatchRegex(ref pvalue, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(pkey) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(pkey, v));
}
}
}
pb.mall_id = BaseRegex.GetLongJson(ref goodStr, "mall_id");
pb.from_site_id = 2;
pb.price = 0;
if (pb.price == 0 && pb.SkuMaps.Count > 0)
pb.price = pb.SkuMaps[0].price;
string sale = BaseRegex.GetStringJson(ref goodStr, "side_sales_tip");
sale = BaseRegex.GetMatchRegexString(ref sale, @"([\d\.万]+)");
if (!string.IsNullOrEmpty(sale))
{
sale = sale.Replace(".", "").Replace("万", "0000");
int sa = 0;
int.TryParse(sale, out sa);
pb.saleCount = sa;
}
//if (!userData)
// ServerTemp.Set(2, Product.FromId.ToString(), html);
if (html.Contains("class=\"RWpliLUr\"") && html.Contains("https://pinduoduoimg.yangkeduo.com/deposit/global_shopping.png"))
{
pb.main_cid = Product.MainCatId = 8;
pb.main_cat_name = Product.MainCatName = "海淘进口";
pb.country = Product.country = BaseRegex.GetStringJson(ref html, "countryDesc").Replace("品牌", "");
}
if (TaobaoMobileCollect.ProductTemp.Count > 100000)
{
TaobaoMobileCollect.ProductTemp.Clear();
}
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(pb.from_id))
{
try
{
TaobaoMobileCollect.ProductTemp.Add(pb.from_id, pb);
}
catch
{
}
}
else
{
TaobaoMobileCollect.ProductTemp[pb.from_id] = pb;
}
}
}
catch
{
}
}
#endregion
if (html.Contains("cat_id_1") && !html.Contains("share_desc"))
{
GenerateProductInfo(html);
return;
}
#region 从 http://api.yangkeduo.com/v5/goods获取的数据 手机数据
html = html.Replace(" ", "");
if (html.Contains("cat_id_1") && pb.SkuMaps.Count == 0)
{
if (!html.Contains(@"""is_onsale"":1") || DeleteAndDown(html))
{
if (!userData)
{
ServerTemp.Set(2, Product.FromId.ToString(), html);
BigDataBuild.Delete(Product.FromId, 2);
}
//LogSave.Add(Name, "商品获取成功:" + Product.FromId + "没有在线sku");
message = "商品获取成功:" + Product.FromId + "商品已下架";
OnSale = false;
if (!DeleteIds.Contains(Product.FromId))
DeleteIds.Add(Product.FromId);
return;
}
html = GetHtml.Decode(html);
pb.from = "拼多多";
pb.id = Product.FromId;
pb.from_id = Product.FromId;
LogSave.Add(Name, "获取成功:" + Product.FromId);
pb.name = BaseRegex.GetStringJson(ref html, "goods_name");
pb.name_share = BaseRegex.GetStringJson(ref html, "share_desc");
pb.from_shop_name = BaseRegex.GetStringJson(ref html, "mallName");
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goods_desc");
string temp = BaseRegex.GetMatchRegexString(ref html, @"""gallery"":\[(.*?)\]");
var m = BaseRegex.GetMatchRegex(ref temp, @"""url"":""([^""]+?)"",""width"":([\d]+),""height"":([\d]+),""priority"":([\d]+),""type"":([\d]+)");
string content = "";
Dictionary<int, string> mainImage = new Dictionary<int, string>();
Dictionary<int, string> contentImage = new Dictionary<int, string>();
for (int i = 0; i < m.Count; i++)
{
string item = m[i].Groups[0].Value;
int type = int.Parse(m[i].Groups[5].Value);
if (type == 6)
continue;
if (type == 1)
{
string img = m[i].Groups[1].Value;
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
int index = BaseRegex.GetIntJson(ref item, "priority");//int.Parse(m[i].Groups[4].Value);
mainImage.Add(index, img);
//pb.Images.Add(img);
}
else
{
string img = m[i].Groups[1].Value;
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
//int width = int.Parse(m[i].Groups[2].Value);
//int height = int.Parse(m[i].Groups[3].Value);
int index = BaseRegex.GetIntJson(ref item, "priority");// int.Parse(m[i].Groups[4].Value);
contentImage.Add(index, img);
//content += "<img src='" + img + "'>";
}
}
var mainlst = mainImage.OrderBy(p => p.Key).ToList();
for (int i = 0; i < mainlst.Count; i++)
{
pb.Images.Add(mainlst[i].Value);
}
var contentlst = contentImage.OrderBy(p => p.Key).ToList();
for (int i = 0; i < contentlst.Count; i++)
{
content += "<img src='" + contentlst[i].Value + "'>";
}
m = BaseRegex.GetMatchRegex(ref html, @"\{""sku_id"".*?\}\].*?\}");
for (int i = 0; i < m.Count; i++)
{
string list = m[i].Groups[0].Value;
SkuMapBase s = new SkuMapBase();
s.id = BaseRegex.GetLongJson(ref list, "sku_id");
s.price = BaseRegex.GetDecimalJson(ref list, "group_price") / 100;
if (s.price < 1)
continue;
int num = BaseRegex.GetIntJson(ref list, "quantity");
s.number = BaseRegex.GetIntJson(ref list, "is_onsale") == 1 ? 99 : 0;
if (num < 3)
num = 0;
if (s.number > num)
s.number = num;
s.sale_count = BaseRegex.GetIntJson(ref list, "sold_quantity");
pb.saleCount += s.sale_count;
s.prop_image = BaseRegex.GetStringJson(ref list, "thumb_url");
if (!string.IsNullOrEmpty(s.prop_image))
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
if (s.prop_image.Contains("?"))
s.prop_image = s.prop_image.Substring(0, s.prop_image.IndexOf("?"));
UpPinduoduoProductSet.AddImage(s.prop_image, s.prop_image, 0, 0);
s.name = GetName(list, ref pb, s.prop_image);
pb.SkuMaps.Add(s);
}
decimal maxPriceNew = 0;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (maxPriceNew < pb.SkuMaps[i].price)
maxPriceNew = pb.SkuMaps[i].price;
}
string firstSkuImage = pb.SkuMaps[0].prop_image;
if (pb.Props.Count == 1)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
bool ishad = false;
for (int k = 0; k < pb.SkuMaps.Count; k++)
{
if (pb.SkuMaps[k].name.Contains(pb.Props[0].Values[j].name))
{
ishad = true;
break;
}
}
if (!ishad)
{
SkuMapBase sm = new SkuMapBase();
sm.id = BaseClass.GetTime(DateTime.Today);
sm.price = maxPriceNew;
sm.number = 0;
sm.sale_count = 0;
pb.saleCount += sm.sale_count;
sm.prop_image = firstSkuImage;
sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";";
pb.SkuMaps.Add(sm);
}
}
}
if (pb.Props.Count == 2)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
for (int k = 0; k < pb.Props[1].Values.Count; k++)
{
bool ishad = false;
for (int l = 0; l < pb.SkuMaps.Count; l++)
{
string[] li = pb.SkuMaps[l].name.Split(';');
if (li.Length == 2)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1)
{
ishad = true;
break;
}
}
if (li.Length == 3)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
}
if (li.Length == 4)
{
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
string n4 = li[3].Substring(li[3].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
if (pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n3
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n1
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n2)
{
ishad = true;
break;
}
}
}
if (!ishad)
{
SkuMapBase sm = new SkuMapBase();
sm.id = BaseClass.GetTime(DateTime.Today);
sm.price = maxPriceNew;
sm.number = 0;
sm.sale_count = 0;
pb.saleCount += sm.sale_count;
sm.prop_image = firstSkuImage;
sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";" + pb.Props[1].name + ":" + pb.Props[1].Values[k].name + ";";
pb.SkuMaps.Add(sm);
}
}
}
}
pb.cat1 = BaseRegex.GetIntJson(ref html, "cat_id_1");
pb.cat2 = BaseRegex.GetIntJson(ref html, "cat_id_2");
pb.cat3 = BaseRegex.GetIntJson(ref html, "cat_id_3");
pb.cat_id = BaseRegex.GetIntJson(ref html, "cat_id");
if (pb.cat_id != pb.cat3)
pb.cat4 = pb.cat_id;
int cid = PinduoduoCatList.GetNewCat3(pb.cat_id);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
pb.cat_id = ci.id;
pb.cat1 = ci.cat1;
pb.cat2 = ci.cat2;
pb.cat3 = ci.cat3;
pb.cat4 = ci.cat4;
pb.main_cid = ci.main_cat_id;
}
pb.before_price = BaseRegex.GetIntJson(ref html, "market_price") / 100m;
pb.content = content;
var ft = new FromTitleToCat();
pb.main_cid = ft.GetMainCatId(pb.cat1);
pb.main_cat_name = ft.MainCatName;
Product.Cat1 = pb.cat1;
Product.Cat2 = pb.cat2;
Product.Cat3 = pb.cat3;
Product.Cat4 = pb.cat4;
Product.CatId = pb.cat_id;
Product.MainCatId = pb.main_cid;
Product.MainCatName = pb.main_cat_name;
string sepc = BaseRegex.GetMatchRegexString(ref html, @"(""goods_property"":\[\{([\w\W]+?)\}\])");
m = BaseRegex.GetMatchRegex(ref sepc, @"\{""key"":""([^""]+?)"",""values"":\[([\w\W]+?)\][\w\W]+?\}");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[1].Value;
string val = m[i].Groups[2].Value;
var list = BaseRegex.GetMatchRegex(ref val, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(name, v));
}
pb.mall_id = BaseRegex.GetLongJson(ref html, "mall_id");
pb.from_site_id = 2;
pb.price = Product.Price;
if (pb.price == 0 && pb.SkuMaps.Count > 0)
pb.price = pb.SkuMaps[0].price;
string sale = BaseRegex.GetStringJson(ref html, "sold_quantity");
if (string.IsNullOrEmpty(sale))
{
sale = BaseRegex.GetStringJson(ref html, "side_sales_tip");
sale = BaseRegex.GetMatchRegexString(ref sale, @"([\d\.万]+)");
}
if (!string.IsNullOrEmpty(sale))
{
sale = sale.Replace(".", "").Replace("万", "000");
int sa = 0;
int.TryParse(sale, out sa);
pb.saleCount = sa;
}
Product.SaleCount = pb.saleCount;
if (!userData)
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = Product.FromId.ToString(), SaveHtml = html });
//ServerTemp.Set(2, Product.FromId.ToString(), html);
}
#endregion
if (html.Contains("class=\"RWpliLUr\"") && html.Contains("https://pinduoduoimg.yangkeduo.com/deposit/global_shopping.png"))
{
pb.main_cid = Product.MainCatId = 8;
pb.main_cat_name = Product.MainCatName = "海淘进口";
pb.country = Product.country = BaseRegex.GetStringJson(ref html, "countryDesc").Replace("品牌", "");
}
if (pb.cat3 == 3109)
{
var pro = pb.Props.Where(s => s.name.Contains("容量")).FirstOrDefault();
if (pro == null)
{
string mah = BaseRegex.GetMatchRegexString(ref pb.name, @"([\d]+)毫安");
PropBase p = new PropBase();
p.pinduoduo_id = "140871455";
p.id = 140871455;
p.name = "电池容量";
PropValueBase pr = new PropValueBase();
pr.id = PinduoduoCatList.GetDianYuanId(int.Parse(mah)).ToString();
pr.value = pr.id;
pr.name = mah + "毫安";
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
pr.image = "";
pr.image_from_url = "";
p.Values.Add(pr);
pb.Props.Add(p);
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
var sku = pb.SkuMaps[i];
sku.name = sku.name + ";" + mah + "毫安";
sku.nameLite = sku.nameLite + mah + "毫安";
}
}
else
{
if (string.IsNullOrEmpty(pro.pinduoduo_id))
{
pro.pinduoduo_id = "140871455";
pro.id = 140871455;
}
for (int i = 0; i < pro.Values.Count; i++)
{
var pr = pro.Values[i];
string mah = BaseRegex.GetMatchRegexString(ref pr.name, @"([\d]+)毫安");
pr.id = PinduoduoCatList.GetDianYuanId(int.Parse(mah)).ToString();
pr.value = pr.id;
}
}
}
if (Product.FromType == "搜款网净化")
{
string jhtml = ServerTemp.GetJinHuaCache(Product.FromId.ToString());
AslasyHtml(jhtml);
}
if (TaobaoMobileCollect.ProductTemp.Count > 1000)
{
TaobaoMobileCollect.ProductTemp.Clear();
}
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(pb.from_id))
{
try
{
TaobaoMobileCollect.ProductTemp.Add(pb.from_id, pb);
}
catch
{
}
}
else
{
TaobaoMobileCollect.ProductTemp[pb.from_id] = pb;
}
}
public string GetNameNew(string list, ref ProductCollectBase pb, string image)
{
string temp = "";
var m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)"",""spec_key_id"":([\d]+),""spec_value_id"":([\d]+)");
if (m.Count == 0)
m = BaseRegex.GetMatchRegex(ref list, @"\{""specKey"":""([^""]+?)"",""specValue"":""([^""]+?)""");
if (m.Count == 0)
m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_value_id"":([\d]+),""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)"",""spec_key_id"":([\d]+)");
for (int i = 0; i < m.Count; i++)
{
temp += m[i].Groups[1].Value + ":" + m[i].Groups[2].Value + ";";
bool had = false;
PropBase p = new PropBase();
for (int j = 0; j < pb.Props.Count; j++)
{
if (pb.Props[j].name == m[i].Groups[1].Value)
{
had = true;
p = pb.Props[j];
break;
}
}
if (!had)
{
p = new PropBase();
p.name = m[i].Groups[1].Value;
if (m[i].Groups.Count > 3)
p.pinduoduo_id = m[i].Groups[3].Value;
pb.Props.Add(p);
}
had = false;
for (int j = 0; j < p.Values.Count; j++)
{
if (p.Values[j].name == m[i].Groups[2].Value)
{
p.Values[j].image = image;
p.Values[j].image_from_url = image;
had = true;
break;
}
}
if (!had)
{
PropValueBase pv = new PropValueBase();
if (m[i].Groups.Count > 4)
pv.id = m[i].Groups[4].Value;
pv.name = m[i].Groups[2].Value;
pv.image = image;
pv.image_from_url = image;
p.Values.Add(pv);
}
}
return temp;
}
public void AslasyHtml(string html)
{
if (string.IsNullOrEmpty(html) || html == "null")
return;
try
{
//string title = BaseRegex.GetStringJson(ref html, "fession_title");
//string[] goodTitle = title.Split(';');
//主图
string mainPic = BaseRegex.GetStringJson(ref html, "main_pic");
string[] images = mainPic.Split(';');
pb.Images.Clear();
for (int i = 0; i < images.Length; i++)
{
string img = images[i];
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
pb.Images.Add(img);
}
//详情图
string container_info = BaseRegex.GetMatchRegexString(ref html, @"""container_info"":""(.*?)""");
string[] contentimage = container_info.Split(';');
var m = BaseRegex.GetMatchRegex(ref container_info, @"<img([^""]+?)>");
string content = "";
for (int i = 0; i < m.Count; i++)
{
string img = m[i].Groups[0].Value;
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
content += img;
}
pb.content = content;
pb.Props.Clear();
string temp = "";
m = BaseRegex.GetMatchRegex(ref html,
@"\{""id"":([-\d]+),""name"":""([^}]+)"",""pinduoduo_name"":[^}]+?,""Values"":\[([\w\W]+?)\]\}");
for (int i = 0; i < m.Count; i++)
{
PropBase p = new PropBase();
p.id = long.Parse(m[i].Groups[1].Value);
p.name = m[i].Groups[2].Value;
p.name = BaseRegex.Relpace(p.name, "(&[a-zA-z0-9]+?;)", "");
bool had = false;
for (int j = 0; j < pb.Props.Count; j++)
{
if (pb.Props[j].name == p.name)
{
p = pb.Props[j];
had = true;
break;
}
}
temp = m[i].Groups[3].Value;
var mm = BaseRegex.GetMatchRegex(ref temp, @"""value"":""([-\d]*?)"",""name"":""([^""]+?)""[^\}]*\}");
for (int j = 0; j < mm.Count; j++)
{
string v = mm[j].Groups[1].Value;
string vi = mm[j].Groups[0].Value;
string image = BaseRegex.GetStringJson(ref vi, "image");
if (image == "null")
image = "";
PropValueBase pr = new PropValueBase();
pr.value = v;
pr.name = mm[j].Groups[2].Value;
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
pr.image = image;
pr.image_from_url = image;
bool hadx = false;
for (int k = 0; k < p.Values.Count; k++)
{
if (p.Values[k].name == pr.name)
{
hadx = true;
break;
}
}
if (!hadx)
p.Values.Add(pr);
}
if (!had)
{
p.sort = i + 1;
pb.Props.Add(p);
}
}
if (pb.Props.Count == 1)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
if (pb.Props[0].Values[j].image.Contains("yangkeduo"))
continue;
bool ishad = false;
for (int k = 0; k < pb.SkuMaps.Count; k++)
{
if (pb.SkuMaps[k].name.Contains(pb.Props[0].Values[j].name))
{
pb.SkuMaps[k].prop_image = pb.Props[0].Values[j].image;
ishad = true;
break;
}
}
}
}
if (pb.Props.Count == 2)
{
for (int j = 0; j < pb.Props[0].Values.Count; j++)
{
if (pb.Props[0].Values[j].image.Contains("yangkeduo"))
continue;
for (int l = pb.SkuMaps.Count - 1; l > 0; l--)
{
string[] li = pb.SkuMaps[l].name.Split(';');
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
if (pb.Props[0].Values[j].name == n1 || pb.Props[0].Values[j].name == n2)
{
pb.SkuMaps[l].prop_image = pb.Props[0].Values[j].image;
break;
}
}
}
for (int j = 0; j < pb.Props[1].Values.Count; j++)
{
if (pb.Props[1].Values[j].image.Contains("yangkeduo"))
continue;
for (int l = pb.SkuMaps.Count - 1; l > 0; l--)
{
string[] li = pb.SkuMaps[l].name.Split(';');
string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
if (pb.Props[1].Values[j].name == n1 || pb.Props[1].Values[j].name == n2)
{
pb.SkuMaps[l].prop_image = pb.Props[0].Values[j].image;
break;
}
}
}
}
//pb.name = goodTitle[0];
//char[] idc = Product.FromId.ToString().ToCharArray();
//if (Product.FromId.ToString().Length < Product.TolerantFormId.Length)
// idc = Product.TolerantFormId.ToString().ToCharArray();
//string ld = idc[idc.Length - 1].ToString();
//for (int i = 1; i < idc.Length - 1; i++)
//{
// ld += idc[i];
//}
//ld += idc[0];
//for (int i = 1; i < goodTitle.Length; i++)
//{
// var p = Product.Clone();
// p.FromId = long.Parse(ld);
// p.Titlte = goodTitle[i];
// p.FromType = "搜款网";
// p.Uped = false;
// UploadPinduoduoMain.ProductStock.Insert(0, p);
//}
}
catch
{
}
}
public Dictionary<string, bool> GetApiUidList()
{
DicApiUid.Clear();
Dictionary<string, bool> dicApiUid = new Dictionary<string, bool>();
string url = BaseClass.LoginApiUrl + "?obj=littlecow/sign&act=get_api_uid";
string html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex());
if (string.IsNullOrEmpty(html) || html.Contains("error"))
{
return dicApiUid;
}
var result = html.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (result.Count() > 0)
{
foreach (var v in result)
{
dicApiUid.Add(v, true);
}
}
DicApiUid = dicApiUid;
return dicApiUid;
}
public bool DeleteAndDown(string html)
{
if (string.IsNullOrEmpty(html))
return false;
if (html.Contains("<p>商品不存在</p>"))
return true;
if (html.Contains(">原商品已下架"))
return true;
if (html.Contains("预售"))
{
pb.IsPreSale = IsAdvance = true;
return false;
}
return false;
}
public void GetShop(long mainId)
{
for (int i = 1; i <= CollectKeywordByTaobao.PageTop; i++)
{
string url = "http://apiv4.yangkeduo.com/v2/mall/" + mainId + "/goods?page=" + i + "&size=50&sort_type=GMV&pdduid=0";
string refere = BaseClass.NewUrl + "/mall_page.html?is_spike=0&mall_id=" + mainId + "&refer_page_name=goods_detail&refer_page_id=goods_detail_1510305388010_pSoDpFSdOa&refer_page_sn=10014&sort_type=1";
string html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
var m = BaseRegex.GetMatchRegex(ref html, @"\{""normal_price"":(.*?)""group"":\{.*?\}(.*?)\}");
for (int j = 0; m != null && j < m.Count; j++)
{
if (!CollectKeywordByTaobao.Running)
return;
string list = m[j].Groups[0].Value;
TaobaoProductBase t = new TaobaoProductBase();
t.SaleCount = BaseRegex.GetIntJson(ref list, "cnt");
t.Price = BaseRegex.GetDecimalJson(ref list, "price") / 100m;
string country = BaseRegex.GetStringJson(ref list, "country");
if (!string.IsNullOrEmpty(country) || t.Price < CollectKeywordByTaobao.MinPrice || t.Price > CollectKeywordByTaobao.MaxPrice)
{
continue;
}
if (CollectKeywordByTaobao.MinSale > t.SaleCount)
{
break;
}
t.FromId = BaseRegex.GetLongJson(ref list, "goods_id");
t.Titlte = BaseRegex.GetStringJson(ref list, "goods_name");
t.FromType = "拼多多";
var p = new PinduoduoProductCollect(Name, t);
p.Cloud = Cloud;
p.Get();
}
}
}
public string GetNewName(string list, ref ProductCollectBase pb, string image)
{
list = list.Replace("\r\n", "").Replace(" ", "");
string temp = "";
var m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_value_id"":([\d]+),""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)"",""spec_key_id"":([\d]+)");
if (m != null && m.Count == 0)
{
m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_key_id"":([\d]+),""spec_value"":""([^""]+?)"",""spec_value_id"":([\d]+)");
}
if (m != null && m.Count == 0)
m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_key_id"":([\d]+),""spec_value"":""([^""]+?)""");
if (m.Count == 0)
{
var jSkuValue = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(list.ToString());
var props = JArray.Parse(jSkuValue["specs"].ToString()).ToObject<List<Object>>();
for (int i = 0; i < props.Count; i++)
{
var specStr = props[i].ToString();
var spec_key = BaseRegex.GetStringJson(ref specStr, "spec_key");
var spec_key_id = BaseRegex.GetStringJson(ref specStr, "spec_key_id");
var spec_value = BaseRegex.GetStringJson(ref specStr, "spec_value");
var spec_value_id = BaseRegex.GetStringJson(ref specStr, "spec_value_id");
temp += spec_key + ":" + spec_value + ";";
bool had = false;
PropBase p = new PropBase();
for (int j = 0; j < pb.Props.Count; j++)
{
if (pb.Props[j].name == spec_key)
{
had = true;
p = pb.Props[j];
break;
}
}
if (!had)
{
p = new PropBase();
p.name = spec_key;
p.pinduoduo_id = spec_key_id;
pb.Props.Add(p);
}
had = false;
for (int j = 0; j < p.Values.Count; j++)
{
if (p.Values[j].name == spec_value)
{
p.Values[j].image = image;
p.Values[j].image_from_url = image;
had = true;
break;
}
}
if (!had)
{
PropValueBase pv = new PropValueBase();
pv.id = spec_value_id;
pv.name = spec_value;
pv.image = image;
pv.image_from_url = image;
p.Values.Add(pv);
}
}
return temp;
}
for (int i = 0; i < m.Count; i++)
{
temp += m[i].Groups[2].Value + ":" + m[i].Groups[3].Value + ";";
bool had = false;
PropBase p = new PropBase();
for (int j = 0; j < pb.Props.Count; j++)
{
if (pb.Props[j].name == m[i].Groups[2].Value)
{
had = true;
p = pb.Props[j];
break;
}
}
if (!had)
{
p = new PropBase();
p.name = m[i].Groups[2].Value;
if (m[i].Groups.Count > 3)
p.pinduoduo_id = m[i].Groups[4].Value;
pb.Props.Add(p);
}
had = false;
for (int j = 0; j < p.Values.Count; j++)
{
if (p.Values[j].name == m[i].Groups[3].Value)
{
p.Values[j].image = image;
p.Values[j].image_from_url = image;
had = true;
break;
}
}
if (!had)
{
PropValueBase pv = new PropValueBase();
if (m[i].Groups.Count > 4)
pv.id = m[i].Groups[1].Value;
pv.name = m[i].Groups[3].Value;
pv.image = image;
pv.image_from_url = image;
p.Values.Add(pv);
}
}
return temp;
//string temp = "";
////var m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_value_id"":([\d]+),""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)"",""spec_key_id"":([\d]+)");
////if (m!=null&&m.Count==0)
////{
//// m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_key_id"":([\d]+),""spec_value"":""([^""]+?)"",""spec_value_id"":([\d]+)");
////}
////if (m != null && m.Count == 0)
//// m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_key_id"":([\d]+),""spec_value"":""([^""]+?)""");
//var jSkuProp = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(list.ToString());
//string specStr = jSkuProp["specs"].ToString();
////for (int i = 0; i < m.Count; i++)
////{
// var spec_key = BaseRegex.GetStringJson(ref specStr, "spec_key");
// var spec_key_id = BaseRegex.GetStringJson(ref specStr, "spec_key_id");
// var spec_value = BaseRegex.GetStringJson(ref specStr, "spec_value");
// var spec_value_id = BaseRegex.GetStringJson(ref specStr, "spec_value_id");
// temp += spec_key + ":" + spec_value + ";";
// //temp += m[i].Groups[2].Value + ":" + m[i].Groups[3].Value + ";";
// bool had = false;
// PropBase p = new PropBase();
// for (int j = 0; j < pb.Props.Count; j++)
// {
// if (pb.Props[j].name == spec_key)
// {
// had = true;
// p = pb.Props[j];
// break;
// }
// }
// if (!had)
// {
// p = new PropBase();
// p.name = spec_key;
// p.pinduoduo_id = spec_key_id;
// pb.Props.Add(p);
// }
// had = false;
// for (int j = 0; j < p.Values.Count; j++)
// {
// if (p.Values[j].name == spec_value)
// {
// p.Values[j].image = image;
// p.Values[j].image_from_url = image;
// had = true;
// break;
// }
// }
// if (!had)
// {
// PropValueBase pv = new PropValueBase();
// pv.id = spec_value_id;
// pv.name = spec_value;
// pv.image = image;
// pv.image_from_url = image;
// p.Values.Add(pv);
// }
////}
//return temp;
}
public static void GetServerCookies()
{
//string url = BaseClass.LoginApiUrl + "?obj=upshopid/user_cookies";
//string html = GetHtml.PostUtf8(url, "act=get_rand");
//if (string.IsNullOrEmpty(html))
// html = GetHtml.PostUtf8(url, "act=get_rand");
//var m = BaseRegex.GetMatchRegex(ref html, "<user([^>]+?>)");
//for (int i = 0; m != null && i < m.Count; i++)
//{
// string list = m[i].Groups[0].Value;
// string mobile = BaseRegex.GetStringJson(ref list, "mobile");
// string cookies = BaseRegex.GetStringJson(ref list, "cookies");
// Mobiles.Add(new KeyValueBase(mobile, cookies));
//}
}
public static string GetRandomPDDAccessToken(Func<PinDuoDuoTokenInfo, bool> predicateToken)
{
var tokenList = PinDuoDuoTokenList.Where(p => predicateToken(p)).Select(p => p.PDDAccessToken).ToArray();
if (!tokenList.Any())
{
return string.Empty;
}
string pddAccessToken = tokenList[new Random(BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0)).Next(0, tokenList.Length)];
return pddAccessToken;
}
public static string GetPinDuoDuoSimilarProductNameByImage(string imageUrl, string pddToken)
{
var url = "http://api.yangkeduo.com/api/search/img";
var data = JsonConvert.SerializeObject(new { flip = "1#1#" + Guid.NewGuid().ToString(), url = imageUrl.StartsWith("//") ? "https:" + imageUrl : imageUrl, sort = "_sales" });
string userAgent = BaseClass.AndroidUserAgent;
WebClientx wb = new WebClientx();
wb.Timeout = 30;
wb.Headers.Add("AccessToken", pddToken);
wb.Headers.Add("User-Agent", userAgent);
wb.Proxy = null;
wb.Headers.Add("Referer", "Android");
wb.Headers.Add("Content-Type", "application/json; charset=UTF-8");
string antiToken = SignHelper.GetSign();
wb.Headers.Add("anti-token", antiToken);
wb.Headers.Add("PDD-CONFIG", "00102");
wb.Headers.Add("p-appname", "pinduoduo");
wb.Headers.Add("X-PDD-QUERIES", "width=810&height=1440&net=1&brand=Android&model=MuMu&osv=6.0.1&appv=4.70.0&pl=2");
byte[] postData = Encoding.UTF8.GetBytes(data);
try
{
wb.Headers.Add("ContentLength", postData.Length.ToString());
var html = Encoding.UTF8.GetString(wb.UploadData(url, "POST", postData));
JObject jObj = JObject.Parse(html);
var productName = string.Empty;
if (jObj["items"] != null)
{
foreach (var item in jObj["items"])
{
productName = item["goods_name"].ParseToString();
break;
}
}
return productName;
}
catch (Exception e)
{
LogSave.Add(e.ToString());
return "";
}
}
public static string GetPDDProductImageUrl(long goodsId, string pddToken)
{
var imgUrl = GetProductImageUrlViaYouHui(goodsId);
if (string.IsNullOrEmpty(imgUrl))
{
imgUrl = GetProductImageUrlViaProductId(goodsId, pddToken);
}
return imgUrl;
}
public static string GetProductImageUrlViaYouHui(long goodsId)
{
string imgUrl = string.Empty;
try
{
string url = "https://youhui.pinduoduo.com/goods/goods-detail?goodsId=" + goodsId + "&r=" + BitConverter.ToInt32(Guid.NewGuid().ToByteArray(), 0);
string html = GetHtml.GetUtf8(url, BaseClass.ChromeUserAgent, "", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
string json = GetHtml.Resove(html, "<script id=\"__NEXT_DATA__\" type=\"application/json\">", "</script>");
if (!string.IsNullOrEmpty(json))
{
JObject jObj = JObject.Parse(json);
if (jObj != null)
{
foreach (string image in jObj["props"]["pageProps"]["goodsDetail"]["goodsGalleryUrls"].ToObject<JArray>())
{
imgUrl = image;
break;
}
}
}
}
catch (Exception ex)
{
LogSave.Add(ex.ToString());
}
return imgUrl;
}
public static string GetProductImageUrlViaProductId(long goodsId, string pddToken)
{
string imgUrl = string.Empty;
try
{
string url = "http://yangkeduo.com/goods.html?goods_id=" + goodsId;
string html = GetHtml.GetUtf8(url, BaseClass.ChromeUserAgent, "PDDAccessToken=" + pddToken);
string json = GetHtml.Resove(html, "window.rawData=", "}};");
if (!string.IsNullOrEmpty(json))
{
json += "}}";
JObject jObj = JObject.Parse(json);
if (jObj != null)
{
foreach (string image in jObj["store"]["initDataObj"]["goods"]["topGallery"].ToObject<JArray>())
{
imgUrl = image;
break;
}
}
}
}
catch (Exception ex)
{
LogSave.Add(ex.ToString());
}
return imgUrl;
}
public static string GenerateLowPriceSkus(long goodsId, decimal lowPrice, List<PropBase> productPropList, List<string> lowPriceSpecs, string pddToken)
{
string skuContent = string.Empty;
if (productPropList == null || productPropList.Count < 1)
return skuContent;
try
{
string url = "http://yangkeduo.com/goods.html?goods_id=" + goodsId;
string html = GetHtml.GetUtf8(url, BaseClass.ChromeUserAgent, "PDDAccessToken=" + pddToken);
string json = GetHtml.Resove(html, "window.rawData=", "}};");
if (!string.IsNullOrEmpty(json))
{
json += "}}";
JObject jObj = JObject.Parse(json);
if (jObj != null)
{
var goodsDetail = jObj["store"]["initDataObj"]["goods"];
if (goodsDetail != null)
{
StringBuilder sbSkuContent = new StringBuilder();
//把spec value名字从要上传的商品中拿出
List<string>[] propValueList = new List<string>[2];
string[] specTypeNames = new string[2];
for (int i = 0; i < productPropList.Count; i++)
{
propValueList[i] = new List<string>();
specTypeNames[i] = productPropList[i].pinduoduo_id;
foreach (var propValue in productPropList[i].Values)
{
if (propValue.is_used)
propValueList[i].Add(propValue.id);
}
}
var skuList = goodsDetail["skus"].ToObject<JArray>();
JToken pickedSku = null;
string specFirstValue = null;
List<string> specSecondList = new List<string>();
List<JToken> pickedSkuList = new List<JToken>();
var thumbUrl = string.Empty;
int specFirstIndex = -1;
//从低价引流商品中选出一个sku,有上传商品spec第一组中没有的spec
foreach (var sku in skuList)
{
var specs = sku["specs"].ToObject<JArray>();
decimal groupPrice = sku["groupPrice"].ParseToDecimal();
int quantity = sku["quantity"].ParseToInt();
if (specs.Count > 0 && quantity != 0 && groupPrice != 0 && groupPrice <= lowPrice)
{
for (int ii = 0; specFirstIndex == -1 && ii < specs.Count; ii++)
{
// 比较得出上传商品中第一组spec对应低价引流商品的spec索引
if (specs[ii]["spec_key_id"].ParseToString() == specTypeNames[0])
{
specFirstIndex = ii;
if (productPropList.Count == 2)
{
if (specs[1 - specFirstIndex]["spec_key_id"].ParseToString() != specTypeNames[1])
{
specFirstIndex = -1;
}
}
break;
}
}
if (specFirstIndex == -1)
{
break;
}
if (specFirstValue == null && !propValueList[0].Contains(specs[specFirstIndex]["spec_value_id"].ParseToString()))
{
specFirstValue = specs[specFirstIndex]["spec_value_id"].ParseToString();
pickedSku = sku;
thumbUrl = pickedSku["thumbUrl"].ParseToString();
thumbUrl = thumbUrl.StartsWith("//") ? "https:" + thumbUrl : thumbUrl;
if (productPropList.Count == 1)
{
break;
}
}
if (specFirstValue != null && specs[specFirstIndex]["spec_value_id"].ParseToString() == specFirstValue)
{
specSecondList.Add(specs[1 - specFirstIndex]["spec_value_id"].ParseToString());
pickedSkuList.Add(sku);
}
}
}
if (specSecondList.Count > 0)
{
//比较上传商品中第二组spec中没有的spec进行增加,保证使用最低价格区间的价格并且高于上家价格
int addNewSpecSecondIndex = -1;
for (int i = 0; i < specSecondList.Count; i++)
{
if (!propValueList[1].Contains(specSecondList[i]))
{
foreach (var productSpecFirst in propValueList[0])
{
//在上传商品中增加第二组没有的spec
sbSkuContent.AppendFormat(",{{\"is_onsale\":1,\"limit_quantity\":0,\"price\":\"{0}\",\"weight\":1000,\"multi_price\":\"{1}\"," +
"\"thumb_url\":\"{2}\",\"out_sku_sn\":\"{3}\",\"quantity\":0,\"spec_id_list\":\"[{4}]\",\"defaultQuantity\":0}}",
((int)((lowPrice + 1) * 100)).ToString(),
((int)(lowPrice * 100)).ToString(),
thumbUrl, goodsId.ToString(),
productSpecFirst + "," + ChooseSpecValue(lowPriceSpecs, 2, 1, specSecondList[i]));
}
addNewSpecSecondIndex = i;
//只需要增加一组没有的spec即可
break;
}
}
if (addNewSpecSecondIndex != -1)
{
//增加低价引流商品的一组sku
for (int i = 0; i < propValueList[1].Count; i++)
{
if (specSecondList.Contains(propValueList[1][i]))
{
//增加低价引流中第二组spec在上传商品中存在的
var ind = specSecondList.IndexOf(propValueList[1][i]);
sbSkuContent.AppendFormat(",{{\"is_onsale\":1,\"limit_quantity\":{0},\"price\":\"{1}\",\"weight\":1000,\"multi_price\":\"{2}\"," +
"\"thumb_url\":\"{3}\",\"out_sku_sn\":\"{4}\",\"quantity\":{5},\"spec_id_list\":\"[{6}]\",\"defaultQuantity\":{7}}}",
pickedSkuList[ind]["limitQuantity"].ParseToString(),
((int)((lowPrice + 1) * 100)).ToString(),
((int)(lowPrice * 100)).ToString(),
thumbUrl, goodsId.ToString(), pickedSkuList[ind]["quantity"].ParseToString(),
ChooseSpecValue(lowPriceSpecs, 2, 0, specFirstValue) + "," + ChooseSpecValue(lowPriceSpecs, 2, 1, specSecondList[ind]),
pickedSkuList[ind]["defaultQuantity"].ParseToString());
}
else
{
//在低价引流中增加上传商品有但低价引流第二组spec没有的
sbSkuContent.AppendFormat(",{{\"is_onsale\":1,\"limit_quantity\":0,\"price\":\"{0}\",\"weight\":1000,\"multi_price\":\"{1}\"," +
"\"thumb_url\":\"{2}\",\"out_sku_sn\":\"{3}\",\"quantity\":0,\"spec_id_list\":\"[{4}]\",\"defaultQuantity\":0}}",
((int)((lowPrice + 1) * 100)).ToString(),
((int)(lowPrice * 100)).ToString(),
thumbUrl, goodsId.ToString(),
ChooseSpecValue(lowPriceSpecs, 2, 0, specFirstValue) + "," + propValueList[1][i]);
}
}
//在低价引流中增加上传商品中第二组spec中没有的spec,保证有库存
sbSkuContent.AppendFormat(",{{\"is_onsale\":1,\"limit_quantity\":{0},\"price\":\"{1}\",\"weight\":1000,\"multi_price\":\"{2}\"," +
"\"thumb_url\":\"{3}\",\"out_sku_sn\":\"{4}\",\"quantity\":{5},\"spec_id_list\":\"[{6}]\",\"defaultQuantity\":{7}}}",
pickedSkuList[addNewSpecSecondIndex]["limitQuantity"].ParseToString(),
((int)((lowPrice + 1) * 100)).ToString(),
((int)(lowPrice * 100)).ToString(),
thumbUrl, goodsId.ToString(), pickedSkuList[addNewSpecSecondIndex]["quantity"].ParseToString(),
ChooseSpecValue(lowPriceSpecs, 2, 0, specFirstValue) + "," + ChooseSpecValue(lowPriceSpecs, 2, 1, specSecondList[addNewSpecSecondIndex]),
pickedSkuList[addNewSpecSecondIndex]["defaultQuantity"].ParseToString());
}
}
else if (specFirstValue != null)
{
//只有一个类型的spec
sbSkuContent.AppendFormat(",{{\"is_onsale\":1,\"limit_quantity\":{0},\"price\":\"{1}\",\"weight\":1000,\"multi_price\":\"{2}\"," +
"\"thumb_url\":\"{3}\",\"out_sku_sn\":\"{4}\",\"quantity\":{5},\"spec_id_list\":\"[{6}]\",\"defaultQuantity\":{7}}}",
pickedSku["limitQuantity"].ParseToString(),
((int)((lowPrice + 1) * 100)).ToString(),
((int)(lowPrice * 100)).ToString(),
thumbUrl, goodsId.ToString(), pickedSku["quantity"].ParseToString(),
ChooseSpecValue(lowPriceSpecs, 1, 0, specFirstValue), pickedSku["defaultQuantity"].ParseToString());
}
skuContent = sbSkuContent.ToString();
}
}
}
}
catch (Exception ex)
{
LogSave.Add(ex.ToString());
}
return skuContent;
}
private static string ChooseSpecValue(List<string> lowPriceSpecs, int itemsCount, int itemIndex, string defaultValue)
{
return (lowPriceSpecs != null && lowPriceSpecs.Count == itemsCount && !string.IsNullOrEmpty(lowPriceSpecs[itemIndex])) ? lowPriceSpecs[itemIndex] : defaultValue;
}
public static string MakeRequestForGetPddProdDetailByWeixin(long lProdId)
{
while (true)
{
for (int i = 0; i < GetProxyHtml.loopCount; i++)
{
for (int j = 0; j < GetProxyHtml.ipCount; j++)
{
var proxyObject = GetProxyHtml.GetIPSProxyQueue();
if (proxyObject == null)
continue;
HttpWebResponse response = null;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wxapp.yangkeduo.com/compose/vtx/goods/detail/first/v3?pdduid=4014246301&xcx=20161201&xcx_version=v5.7.6.1&xcx_hash=" + GetTimeStampMilliSec() + GetRandomString(16));
request.KeepAlive = true;
request.Headers.Set(HttpRequestHeader.CacheControl, "no-cache");
request.Headers.Add("GZToken", GetRandomString(32));//@"8dc2715af33d80577efe1cccd945fd38"
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat";
request.ContentType = "application/json;charset=UTF-8";
request.Referer = "https://servicewechat.com/wx32540bd863b27570/1116/page-frame.html";
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
System.Net.WebProxy proxy = proxyObject;
request.Proxy = proxy;
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
string body = @"{""goods_id"":""" + lProdId + @""",""from"":""24"",""has_rec"":true,""address_list"":[{""address_id"":""19159230174"",""province_id"":""3"",""city_id"":""3401"",""district_id"":""4124"",""is_default"":""1"",""is_top"":0}],""page_version"":7,""show_type"":1,""xcx_trace_id"":""" + GetRandomInt(16) + @""",""client_time"":" + GetTimeStampMilliSec() + @",""anti_content"":""3aje" + GetRandomString(122) + @""",""xcx_version"":""v5.7.6.1""}";
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
request.ContentLength = postBytes.Length;
Stream stream = request.GetRequestStream();
stream.Write(postBytes, 0, postBytes.Length);
stream.Close();
response = (HttpWebResponse)request.GetResponse();
GetProxyHtml.IpIndex++;
}
catch
{
}
try
{
string result = ReadResponse(response);
if (result.Contains("goods_detail"))
{
//GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
return result;
}
}
catch
{
}
Thread.Sleep(500);
}
GetProxyHtml.IpList = null;
}
//GlobalProxyHelper.CloseIp(listIp);//没找到也关闭
Thread.Sleep(3000);
}
}
public string GenerateProductInfo(string html)
{
JObject ja = JObject.Parse(html);
try
{
html = html.Replace("\r\n", "").Replace(" ", "");
if (ja["data"]["goods_detail"] != null)
{
string goodStr = ja["data"]["goods_detail"]["goods"].ToString();
pb.from = "拼多多";
pb.id = BaseRegex.GetLongJson(ref goodStr, "goods_id");
pb.from_id = BaseRegex.GetLongJson(ref goodStr, "goods_id");
pb.name = BaseRegex.GetStringJson(ref goodStr, "goods_name");
//pb.name_share = BaseRegex.GetStringJson(ref html, "goods_desc");
pb.from_shop_name = BaseRegex.GetStringJson(ref html, "mall_name");
pb.content_pinduoduo = BaseRegex.GetStringJson(ref html, "goods_desc");
string gallerys = ja["data"]["goods_detail"]["goods"]["gallery"].ToString();
gallerys = gallerys.Replace("\r\n", "").Replace(" ", "");
var m = BaseRegex.GetMatchRegex(ref gallerys, @"{[^}]+?""url""[^}]+?}");
string content = "";
for (int i = m.Count - 1; i >= 0; i--)
{
var item = m[i].Groups[0].Value;
int type = BaseRegex.GetIntJson(ref item, "type");
if (type == 1)
{
string img = BaseRegex.GetStringJson(ref item, "url");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
pb.Images.Add(img);
}
else
{
string img = BaseRegex.GetStringJson(ref item, "url");
if (img.Contains("?"))
img = img.Substring(0, img.IndexOf("?"));
int width = BaseRegex.GetIntJson(ref item, "width");
int height = BaseRegex.GetIntJson(ref item, "height");
content += "<img src='" + img + "'>";
}
}
string skumaps = ja["data"]["goods_detail"]["sku"].ToString();
skumaps = skumaps.Replace("\r\n", "").Replace(" ", "");
m = BaseRegex.GetMatchRegex(ref html, @"\{[^}]+?""sku_id"".*?\}\].*?\}");
for (int i = 0; i < m.Count; i++)
{
string list = m[i].Groups[0].Value;
SkuMapBase s = new SkuMapBase();
s.id = BaseRegex.GetLongJson(ref list, "sku_id");
s.price = BaseRegex.GetDecimalJson(ref list, "group_price") / 100;
if (s.price < 1)
continue;
int num = BaseRegex.GetIntJson(ref list, "quantity");
s.number = BaseRegex.GetIntJson(ref list, "is_onsale") == 1 ? 99 : 0;
if (num < 3)
num = 0;
if (s.number > num)
s.number = num;
s.sale_count = BaseRegex.GetIntJson(ref list, "sold_quantity");
pb.saleCount += s.sale_count;
s.prop_image = BaseRegex.GetStringJson(ref list, "thumb_url");
if (!string.IsNullOrEmpty(s.prop_image))
s.prop_image = s.prop_image.Replace("@750w_1l_50Q", "");
if (s.prop_image.Contains("?"))
s.prop_image = s.prop_image.Substring(0, s.prop_image.IndexOf("?"));
UpPinduoduoProductSet.AddImage(s.prop_image, s.prop_image, 0, 0);
s.name = GetNewName(list, ref pb, s.prop_image);
pb.SkuMaps.Add(s);
}
decimal maxPriceNew = 0;
for (int i = 0; i < pb.SkuMaps.Count; i++)
{
if (maxPriceNew < pb.SkuMaps[i].price)
maxPriceNew = pb.SkuMaps[i].price;
}
string firstSkuImage = pb.SkuMaps[0].prop_image;
#region 原来有
//if (pb.Props.Count == 1)
//{
// for (int j = 0; j < pb.Props[0].Values.Count; j++)
// {
// bool ishad = false;
// for (int k = 0; k < pb.SkuMaps.Count; k++)
// {
// if (pb.SkuMaps[k].name.Contains(pb.Props[0].Values[j].name))
// {
// ishad = true;
// break;
// }
// }
// if (!ishad)
// {
// SkuMapBase sm = new SkuMapBase();
// sm.id = BaseClass.GetTime(DateTime.Today);
// sm.price = maxPriceNew;
// sm.number = 0;
// sm.sale_count = 0;
// pb.saleCount += sm.sale_count;
// sm.prop_image = firstSkuImage;
// sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";";
// pb.SkuMaps.Add(sm);
// }
// }
//}
// if (pb.Props.Count == 2)
// {
// for (int j = 0; j < pb.Props[0].Values.Count; j++)
// {
// for (int k = 0; k < pb.Props[1].Values.Count; k++)
// {
// bool ishad = false;
// for (int l = 0; l < pb.SkuMaps.Count; l++)
// {
// string[] li = pb.SkuMaps[l].name.Split(';');
// if (li.Length == 2)
// {
// string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
// string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
// if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1)
// {
// ishad = true;
// break;
// }
// }
// if (li.Length == 3)
// {
// string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
// string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
// string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
// if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
// || pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
// || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
// {
// ishad = true;
// break;
// }
// }
// if (li.Length == 4)
// {
// string n1 = li[0].Substring(li[0].IndexOf(":") + 1);
// string n2 = li[1].Substring(li[1].IndexOf(":") + 1);
// string n3 = li[2].Substring(li[2].IndexOf(":") + 1);
// string n4 = li[3].Substring(li[3].IndexOf(":") + 1);
// if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
// || pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
// || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
// {
// ishad = true;
// break;
// }
// if (pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n3
//|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n1
//|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n2)
// {
// ishad = true;
// break;
// }
// }
// }
// if (!ishad)
// {
// SkuMapBase sm = new SkuMapBase();
// sm.id = BaseClass.GetTime(DateTime.Today);
// sm.price = maxPriceNew;
// sm.number = 0;
// sm.sale_count = 0;
// pb.saleCount += sm.sale_count;
// sm.prop_image = firstSkuImage;
// sm.name = pb.Props[0].name + ":" + pb.Props[0].Values[j].name + ";" + pb.Props[1].name + ":" + pb.Props[1].Values[k].name + ";";
// pb.SkuMaps.Add(sm);
// }
// }
// }
// }
#endregion
pb.cat1 = BaseRegex.GetIntJson(ref goodStr, "cat_id_1");
pb.cat2 = BaseRegex.GetIntJson(ref goodStr, "cat_id_2");
pb.cat3 = BaseRegex.GetIntJson(ref goodStr, "cat_id_3");
pb.cat_id = BaseRegex.GetIntJson(ref goodStr, "cat_id");
if (pb.cat_id != pb.cat3)
pb.cat4 = pb.cat_id;
int cid = PinduoduoCatList.GetNewCat3(pb.cat_id);
if (PinduoduoCatList.CatIds.ContainsKey(cid))
{
var ci = PinduoduoCatList.CatIds[cid];
pb.cat_id = ci.id;
pb.cat1 = ci.cat1;
pb.cat2 = ci.cat2;
pb.cat3 = ci.cat3;
pb.cat4 = ci.cat4;
pb.main_cid = ci.main_cat_id;
}
pb.before_price = BaseRegex.GetIntJson(ref goodStr, "market_price") / 100m;
pb.content = content;
var ft = new FromTitleToCat();
pb.main_cid = ft.GetMainCatId(pb.cat1);
pb.main_cat_name = ft.MainCatName;
string goodPropertyStr = ja["data"]["goods_detail"]["goods"]["goods_property"].ToString();
goodPropertyStr = goodPropertyStr.Replace("\r\n", "").Replace(" ", "");
m = BaseRegex.GetMatchRegex(ref goodPropertyStr, @"\{[^}]+?""values"":\[([\w\W]+?)\],""key"":""([^""]+?)""\}");
for (int i = 0; m != null && i < m.Count; i++)
{
string name = m[i].Groups[2].Value;
string val = m[i].Groups[1].Value;
var list = BaseRegex.GetMatchRegex(ref val, @"""([^""]+?)""");
string v = "";
for (int j = 0; list != null && j < list.Count; j++)
v += "、" + list[j].Groups[1].Value;
if (!string.IsNullOrEmpty(v))
v = v.Substring(1);
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(v))
pb.Prop.Add(new KeyValueBase(name, v));
}
pb.mall_id = BaseRegex.GetLongJson(ref goodStr, "mall_id");
pb.from_site_id = 2;
pb.price = 0;
if (pb.price == 0 && pb.SkuMaps.Count > 0)
pb.price = pb.SkuMaps[0].price;
string sale = BaseRegex.GetStringJson(ref goodStr, "side_sales_tip");
sale = BaseRegex.GetMatchRegexString(ref sale, @"([\d\.万]+)");
if (!string.IsNullOrEmpty(sale))
{
sale = sale.Replace(".", "").Replace("万", "0000");
int sa = 0;
int.TryParse(sale, out sa);
pb.saleCount = sa;
}
//if (!userData)
// ServerTemp.Set(2, Product.FromId.ToString(), html);
if (html.Contains("class=\"RWpliLUr\"") && html.Contains("https://pinduoduoimg.yangkeduo.com/deposit/global_shopping.png"))
{
pb.main_cid = Product.MainCatId = 8;
pb.main_cat_name = Product.MainCatName = "海淘进口";
pb.country = Product.country = BaseRegex.GetStringJson(ref html, "countryDesc").Replace("品牌", "");
}
if (TaobaoMobileCollect.ProductTemp.Count > 1000)
{
TaobaoMobileCollect.ProductTemp.Clear();
}
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(pb.from_id))
{
try
{
TaobaoMobileCollect.ProductTemp.Add(pb.from_id, pb);
}
catch
{
}
}
else
{
TaobaoMobileCollect.ProductTemp[pb.from_id] = pb;
}
}
}
catch
{
}
return "";
}
public string GetName(string list, ref ProductCollectBase pb, string image)
{
string temp = "";
var m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)"",""spec_key_id"":([\d]+),""spec_value_id"":([\d]+)");
if (m.Count == 0)
m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)""");
if (m.Count == 0)
m = BaseRegex.GetMatchRegex(ref list, @"\{""spec_value_id"":([\d]+),""spec_key"":""([^""]+?)"",""spec_value"":""([^""]+?)"",""spec_key_id"":([\d]+)");
for (int i = 0; i < m.Count; i++)
{
temp += m[i].Groups[1].Value + ":" + m[i].Groups[2].Value + ";";
bool had = false;
PropBase p = new PropBase();
for (int j = 0; j < pb.Props.Count; j++)
{
if (pb.Props[j].name == m[i].Groups[1].Value)
{
had = true;
p = pb.Props[j];
break;
}
}
if (!had)
{
p = new PropBase();
p.name = m[i].Groups[1].Value;
if (m[i].Groups.Count > 3)
p.pinduoduo_id = m[i].Groups[3].Value;
pb.Props.Add(p);
}
had = false;
for (int j = 0; j < p.Values.Count; j++)
{
if (p.Values[j].name == m[i].Groups[2].Value)
{
p.Values[j].image = image;
p.Values[j].image_from_url = image;
had = true;
break;
}
}
if (!had)
{
PropValueBase pv = new PropValueBase();
if (m[i].Groups.Count > 4)
pv.id = m[i].Groups[4].Value;
pv.name = m[i].Groups[2].Value;
pv.image = image;
pv.image_from_url = image;
p.Values.Add(pv);
}
}
return temp;
}
private static string GetRandomString(int iLength)
{
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
Random rd = new Random();
for (int i = 0; i < iLength; i++)
{
newRandom.Append(constant[rd.Next(62)]);
}
return newRandom.ToString();
}
private static string GetRandomInt(int iLength)
{
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
Random rd = new Random();
for (int i = 0; i < iLength; i++)
{
newRandom.Append(constInt[rd.Next(9)]);
}
return newRandom.ToString();
}
private static char[] constant =
{
'0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
};
private static char[] constInt =
{
'1','2','3','4','5','6','7','8','9'
};
public static string GetTimeStampMilliSec()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalMilliseconds).ToString();
}
public static string ReadResponse(HttpWebResponse response)
{
using (Stream responseStream = response.GetResponseStream())
{
Stream streamToRead = responseStream;
if (response.ContentEncoding.ToLower().Contains("gzip"))
{
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
}
else if (response.ContentEncoding.ToLower().Contains("deflate"))
{
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
}
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8))
{
return streamReader.ReadToEnd();
}
}
}
}
public class TData<T>
{
/// <summary>
/// 操作结果,Tag为1代表成功,0代表失败,其他的验证返回结果,可根据需要设置
/// </summary>
public int Tag { get; set; }
/// <summary>
/// 提示信息或异常信息
/// </summary>
public string Message { get; set; }
/// <summary>
/// 扩展Message
/// </summary>
public string Description { get; set; }
/// <summary>
/// 列表的记录数
/// </summary>
public int TotalCount { get; set; }
/// <summary>
/// 数据
/// </summary>
public T Result { get; set; }
}
public class PinDuoDuoTokenInfo
{
public long UserId { get; set; }
public string PDDAccessToken { get; set; }
public int ProductDetailStatus { get; set; }
public int LoginStatus { get; set; }
public int SearchStatus { get; set; }
public bool IsCaptcha { get; set; }
}
public enum TokenStatus
{
Dead = -1,
Invalid = 0,
Valid = 1
}
}