优化了微店商品上传 优化pdd买手读单
This commit is contained in:
1 parent
6c4f16b897
commit
f360688c43
62 files changed
+5620
-1432
No files matched your search
@@ -274,6 +274,11 @@ namespace TemuKJD.BLL.VDian
|
||||
{
|
||||
vDToken = vDianShop.Wdtoken;
|
||||
vDCookie = vDianShop.Cookies;
|
||||
if (vDToken.IsNullOrEmpty())
|
||||
{
|
||||
vDToken = "" + BaseRegex.GetMatchRegexString(ref vDCookie, "wdtoken=([^;]+?);");
|
||||
vDianShop.Wdtoken = vDToken;
|
||||
}
|
||||
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
|
||||
|
||||
bool useCache = false;
|
||||
@@ -289,54 +294,54 @@ namespace TemuKJD.BLL.VDian
|
||||
// 商品标题赋值
|
||||
vDianProduct.itemName = prod.ProductTitle;
|
||||
|
||||
var allAttrResult = "";
|
||||
for (int i = 0; !allAttrResult.Contains("\"message\":\"OK\"") && i < 20; i++)
|
||||
{
|
||||
allAttrResult = request_vdian_all_attr_com();
|
||||
Thread.Sleep(Randomx.GetId(300, 500));
|
||||
}
|
||||
if (allAttrResult.Contains("\"message\":\"OK\""))
|
||||
{
|
||||
var AttrMatches = BaseRegex.GetMatchRegex(ref allAttrResult, "\"attr_id\":([\\s\\S]*?),");
|
||||
List<string> lst = new List<string>();
|
||||
foreach (Match match in AttrMatches)
|
||||
{
|
||||
var attr = BaseRegex.GetMatchRegexString(match.ToString(), "\"attr_id\":([\\s\\S]*?),");
|
||||
lst.Add(attr);
|
||||
if (lst.Count >= 100)
|
||||
{
|
||||
var hideAttrResult = request_vdian_hideAttr_com(lst);
|
||||
if (!hideAttrResult.Contains("\"message\":\"OK\""))
|
||||
{
|
||||
prod.MappingResult = BaseRegex.GetMatchRegexString(hideAttrResult, "\"message\":\"([\\s\\S]+?)\"");
|
||||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||||
prod.MappingResult = hideAttrResult;
|
||||
if (hideAttrResult.Contains("LOGIN ERROR"))
|
||||
{
|
||||
vDianShop.LoginStatus = 2;
|
||||
vDianShop.UpGoodAuth = "请先登录";
|
||||
prod.MappingResult = "店铺 " + vDianShop.ShopName + " 未登录";
|
||||
}
|
||||
prod.MappingResult = "转换失败,删除attribute出错" + prod.MappingResult;
|
||||
LogSave.Add("[微店批量删除店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
|
||||
return null;
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
lst.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
prod.MappingResult = BaseRegex.GetMatchRegexString(allAttrResult, "\"message\":\"([\\s\\S]+?)\"");
|
||||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||||
prod.MappingResult = allAttrResult;
|
||||
prod.MappingResult = "转换失败,获取attribute出错" + prod.MappingResult;
|
||||
LogSave.Add("[微店获取店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
|
||||
return null;
|
||||
}
|
||||
//var allAttrResult = "";
|
||||
//for (int i = 0; !allAttrResult.Contains("\"message\":\"OK\"") && i < 20; i++)
|
||||
//{
|
||||
// allAttrResult = request_vdian_all_attr_com();
|
||||
// Thread.Sleep(Randomx.GetId(300, 500));
|
||||
//}
|
||||
//if (allAttrResult.Contains("\"message\":\"OK\""))
|
||||
//{
|
||||
// var AttrMatches = BaseRegex.GetMatchRegex(ref allAttrResult, "\"attr_id\":([\\s\\S]*?),");
|
||||
// List<string> lst = new List<string>();
|
||||
// foreach (Match match in AttrMatches)
|
||||
// {
|
||||
// var attr = BaseRegex.GetMatchRegexString(match.ToString(), "\"attr_id\":([\\s\\S]*?),");
|
||||
// lst.Add(attr);
|
||||
// if (lst.Count >= 100)
|
||||
// {
|
||||
// var hideAttrResult = request_vdian_hideAttr_com(lst);
|
||||
// if (!hideAttrResult.Contains("\"message\":\"OK\""))
|
||||
// {
|
||||
// prod.MappingResult = BaseRegex.GetMatchRegexString(hideAttrResult, "\"message\":\"([\\s\\S]+?)\"");
|
||||
// if (string.IsNullOrEmpty(prod.MappingResult))
|
||||
// prod.MappingResult = hideAttrResult;
|
||||
// if (hideAttrResult.Contains("LOGIN ERROR"))
|
||||
// {
|
||||
// vDianShop.LoginStatus = 2;
|
||||
// vDianShop.UpGoodAuth = "请先登录";
|
||||
// prod.MappingResult = "店铺 " + vDianShop.ShopName + " 未登录";
|
||||
// }
|
||||
// prod.MappingResult = "转换失败,删除attribute出错" + prod.MappingResult;
|
||||
// LogSave.Add("[微店批量删除店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||||
// + " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
|
||||
// return null;
|
||||
// }
|
||||
// Thread.Sleep(500);
|
||||
// lst.Clear();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// prod.MappingResult = BaseRegex.GetMatchRegexString(allAttrResult, "\"message\":\"([\\s\\S]+?)\"");
|
||||
// if (string.IsNullOrEmpty(prod.MappingResult))
|
||||
// prod.MappingResult = allAttrResult;
|
||||
// prod.MappingResult = "转换失败,获取attribute出错" + prod.MappingResult;
|
||||
// LogSave.Add("[微店获取店铺attribute出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||||
// + " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
|
||||
// return null;
|
||||
//}
|
||||
|
||||
// 商品属性
|
||||
retry:
|
||||
@@ -372,10 +377,27 @@ namespace TemuKJD.BLL.VDian
|
||||
// 上传属性获取属性ID
|
||||
if (wdAttrList.Count > 0)
|
||||
{
|
||||
Thread.Sleep(Randomx.GetId(2000, 5000));
|
||||
|
||||
List<VDianParam.VDianAttr> wdAttrList_New = new List<VDianParam.VDianAttr>();
|
||||
|
||||
var res = this.upLoadAttrx(prod, vDianShop, wdAttrList, wdAttrList_New);
|
||||
if (!res) return null;
|
||||
//var res = this.upLoadAttrx(prod, vDianShop, wdAttrList, wdAttrList_New);
|
||||
//if (!res) return null;
|
||||
|
||||
var inAttr = JsonHelper.SerializeObject(wdAttrList);
|
||||
var outAttr = JsonHelper.SerializeObject(wdAttrList_New);
|
||||
|
||||
wdAttrList_New = JsonHelper.DeserializeJsonToList<VDianParam.VDianAttr>(JsonHelper.SerializeObject(wdAttrList));
|
||||
foreach (var wdAttr in wdAttrList_New)
|
||||
{
|
||||
int id = 0;
|
||||
foreach (var atv in wdAttr.attr_values)
|
||||
{
|
||||
id++;
|
||||
atv.attr_id = id;
|
||||
atv.attr_title = wdAttr.attr_title;
|
||||
}
|
||||
}
|
||||
|
||||
wdAttrList = wdAttrList_New;
|
||||
vDianProduct.attrList = wdAttrList_New;
|
||||
@@ -431,7 +453,8 @@ namespace TemuKJD.BLL.VDian
|
||||
}
|
||||
}
|
||||
}
|
||||
vDianSku.price = ((sku.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price).ToString();
|
||||
int priceFen = (((sku.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price) * 100).ParseToInt();
|
||||
vDianSku.price = (priceFen * 0.01m).ToString();
|
||||
vDianSku.stock = sku.number > 999999 ? 999999.ToString() : sku.number.ToString();
|
||||
if (vDianSku.stock == "0")
|
||||
vDianSku.stock = "1";
|
||||
@@ -446,7 +469,7 @@ namespace TemuKJD.BLL.VDian
|
||||
var wdMaxPrice = 0M;
|
||||
try
|
||||
{
|
||||
wdMaxPrice = (product.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price;
|
||||
//wdMaxPrice = (product.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price;
|
||||
wdMaxPrice = vDianProduct.sku.Max(wd => Convert.ToDecimal(wd.price));
|
||||
}
|
||||
catch
|
||||
@@ -628,15 +651,15 @@ namespace TemuKJD.BLL.VDian
|
||||
if (mainImgResult.Contains("\"message\":\"SUCCESS\""))
|
||||
{
|
||||
var imgUrl = BaseRegex.GetMatchRegexString(mainImgResult, "\"url\":\"([\\s\\S]*?)\"");
|
||||
//if (!string.IsNullOrEmpty(imgUrl))
|
||||
//{
|
||||
// bigImages.Add(imgUrl);
|
||||
if (!string.IsNullOrEmpty(imgUrl))
|
||||
{
|
||||
bigImages.Add(imgUrl);
|
||||
|
||||
// // 写图片缓存
|
||||
// var url = BaseClass.LoginApiUrl + "?obj=upshopid/image_weidian&act=weidian_add";
|
||||
// var data = UserLogin.GetSignaturex() + "&data=" + item.Item2.Key + "," + imgUrl + ";";
|
||||
// var html = GetHtml.PostUtf8(url, data);
|
||||
//}
|
||||
//// 写图片缓存
|
||||
//var url = BaseClass.LoginApiUrl + "?obj=upshopid/image_weidian&act=weidian_add";
|
||||
//var data = UserLogin.GetSignaturex() + "&data=" + item.Item2.Key + "," + imgUrl + ";";
|
||||
//var html = GetHtml.PostUtf8(url, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -753,7 +776,7 @@ namespace TemuKJD.BLL.VDian
|
||||
if (++timesx > 1 || !IsUploadLimitedFailed(tmp_detailId)) break;
|
||||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||||
}
|
||||
if (tmp_detailId.Contains("\"message\":\"OK\""))
|
||||
if (tmp_detailId.ParseToString().Contains("\"message\":\"OK\""))
|
||||
{
|
||||
tmp_detailId = BaseRegex.GetMatchRegexString(tmp_detailId, "\"tmp_detail_id\":\"([\\s\\S]*?)\"");
|
||||
vDianProduct.tmpDetailId = tmp_detailId;
|
||||
@@ -763,7 +786,7 @@ namespace TemuKJD.BLL.VDian
|
||||
prod.MappingResult = BaseRegex.GetMatchRegexString(tmp_detailId, "\"message\":\"([\\s\\S]+?)\"");
|
||||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||||
prod.MappingResult = tmp_detailId;
|
||||
if (tmp_detailId.Contains("LOGIN ERROR"))
|
||||
if (tmp_detailId.ParseToString().Contains("LOGIN ERROR"))
|
||||
{
|
||||
vDianShop.LoginStatus = 2;
|
||||
vDianShop.UpGoodAuth = "请先登录";
|
||||
@@ -824,20 +847,27 @@ namespace TemuKJD.BLL.VDian
|
||||
vDianProduct.bgCateId = 50023878;
|
||||
}
|
||||
|
||||
vDianProduct.merchantCode = product.out_goods_sn;
|
||||
|
||||
// 上货上传商品
|
||||
var jsonStr = JsonHelper.SerializeObject(vDianProduct);
|
||||
var result = "";
|
||||
int timesxx = 0;
|
||||
while (true)
|
||||
{
|
||||
//Thread.Sleep(15000);
|
||||
Thread.Sleep(Randomx.GetId(8000, 11000));
|
||||
var ua = getUa(vDianShop);
|
||||
Thread.Sleep(Randomx.GetId(8000, 11000));
|
||||
if (string.IsNullOrEmpty(ua))
|
||||
ua = getUa(vDianShop);
|
||||
if (string.IsNullOrEmpty(ua))
|
||||
LogSave.Add("[微店获取Ua失败]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
|
||||
|
||||
Thread.Sleep(15000);
|
||||
//JObject obj = JsonHelper.JObjectParse(jsonStr);
|
||||
//(obj["attrList"] as JArray).RemoveAt(0);
|
||||
//var str1 = JsonHelper.SerializeObject(obj);
|
||||
|
||||
result = request_vdian_product_com(jsonStr, ua);
|
||||
if (string.IsNullOrEmpty(result))
|
||||
@@ -895,7 +925,7 @@ namespace TemuKJD.BLL.VDian
|
||||
}
|
||||
if (result.Contains("创建商品过于频繁"))
|
||||
{
|
||||
prod.MappingResult = "商品驳回,请更换其它商品转换";
|
||||
prod.MappingResult = "过于频繁,商品驳回,请更换其它商品转换";
|
||||
}
|
||||
prod.MappingResult = "转换失败,上传商品出错:" + prod.MappingResult;
|
||||
LogSave.Add("[微店上传商品出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||||
@@ -1009,7 +1039,8 @@ namespace TemuKJD.BLL.VDian
|
||||
request.KeepAlive = true;
|
||||
request.Accept = "application/json, */*";
|
||||
request.Headers.Add("Origin", @"https://d.weidian.com");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
|
||||
//request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.ContentType = "multipart/form-data; boundary=----WebKitFormBoundaryl8PNkxxP0AKTlrpf";
|
||||
request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||||
@@ -1117,6 +1148,7 @@ Content-Disposition: form-data; name=""wdtoken""
|
||||
isGetAttrId = true;
|
||||
|
||||
string param = attrList;
|
||||
//https://thor.weidian.com/wditem/itemSearch.searchAttrs/1.0
|
||||
string url = "https://thor.weidian.com/wditem/itemWrite.updateAttrList/1.0";
|
||||
var result = request_vdian_common(url, param);
|
||||
|
||||
@@ -1165,7 +1197,8 @@ Content-Disposition: form-data; name=""wdtoken""
|
||||
request.KeepAlive = true;
|
||||
request.Accept = "application/json, */*";
|
||||
request.Headers.Add("Origin", @"https://d.weidian.com");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
|
||||
//request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
|
||||
request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||||
@@ -1261,7 +1294,8 @@ Content-Disposition: form-data; name=""wdtoken""
|
||||
request.Headers.Add("sec-ch-ua", @"""Google Chrome"";v=""89"", ""Chromium"";v=""89"", "";Not A Brand"";v=""99""");
|
||||
request.Accept = "application/json, */*";
|
||||
request.Headers.Add("sec-ch-ua-mobile", @"?0");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36";
|
||||
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36";
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
|
||||
request.Headers.Add("Origin", @"https://d.weidian.com");
|
||||
request.Headers.Add("Sec-Fetch-Site", @"same-site");
|
||||
@@ -1453,6 +1487,7 @@ Content-Disposition: form-data; name=""wdtoken""
|
||||
request.Accept = "application/json, */*";
|
||||
request.Headers.Add("Origin", @"https://d.weidian.com");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36";
|
||||
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36";
|
||||
request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
@@ -1658,6 +1693,8 @@ Content-Disposition: form-data; name=""wdtoken""
|
||||
/// <returns></returns>
|
||||
private static bool IsUploadLimitedFailed(string result)
|
||||
{
|
||||
if (result == null)
|
||||
result = "";
|
||||
return result.Contains("无法连接到远程服务器") || result.Contains("操作超时") || result.Contains("基础连接已经关闭")
|
||||
|| result.Contains("远程主机强迫关闭") || result.Contains("Unable to write data") || result.Contains("现在人太多了, 请稍后重试");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user