temu客户端程序
This commit is contained in:
commit
4aaf264e89
694 files changed
+263780
No files matched your search
@@ -0,0 +1,938 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AllBase;
|
||||
using Work.Api;
|
||||
using Work.CollectClass;
|
||||
|
||||
namespace Work.ManageClass
|
||||
{
|
||||
public class UpPinduoduoProduct
|
||||
{
|
||||
public static string ExpressId = "";
|
||||
public static int NoReplaceDay = 0;
|
||||
public static int LimitBuy, GroupCount, LimitBuyTimes, AddPercent, AddPrice, SingleBuyAddPrice, BaseBuy, BaseBuyAdd, ThreadCount;
|
||||
public static bool RandAddPrice = false, CatSame = false, NoReplaceDays = false;
|
||||
public static Dictionary<long, DateTime> EditDayTemp = new Dictionary<long, DateTime>();
|
||||
public static Dictionary<int, Dictionary<string, PinduoduoPropBase>> PinduoduoProp = new Dictionary<int, Dictionary<string, PinduoduoPropBase>>();
|
||||
public static string Name;
|
||||
public static List<TaobaoProductBase> ProductTemp = new List<TaobaoProductBase>();
|
||||
public UpPinduoduoProduct(ShopChatBase shop,string name)
|
||||
{
|
||||
Shop = shop;
|
||||
Name = name;
|
||||
}
|
||||
public UpPinduoduoProduct()
|
||||
{
|
||||
}
|
||||
|
||||
public ShopChatBase Shop = null;
|
||||
/// <summary>
|
||||
/// 初始化属性名称
|
||||
/// </summary>
|
||||
public void IniProp(int mainCatId, string cookies)
|
||||
{
|
||||
if (PinduoduoProp.ContainsKey(mainCatId) && PinduoduoProp[mainCatId].Count > 0)
|
||||
return;
|
||||
Dictionary<string, PinduoduoPropBase> props = new Dictionary<string, PinduoduoPropBase>();
|
||||
PinduoduoApiPropId p = new PinduoduoApiPropId(Shop);
|
||||
string html = p.Get(mainCatId);
|
||||
var mm = BaseRegex.GetMatchRegex(ref html,
|
||||
@"\{""parent_spec_id"":([\d]+),""cat_id"":[\d]+,""parent_spec_name"":""([^""]+?)""");
|
||||
for (int j = 0; mm != null && j < mm.Count; j++)
|
||||
{
|
||||
PinduoduoPropBase pp = new PinduoduoPropBase();
|
||||
pp.Name = mm[j].Groups[2].Value;
|
||||
pp.Id = mm[j].Groups[1].Value;
|
||||
try
|
||||
{
|
||||
props.Add(pp.Name, pp);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
if (props.Count > 0)
|
||||
PinduoduoProp.Add(mainCatId, props);
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
}
|
||||
if (props.Count > 0)
|
||||
return;
|
||||
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/name/list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(30 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(30 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
//MessageBox.Show("请不要单个店铺同时开多个软件上传\r\n请调整", "提示");
|
||||
Thread.Sleep(60 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(60 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""value"":""(.*?)""");
|
||||
for (int j = 0; m != null && j < m.Count; j++)
|
||||
{
|
||||
PinduoduoPropBase pp = new PinduoduoPropBase();
|
||||
pp.Name = m[j].Groups[1].Value;
|
||||
try
|
||||
{
|
||||
if (!props.ContainsKey(pp.Name))
|
||||
props.Add(pp.Name, pp);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
PinduoduoProp.Add(mainCatId, props);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动给无图片的SKU识别对应的图片
|
||||
/// </summary>
|
||||
/// <param name="p"></param>
|
||||
public void BuildSkuMapProps(ref ProductCollectBase p)
|
||||
{
|
||||
if (p.Props.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string cookies = Shop.Cookies;
|
||||
int mainCatId = Shop.MainCatId;
|
||||
int maxImageCut = 0, maxImageCount = 0;
|
||||
for (int i = 0; i < p.Props.Count; i++)
|
||||
{
|
||||
//if (p.Props[i].Values.Count <= 1 && p.from == "淘宝"&&p.cat_id != 3109)//只有一个属性的删除
|
||||
//{
|
||||
// p.Props.RemoveAt(i);
|
||||
// i--;
|
||||
// continue;
|
||||
//}
|
||||
for (int j = 0; j < p.Props[i].Values.Count; j++)
|
||||
{
|
||||
if ( p.Props[i].Values[j].name.Contains("代理"))
|
||||
p.Props[i].Values.RemoveAt(j);
|
||||
continue;
|
||||
}
|
||||
|
||||
int imageCount = 0;
|
||||
for (int j = 0; j < p.Props[i].Values.Count; j++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(p.Props[i].Values[j].image))
|
||||
imageCount++;
|
||||
|
||||
}
|
||||
if (imageCount > maxImageCount)
|
||||
{
|
||||
maxImageCount = imageCount;
|
||||
maxImageCut = i;
|
||||
}
|
||||
}
|
||||
if (p.Props.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string[] l = @"客服
|
||||
QQ
|
||||
定制品
|
||||
定制
|
||||
定金
|
||||
差价
|
||||
限量
|
||||
联系
|
||||
VX
|
||||
抽奖
|
||||
留言
|
||||
明式
|
||||
四季
|
||||
特价
|
||||
专拍
|
||||
补差
|
||||
尺寸
|
||||
价格
|
||||
客服
|
||||
运费到付
|
||||
发货
|
||||
直接拍
|
||||
运费险
|
||||
团购
|
||||
".Split('\n');
|
||||
for (int i = 0; i < p.SkuMaps.Count; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(p.SkuMaps[i].prop_image))
|
||||
{
|
||||
foreach (string s in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
continue;
|
||||
string m = s.Trim();
|
||||
BaseRegex.Relpace(ref p.SkuMaps[i].name, m, "");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (int j = 0; j < p.Props[maxImageCut].Values.Count; j++)
|
||||
{
|
||||
if (p.SkuMaps[i].name.Contains(p.Props[maxImageCut].Values[j].name))
|
||||
{
|
||||
p.SkuMaps[i].prop_image = p.Props[maxImageCut].Values[j].image;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (string s in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
continue;
|
||||
string m = s.Trim();
|
||||
BaseRegex.Relpace(ref p.SkuMaps[i].name, m, "");
|
||||
}
|
||||
|
||||
}
|
||||
int cut = 0;
|
||||
for (int i = 0; i < p.SkuMaps.Count; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(p.SkuMaps[i].prop_image))
|
||||
continue;
|
||||
p.SkuMaps[i].prop_image = p.Images[cut];
|
||||
cut++;
|
||||
if (cut >= p.Images.Count)
|
||||
cut = 0;
|
||||
}
|
||||
if (p.Props.Count > 2 && p.from == "淘宝")//两个属性以上,去掉一个
|
||||
{
|
||||
int minCount = 100, minCut = -1;
|
||||
for (int i = 0; i < p.Props.Count; i++)
|
||||
{
|
||||
if (p.Props[i].Values.Count < minCount && string.IsNullOrEmpty(p.Props[i].Values[0].image))
|
||||
{
|
||||
minCount = p.Props[i].Values.Count;
|
||||
minCut = i;
|
||||
}
|
||||
}
|
||||
if (minCut > -1)
|
||||
{
|
||||
p.Props.RemoveAt(minCut);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cutId = 0;
|
||||
PinduoduoPropBase first = new PinduoduoPropBase();
|
||||
PinduoduoPropBase second = new PinduoduoPropBase();
|
||||
if (!PinduoduoProp.ContainsKey(mainCatId))
|
||||
{
|
||||
LogSave.Add(Name, "分类初始化异常,请重新打开软件");
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < p.Props.Count; j++)
|
||||
{
|
||||
foreach (KeyValuePair<string, PinduoduoPropBase> pb in PinduoduoProp[mainCatId])
|
||||
{
|
||||
if (cutId == 0)
|
||||
first = pb.Value;
|
||||
if (cutId == 1)
|
||||
second = pb.Value;
|
||||
if (pb.Key == p.Props[j].name)
|
||||
{
|
||||
p.Props[j].pinduoduo_name = pb.Key;
|
||||
if (p.cat_id != 3109 || (p.cat_id == 3109 && p.Props[j].pinduoduo_name != "容量"))
|
||||
p.Props[j].pinduoduo_id = pb.Value.Id;
|
||||
break;
|
||||
}
|
||||
cutId++;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < p.Props.Count; j++)
|
||||
{
|
||||
foreach (KeyValuePair<string, PinduoduoPropBase> pb in PinduoduoProp[mainCatId])
|
||||
{
|
||||
if (string.IsNullOrEmpty(p.Props[j].pinduoduo_name) && p.Props[j].name.Contains(pb.Key))
|
||||
{
|
||||
p.Props[j].pinduoduo_name = pb.Key;
|
||||
if (p.cat_id != 3109||(p.cat_id == 3109 && p.Props[j].pinduoduo_name!="容量"))
|
||||
p.Props[j].pinduoduo_id = pb.Value.Id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (p.Props.Count == 1 && string.IsNullOrEmpty(p.Props[0].pinduoduo_name))
|
||||
{
|
||||
p.Props[0].pinduoduo_name = first.Name;
|
||||
p.Props[0].pinduoduo_id = first.Id;
|
||||
}
|
||||
else if (p.Props.Count == 2)
|
||||
{
|
||||
if (string.IsNullOrEmpty(p.Props[0].pinduoduo_name) &&
|
||||
string.IsNullOrEmpty(p.Props[1].pinduoduo_name))
|
||||
{
|
||||
p.Props[0].pinduoduo_name = first.Name;
|
||||
p.Props[0].pinduoduo_id = first.Id;
|
||||
p.Props[1].pinduoduo_name = second.Name;
|
||||
p.Props[1].pinduoduo_id = second.Id;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(p.Props[0].pinduoduo_name))
|
||||
{
|
||||
if (p.Props[1].pinduoduo_name == first.Name)
|
||||
{
|
||||
p.Props[0].pinduoduo_name = second.Name;
|
||||
p.Props[0].pinduoduo_id = second.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Props[0].pinduoduo_name = first.Name;
|
||||
p.Props[0].pinduoduo_id = first.Id;
|
||||
}
|
||||
}
|
||||
else if (string.IsNullOrEmpty(p.Props[1].pinduoduo_name))
|
||||
{
|
||||
if (p.Props[0].pinduoduo_name == first.Name)
|
||||
{
|
||||
p.Props[1].pinduoduo_name = second.Name;
|
||||
p.Props[1].pinduoduo_id = second.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
p.Props[1].pinduoduo_name = first.Name;
|
||||
p.Props[1].pinduoduo_id = first.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < p.Props.Count; i++)
|
||||
{
|
||||
if (p.cat3 == 3109 && p.Props[i].name.Contains("容量"))
|
||||
continue;
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
if (string.IsNullOrEmpty(p.Props[i].pinduoduo_id) || p.Props[i].pinduoduo_id == "0")
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/by/name";
|
||||
string data = "{\"parent_id\":0,\"name\":\"" + p.Props[i].pinduoduo_name + "\"}";
|
||||
string html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
string id = BaseRegex.GetLongJson(ref html, "result").ToString();
|
||||
if (id == "0")
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
id = BaseRegex.GetLongJson(ref html, "spec_id").ToString();
|
||||
}
|
||||
if (id == "0")
|
||||
{
|
||||
LogSave.Add(Name, "获取类别ID异常:" + p.Props[i].pinduoduo_name);
|
||||
continue;
|
||||
}
|
||||
if (PinduoduoProp[mainCatId].ContainsKey(p.Props[i].pinduoduo_name))
|
||||
PinduoduoProp[mainCatId][p.Props[i].pinduoduo_name].Id = id;
|
||||
p.Props[i].pinduoduo_id = id;
|
||||
}
|
||||
|
||||
for (int j = 0; j < p.Props[i].Values.Count; j++)
|
||||
{
|
||||
//if (p.from_site_id == 1 && j > 12 && p.Props[i].Values.Count > 12)//属性元素超过15个的就丢弃
|
||||
//{
|
||||
// p.Props[i].Values.RemoveAt(j);
|
||||
// j--;
|
||||
// continue;
|
||||
//}
|
||||
foreach (string s in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
continue;
|
||||
string m = s.Trim();
|
||||
BaseRegex.Relpace(ref p.Props[i].Values[j].name, m, "");
|
||||
}
|
||||
|
||||
if (PinduoduoProp[mainCatId].ContainsKey(p.Props[i].pinduoduo_name) &&
|
||||
PinduoduoProp[mainCatId][p.Props[i].pinduoduo_name].Values.ContainsKey(p.Props[i].Values[j].name))
|
||||
{
|
||||
p.Props[i].Values[j].id =
|
||||
PinduoduoProp[mainCatId][p.Props[i].pinduoduo_name].Values[p.Props[i].Values[j].name].ToString();
|
||||
continue;
|
||||
}
|
||||
string html, propvid="";
|
||||
if (BaseClass.UseApiFirst)
|
||||
{
|
||||
PinduoduoApiPropId api = new PinduoduoApiPropId(Shop);
|
||||
html = api.GetPropId(p.Props[i].pinduoduo_id, p.Props[i].Values[j].name);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "spec_id");
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/by/name";
|
||||
string data = "{\"parent_id\":" + p.Props[i].pinduoduo_id + ",\"name\":\"" +
|
||||
p.Props[i].Values[j].name + "\"}";
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/by/name";
|
||||
string data = "{\"parent_id\":" + p.Props[i].pinduoduo_id + ",\"name\":\"" + p.Props[i].Values[j].name + "\"}";
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
if(html.Contains("规格名称字数过长"))
|
||||
{
|
||||
string title = p.Props[i].Values[j].name;
|
||||
if (BaseClass.GetCharLength(title) > 30)
|
||||
title = BaseClass.SubCharLength(title, 30);
|
||||
data = "{\"parent_id\":" + p.Props[i].pinduoduo_id + ",\"name\":\"" + title + "\"}";
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
}
|
||||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||||
}
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
PinduoduoApiPropId api = new PinduoduoApiPropId(Shop);
|
||||
html = api.GetPropId(p.Props[i].pinduoduo_id, p.Props[i].Values[j].name);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "spec_id");
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
p.Props[i].Values.RemoveAt(j);
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
|
||||
p.Props[i].Values[j].id = propvid;
|
||||
try
|
||||
{
|
||||
PinduoduoProp[mainCatId][p.Props[i].pinduoduo_name].Values.Add(p.Props[i].Values[j].name, long.Parse(p.Props[i].Values[j].id));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void BuildSkuMapProps(ref ProductCollectBase prod, string cookies, int mainCatId)
|
||||
{
|
||||
if (prod.Props.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int maxImageCut = 0, maxImageCount = 0;
|
||||
for (int i = 0; i < prod.Props.Count; i++)
|
||||
{
|
||||
if (prod.Props[i].Values.Count <= 1 && prod.from == "淘宝")//只有一个属性的删除
|
||||
{
|
||||
prod.Props.RemoveAt(i);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
|
||||
int imageCount = 0;
|
||||
for (int j = 0; j < prod.Props[i].Values.Count; j++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.Props[i].Values[j].image))
|
||||
imageCount++;
|
||||
}
|
||||
if (imageCount > maxImageCount)
|
||||
{
|
||||
maxImageCount = imageCount;
|
||||
maxImageCut = i;
|
||||
}
|
||||
}
|
||||
if (prod.Props.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < prod.SkuMaps.Count; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.SkuMaps[i].prop_image))
|
||||
continue;
|
||||
for (int j = 0; j < prod.Props[maxImageCut].Values.Count; j++)
|
||||
{
|
||||
if (prod.SkuMaps[i].name.Contains(prod.Props[maxImageCut].Values[j].name))
|
||||
{
|
||||
prod.SkuMaps[i].prop_image = prod.Props[maxImageCut].Values[j].image;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
int cut = 0;
|
||||
for (int i = 0; i < prod.SkuMaps.Count; i++)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.SkuMaps[i].prop_image))
|
||||
continue;
|
||||
prod.SkuMaps[i].prop_image = prod.Images[cut];
|
||||
cut++;
|
||||
if (cut >= prod.Images.Count)
|
||||
cut = 0;
|
||||
}
|
||||
if (prod.Props.Count > 2 && prod.from == "淘宝")//两个属性以上,去掉一个
|
||||
{
|
||||
int minCount = 100, minCut = -1;
|
||||
for (int i = 0; i < prod.Props.Count; i++)
|
||||
{
|
||||
if (prod.Props[i].Values.Count < minCount && string.IsNullOrEmpty(prod.Props[i].Values[0].image))
|
||||
{
|
||||
minCount = prod.Props[i].Values.Count;
|
||||
minCut = i;
|
||||
}
|
||||
}
|
||||
if (minCut > -1)
|
||||
{
|
||||
prod.Props.RemoveAt(minCut);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int cutId = 0;
|
||||
PinduoduoPropBase first = new PinduoduoPropBase();
|
||||
PinduoduoPropBase second = new PinduoduoPropBase();
|
||||
if (!PinduoduoProp.ContainsKey(mainCatId))
|
||||
{
|
||||
LogSave.Add(Name, "分类初始化异常,请重新打开软件");
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < prod.Props.Count; j++)
|
||||
{
|
||||
foreach (KeyValuePair<string, PinduoduoPropBase> pb in PinduoduoProp[mainCatId])
|
||||
{
|
||||
if (cutId == 0)
|
||||
first = pb.Value;
|
||||
if (cutId == 1)
|
||||
second = pb.Value;
|
||||
if (pb.Key == prod.Props[j].name)
|
||||
{
|
||||
prod.Props[j].pinduoduo_name = pb.Key;
|
||||
prod.Props[j].pinduoduo_id = pb.Value.Id;
|
||||
break;
|
||||
}
|
||||
cutId++;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < prod.Props.Count; j++)
|
||||
{
|
||||
foreach (KeyValuePair<string, PinduoduoPropBase> pb in PinduoduoProp[mainCatId])
|
||||
{
|
||||
if (string.IsNullOrEmpty(prod.Props[j].pinduoduo_name) && prod.Props[j].name.Contains(pb.Key))
|
||||
{
|
||||
prod.Props[j].pinduoduo_name = pb.Key;
|
||||
prod.Props[j].pinduoduo_id = pb.Value.Id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prod.Props.Count == 1 && string.IsNullOrEmpty(prod.Props[0].pinduoduo_name))
|
||||
{
|
||||
prod.Props[0].pinduoduo_name = first.Name;
|
||||
prod.Props[0].pinduoduo_id = first.Id;
|
||||
}
|
||||
else if (prod.Props.Count == 2)
|
||||
{
|
||||
if (string.IsNullOrEmpty(prod.Props[0].pinduoduo_name) &&
|
||||
string.IsNullOrEmpty(prod.Props[1].pinduoduo_name))
|
||||
{
|
||||
prod.Props[0].pinduoduo_name = first.Name;
|
||||
prod.Props[0].pinduoduo_id = first.Id;
|
||||
prod.Props[1].pinduoduo_name = second.Name;
|
||||
prod.Props[1].pinduoduo_id = second.Id;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(prod.Props[0].pinduoduo_name))
|
||||
{
|
||||
if (prod.Props[1].pinduoduo_name == first.Name)
|
||||
{
|
||||
prod.Props[0].pinduoduo_name = second.Name;
|
||||
prod.Props[0].pinduoduo_id = second.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
prod.Props[0].pinduoduo_name = first.Name;
|
||||
prod.Props[0].pinduoduo_id = first.Id;
|
||||
}
|
||||
}
|
||||
else if (string.IsNullOrEmpty(prod.Props[1].pinduoduo_name))
|
||||
{
|
||||
if (prod.Props[0].pinduoduo_name == first.Name)
|
||||
{
|
||||
prod.Props[1].pinduoduo_name = second.Name;
|
||||
prod.Props[1].pinduoduo_id = second.Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
prod.Props[1].pinduoduo_name = first.Name;
|
||||
prod.Props[1].pinduoduo_id = first.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < prod.Props.Count; i++)
|
||||
{
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
if (string.IsNullOrEmpty(prod.Props[i].pinduoduo_id) || prod.Props[i].pinduoduo_id == "0")
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/by/name";
|
||||
string data = "{\"parent_id\":0,\"name\":\"" + prod.Props[i].pinduoduo_name + "\"}";
|
||||
string html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
string id = BaseRegex.GetLongJson(ref html, "result").ToString();
|
||||
if (id == "0")
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
id = BaseRegex.GetLongJson(ref html, "spec_id").ToString();
|
||||
}
|
||||
if (id == "0")
|
||||
{
|
||||
LogSave.Add(Name, "获取类别ID异常:" + prod.Props[i].pinduoduo_name);
|
||||
continue;
|
||||
}
|
||||
if (PinduoduoProp[mainCatId].ContainsKey(prod.Props[i].pinduoduo_name))
|
||||
PinduoduoProp[mainCatId][prod.Props[i].pinduoduo_name].Id = id;
|
||||
prod.Props[i].pinduoduo_id = id;
|
||||
}
|
||||
|
||||
for (int j = 0; j < prod.Props[i].Values.Count; j++)
|
||||
{
|
||||
//if (prod.from_site_id == 1 && j >= 30 && prod.Props[i].Values.Count >= 30) // 属性元素超过30个的就丢弃
|
||||
//{
|
||||
// prod.Props[i].Values.RemoveAt(j);
|
||||
// j--;
|
||||
// continue;
|
||||
//}
|
||||
|
||||
if (PinduoduoProp[mainCatId].ContainsKey(prod.Props[i].pinduoduo_name) &&
|
||||
PinduoduoProp[mainCatId][prod.Props[i].pinduoduo_name].Values.ContainsKey(prod.Props[i].Values[j].name))
|
||||
{
|
||||
prod.Props[i].Values[j].id =
|
||||
PinduoduoProp[mainCatId][prod.Props[i].pinduoduo_name].Values[prod.Props[i].Values[j].name].ToString();
|
||||
continue;
|
||||
}
|
||||
PinduoduoApiPropId api = new PinduoduoApiPropId(Shop);
|
||||
string html = api.GetPropId(prod.Props[i].pinduoduo_id, prod.Props[i].Values[j].name);
|
||||
string propvid = BaseRegex.GetStringJson(ref html, "spec_id");
|
||||
if (!string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
prod.Props[i].Values[j].id = propvid;
|
||||
try
|
||||
{
|
||||
PinduoduoProp[mainCatId][prod.Props[i].pinduoduo_name].Values.Add(prod.Props[i].Values[j].name, long.Parse(prod.Props[i].Values[j].id));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
continue;
|
||||
}
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/by/name";
|
||||
string data = "{\"parent_id\":" + prod.Props[i].pinduoduo_id + ",\"name\":\"" + prod.Props[i].Values[j].name + "\"}";
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||||
}
|
||||
if (string.IsNullOrEmpty(propvid))
|
||||
{
|
||||
prod.Props[i].Values.RemoveAt(j);
|
||||
j--;
|
||||
continue;
|
||||
}
|
||||
|
||||
prod.Props[i].Values[j].id = propvid;
|
||||
try
|
||||
{
|
||||
PinduoduoProp[mainCatId][prod.Props[i].pinduoduo_name].Values.Add(prod.Props[i].Values[j].name, long.Parse(prod.Props[i].Values[j].id));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
public static Dictionary<string, int> PriceTemp = new Dictionary<string, int>();
|
||||
public static int GetNewPrice(decimal beforePrice, int addPercent, int addPrice, long pid, int addSinglePrice, decimal maxPrice)
|
||||
{
|
||||
//if (UserStepPrice)
|
||||
//{
|
||||
// int p = (int)(beforePrice * 100) + PriceAllAdd*100;
|
||||
// if (beforePrice >= PriceBefor1 && beforePrice <= PriceEnd1)
|
||||
// return p + PriceAdd1 * 100;
|
||||
// if (beforePrice >= PriceBefor2 && beforePrice <= PriceEnd2)
|
||||
// return p + PriceAdd2 * 100;
|
||||
// if (beforePrice >= PriceBefor3 && beforePrice <= PriceEnd3)
|
||||
// return p + PriceAdd3 * 100;
|
||||
// if (beforePrice >= PriceBefor4 && beforePrice <= PriceEnd4)
|
||||
// return p + PriceAdd4 * 100;
|
||||
// if (beforePrice >= PriceBefor5 && beforePrice <= PriceEnd5)
|
||||
// return p + PriceAdd5 * 100;
|
||||
//}
|
||||
|
||||
if (beforePrice < 1)
|
||||
beforePrice = maxPrice;
|
||||
if (beforePrice < 1)
|
||||
beforePrice = 10000;
|
||||
int before = (int)(beforePrice * 100);
|
||||
string key = pid + "," + before + "," + addPercent + "," + addPrice + "," + addSinglePrice;
|
||||
int price;
|
||||
if (PriceTemp.ContainsKey(key))
|
||||
{
|
||||
price = PriceTemp[key];
|
||||
return price;
|
||||
}
|
||||
//if (addSinglePrice == 0)
|
||||
// {
|
||||
price = before * (100 + addPercent) / 100 + addPrice * 100 + (RandAddPrice ? new Random(Guid.NewGuid().GetHashCode()).Next(10, 90) : 0);
|
||||
// }
|
||||
// else
|
||||
// price = (int)((beforePrice + addSinglePrice) * 100) + (RandAddPrice ? new Random(Guid.NewGuid().GetHashCode()).Next(10, 90) : 0);
|
||||
try
|
||||
{
|
||||
PriceTemp.Add(key, price);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
public static string UploadImage(byte[] img)
|
||||
{
|
||||
return UploadImage(img, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 上传图片
|
||||
/// </summary>
|
||||
/// <param name="img"></param>
|
||||
/// <returns></returns>
|
||||
public static string UploadImage(byte[] img, ShopChatBase Shop)
|
||||
{
|
||||
PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||||
string html = p.UploadImage(img);
|
||||
string imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||||
if (string.IsNullOrEmpty(imgUrl))
|
||||
{
|
||||
string Cookies = Shop.Cookies;
|
||||
string url = "https://mms.pinduoduo.com/earth/api/upload/getSignature";
|
||||
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=5146155709&type=edit&from=category";
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{}", Cookies);
|
||||
string sign = BaseRegex.GetStringJson(ref html, "signature");
|
||||
if (string.IsNullOrEmpty(sign))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
string data =
|
||||
"{\"upload_sign\":\"" + sign + "\",\"image\":\"data:image/jpeg;base64," +
|
||||
Convert.ToBase64String(img) + "\"}";
|
||||
url = "https://file.yangkeduo.com/v2/store_image";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Cookies);
|
||||
imgUrl = BaseRegex.GetStringJson(ref html, "url");
|
||||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||||
return imgUrl;
|
||||
}
|
||||
return imgUrl;
|
||||
}
|
||||
|
||||
|
||||
public static Dictionary<string, int> TypeName = new Dictionary<string, int>();
|
||||
public static Dictionary<string, int> TypeValues = new Dictionary<string, int>();
|
||||
private static int firstKeyId = 0, firstValueId = 0;
|
||||
public static string AddType(ref ProductCollectBase p, int mainCatId, string cookies, int mallId)
|
||||
{
|
||||
if (mainCatId == 5)
|
||||
{
|
||||
if (TypeName.Count == 0)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/malls/" + mallId + "/transport/glide/query/clothes_fabric/list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, "{}", cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""code"":([\d]+),""desc"":""(.*?)""");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
string name = m[i].Groups[2].Value;
|
||||
int value = int.Parse(m[i].Groups[1].Value);
|
||||
if (firstKeyId == 0)
|
||||
firstKeyId = value;
|
||||
if (!TypeName.ContainsKey(name))
|
||||
TypeName.Add(name, value);
|
||||
}
|
||||
}
|
||||
if (TypeValues.Count == 0)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/malls/" + mallId + "/transport/glide/query/clothes_fabric_content/list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, "{}", cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""code"":([\d]+),""desc"":""(.*?)""");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
string name = m[i].Groups[2].Value;
|
||||
int value = int.Parse(m[i].Groups[1].Value);
|
||||
if (firstValueId == 0)
|
||||
firstValueId = value;
|
||||
if (!TypeValues.ContainsKey(name))
|
||||
TypeValues.Add(name, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mainCatId == 5)
|
||||
{
|
||||
string name = "材质成分";
|
||||
string value = "";
|
||||
for (int i = 0; i < p.Prop.Count; i++)
|
||||
{
|
||||
if (p.Prop[i].Key == name)
|
||||
{
|
||||
value = p.Prop[i].Value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int keyId = 0, valueId = 0;
|
||||
if (!string.IsNullOrEmpty(value) && value.Contains("%"))
|
||||
{
|
||||
string v = BaseRegex.GetMatchRegexString(ref value, @"([\d]+)%");
|
||||
string namex = value.Substring(0, value.IndexOf(v + "%"));
|
||||
if (string.IsNullOrEmpty(v) || string.IsNullOrEmpty(namex))
|
||||
{
|
||||
goto NoValue;
|
||||
}
|
||||
int pe = int.Parse(v);
|
||||
|
||||
foreach (KeyValuePair<string, int> k in TypeName)
|
||||
{
|
||||
if (k.Key.Contains(namex) || namex.Contains(k.Key))
|
||||
{
|
||||
keyId = k.Value;
|
||||
foreach (KeyValuePair<string, int> vv in TypeValues)
|
||||
{
|
||||
var mm = BaseRegex.GetMatchRegex(vv.Key, @"([\d]+)%");
|
||||
if (mm.Count == 2)
|
||||
{
|
||||
int min = int.Parse(mm[0].Groups[1].Value);
|
||||
int max = int.Parse(mm[1].Groups[1].Value);
|
||||
if (pe >= min && pe <= max)
|
||||
{
|
||||
valueId = vv.Value;
|
||||
goto NoValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
NoValue:
|
||||
if (keyId == 0)
|
||||
keyId = firstKeyId;
|
||||
if (valueId == 0)
|
||||
valueId = firstValueId;
|
||||
string addContent = ",\"fabric\":" + keyId + ",\"fabric_content\":" + valueId;
|
||||
return addContent;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下架产品
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SetOffLine(long id, ShopChatBase shop)
|
||||
{
|
||||
string cookies = shop == null ? "" : shop.Cookies;
|
||||
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(shop);
|
||||
api.Name = Name;
|
||||
string html = api.SetOnline(id, false);
|
||||
//string data = "{\"goods_id\":" + id + "}";
|
||||
string urlx = "https://mms.pinduoduo.com/vodka/v2/mms/batchOffSale";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
//string html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, cookies);
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
LogSave.Add(Name, "速度太快,休眠2-5分钟");
|
||||
Thread.Sleep(100 * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogSave.Add(Name, "不能下架");
|
||||
return false;
|
||||
}
|
||||
html = api.SetOnline(id, false);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(100 * 1000);
|
||||
html = api.SetOnline(id, false);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(100 * 1000);
|
||||
LogSave.Add(Name, "下架产品失败:" + id);
|
||||
return false;
|
||||
}
|
||||
if (html.Contains("使用MMS后台做此"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(PinduoduoAuth.strContent))
|
||||
{
|
||||
PinduoduoAuth.strContent = GetVisitProductNew.strJs;//FileBase.ReadAllText(path);
|
||||
}
|
||||
string NoCode = "";
|
||||
string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000";
|
||||
if (string.IsNullOrEmpty(NoCode))
|
||||
{
|
||||
string htmlx = GetHtml.Gbk("http://nano.qixiaoke.com/nano.txt");
|
||||
NoCode = BaseRegex.GetMatchRegexString(ref htmlx, @"([\w\W]+?)-----");
|
||||
}
|
||||
string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, NoCode, "");
|
||||
string codex = UploadPinduoduoSet.ExecuteScript(fun2, PinduoduoAuth.strContent);
|
||||
|
||||
string data = "{\"goodsId\":" + id + ",\"crawlerInfo\":\"" + codex + "\"}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, cookies);
|
||||
}
|
||||
LogSave.Add(Name, "下架产品成功:" + id);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class PinduoduoPropBase
|
||||
{
|
||||
public string Name;
|
||||
public string Id;
|
||||
public Dictionary<string, long> Values = new Dictionary<string, long>();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user