1抖音上传服务端模板 2拼多多活动调整80% 3拼多多机会商品抓取 20%
This commit is contained in:
1 parent
9e5fed3989
commit
96ca090fc4
25 files changed
+1512
-586
No files matched your search
@@ -25,7 +25,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
public delegate void InfoReceivedHandler(string information);
|
||||
public event InfoReceivedHandler OnInfoReceived;
|
||||
|
||||
public string getProduct(string sProdId, string supplierId, PDDProductInfo prodInfo = null, bool notSaveDb = false)
|
||||
public string getProduct(string sProdId, string supplierId, bool notSaveDb = false)
|
||||
{
|
||||
var prodId = sProdId.ParseToLong();
|
||||
if (prodId <= 0)
|
||||
@@ -43,91 +43,107 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
var msg = getPDDProductWidthEdit(shop, sProdId, "", false, notSaveDb);
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
if (!msg.StartsWith("success") && !msg.StartsWith("商品采集保存成功"))
|
||||
{
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowError(msg);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowInfo(msg);
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
public string getPDDProductWidthEdit(ShopLoginInfo shop, string prodId, string commitId = "", bool isChance = false, bool notSaveDb = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sourceShop = shop;
|
||||
var sourceProdId = prodId;
|
||||
string success_err_msg = "";
|
||||
//string errorMsg = "";
|
||||
if (string.IsNullOrEmpty(commitId))
|
||||
{
|
||||
var sourceShop = shop;
|
||||
var sourceProdId = prodId;
|
||||
string success_err_msg = "";
|
||||
//string errorMsg = "";
|
||||
var commit_id_rst = GetPddProdCommitId(sourceShop, sourceProdId.ToString());
|
||||
if (!commit_id_rst.Contains("\"success\":true") || !commit_id_rst.Contains("\"result\""))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJson(ref commit_id_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = commit_id_rst;
|
||||
OnInfoReceived("商品获取失败!" + errMsg);
|
||||
return;
|
||||
//OnInfoReceived("商品获取失败!" + errMsg);
|
||||
return "商品获取失败!" + errMsg;
|
||||
}
|
||||
var commitId = BaseRegex.GetStringJson(ref commit_id_rst, "goods_commit_id");
|
||||
commitId = BaseRegex.GetStringJson(ref commit_id_rst, "goods_commit_id");
|
||||
if (string.IsNullOrEmpty(commitId))
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品提交编号获取失败!");
|
||||
return;
|
||||
//OnInfoReceived("商品获取失败!商品提交编号获取失败!");
|
||||
return "商品获取失败!商品提交编号获取失败!";
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var detail_json = "{}";
|
||||
PDDProductDetailInfo product = null;
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var detail_json = "{}";
|
||||
PDDProductDetailInfo product = null;
|
||||
try
|
||||
{
|
||||
var prod_detail_rst = GetPddProdDetail(sourceShop, sourceProdId.ToString(), commitId);
|
||||
JObject prod_detail_obj = JObject.Parse(prod_detail_rst);
|
||||
detail_json = JsonHelper.SerializeObject(prod_detail_obj["result"]);
|
||||
|
||||
product = JsonHelper.DeserializeJsonToObject<PDDProductDetailInfo>(detail_json);
|
||||
if (product == null || detail_json.Length < 10)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品数据格式获取失败!");
|
||||
return "商品获取失败!商品数据格式获取失败!";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品数据格式获取失败!" + ex.Message);
|
||||
return "商品获取失败!商品数据格式获取失败!" + ex.Message;
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var size_json = "{}";
|
||||
if (product.size_spec_id.ParseToLong() != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prod_detail_rst = GetPddProdDetail(sourceShop, sourceProdId.ToString(), commitId);
|
||||
JObject prod_detail_obj = JObject.Parse(prod_detail_rst);
|
||||
detail_json = JsonHelper.SerializeObject(prod_detail_obj["result"]);
|
||||
|
||||
product = JsonHelper.DeserializeJsonToObject<PDDProductDetailInfo>(detail_json);
|
||||
if (product == null || detail_json.Length < 10)
|
||||
var prod_size_rst = GetPddProdSizeSpec(sourceShop, sourceProdId.ToString(), commitId, product.size_spec_id.ParseToString());
|
||||
prod_size_rst = GetHtml.Unicode2String(prod_size_rst);
|
||||
JObject prod_size_obj = JObject.Parse(prod_size_rst);
|
||||
size_json = JsonHelper.SerializeObject(prod_size_obj["result"]);
|
||||
var size = JsonHelper.DeserializeJsonToObject<PDDSizeSpecInfo>(size_json);
|
||||
if (size == null)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品数据格式获取失败!");
|
||||
return;
|
||||
//OnInfoReceived("尺码表获取失败!尺码数据格式获取失败!");
|
||||
return "尺码表获取失败!尺码数据格式获取失败!";
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品数据格式获取失败!" + ex.Message);
|
||||
return;
|
||||
//OnInfoReceived("尺码表获取失败!尺码数据格式获取失败!" + ex.Message);
|
||||
return "尺码表获取失败!尺码数据格式获取失败!" + ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var size_json = "{}";
|
||||
if (product.size_spec_id.ParseToLong() != 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prod_size_rst = GetPddProdSizeSpec(sourceShop, sourceProdId.ToString(), commitId, product.size_spec_id.ParseToString());
|
||||
prod_size_rst = GetHtml.Unicode2String(prod_size_rst);
|
||||
JObject prod_size_obj = JObject.Parse(prod_size_rst);
|
||||
size_json = JsonHelper.SerializeObject(prod_size_obj["result"]);
|
||||
var size = JsonHelper.DeserializeJsonToObject<PDDSizeSpecInfo>(size_json);
|
||||
if (size == null)
|
||||
{
|
||||
OnInfoReceived("尺码表获取失败!尺码数据格式获取失败!");
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("尺码表获取失败!尺码数据格式获取失败!" + ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//temu尺码表暂时注释
|
||||
//if (product.sizeTemplateId > 0)
|
||||
//{
|
||||
// html = SizeSpecQuery(shop1, prodId1.ToString(), product.sizeTemplateId.ToString());
|
||||
// if(!html.Contains("\"success\":true"))
|
||||
// {
|
||||
// success_err_msg += " 尺码表获取失败!" + BaseRegex.GetStringJson(ref html, "errorMsg");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// obj = JObject.Parse(html);
|
||||
// sizeRst = JsonHelper.SerializeObject(obj["result"]);
|
||||
// }
|
||||
//}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var property_json = "{}";
|
||||
PDDProductPropertyInfo property = null;
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var property_json = "{}";
|
||||
PDDProductPropertyInfo property = null;
|
||||
if (!isChance)
|
||||
{
|
||||
try
|
||||
{
|
||||
var prod_property_rst = GetPddProdProperty(sourceShop, sourceProdId.ToString(), commitId);
|
||||
@@ -139,30 +155,123 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
catch (Exception ex) { }
|
||||
if (property == null)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品属性获取失败!");
|
||||
return;
|
||||
//OnInfoReceived("商品获取失败!商品属性获取失败!");
|
||||
return "商品获取失败!商品属性获取失败!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
var prod_property_rst = get_chance_cat_prop_template(sourceShop, "", sourceProdId.ToString(), commitId);
|
||||
prod_property_rst = GetHtml.Unicode2String(prod_property_rst);
|
||||
JObject prod_property_obj = JObject.Parse(prod_property_rst);
|
||||
property_json = JsonHelper.SerializeObject(prod_property_obj["result"]);
|
||||
property = JsonHelper.DeserializeJsonToObject<PDDProductPropertyInfo>(property_json);
|
||||
}
|
||||
catch (Exception ex) { }
|
||||
if (property == null)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品属性获取失败!");
|
||||
return "商品获取失败!商品属性获取失败!";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 属性模板暂时注释
|
||||
//var prop_template_json = "{}";
|
||||
//PDDProductTemplateInfo templateInfo = null;
|
||||
// 属性模板暂时注释
|
||||
//var prop_template_json = "{}";
|
||||
//PDDProductTemplateInfo templateInfo = null;
|
||||
//try
|
||||
//{
|
||||
// var prop_template_rst = GetPddCatPropTemplate(sourceShop, product.cat_id.ParseToString(), sourceProdId.ToString(), commitId);
|
||||
// JObject prop_template_obj = JObject.Parse(prop_template_rst);
|
||||
// prop_template_json = JsonHelper.SerializeObject(prop_template_obj["result"]);
|
||||
// templateInfo = JsonHelper.DeserializeJsonToObject<PDDProductTemplateInfo>(prop_template_json);
|
||||
//}
|
||||
//catch (Exception ex) { }
|
||||
//if (templateInfo == null)
|
||||
//{
|
||||
// OnInfoReceived("商品获取失败!商品属性模板获取失败!");
|
||||
// return;
|
||||
//}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var decoration_json = "{}";
|
||||
PDDProductDecorationInfo decoration = null;
|
||||
try
|
||||
{
|
||||
var prod_decoration_rst = GetPddProdDecoration(sourceShop, sourceProdId.ToString(), commitId);
|
||||
if (!prod_decoration_rst.Contains("\"success\":true"))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJson(ref prod_decoration_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = prod_decoration_rst;
|
||||
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + errMsg);
|
||||
return "商品获取失败!商品详情图获取失败!" + errMsg;
|
||||
}
|
||||
JObject prod_decoration_obj = JObject.Parse(prod_decoration_rst);
|
||||
if (!prod_decoration_obj["result"].IsNullOrEmpty())
|
||||
decoration_json = JsonHelper.SerializeObject(prod_decoration_obj["result"]);
|
||||
decoration = JsonHelper.DeserializeJsonToObject<PDDProductDecorationInfo>(decoration_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
|
||||
return "商品获取失败!商品详情图获取失败!" + ex.Message;
|
||||
}
|
||||
if (decoration != null && decoration_json.ParseToString().Length < 20)
|
||||
{
|
||||
//try
|
||||
//{
|
||||
// var prop_template_rst = GetPddCatPropTemplate(sourceShop, product.cat_id.ParseToString(), sourceProdId.ToString(), commitId);
|
||||
// JObject prop_template_obj = JObject.Parse(prop_template_rst);
|
||||
// prop_template_json = JsonHelper.SerializeObject(prop_template_obj["result"]);
|
||||
// templateInfo = JsonHelper.DeserializeJsonToObject<PDDProductTemplateInfo>(prop_template_json);
|
||||
//{ // 获取另一组详情数据,结构和主详情不一样无法通用
|
||||
// var prod_detail_decoration_rst = GetPddProdOnShopDetail(sourceShop, sourceProdId.ToString(), commitId);
|
||||
// JObject prod_detail_decoration_obj = JObject.Parse(prod_detail_decoration_rst);
|
||||
// foreach (JObject ob in prod_detail_decoration_obj["result"]["carousel_gallery"])
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex) { }
|
||||
//if (templateInfo == null)
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// OnInfoReceived("商品获取失败!商品属性模板获取失败!");
|
||||
// OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
|
||||
// return;
|
||||
//}
|
||||
|
||||
PDDProdDecorationCommitParam decorationParam = new PDDProdDecorationCommitParam();
|
||||
decorationParam.goods_id = product.goods_id;
|
||||
decorationParam.goods_commit_id = commitId.ParseToLong();
|
||||
decorationParam.preview_key = "";
|
||||
decorationParam.decoration_floor_list = new List<decoration_floor_param>();
|
||||
foreach (var gallary in product.galleries)
|
||||
{
|
||||
if (gallary.type != 2)
|
||||
continue;
|
||||
|
||||
var floor_param = new decoration_floor_param();
|
||||
//floor_param.floor_id = 0; // floorItem.floor_id;
|
||||
floor_param.type = "image"; // floorItem.type;
|
||||
floor_param.content_list = new List<decoration_content_param>();
|
||||
//foreach (var c in floorItem.content_list)
|
||||
{
|
||||
var decorationContentParam = new decoration_content_param()
|
||||
{
|
||||
//file_id = c.file_id,
|
||||
img_url = gallary.url, //c.img_url,
|
||||
//height = c.height,
|
||||
//text = c.text,
|
||||
//text_module_details = null,
|
||||
//width = c.width,
|
||||
};
|
||||
//try { decorationContentParam.text_module_details = JsonHelper.DeserializeJsonToObject<text_module_detail_param>(JsonHelper.SerializeObject(c.text_module_details)); }
|
||||
//catch (Exception ex) { }
|
||||
floor_param.content_list.Add(decorationContentParam);
|
||||
}
|
||||
decorationParam.decoration_floor_list.Add(floor_param);
|
||||
}
|
||||
|
||||
var addDecorationRst = save_decoration(shop, decorationParam, product.goods_id.ParseToString(), commitId);
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var decoration_json = "{}";
|
||||
PDDProductDecorationInfo decoration = null;
|
||||
|
||||
// 第二次获取详情图
|
||||
try
|
||||
{
|
||||
var prod_decoration_rst = GetPddProdDecoration(sourceShop, sourceProdId.ToString(), commitId);
|
||||
@@ -171,8 +280,8 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
var errMsg = BaseRegex.GetStringJson(ref prod_decoration_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = prod_decoration_rst;
|
||||
OnInfoReceived("商品获取失败!商品详情图获取失败!" + errMsg);
|
||||
return;
|
||||
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + errMsg);
|
||||
return "商品获取失败!商品详情图获取失败!" + errMsg;
|
||||
}
|
||||
JObject prod_decoration_obj = JObject.Parse(prod_decoration_rst);
|
||||
if (!prod_decoration_obj["result"].IsNullOrEmpty())
|
||||
@@ -181,272 +290,185 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
|
||||
return;
|
||||
//OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
|
||||
return "商品获取失败!商品详情图获取失败!" + ex.Message;
|
||||
}
|
||||
if (decoration != null && decoration_json.ParseToString().Length < 20)
|
||||
}
|
||||
|
||||
|
||||
if (decoration == null || decoration_json.ParseToString().Length < 20)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品详情图获取失败!");
|
||||
return "商品获取失败!商品详情图获取失败!";
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var material3_json = "{}";
|
||||
PDDMaterialInfo material3 = null;
|
||||
try
|
||||
{
|
||||
var material3_rst = GetPddGoodsMaterial(sourceShop, sourceProdId.ToString(), commitId, 3);
|
||||
if (!material3_rst.Contains("\"success\":true"))
|
||||
{
|
||||
//try
|
||||
//{ // 获取另一组详情数据,结构和主详情不一样无法通用
|
||||
// var prod_detail_decoration_rst = GetPddProdOnShopDetail(sourceShop, sourceProdId.ToString(), commitId);
|
||||
// JObject prod_detail_decoration_obj = JObject.Parse(prod_detail_decoration_rst);
|
||||
// foreach (JObject ob in prod_detail_decoration_obj["result"]["carousel_gallery"])
|
||||
// {
|
||||
|
||||
// }
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
|
||||
// return;
|
||||
//}
|
||||
|
||||
PDDProdDecorationCommitParam decorationParam = new PDDProdDecorationCommitParam();
|
||||
decorationParam.goods_id = product.goods_id;
|
||||
decorationParam.goods_commit_id = commitId.ParseToLong();
|
||||
decorationParam.preview_key = "";
|
||||
decorationParam.decoration_floor_list = new List<decoration_floor_param>();
|
||||
foreach (var gallary in product.galleries)
|
||||
{
|
||||
if (gallary.type != 2)
|
||||
continue;
|
||||
|
||||
var floor_param = new decoration_floor_param();
|
||||
//floor_param.floor_id = 0; // floorItem.floor_id;
|
||||
floor_param.type = "image"; // floorItem.type;
|
||||
floor_param.content_list = new List<decoration_content_param>();
|
||||
//foreach (var c in floorItem.content_list)
|
||||
{
|
||||
var decorationContentParam = new decoration_content_param()
|
||||
{
|
||||
//file_id = c.file_id,
|
||||
img_url = gallary.url, //c.img_url,
|
||||
//height = c.height,
|
||||
//text = c.text,
|
||||
//text_module_details = null,
|
||||
//width = c.width,
|
||||
};
|
||||
//try { decorationContentParam.text_module_details = JsonHelper.DeserializeJsonToObject<text_module_detail_param>(JsonHelper.SerializeObject(c.text_module_details)); }
|
||||
//catch (Exception ex) { }
|
||||
floor_param.content_list.Add(decorationContentParam);
|
||||
}
|
||||
decorationParam.decoration_floor_list.Add(floor_param);
|
||||
}
|
||||
|
||||
var addDecorationRst = save_decoration(shop, decorationParam, product.goods_id.ParseToString(), commitId);
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
|
||||
// 第二次获取详情图
|
||||
try
|
||||
{
|
||||
var prod_decoration_rst = GetPddProdDecoration(sourceShop, sourceProdId.ToString(), commitId);
|
||||
if (!prod_decoration_rst.Contains("\"success\":true"))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJson(ref prod_decoration_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = prod_decoration_rst;
|
||||
OnInfoReceived("商品获取失败!商品详情图获取失败!" + errMsg);
|
||||
return;
|
||||
}
|
||||
JObject prod_decoration_obj = JObject.Parse(prod_decoration_rst);
|
||||
if (!prod_decoration_obj["result"].IsNullOrEmpty())
|
||||
decoration_json = JsonHelper.SerializeObject(prod_decoration_obj["result"]);
|
||||
decoration = JsonHelper.DeserializeJsonToObject<PDDProductDecorationInfo>(decoration_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品详情图获取失败!" + ex.Message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (decoration == null || decoration_json.ParseToString().Length < 20)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品详情图获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var material3_json = "{}";
|
||||
PDDMaterialInfo material3 = null;
|
||||
try
|
||||
{
|
||||
var material3_rst = GetPddGoodsMaterial(sourceShop, sourceProdId.ToString(), commitId, 3);
|
||||
if (!material3_rst.Contains("\"success\":true"))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJson(ref material3_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = material3_rst;
|
||||
OnInfoReceived("商品获取失败!商品长图获取失败!" + errMsg);
|
||||
return;
|
||||
}
|
||||
JObject material3_obj = JObject.Parse(material3_rst);
|
||||
if (!material3_obj["result"].IsNullOrEmpty())
|
||||
material3_json = JsonHelper.SerializeObject(material3_obj["result"]);
|
||||
material3 = JsonHelper.DeserializeJsonToObject<PDDMaterialInfo>(material3_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品长图获取失败!" + ex.Message);
|
||||
return;
|
||||
}
|
||||
if (material3 == null)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品长图获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var material1_json = "{}";
|
||||
PDDMaterialInfo material1 = null;
|
||||
try
|
||||
{
|
||||
var material1_rst = GetPddGoodsMaterial(sourceShop, sourceProdId.ToString(), commitId, 1);
|
||||
if (!material1_rst.Contains("\"success\":true"))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJson(ref material1_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = material1_rst;
|
||||
OnInfoReceived("商品获取失败!商品白底图获取失败!" + errMsg);
|
||||
return;
|
||||
}
|
||||
JObject material1_obj = JObject.Parse(material1_rst);
|
||||
if (!material1_obj["result"].IsNullOrEmpty())
|
||||
material1_json = JsonHelper.SerializeObject(material1_obj["result"]);
|
||||
material1 = JsonHelper.DeserializeJsonToObject<PDDMaterialInfo>(material1_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品白底图获取失败!" + ex.Message);
|
||||
return;
|
||||
}
|
||||
if (material1 == null)
|
||||
{
|
||||
OnInfoReceived("商品获取失败!商品白底图获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool isExist = false;
|
||||
var existUrl = BaseClass.BuildObjString("product/get_product_list");
|
||||
string existData = UserLogin.GetSignaturex() + "&search_spu=" + product.goods_id;
|
||||
string html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("\"code\":200"))
|
||||
{
|
||||
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
|
||||
isExist = true;
|
||||
}
|
||||
|
||||
|
||||
string product_json = "{\"detail\":" + detail_json + ",\"size\":" + size_json + ",\"decoration\":" + decoration_json +
|
||||
",\"material3\":" + material3_json + ",\"material1\":" + material1_json + ",\"property\":" + property_json + "}";
|
||||
|
||||
if (notSaveDb)
|
||||
{
|
||||
prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(product_json);
|
||||
}
|
||||
else
|
||||
{
|
||||
string main_img = product.image_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = product.hd_thumb_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = product.thumb_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = (product.galleries?.FirstOrDefault()?.url).ParseToString().Replace("https://", "http://");
|
||||
var url = BaseClass.BuildObjString("product/add_product");
|
||||
if (isExist)
|
||||
{
|
||||
bool isCover = false;
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
var ok = BaseMsgForm.ShowConfirm("产品库内已存在相同id商品,是否更新?").DialogResult;
|
||||
if (ok == DialogResult.OK)
|
||||
isCover = true;
|
||||
}));
|
||||
if (isCover)
|
||||
url = BaseClass.BuildObjString("product/mdy_product");
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
var data = Work.UserLogin.GetSignaturex() +
|
||||
"&from_shop_id=" + shop.ShopId +
|
||||
"&spu_id=" + product.goods_id.ParseToString() +
|
||||
"&skc_id=" + product.goods_id.ParseToString() +
|
||||
"&price_text=" + product.sku.Min(s => s.multi_price).ParseToInt() * 0.01m + "-" + product.sku.Max(s => s.multi_price).ParseToInt() * 0.01m +
|
||||
"&main_cat_id=" + (product.cat_ids?.FirstOrDefault(c => c != null)).ParseToString() +
|
||||
"&main_cat_name=" + HttpUtility.UrlEncode((product.cats?.FirstOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
|
||||
"&cat_id=" + (product.cat_id).ParseToString() +
|
||||
"&cat_name=" + HttpUtility.UrlEncode((product.cats?.LastOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
|
||||
"&ext_code=" + HttpUtility.UrlEncode(product.out_goods_sn, Encoding.UTF8) +
|
||||
"&product_name=" + HttpUtility.UrlEncode(product.goods_name, Encoding.UTF8) +
|
||||
"&product_json=" + HttpUtility.UrlEncode(product_json, Encoding.UTF8) +
|
||||
"&size_json=" + HttpUtility.UrlEncode(size_json, Encoding.UTF8) +
|
||||
"&main_img=" + HttpUtility.UrlEncode(main_img, Encoding.UTF8);
|
||||
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
string msg = "选品商品保存失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg");
|
||||
//OnInfoReceived(msg);
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowError(msg);
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
//OnInfoReceived("选品商品保存成功!" + success_err_msg);
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
BaseMsgForm.ShowInfo("选品商品保存成功!" + success_err_msg);
|
||||
}));
|
||||
}
|
||||
|
||||
//// 创建 SaveFileDialog 的实例
|
||||
//SaveFileDialog saveFileDialog = new SaveFileDialog();
|
||||
|
||||
//// 单线程单元(STA)模式运行文件对话框,否则会报错。
|
||||
//System.Threading.Thread InvokeThread = new System.Threading.Thread(new System.Threading.ThreadStart(()=> {
|
||||
|
||||
// // 设置对话框的属性
|
||||
// saveFileDialog.Title = "保存商品";
|
||||
// saveFileDialog.Filter = "商品文件 (*.prd)|*.prd|所有文件 (*.*)|*.*"; // 过滤文件类型
|
||||
// saveFileDialog.FileName = product.productId.ParseToString(); // 默认文件名
|
||||
// saveFileDialog.DefaultExt = "txt"; // 默认文件扩展名
|
||||
|
||||
// // 显示对话框并获取结果
|
||||
// if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
// {
|
||||
// // 用户点击了“保存”按钮,此时可以获取文件的路径
|
||||
// string filePath = saveFileDialog.FileName;
|
||||
// // 在这里处理文件保存逻辑,例如写入数据到文件
|
||||
// System.IO.File.WriteAllText(filePath, result);
|
||||
|
||||
// //BaseMsgForm.ShowInfo("商品保存成功!");
|
||||
// }
|
||||
//}));
|
||||
//InvokeThread.SetApartmentState(System.Threading.ApartmentState.STA);
|
||||
//InvokeThread.Start();
|
||||
//InvokeThread.Join();
|
||||
var errMsg = BaseRegex.GetStringJson(ref material3_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = material3_rst;
|
||||
//OnInfoReceived("商品获取失败!商品长图获取失败!" + errMsg);
|
||||
return "商品获取失败!商品长图获取失败!" + errMsg;
|
||||
}
|
||||
JObject material3_obj = JObject.Parse(material3_rst);
|
||||
if (!material3_obj["result"].IsNullOrEmpty())
|
||||
material3_json = JsonHelper.SerializeObject(material3_obj["result"]);
|
||||
material3 = JsonHelper.DeserializeJsonToObject<PDDMaterialInfo>(material3_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品长图获取失败!" + ex.Message);
|
||||
return "商品获取失败!商品长图获取失败!" + ex.Message;
|
||||
}
|
||||
if (material3 == null)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品长图获取失败!");
|
||||
return "商品获取失败!商品长图获取失败!";
|
||||
}
|
||||
});
|
||||
|
||||
return "success";
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
var material1_json = "{}";
|
||||
PDDMaterialInfo material1 = null;
|
||||
try
|
||||
{
|
||||
var material1_rst = GetPddGoodsMaterial(sourceShop, sourceProdId.ToString(), commitId, 1);
|
||||
if (!material1_rst.Contains("\"success\":true"))
|
||||
{
|
||||
var errMsg = BaseRegex.GetStringJson(ref material1_rst, "error_msg");
|
||||
if (string.IsNullOrEmpty(errMsg))
|
||||
errMsg = material1_rst;
|
||||
//OnInfoReceived("商品获取失败!商品白底图获取失败!" + errMsg);
|
||||
return "商品获取失败!商品白底图获取失败!" + errMsg;
|
||||
}
|
||||
JObject material1_obj = JObject.Parse(material1_rst);
|
||||
if (!material1_obj["result"].IsNullOrEmpty())
|
||||
material1_json = JsonHelper.SerializeObject(material1_obj["result"]);
|
||||
material1 = JsonHelper.DeserializeJsonToObject<PDDMaterialInfo>(material1_json);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品白底图获取失败!" + ex.Message);
|
||||
return "商品获取失败!商品白底图获取失败!" + ex.Message;
|
||||
}
|
||||
if (material1 == null)
|
||||
{
|
||||
//OnInfoReceived("商品获取失败!商品白底图获取失败!");
|
||||
return "商品获取失败!商品白底图获取失败!";
|
||||
}
|
||||
|
||||
|
||||
bool isExist = false;
|
||||
var existUrl = BaseClass.BuildObjString("product/get_product_list");
|
||||
string existData = UserLogin.GetSignaturex() + "&search_spu=" + product.goods_id;
|
||||
string html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(existUrl, existData);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("\"code\":200"))
|
||||
{
|
||||
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
|
||||
isExist = true;
|
||||
}
|
||||
|
||||
string product_json = "{\"detail\":" + detail_json + ",\"size\":" + size_json + ",\"decoration\":" + decoration_json +
|
||||
",\"material3\":" + material3_json + ",\"material1\":" + material1_json + ",\"property\":" + property_json + "}";
|
||||
|
||||
if (notSaveDb)
|
||||
{
|
||||
//prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(product_json);
|
||||
|
||||
string main_img = product.image_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = product.hd_thumb_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = product.thumb_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = (product.galleries?.FirstOrDefault()?.url).ParseToString().Replace("https://", "http://");
|
||||
KJDDBProduct dbProd = new KJDDBProduct();
|
||||
dbProd.from_shop_id = shop.ShopId;
|
||||
dbProd.spu_id = product.goods_id.ParseToString();
|
||||
dbProd.skc_id = product.goods_id.ParseToString();
|
||||
dbProd.main_cat_id = (product.cat_ids?.FirstOrDefault(c => c != null)).ParseToString();
|
||||
dbProd.main_cat_name = (product.cats?.FirstOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString();
|
||||
dbProd.cat_id = (product.cat_id).ParseToString();
|
||||
dbProd.cat_name = (product.cats?.LastOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString();
|
||||
dbProd.ext_code = product.out_goods_sn;
|
||||
dbProd.product_name = product.goods_name;
|
||||
dbProd.product_json = product_json;
|
||||
dbProd.size_json = size_json;
|
||||
dbProd.main_img = main_img;
|
||||
|
||||
return "success" + JsonHelper.SerializeObject(dbProd);
|
||||
}
|
||||
else
|
||||
{
|
||||
string main_img = product.image_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = product.hd_thumb_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = product.thumb_url;
|
||||
if (string.IsNullOrEmpty(main_img))
|
||||
main_img = (product.galleries?.FirstOrDefault()?.url).ParseToString().Replace("https://", "http://");
|
||||
var url = BaseClass.BuildObjString("product/add_product");
|
||||
if (isExist)
|
||||
{
|
||||
bool isOverride = false;
|
||||
MainForm.instance.Invoke(new Action(() =>
|
||||
{
|
||||
var ok = BaseMsgForm.ShowConfirm("产品库内已存在相同id商品,是否更新?").DialogResult;
|
||||
if (ok == DialogResult.OK)
|
||||
isOverride = true;
|
||||
}));
|
||||
if (isOverride)
|
||||
url = BaseClass.BuildObjString("product/mdy_product");
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
var data = Work.UserLogin.GetSignaturex() +
|
||||
"&from_shop_id=" + shop.ShopId +
|
||||
"&spu_id=" + product.goods_id.ParseToString() +
|
||||
"&skc_id=" + product.goods_id.ParseToString() +
|
||||
"&price_text=" + product.sku.Min(s => s.multi_price).ParseToInt() * 0.01m + "-" + product.sku.Max(s => s.multi_price).ParseToInt() * 0.01m +
|
||||
"&main_cat_id=" + (product.cat_ids?.FirstOrDefault(c => c != null)).ParseToString() +
|
||||
"&main_cat_name=" + HttpUtility.UrlEncode((product.cats?.FirstOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
|
||||
"&cat_id=" + (product.cat_id).ParseToString() +
|
||||
"&cat_name=" + HttpUtility.UrlEncode((product.cats?.LastOrDefault(c => !string.IsNullOrEmpty(c))).ParseToString(), Encoding.UTF8) +
|
||||
"&ext_code=" + HttpUtility.UrlEncode(product.out_goods_sn, Encoding.UTF8) +
|
||||
"&product_name=" + HttpUtility.UrlEncode(product.goods_name, Encoding.UTF8) +
|
||||
"&product_json=" + HttpUtility.UrlEncode(product_json, Encoding.UTF8) +
|
||||
"&size_json=" + HttpUtility.UrlEncode(size_json, Encoding.UTF8) +
|
||||
"&main_img=" + HttpUtility.UrlEncode(main_img, Encoding.UTF8);
|
||||
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
|
||||
{
|
||||
string msg = "商品采集保存失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg");
|
||||
//OnInfoReceived(msg);
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
string msg = "商品采集保存成功!" + success_err_msg;
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "商品采集失败!" + ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -662,7 +684,7 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private string GetPddProdDetail(ShopLoginInfo shop, string prodId, string commitId)
|
||||
public static string GetPddProdDetail(ShopLoginInfo shop, string prodId, string commitId)
|
||||
{
|
||||
var anti = shop.AntiContents.LastOrDefault().ParseToString();
|
||||
if (shop.AntiContents.Count > 0)
|
||||
@@ -687,6 +709,29 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetPddProdDetailOnShop(ShopLoginInfo shop, string prodId, string commitId)
|
||||
{
|
||||
var anti = shop.AntiContents.LastOrDefault().ParseToString();
|
||||
if (shop.AntiContents.Count > 0)
|
||||
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/on_shop/detail"; //on_shop
|
||||
string body = @"{""goods_commit_id"":""" + commitId + @""",""goods_id"":""" + prodId + @"""}";
|
||||
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=" + commitId + "&goods_id=" + prodId + "&type=edit";
|
||||
var result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
|
||||
for (int i = 0; i < 5 && result.Contains("网络繁忙,请不要频繁操作"); i++)
|
||||
{
|
||||
shop.AntiContents.Remove(anti);
|
||||
anti = shop.AntiContents.FirstOrDefault().ParseToString();
|
||||
if (shop.AntiContents.Count > 0)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(300, 500));
|
||||
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
|
||||
result = HttpResponseBLL.PDDPostResponse(shop, url, body, refere, anti);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private string GetPddProdOnShopDetail(ShopLoginInfo shop, string prodId, string commitId)
|
||||
{
|
||||
@@ -793,6 +838,33 @@ namespace TemuKJD.PDDForms.ShopForms
|
||||
}
|
||||
return result;
|
||||
}
|
||||
private string get_chance_cat_prop_template(ShopLoginInfo shop, string catId, string goodsId, string commitId, string chanceTab = "")
|
||||
{
|
||||
var anti = shop.AntiContents.LastOrDefault().ParseToString();
|
||||
if (shop.AntiContents.Count > 0)
|
||||
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
|
||||
string url = "https://mms.pinduoduo.com/draco-ms/mms/template/mall?catId=" + catId +
|
||||
"&goodsCommitId=" + commitId + "&goodsId=" + goodsId;
|
||||
string body = @"";
|
||||
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?type=add&from=chance&id=" + commitId +
|
||||
"&goods_id=" + goodsId + "&chance_tab=hot_theme&sourcePage=goodsListTopButton_CHANCE"; // chance_tab=search
|
||||
if (!string.IsNullOrEmpty(chanceTab))
|
||||
refere = refere.Replace("chance_tab=hot_theme", "chance_tab=" + chanceTab);
|
||||
var result = HttpResponseBLL.PDDGetResponse(shop, url, body, refere, anti);
|
||||
for (int i = 0; i < 5 && (result.Contains("操作太过频繁") || result.Contains("网络繁忙,请不要频繁操作")); i++)
|
||||
{
|
||||
shop.AntiContents.Remove(anti);
|
||||
anti = shop.AntiContents.LastOrDefault().ParseToString();
|
||||
if (shop.AntiContents.Count > 0)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(300, 500));
|
||||
anti = shop.AntiContents[Randomx.GetId(shop.AntiContents.Count)];
|
||||
result = HttpResponseBLL.PDDGetResponse(shop, url, body, refere, anti);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private string GetPddProdDecoration(ShopLoginInfo shop, string prodId, string commitId)
|
||||
{
|
||||
var anti = shop.AntiContents.LastOrDefault().ParseToString();
|
||||
|
||||
Reference in new issue
Block a user