1666 lines
77 KiB
C#
1666 lines
77 KiB
C#
using AllBase;
|
||
using AllBase.Model.Param.ToolsManage;
|
||
using AllBase.Model.Param.VDianManage;
|
||
using AllBase.Model.Result;
|
||
using NaiBa.Util.Extension;
|
||
using NaiBa.Util.Model;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace TemuKJD.BLL.VDian
|
||
{
|
||
public class VDianUpProdMappingBLL
|
||
{
|
||
string vDCookie = "";
|
||
string vDToken = "";
|
||
string spider_token = "";
|
||
private static bool isGetCate = false;
|
||
private static bool isGetAttrId = false;
|
||
private static bool isUpLoadImg = false;
|
||
private static bool isHideAttr = false;
|
||
private static bool isUpLoadDetail = false;
|
||
private static bool isUpLoad = false;
|
||
public static bool IsUseProxy = false;
|
||
public static bool IsChangeAdsl { get; set; }
|
||
|
||
public static List<ProductMappingImportParam> listPurifyData = new List<ProductMappingImportParam>();
|
||
/// <summary>
|
||
/// 上货时按上货拼多多上家93%需求适当减少的价格比例,如果是真实上货则不减少
|
||
/// </summary>
|
||
decimal reduceRate = 0.96M;
|
||
|
||
public VDianUpProdMappingBLL()
|
||
{
|
||
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
|
||
}
|
||
|
||
public string upLoadSingleImg(ProductMappingImportParam prod, VDianShopLoginInfo vDianShop, string baseImgStr)
|
||
{
|
||
vDToken = vDianShop.Wdtoken;
|
||
vDCookie = vDianShop.Cookies;
|
||
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
|
||
|
||
string imgStr = baseImgStr;
|
||
if (imgStr.EndsWith(".src"))
|
||
imgStr = imgStr.Substring(0, imgStr.Length - 4);
|
||
if (imgStr.Contains("@"))
|
||
imgStr = imgStr.Substring(0, imgStr.LastIndexOf("@")); //omsproductionimg.yangkeduo.com/images/2017-12-06/c5286b86a0ef6a982dcabbdf517a7d55.jpeg@750w_1l_50Q.src
|
||
if (!imgStr.ToLower().EndsWith("jpg") && !imgStr.ToLower().EndsWith("jpeg") && !imgStr.ToLower().EndsWith("png"))
|
||
return "error,无法识别的图片扩展名";
|
||
|
||
if (!imgStr.StartsWith("http"))
|
||
imgStr = "https://" + imgStr.TrimStart('/');
|
||
byte[] imgBytes = GetImgByte(imgStr);
|
||
if (imgBytes != null && imgBytes.Length > 0)
|
||
return upLoadSingleImg(prod, vDianShop, ref imgBytes, imgStr);
|
||
else
|
||
return "error,未能识别图片";
|
||
}
|
||
|
||
public string upLoadSingleImg(ProductMappingImportParam prod, VDianShopLoginInfo vDianShop, ref byte[] imgBytes, string imgStr)
|
||
{
|
||
if (imgBytes == null || imgBytes.Length == 0)
|
||
return "error,未能识别图片";
|
||
|
||
string result = null;
|
||
vDToken = vDianShop.Wdtoken;
|
||
vDCookie = vDianShop.Cookies;
|
||
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
|
||
|
||
var mainImgResult = "";
|
||
int times = 0;
|
||
while (true)
|
||
{
|
||
mainImgResult = request_vimg_vdian_com(ref imgBytes);
|
||
|
||
if (++times > 1 || !IsUploadLimitedFailed(mainImgResult)) break;
|
||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||
}
|
||
if (mainImgResult.Contains("\"message\":\"SUCCESS\""))
|
||
{
|
||
result = "ok," + BaseRegex.GetMatchRegexString(mainImgResult, "\"url\":\"([\\s\\S]*?)\"");
|
||
}
|
||
else
|
||
{
|
||
if (mainImgResult.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
}
|
||
result = BaseRegex.GetMatchRegexString(mainImgResult, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(result))
|
||
result = mainImgResult;
|
||
result = "error," + result;
|
||
LogSave.Add("[微店上传图片出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult + " pimg-" + imgStr);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public string upLoadAttr(ProductMappingImportParam prod, VDianShopLoginInfo vDianShop, string attrData)
|
||
{
|
||
string result = null;
|
||
vDToken = vDianShop.Wdtoken;
|
||
vDCookie = vDianShop.Cookies;
|
||
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
|
||
|
||
var attrResult = "";
|
||
int times = 0;
|
||
while (true)
|
||
{
|
||
attrResult = request_vdian_attr_multi(attrData);
|
||
|
||
if (++times > 1 || !IsUploadLimitedFailed(attrResult)) break;
|
||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||
}
|
||
if (attrResult.Contains("含敏感词"))
|
||
{
|
||
}
|
||
else
|
||
{
|
||
if (!attrResult.Contains("\"message\":\"OK\""))
|
||
{
|
||
Thread.Sleep(Randomx.GetId(8000, 12000));
|
||
attrResult = request_vdian_attr_multi(attrData);
|
||
}
|
||
if (!attrResult.Contains("\"message\":\"OK\""))
|
||
{
|
||
Thread.Sleep(Randomx.GetId(12000, 16000));
|
||
attrResult = request_vdian_attr_multi(attrData);
|
||
}
|
||
}
|
||
if (attrResult.Contains("\"message\":\"OK\""))
|
||
{
|
||
result = attrResult;
|
||
}
|
||
else
|
||
{
|
||
if (attrResult.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
}
|
||
result = BaseRegex.GetMatchRegexString(attrResult, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(result))
|
||
result = attrResult;
|
||
result = "error," + result;
|
||
LogSave.Add("[微店上传属性出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult + " pattr-" + attrData);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 将过多的sku attr属性拆分并模拟上传
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public bool upLoadAttrx(ProductMappingImportParam prod, VDianShopLoginInfo vDianShop, List<VDianParam.VDianAttr> wdAttrList,
|
||
List<VDianParam.VDianAttr> wdAttrList_New)
|
||
{
|
||
foreach (var attr in wdAttrList)
|
||
{
|
||
VDianParam.VDianAttr attr_new = new VDianParam.VDianAttr();
|
||
attr_new.attr_title = attr.attr_title;
|
||
attr_new.attr_values = new List<VDianParam.VDianAttrValue>();
|
||
foreach (var attr_value in attr.attr_values)
|
||
{
|
||
attr_new.attr_values.Add(attr_value);
|
||
// 模拟接口一次不能传太多属性数据,因此分开分多次上传
|
||
if (attr_new.attr_values.Count >= 10 || attr_value == attr.attr_values.LastOrDefault())
|
||
{
|
||
var data = "{\"attr_list\":[" + JsonHelper.SerializeObject(attr_new) + "]}";
|
||
attr_new.attr_values.Clear();
|
||
|
||
//data = GetHtml.UrlEncodeUtf8(data);
|
||
// 批量上传属性
|
||
var attrAddResult = "";
|
||
int times = 0;
|
||
while (true)
|
||
{
|
||
attrAddResult = this.upLoadAttr(prod, vDianShop, data);
|
||
Thread.Sleep(Randomx.GetId(300, 500));
|
||
|
||
if (++times > 1 || !IsUploadLimitedFailed(attrAddResult)) break;
|
||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||
}
|
||
if (attrAddResult.Contains("非法请求(每个型号分类下的可选型号数不能超过500个-95002)"))
|
||
{
|
||
// Todo:删除多余的属性
|
||
}
|
||
if (attrAddResult.Contains("invalid".ToUpper()))
|
||
{
|
||
}
|
||
if (!attrAddResult.Contains("\"message\":\"OK\""))
|
||
{
|
||
// 转换失败,添加属性出错:error: 远程服务器返回错误: (413) Request Entity Too Large。
|
||
prod.MappingResult = BaseRegex.GetMatchRegexString(attrAddResult, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||
prod.MappingResult = attrAddResult;
|
||
if (attrAddResult.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
prod.MappingResult = "店铺 " + vDianShop.ShopName + " 未登录";
|
||
}
|
||
prod.MappingResult = "转换失败,添加属性出错:" + prod.MappingResult;
|
||
LogSave.Add("[微店添加商品属性出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult
|
||
+ " pvattrs-" + JsonHelper.SerializeObject(wdAttrList));
|
||
return false;
|
||
}
|
||
if (attrAddResult.Contains("\"message\":\"OK\""))
|
||
{
|
||
try
|
||
{
|
||
JObject jObj = JObject.Parse(attrAddResult);
|
||
var resultArr = jObj["result"] as JArray;
|
||
if (resultArr == null)
|
||
resultArr = jObj["result"]?["data"] as JArray;
|
||
if (resultArr != null)
|
||
{
|
||
var str = resultArr.ToString().Replace("attrTitle", "attr_title").Replace("attrValues", "attr_values")
|
||
.Replace("attrId", "attr_id").Replace("attrValue", "attr_value");
|
||
var VDianAttrL = JsonHelper.DeserializeJsonToObject<List<VDianParam.VDianAttr>>(str);
|
||
if (VDianAttrL != null && VDianAttrL.Count > 0)
|
||
{
|
||
var attrExist = wdAttrList_New.FirstOrDefault(a => a.attr_title == VDianAttrL[0].attr_title);
|
||
if (attrExist == null)
|
||
wdAttrList_New.AddRange(VDianAttrL);
|
||
else
|
||
attrExist.attr_values.AddRange(VDianAttrL[0].attr_values);
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
prod.MappingResult = "转换失败,转换sku_map出错" + ex.Message;
|
||
LogSave.Add("[数据转换sku_map出错] " + data);
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public VDianParam.VDianProductBase ProductToVDianBySim(ProductMappingImportParam prod, ProductCollectBase product, VDianShopLoginInfo vDianShop, decimal addPercent, decimal addPrice, Func<VDianShopLoginInfo, string> getUa, bool isConvertUseAddMinPrice = true)
|
||
{
|
||
if (isConvertUseAddMinPrice) // 转换用
|
||
{
|
||
var addPercentNew = 100M;
|
||
var addPriceNew = Convert.ToDecimal(Randomx.GetId(10, 16));
|
||
if (addPercent < addPercentNew)
|
||
addPercent = addPercentNew;
|
||
if (addPrice < 10)
|
||
addPrice = addPriceNew;
|
||
addPrice += 0.1M;
|
||
}
|
||
else
|
||
{
|
||
reduceRate = 1.0M;
|
||
}
|
||
|
||
try
|
||
{
|
||
vDToken = vDianShop.Wdtoken;
|
||
vDCookie = vDianShop.Cookies;
|
||
spider_token = BaseClass.GetMd5(DateTime.Now.ToString()).Substring(0, 4).ToLower();
|
||
|
||
bool useCache = false;
|
||
bool getCache = false;
|
||
|
||
List<string> bigImages = new List<string>();
|
||
List<string> contentImages = new List<string>();
|
||
VDianParam.VDianProductBase vDianProduct = new VDianParam.VDianProductBase();
|
||
|
||
vDianProduct.shopId = vDianShop.ShopId;
|
||
vDianProduct.shopName = vDianShop.ShopName;
|
||
vDianProduct.itemId = "";
|
||
// 商品标题赋值
|
||
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;
|
||
}
|
||
|
||
// 商品属性
|
||
retry:
|
||
List<VDianParam.VDianAttr> wdAttrList = new List<VDianParam.VDianAttr>();
|
||
foreach (var prop in product.Props)
|
||
{
|
||
VDianParam.VDianAttr wdAttr = new VDianParam.VDianAttr();
|
||
|
||
wdAttr.attr_title = prop.name;
|
||
wdAttr.attr_values = new List<VDianParam.VDianAttrValue>();
|
||
foreach (var propValue in prop.Values)
|
||
{
|
||
if (propValue.name.Contains("收藏"))
|
||
continue;
|
||
var propValue_name = propValue.name.Replace("少先队", "SXD").Replace("共产党", "GCD").Replace("烟酒", "YJ").Replace("口罩", "KZ").Replace("*", "").Replace("收藏", "S-C").Replace("新品", "XP").Replace("推荐", "TJ");
|
||
//propValue_name = propValue_name.Replace("/", "-");
|
||
var attrValue = new VDianParam.VDianAttrValue()
|
||
{
|
||
attr_value = propValue_name,
|
||
attr_title = ""
|
||
};
|
||
//attrValue.attr_value = attrValue.attr_value.Replace("【", "").Replace("】", "");
|
||
if (attrValue.attr_value.Length > 20)
|
||
attrValue.attr_value = attrValue.attr_value.Substring(0, 18) + Randomx.GetWordWithNumber(2);
|
||
if (!wdAttr.attr_values.Any(at => at.attr_value == attrValue.attr_value))
|
||
{
|
||
wdAttr.attr_values.Add(attrValue);
|
||
propValue.name_pinduoduo = attrValue.attr_value;
|
||
}
|
||
}
|
||
wdAttrList.Add(wdAttr);
|
||
}
|
||
// 上传属性获取属性ID
|
||
if (wdAttrList.Count > 0)
|
||
{
|
||
List<VDianParam.VDianAttr> wdAttrList_New = new List<VDianParam.VDianAttr>();
|
||
|
||
var res = this.upLoadAttrx(prod, vDianShop, wdAttrList, wdAttrList_New);
|
||
if (!res) return null;
|
||
|
||
wdAttrList = wdAttrList_New;
|
||
vDianProduct.attrList = wdAttrList_New;
|
||
}
|
||
else
|
||
{
|
||
vDianProduct.attrList = new List<VDianParam.VDianAttr>();
|
||
}
|
||
|
||
// 商品sku
|
||
vDianProduct.sku = new List<VDianParam.VDianSkuProp>();
|
||
foreach (var sku in product.SkuMaps)
|
||
{
|
||
VDianParam.VDianSkuProp vDianSku = new VDianParam.VDianSkuProp();
|
||
vDianSku.attrIds = new List<long>();
|
||
|
||
var skuItems = sku.name.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
|
||
// 给sku匹配相对应的属性id
|
||
foreach (var item in skuItems)
|
||
{
|
||
var skuAttrStr = item;
|
||
var skuAttrNameStr = "";
|
||
if (skuAttrStr != null && skuAttrStr.Contains(":"))
|
||
{
|
||
skuAttrNameStr = skuAttrStr.Substring(0, skuAttrStr.IndexOf(':'));
|
||
skuAttrStr = skuAttrStr.Substring(skuAttrStr.IndexOf(':')).TrimStart(':');
|
||
}
|
||
|
||
|
||
foreach (var prop in product.Props)
|
||
{
|
||
if (!string.IsNullOrEmpty(skuAttrNameStr) && prop.name != skuAttrNameStr)
|
||
continue;
|
||
|
||
// 根据原商品sku找到对应的原商品prop属性
|
||
PropValueBase propValue = prop.Values.FirstOrDefault(p => p.name == skuAttrStr);
|
||
if (propValue != null)
|
||
{
|
||
foreach (var vDianAttr in wdAttrList)
|
||
{
|
||
if (!string.IsNullOrEmpty(skuAttrNameStr) && vDianAttr.attr_title != skuAttrNameStr)
|
||
continue;
|
||
|
||
// 根据原商品prop属性找到已经提交成功的新商品attr属性
|
||
var vDianAttrValue = vDianAttr.attr_values.FirstOrDefault(a => a.attr_value == propValue.name_pinduoduo);
|
||
if (vDianAttrValue != null)
|
||
{
|
||
vDianSku.attrIds.Add(vDianAttrValue.attr_id);
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
vDianSku.price = ((sku.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price).ToString();
|
||
vDianSku.stock = sku.number > 999999 ? 999999.ToString() : sku.number.ToString();
|
||
if (vDianSku.stock == "0")
|
||
vDianSku.stock = "1";
|
||
if (vDianSku.attrIds.Count > 0)
|
||
vDianProduct.sku.Add(vDianSku);
|
||
if (vDianProduct.sku.Count >= 500)
|
||
break;
|
||
}
|
||
if (isConvertUseAddMinPrice) // 转换用,如果是转换,为了满足拼多多上货价格区间,如果差价过大,在微店上货前做修改价格
|
||
{
|
||
// 上货后该商品预期最大价格
|
||
var wdMaxPrice = 0M;
|
||
try
|
||
{
|
||
wdMaxPrice = (product.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price;
|
||
wdMaxPrice = vDianProduct.sku.Max(wd => Convert.ToDecimal(wd.price));
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
// 价格护盾 注释
|
||
//// 计算该商品的拼多多sku最低价和最高价之间的最大倍数
|
||
//var priceTimes = PinduoduoCatList.GetPriceSpace(Convert.ToInt32(prod.CatId)) * 10;
|
||
//if (priceTimes == 12)
|
||
// priceTimes = 10;
|
||
//foreach (var item in vDianProduct.sku) // 拼多多上货二级护盾(价格护盾)
|
||
//{
|
||
// if (item.price.ParseToDecimal() < wdMaxPrice / priceTimes * 10)
|
||
// item.price = (wdMaxPrice / priceTimes * 10).ToString();
|
||
//}
|
||
}
|
||
|
||
if (vDianProduct.attrList.Count == 0)
|
||
{
|
||
if (vDianProduct.sku.Count >= 1)
|
||
{
|
||
vDianProduct.price = vDianProduct.sku[0].price;
|
||
vDianProduct.stock = vDianProduct.sku[0].stock;
|
||
vDianProduct.sku.Clear();
|
||
}
|
||
else
|
||
{
|
||
vDianProduct.price = ((product.price * (100M + addPercent) / 100M + addPrice) * reduceRate + product.express_price).ToString();
|
||
vDianProduct.stock = product.num > 999999 ? 999999.ToString() : product.num.ToString();
|
||
}
|
||
if (vDianProduct.stock == "0")
|
||
vDianProduct.stock = "1";
|
||
}
|
||
// 删除每组只有一个属性值的attr
|
||
for (int i = 0; i < vDianProduct.attrList.Count; i++)
|
||
{
|
||
var item = vDianProduct.attrList[i];
|
||
if (item.attr_values.Count == 1 && vDianProduct.attrList.Count > 1)
|
||
{
|
||
i--;
|
||
vDianProduct.attrList.Remove(item);
|
||
foreach (var sku in vDianProduct.sku)
|
||
{
|
||
sku.attrIds.Remove(item.attr_values[0].attr_id);
|
||
}
|
||
}
|
||
}
|
||
// attr最多三元组,删除多余的
|
||
while (vDianProduct.attrList.Count > 3)
|
||
{
|
||
var item = vDianProduct.attrList[0];
|
||
vDianProduct.attrList.Remove(item);
|
||
foreach (var sku in vDianProduct.sku)
|
||
{
|
||
foreach (var attr_value in item.attr_values)
|
||
sku.attrIds.Remove(attr_value.attr_id);
|
||
}
|
||
}
|
||
var skuTemps = new List<VDianParam.VDianSkuProp>();
|
||
foreach (var sku in vDianProduct.sku)
|
||
{
|
||
bool isContains = false;
|
||
foreach (var skuTemp in skuTemps)
|
||
{
|
||
if (sku.attrIds.All(ai => skuTemp.attrIds.Contains(ai)))
|
||
{
|
||
isContains = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!isContains)
|
||
skuTemps.Add(sku);
|
||
}
|
||
vDianProduct.sku.Clear();
|
||
vDianProduct.sku.AddRange(skuTemps);
|
||
|
||
// Mod图片以便读取缓存
|
||
var imgModStr = "";
|
||
// Mod主图
|
||
List<Tuple<string, KeyValue>> FormatMainImages = new List<Tuple<string, KeyValue>>();
|
||
foreach (var imgBaseStr in product.Images)
|
||
{
|
||
if (FormatMainImages.Count >= 5)
|
||
break;
|
||
|
||
var imgStr = imgBaseStr;
|
||
imgStr = VDianUpProdMappingApiBLL.GetFormattedImgFileName(imgStr);
|
||
if (string.IsNullOrEmpty(imgStr))
|
||
continue;
|
||
var imgMod = Math.Abs(BaseClass.GetLong(imgStr));
|
||
imgModStr += imgMod + ",";
|
||
FormatMainImages.Add(new Tuple<string, KeyValue>(imgStr, new KeyValue { Key = imgMod.ToString(), Value = "" }));
|
||
}
|
||
|
||
// Mod详情图
|
||
// <img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01JV2wi72G9E3yVYgIh_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01vSPIdA2G9E3zSkJhk_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN01t0OBAG2G9E3fQd1kB_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN01NsGKsQ2G9E3iXxhGR_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN01lF7pYV2G9E3ezymPI_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/TB2IRAZX5ERMeJjy0FcXXc7opXa_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN0168WOnD2G9E3gqJmnc_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN01NeuY6J2G9E3i5Dg1G_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i2/199488972/O1CN019Pmpe72G9E3iyirRK_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN01R9U7sl2G9E3dPl4ed_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN01nGTDni2G9E3cEqhz0_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN011ylz4Z2G9E3iyivaj_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN01YEri432G9E3iylCy2_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01ldxYYQ2G9E3iygiEl_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN01QMmemT2G9E3i5Ekbi_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i2/199488972/O1CN01l0Mtyy2G9E3ezz7CO_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN01RtTqI12G9E3fQeZQy_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01NyJoU62G9E3fQccvv_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01msBDD22G9E3ehzk5A_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN01PZxBVq2G9E3gqHyaN_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01IcxuRb2G9E3ei0PfT_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i2/199488972/O1CN01AdJ7af2G9E3dPnh2Y_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01zTdA972G9E3i5DkAf_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i2/199488972/O1CN01Flgk7s2G9E3XgXhag_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i3/199488972/O1CN01PVEQTw2G9E3fPc7wn_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i2/199488972/O1CN01E3L1mU2G9E3fGTtvb_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN014hS7Nk2G9E3fGTd78_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i2/199488972/O1CN01ntZX2w2G9E3iyjOkv_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i4/199488972/O1CN01jkyR8n2G9E3cEpy99_!!199488972.jpg\" /><img src=\"//img.alicdn.com/imgextra/i1/199488972/O1CN012G9DxxYsHebbo6h_!!199488972.jpg\" />
|
||
var matches = BaseRegex.GetMatchRegex(product.content, "<img([\\s\\S]*?)>");
|
||
List<Tuple<string, KeyValue>> FormatContentImages = new List<Tuple<string, KeyValue>>();
|
||
foreach (Match item in matches)
|
||
{
|
||
if (FormatContentImages.Count >= 5)
|
||
break;
|
||
|
||
var imgBaseStr = item.ToString();
|
||
imgBaseStr = BaseRegex.GetMatchRegexString(imgBaseStr, "src=\"([\\s\\S]*?)\"");
|
||
if (string.IsNullOrEmpty(imgBaseStr))
|
||
imgBaseStr = BaseRegex.GetMatchRegexString(item.ToString(), "src='([\\s\\S]*?)'");
|
||
if (string.IsNullOrEmpty(imgBaseStr))
|
||
continue;
|
||
var imgStr = imgBaseStr;
|
||
imgStr = VDianUpProdMappingApiBLL.GetFormattedImgFileName(imgStr);
|
||
if (string.IsNullOrEmpty(imgStr))
|
||
continue;
|
||
|
||
var imgMod = Math.Abs(BaseClass.GetLong(imgStr));
|
||
imgModStr += imgMod + ",";
|
||
FormatContentImages.Add(new Tuple<string, KeyValue>(imgStr, new KeyValue { Key = imgMod.ToString(), Value = "" }));
|
||
}
|
||
imgModStr = imgModStr.TrimEnd(',');
|
||
|
||
//// 读图片缓存
|
||
//var urlCache = BaseClass.LoginApiUrl + "?obj=upshopid/image_weidian&act=weidian_get";
|
||
//var dataCache = UserLogin.GetSignaturex() + "&ids=" + imgModStr;
|
||
//var htmlCache = GetHtml.PostUtf8(urlCache, dataCache);
|
||
//if (string.IsNullOrEmpty(htmlCache))
|
||
// htmlCache = GetHtml.PostUtf8(urlCache, dataCache);
|
||
//if (!string.IsNullOrEmpty(htmlCache))
|
||
//{
|
||
// var resultArr = htmlCache.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
|
||
// foreach (var item in resultArr)
|
||
// {
|
||
// var itemMod = BaseRegex.GetMatchRegexString(item, "(\\d{15,20}),");
|
||
// var imgs = FormatMainImages.Where(i => i.Item2.Key == itemMod);
|
||
// if (imgs.Count() > 0)
|
||
// {
|
||
// foreach (var img in imgs)
|
||
// {
|
||
// img.Item2.Value = item.Replace(itemMod + ",", "");
|
||
// }
|
||
// }
|
||
// imgs = FormatContentImages.Where(i => i.Item2.Key == itemMod);
|
||
// if (imgs.Count() > 0)
|
||
// {
|
||
// foreach (var img in imgs)
|
||
// {
|
||
// img.Item2.Value = item.Replace(itemMod + ",", "");
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
int iCount = 5; // 上货上传五张主图。
|
||
if (isConvertUseAddMinPrice)
|
||
iCount = Randomx.GetId(1, 3); // 数据转换上传随机1-2张主图
|
||
// 上传主图,最多五张主图
|
||
foreach (var item in FormatMainImages)
|
||
{
|
||
// 有缓存使用缓存盗链
|
||
if (!string.IsNullOrEmpty(item.Item2.Value))
|
||
{
|
||
bigImages.Add(item.Item2.Value);
|
||
continue;
|
||
}
|
||
|
||
if (bigImages.Count >= iCount)
|
||
break;
|
||
|
||
var imgStr = item.Item1;
|
||
byte[] imgBytes = GetImgByte(imgStr);
|
||
var mainImgResult = "";
|
||
int times = 0;
|
||
while (true)
|
||
{
|
||
mainImgResult = request_vimg_vdian_com(ref imgBytes);
|
||
|
||
if (++times > 1 || !IsUploadLimitedFailed(mainImgResult)) break;
|
||
Thread.Sleep(Randomx.GetId(2000, 4000));
|
||
}
|
||
if (mainImgResult.Contains("\"message\":\"SUCCESS\""))
|
||
{
|
||
var imgUrl = BaseRegex.GetMatchRegexString(mainImgResult, "\"url\":\"([\\s\\S]*?)\"");
|
||
//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);
|
||
//}
|
||
}
|
||
else
|
||
{
|
||
prod.MappingResult = BaseRegex.GetMatchRegexString(mainImgResult, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||
prod.MappingResult = mainImgResult;
|
||
if (mainImgResult.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
prod.MappingResult = "转换失败,店铺 " + vDianShop.ShopName + " 未登录";
|
||
return null;
|
||
}
|
||
prod.MappingResult = "主图出错:" + prod.MappingResult;
|
||
LogSave.Add("[微店上传主图出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult + " pimg-" + imgStr);
|
||
}
|
||
Thread.Sleep(200);
|
||
}
|
||
// 商品主图赋值
|
||
vDianProduct.imgs = new List<VDianParam.VDianBigImg>();
|
||
foreach (var img in bigImages)
|
||
{
|
||
VDianParam.VDianBigImg vDianImage = new VDianParam.VDianBigImg();
|
||
vDianImage.title = "";
|
||
vDianImage.url = img;
|
||
vDianProduct.imgs.Add(vDianImage);
|
||
}
|
||
if (vDianProduct.imgs.Count == 0 && !string.IsNullOrEmpty(prod.MappingResult))
|
||
return null;
|
||
|
||
iCount = 5; // 上货上传五张详情图
|
||
if (isConvertUseAddMinPrice)
|
||
{
|
||
iCount = 1;
|
||
}
|
||
// 上传详情图,最多五张
|
||
foreach (var item in FormatContentImages)
|
||
{
|
||
if (!string.IsNullOrEmpty(item.Item2.Value))
|
||
{
|
||
contentImages.Add(item.Item2.Value);
|
||
continue;
|
||
}
|
||
|
||
if (contentImages.Count >= iCount)
|
||
break;
|
||
|
||
var imgStr = item.Item1;
|
||
byte[] imgBytes = GetImgByte(imgStr);
|
||
if (imgBytes == null)
|
||
continue;
|
||
|
||
var detailImgResult = "";
|
||
int times = 0;
|
||
while (true)
|
||
{
|
||
detailImgResult = request_vimg_vdian_com(ref imgBytes);
|
||
|
||
if (++times > 1 || !IsUploadLimitedFailed(detailImgResult)) break;
|
||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||
}
|
||
if (detailImgResult.Contains("\"message\":\"SUCCESS\""))
|
||
{
|
||
var imgUrl = BaseRegex.GetMatchRegexString(detailImgResult, "\"url\":\"([\\s\\S]*?)\"");
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
contentImages.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);
|
||
}
|
||
else
|
||
{
|
||
prod.MappingResult = BaseRegex.GetMatchRegexString(detailImgResult, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||
prod.MappingResult = detailImgResult;
|
||
if (detailImgResult.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
prod.MappingResult = "转换失败,店铺 " + vDianShop.ShopName + " 未登录";
|
||
return null;
|
||
}
|
||
prod.MappingResult = "详情图出错:" + prod.MappingResult;
|
||
LogSave.Add("[微店上传详情图出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult + " pimg-" + imgStr);
|
||
}
|
||
Thread.Sleep(200);
|
||
}
|
||
// 如果没有详情图,插入一张主图
|
||
if (contentImages.Count == 0 && bigImages.Count > 0)
|
||
{
|
||
contentImages.Add(bigImages[0]);
|
||
}
|
||
if (vDianProduct.imgs.Count == 0 && contentImages.Count > 0)
|
||
{
|
||
VDianParam.VDianBigImg vDianImage = new VDianParam.VDianBigImg();
|
||
vDianImage.title = "";
|
||
vDianImage.url = contentImages[0];
|
||
vDianProduct.imgs.Add(vDianImage);
|
||
}
|
||
if (contentImages.Count == 0 && !string.IsNullOrEmpty(prod.MappingResult))
|
||
return null;
|
||
|
||
// 上传商品详情
|
||
var tmp_detailId = "";
|
||
int timesx = 0;
|
||
while (true)
|
||
{
|
||
tmp_detailId = request_vdian_good_detail_com(contentImages);
|
||
|
||
if (++timesx > 1 || !IsUploadLimitedFailed(tmp_detailId)) break;
|
||
Thread.Sleep(Randomx.GetId(2000, 3000));
|
||
}
|
||
if (tmp_detailId.Contains("\"message\":\"OK\""))
|
||
{
|
||
tmp_detailId = BaseRegex.GetMatchRegexString(tmp_detailId, "\"tmp_detail_id\":\"([\\s\\S]*?)\"");
|
||
vDianProduct.tmpDetailId = tmp_detailId;
|
||
}
|
||
else
|
||
{
|
||
prod.MappingResult = BaseRegex.GetMatchRegexString(tmp_detailId, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||
prod.MappingResult = tmp_detailId;
|
||
if (tmp_detailId.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
prod.MappingResult = "转换失败,店铺 " + vDianShop.ShopName + " 未登录";
|
||
return null;
|
||
}
|
||
prod.MappingResult = "详情出错:" + prod.MappingResult;
|
||
LogSave.Add("[微店上传商品详情出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult + " pcontentimgs-" + JsonHelper.SerializeObject(contentImages));
|
||
}
|
||
Thread.Sleep(500);
|
||
|
||
// 获取商品类目
|
||
// 取类目缓存
|
||
var cateResult = "";
|
||
//cateResult = GetVDCateCache(prod);
|
||
//if (string.IsNullOrEmpty(cateResult))
|
||
//{
|
||
// Thread.Sleep(Randomx.GetId(250, 750));
|
||
// cateResult = GetVDCateCache(prod);
|
||
//}
|
||
bool isReget = false;
|
||
_ReGetCate:
|
||
if (!string.IsNullOrEmpty(cateResult) && !cateResult.ToLower().Contains("error"))
|
||
{
|
||
vDianProduct.bgCateId = Convert.ToInt64(cateResult);
|
||
}
|
||
else
|
||
{
|
||
cateResult = request_vdian_cate_com(vDianProduct.itemName);
|
||
// 123216014>>33 33为纸质书类目
|
||
if (cateResult.Contains("\"message\":\"OK\""))
|
||
{
|
||
vDianProduct.bgCateId = BaseRegex.GetLongJson(ref cateResult, "id");
|
||
//// 写入类目缓存
|
||
//var cateCache = SaveToVDCateCache(prod, vDianProduct.bgCateId.ToString());
|
||
}
|
||
else
|
||
{
|
||
prod.MappingResult = BaseRegex.GetMatchRegexString(cateResult, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||
prod.MappingResult = cateResult;
|
||
if (cateResult.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
prod.MappingResult = "转换失败,店铺 " + vDianShop.ShopName + " 未登录";
|
||
return null;
|
||
}
|
||
prod.MappingResult = "转换失败,获取类目出错:" + prod.MappingResult;
|
||
LogSave.Add("[微店获取商品类目出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult);
|
||
return null;
|
||
}
|
||
}
|
||
if (vDianProduct.bgCateId == 33)
|
||
{
|
||
vDianProduct.bgCateId = 50023878;
|
||
}
|
||
|
||
// 上货上传商品
|
||
var jsonStr = JsonHelper.SerializeObject(vDianProduct);
|
||
var result = "";
|
||
int timesxx = 0;
|
||
while (true)
|
||
{
|
||
var ua = getUa(vDianShop);
|
||
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);
|
||
|
||
result = request_vdian_product_com(jsonStr, ua);
|
||
if (string.IsNullOrEmpty(result))
|
||
result = request_vdian_product_com(jsonStr, ua);
|
||
if (string.IsNullOrEmpty(result))
|
||
result = request_vdian_product_com(jsonStr, ua);
|
||
if (string.IsNullOrEmpty(result))
|
||
result = "error,服务端返回空";
|
||
|
||
if (++timesxx > 2 || !IsUploadLimitedFailed(result)) break;
|
||
Thread.Sleep(Randomx.GetId(3000, 5000));
|
||
}
|
||
if (result.Contains("invalid".ToUpper()))
|
||
{
|
||
}
|
||
Thread.Sleep(Randomx.GetId(1000, 2000));
|
||
if (result.Contains("类目不存在") && !isReget)
|
||
{
|
||
isReget = true;
|
||
cateResult = "";
|
||
goto _ReGetCate;
|
||
}
|
||
LogSave.Add("[微店获取Ua并上传结束]" + " pid-" + prod.ProductId + "result:" + result);
|
||
if (result != null && result.Contains("\"message\":\"OK\""))
|
||
{
|
||
vDianProduct.itemId = BaseRegex.GetLongJson(ref result, "itemId").ToString();
|
||
if (vDianProduct.itemId.Length <= 5)
|
||
{
|
||
prod.MappingResult = "上传失败,返回了错误的商品id";
|
||
return null;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
prod.MappingResult = BaseRegex.GetMatchRegexString(result, "\"message\":\"([\\s\\S]+?)\"");
|
||
if (string.IsNullOrEmpty(prod.MappingResult))
|
||
{
|
||
prod.MappingResult = result;
|
||
}
|
||
if (result.Contains("属性值非法"))
|
||
{
|
||
if (useCache)
|
||
{
|
||
useCache = false;
|
||
getCache = false;
|
||
goto retry;
|
||
}
|
||
}
|
||
if (result.Contains("LOGIN ERROR"))
|
||
{
|
||
vDianShop.LoginStatus = 2;
|
||
vDianShop.UpGoodAuth = "请先登录";
|
||
prod.MappingResult = "转换失败,店铺 " + vDianShop.ShopName + " 未登录";
|
||
return null;
|
||
}
|
||
if (result.Contains("创建商品过于频繁"))
|
||
{
|
||
prod.MappingResult = "商品驳回,请更换其它商品转换";
|
||
}
|
||
prod.MappingResult = "转换失败,上传商品出错:" + prod.MappingResult;
|
||
LogSave.Add("[微店上传商品出错]" + " pid-" + prod.ProductId + " ptitle-" + prod.ProductTitle + " psid-" + vDianShop.ShopId
|
||
+ " psname-" + vDianShop.ShopName + " pfrom-" + prod.From + " pmsg-" + prod.MappingResult + " presult-" + result);
|
||
return null;
|
||
}
|
||
return vDianProduct;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
StackTrace st = new StackTrace(ex, true);
|
||
StackFrame[] frames = st.GetFrames();
|
||
string Mssg = "";
|
||
var frame = frames.LastOrDefault();
|
||
if (frame != null)
|
||
{
|
||
//Console.WriteLine("{0}:{1}({2},{3})", frame.GetFileName(), frame.GetMethod().Name, frame.GetFileLineNumber(), frame.GetFileColumnNumber());
|
||
var fileName = frame.GetFileName();
|
||
fileName = fileName?.Split('\\').LastOrDefault()?.Split('.').FirstOrDefault();
|
||
|
||
Mssg = "" + fileName + " ----- ";
|
||
Mssg += frame.GetMethod().Name;
|
||
Mssg += "(" + frame.GetFileLineNumber() + ":";
|
||
Mssg += frame.GetFileColumnNumber() + ")";
|
||
}
|
||
if (string.IsNullOrEmpty(Mssg))
|
||
Mssg = ex.Message;
|
||
prod.MappingResult = "商品转换出现异常:" + Mssg;
|
||
//LogSave.Add("商品转换出现异常:" + ex.Message + "-" + ex.StackTrace);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取图片
|
||
/// </summary>
|
||
/// <param name="imgUrl"></param>
|
||
/// <returns></returns>
|
||
public byte[] GetImgByte(string imgUrl)
|
||
{
|
||
try
|
||
{
|
||
imgUrl = imgUrl.TrimStart('/');
|
||
if (!imgUrl.StartsWith("http"))
|
||
{
|
||
imgUrl = "https://" + imgUrl;
|
||
}
|
||
WebClientx web = new WebClientx();
|
||
byte[] img = web.DownloadData(imgUrl);
|
||
return img;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return null;
|
||
}
|
||
}
|
||
|
||
private static void WriteMultipartBodyToRequest(HttpWebRequest request, string body, byte[] imgBytes)
|
||
{
|
||
string[] multiparts = Regex.Split(body, @"<!>");
|
||
byte[] bytes;
|
||
using (MemoryStream ms = new MemoryStream())
|
||
{
|
||
foreach (string part in multiparts)
|
||
{
|
||
if (part == "imgBytes")
|
||
{
|
||
bytes = imgBytes;
|
||
}
|
||
else
|
||
{
|
||
bytes = System.Text.Encoding.UTF8.GetBytes(part.Replace("\r\n", "\n").Replace("\r", "\n").Replace("\n", "\r\n"));
|
||
}
|
||
|
||
ms.Write(bytes, 0, bytes.Length);
|
||
}
|
||
|
||
request.ContentLength = ms.Length;
|
||
using (Stream stream = request.GetRequestStream())
|
||
{
|
||
ms.WriteTo(stream);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 提交商品图片
|
||
/// </summary>
|
||
/// <param name="imgBytes"></param>
|
||
/// <returns>上传到服务器的图片路径</returns>
|
||
public string request_vimg_vdian_com(ref byte[] imgBytes, string url = "https://vimg.weidian.com/upload/v3/direct?scope=pcitem&fileType=image&_=1573797846576")
|
||
{
|
||
while (isUpLoadImg)
|
||
{
|
||
Thread.Sleep(250);
|
||
}
|
||
isUpLoadImg = true;
|
||
int retryCount = 0;
|
||
|
||
_retry:
|
||
HttpWebResponse response = null;
|
||
var responseText = "";
|
||
string proxyStr = null;
|
||
|
||
try
|
||
{
|
||
//Create request to URL.
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||
|
||
//Set request headers.
|
||
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.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");
|
||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||
request.Headers.Set(HttpRequestHeader.Cookie, this.vDCookie);
|
||
request.Timeout = 45000;
|
||
|
||
if (IsUseProxy)
|
||
{
|
||
//proxyStr = GetProxyTemp();
|
||
//if (proxyStr != null) request.Proxy = new WebProxy(proxyStr);
|
||
|
||
//var proxy = NaiBa.Util.GlobalProxyHelper.GetWebProxy();
|
||
//if (request.Proxy != null) // && request.Proxy.Credentials != null)
|
||
// request.Proxy = proxy;
|
||
}
|
||
|
||
request.Method = "POST";
|
||
request.ServicePoint.Expect100Continue = false;
|
||
|
||
//Set request body.
|
||
string body = @"------WebKitFormBoundaryl8PNkxxP0AKTlrpf
|
||
Content-Disposition: form-data; name=""file""; filename=""uploadfile.jpg""
|
||
Content-Type: image/jpeg
|
||
|
||
<!>imgBytes<!>
|
||
------WebKitFormBoundaryl8PNkxxP0AKTlrpf
|
||
Content-Disposition: form-data; name=""wdtoken""
|
||
|
||
<wdtoken>
|
||
------WebKitFormBoundaryl8PNkxxP0AKTlrpf--
|
||
";
|
||
body = body.Replace("<wdtoken>", vDToken);
|
||
WriteMultipartBodyToRequest(request, body, imgBytes);
|
||
|
||
//Get response to request.
|
||
response = (HttpWebResponse)request.GetResponse();
|
||
}
|
||
catch (WebException e)
|
||
{
|
||
if (e.ToString().Contains("888"))
|
||
goto _retry;
|
||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||
else responseText = "error: " + e.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responseText = "error: " + ex.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
if (response != null)
|
||
{
|
||
if (string.IsNullOrEmpty(responseText))
|
||
responseText = GetHtml.ReadResponse(response);
|
||
response.Close();
|
||
}
|
||
|
||
Thread.Sleep(Randomx.GetId(300, 500));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(Randomx.GetId(300, 500));
|
||
isUpLoadImg = false;
|
||
return responseText;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过sku属性值获取sku属性编码,供上传使用
|
||
/// </summary>
|
||
/// <param name="attrType"></param>
|
||
/// <param name="attrValue"></param>
|
||
/// <returns>skuId</returns>
|
||
private string request_vdian_attr_com(string attrTitle, string attrValue)
|
||
{
|
||
while (isGetAttrId || IsChangeAdsl)
|
||
{
|
||
Thread.Sleep(50);
|
||
}
|
||
isGetAttrId = true;
|
||
|
||
string param = "{\"attr_list\":[{\"attr_title\":\"" + attrTitle + "\",\"attr_values\":[{\"attr_value\":\"" + attrValue + "\"}]}]}";
|
||
string url = "https://thor.weidian.com/wditem/itemWrite.updateAttrList/1.0";
|
||
var result = request_vdian_common(url, param);
|
||
|
||
Thread.Sleep(Randomx.GetId(250, 350));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(Randomx.GetId(250, 350));
|
||
isGetAttrId = false;
|
||
return result;
|
||
}
|
||
|
||
private string request_vdian_attr_multi(string attrList)
|
||
{
|
||
while (isGetAttrId || IsChangeAdsl)
|
||
{
|
||
Thread.Sleep(50);
|
||
}
|
||
isGetAttrId = true;
|
||
|
||
string param = attrList;
|
||
string url = "https://thor.weidian.com/wditem/itemWrite.updateAttrList/1.0";
|
||
var result = request_vdian_common(url, param);
|
||
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(100 + Randomx.GetId(200));
|
||
isGetAttrId = false;
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微店商品详情模拟接口
|
||
/// </summary>
|
||
/// <param name="response"></param>
|
||
/// <returns></returns>
|
||
private string request_vdian_good_detail_com(List<string> detailImgs)
|
||
{
|
||
while (isUpLoadDetail || IsChangeAdsl)
|
||
{
|
||
Thread.Sleep(50);
|
||
}
|
||
isUpLoadDetail = true;
|
||
int retryCount = 0;
|
||
|
||
_retry:
|
||
HttpWebResponse response = null;
|
||
string responseText = "";
|
||
string param = "{\"item_detail\":\"[";
|
||
foreach (var img in detailImgs)
|
||
{
|
||
var items = img.Split('/');
|
||
param += "{\\\"type\\\":2,\\\"url\\\":\\\"" + img + "\\\"},";
|
||
}
|
||
param = param.TrimEnd(',');
|
||
param += "]\",\"from\":\"weidian_pc\",\"submitWithLimitWords\":false,\"submitWithSensitiveWord\":false}";
|
||
param = HttpUtility.UrlEncode(param, Encoding.UTF8);
|
||
|
||
string proxyStr = null;
|
||
|
||
try
|
||
{
|
||
//Create request to URL.
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://thor.weidian.com/wditem/itemWrite.updateItemDetail/1.0?_=" + BaseClass.DateTimeToTimestampSeconds(DateTime.Now));
|
||
|
||
//Set request headers.
|
||
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.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");
|
||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||
request.Headers.Set(HttpRequestHeader.Cookie, vDCookie);
|
||
request.Timeout = 30000;
|
||
|
||
if (IsUseProxy)
|
||
{
|
||
//proxyStr = GetProxyTemp();
|
||
//if (proxyStr != null) request.Proxy = new WebProxy(proxyStr);
|
||
|
||
//var proxy = NaiBa.Util.GlobalProxyHelper.GetWebProxy();
|
||
//if (proxy != null) // && proxy.Credentials != null)
|
||
// request.Proxy = proxy;
|
||
}
|
||
|
||
request.Method = "POST";
|
||
request.ServicePoint.Expect100Continue = false;
|
||
|
||
//Set request body.
|
||
string body = @"param=" + param + "&wdtoken=" + vDToken;
|
||
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();
|
||
}
|
||
catch (WebException e)
|
||
{
|
||
if (e.ToString().Contains("888"))
|
||
goto _retry;
|
||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||
else responseText = "error: " + e.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responseText = "error: " + ex.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
if (response != null)
|
||
{
|
||
if (string.IsNullOrEmpty(responseText))
|
||
responseText = GetHtml.ReadResponse(response);
|
||
response.Close();
|
||
}
|
||
|
||
Thread.Sleep(50 + Randomx.GetId(50));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(25 + Randomx.GetId(50));
|
||
isUpLoadDetail = false;
|
||
return responseText;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微店商品上传
|
||
/// </summary>
|
||
/// <param name="response"></param>
|
||
/// <returns></returns>
|
||
private string request_vdian_product_com(string param, string ua = "")
|
||
{
|
||
while (isUpLoad || IsChangeAdsl)
|
||
{
|
||
Thread.Sleep(50);
|
||
}
|
||
|
||
isUpLoad = true;
|
||
int retryCount = 0;
|
||
|
||
_retry:
|
||
HttpWebResponse response = null;
|
||
string responseText = "";
|
||
|
||
string proxyStr = null;
|
||
|
||
try
|
||
{
|
||
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://thor.weidian.com/itemsell/item.create.pc/1.0?_=" + AliMaMaBLL.ConvertDateTimeInt(DateTime.Now));
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://thor.weidian.com/itemsell/item.create.pc/1.0");
|
||
|
||
request.KeepAlive = true;
|
||
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.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");
|
||
request.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||
request.Headers.Add("Sec-Fetch-Dest", @"empty");
|
||
//request.Referer = "https://d.weidian.com/weidian-pc/pc-vue-item/?spider_token=" + spider_token;
|
||
request.Referer = "https://d.weidian.com/";
|
||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||
request.Headers.Set(HttpRequestHeader.Cookie, vDCookie);
|
||
request.Timeout = 30000;
|
||
|
||
#region 以下测试代理ip上传图片
|
||
#endregion
|
||
|
||
if (IsUseProxy)
|
||
{
|
||
//proxyStr = GetProxyTemp();
|
||
//if (proxyStr != null) request.Proxy = new WebProxy(proxyStr);
|
||
|
||
//var proxy = NaiBa.Util.GlobalProxyHelper.GetWebProxy();
|
||
//if (proxy != null) // && request.Proxy.Credentials != null)
|
||
// request.Proxy = proxy;
|
||
}
|
||
|
||
request.Method = "POST";
|
||
request.ServicePoint.Expect100Continue = false;
|
||
|
||
string body = @"param=" + HttpUtility.UrlEncode(param, Encoding.UTF8) + "&ua=" + HttpUtility.UrlEncode(ua, Encoding.UTF8)
|
||
+ "&wdtoken=" + vDToken;
|
||
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();
|
||
}
|
||
catch (WebException e)
|
||
{
|
||
if (e.ToString().Contains("888"))
|
||
goto _retry;
|
||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||
else responseText = "error: " + e.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responseText = "error: " + ex.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
if (response != null)
|
||
{
|
||
if (string.IsNullOrEmpty(responseText))
|
||
responseText = GetHtml.ReadResponse(response);
|
||
response.Close();
|
||
}
|
||
|
||
Thread.Sleep(Randomx.GetId(100, 200));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(25 + Randomx.GetId(50));
|
||
isUpLoad = false;
|
||
return responseText;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微店根据商品标题名称获取类目
|
||
/// </summary>
|
||
/// <param name="response"></param>
|
||
/// <returns></returns>
|
||
private string request_vdian_cate_com(string goodName)
|
||
{
|
||
while (isGetCate || IsChangeAdsl)
|
||
Thread.Sleep(50);
|
||
isGetCate = true;
|
||
|
||
var url = "https://thor.weidian.com/category/predictRegularCategory/1.0";
|
||
var param = "{\"keyword\":\"" + goodName + "\",\"size\":1}";
|
||
var result = request_vdian_common(url, param);
|
||
|
||
Thread.Sleep(1000 + Randomx.GetId(1000));
|
||
isGetCate = false;
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询店铺销量信息,检测微店登录状态。
|
||
/// </summary>
|
||
/// <param name="wdToken"></param>
|
||
/// <param name="wdCookies"></param>
|
||
/// <returns></returns>
|
||
public string request_vdian_sell_com(string wdToken, string wdCookies)
|
||
{
|
||
this.vDToken = wdToken;
|
||
this.vDCookie = wdCookies;
|
||
|
||
string url = "https://thor.weidian.com/didataserver/reporthome.queryPcHomeCoreData/1.0";
|
||
var result = request_vdian_common(url, "");
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除所有属性列表
|
||
/// </summary>
|
||
/// <param name="para"></param>
|
||
/// <returns></returns>
|
||
private string request_vdian_hideAttr_com(List<string> para)
|
||
{
|
||
while (isHideAttr || IsChangeAdsl)
|
||
Thread.Sleep(50);
|
||
isHideAttr = true;
|
||
|
||
var param = "{\"attr_ids\":[";
|
||
foreach (var item in para)
|
||
{
|
||
param += item + ",";
|
||
}
|
||
param = param.TrimEnd(',');
|
||
param += "]}";
|
||
string url = "https://thor.weidian.com/wditem/itemWrite.hideAttr/1.0";
|
||
var result = request_vdian_common(url, param);
|
||
|
||
Thread.Sleep(25 + Randomx.GetId(50));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(25 + Randomx.GetId(50));
|
||
isHideAttr = false;
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有属性列表
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
private string request_vdian_all_attr_com()
|
||
{
|
||
while (isHideAttr || IsChangeAdsl)
|
||
Thread.Sleep(50);
|
||
isHideAttr = true;
|
||
|
||
string url = "https://thor.weidian.com/wditem/item.getAllAttrList/1.0";
|
||
string param = "{}";
|
||
var result = request_vdian_common(url, param);
|
||
|
||
Thread.Sleep(25 + Randomx.GetId(50));
|
||
if (!IsUseProxy)
|
||
Thread.Sleep(25 + Randomx.GetId(50));
|
||
isHideAttr = false;
|
||
return result;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微店Request通用方法
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="param"></param>
|
||
/// <returns></returns>
|
||
private string request_vdian_common(string url, string param)
|
||
{
|
||
int retryCount = 0;
|
||
|
||
_retry:
|
||
HttpWebResponse response = null;
|
||
string responseText = "";
|
||
param = HttpUtility.UrlEncode(param, Encoding.UTF8);
|
||
|
||
string proxyStr = null;
|
||
|
||
try
|
||
{
|
||
var requestUrl = url + "?";
|
||
var queryStr = "";
|
||
|
||
if (!string.IsNullOrEmpty(param))
|
||
{
|
||
queryStr += "param=" + param;
|
||
}
|
||
queryStr += "&wdtoken=" + vDToken + "&_=" + BaseClass.DateTimeToTimestampSeconds(DateTime.Now);
|
||
|
||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl + queryStr.TrimStart('&'));
|
||
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.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");
|
||
request.Headers.Set(HttpRequestHeader.Cookie, vDCookie);
|
||
request.Timeout = 30000;
|
||
|
||
if (IsUseProxy)
|
||
{
|
||
//proxyStr = GetProxyTemp();
|
||
//if (proxyStr != null) request.Proxy = new WebProxy(proxyStr);
|
||
|
||
//var proxy = NaiBa.Util.GlobalProxyHelper.GetWebProxy();
|
||
//if (proxy != null) // && request.Proxy.Credentials != null)
|
||
// request.Proxy = proxy;
|
||
}
|
||
|
||
response = (HttpWebResponse)request.GetResponse();
|
||
}
|
||
catch (WebException e)
|
||
{
|
||
if (e.ToString().Contains("888"))
|
||
goto _retry;
|
||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||
responseText = "error: " + e.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
responseText = "error: " + ex.Message;
|
||
|
||
//if (proxyStr != null && Ips.Keys.Contains(proxyStr))
|
||
// Ips[proxyStr] = false;
|
||
//if (retryCount++ < 20 && IsUseProxy)
|
||
// goto _retry;
|
||
}
|
||
if (response != null)
|
||
{
|
||
var text = GetHtml.ReadResponse(response);
|
||
if (!string.IsNullOrEmpty(text))
|
||
responseText = text;
|
||
|
||
response.Close();
|
||
}
|
||
return responseText;
|
||
}
|
||
|
||
//// 取类目缓存
|
||
//private string GetVDCateCache(ProductMappingImportParam prod)
|
||
//{
|
||
// string url = BaseClass.BuildObjString("weidian_cache&act=product_get");
|
||
// string fromStr = "";
|
||
// if (prod.From == "淘宝")
|
||
// fromStr = "tb-";
|
||
// else if (prod.From == "阿里巴巴")
|
||
// fromStr = "al-";
|
||
// else if (prod.From == "拼多多" || prod.From == "搜款网")
|
||
// fromStr = "pd-";
|
||
// long Id = Convert.ToInt64(prod.RealProductId);
|
||
// fromStr = "cid-";
|
||
// Id = Convert.ToInt64(prod.CatId);
|
||
// var table = Id % 128;
|
||
|
||
// string data = "&product_id=" + fromStr + Id
|
||
// + "&number=" + table
|
||
// + "&" + UserLogin.GetSignaturex();
|
||
// string html = GetHtml.PostUtf8(url, data);
|
||
// return html;
|
||
//}
|
||
|
||
//public static Dictionary<string, bool> Ips { get; set; } = new Dictionary<string, bool>();
|
||
//private string GetProxyTemp()
|
||
//{
|
||
// var ipList = Ips.Where(i => i.Value == true).ToList();
|
||
// if (ipList.Count == 0)
|
||
// {
|
||
// bool IsOverdue = false;
|
||
// if (!string.IsNullOrEmpty(GlobalConfig.ConfigParam.ProxyUrl))
|
||
// {
|
||
// List<string> listIp = Model.Param.CollectManage.PddSameScreeningBLL.InitIp(GlobalConfig.ConfigParam.ProxyUrl, out IsOverdue);
|
||
// Ips.Clear();
|
||
// foreach (var item in listIp)
|
||
// {
|
||
// Ips[item] = true;
|
||
// }
|
||
// }
|
||
// }
|
||
// ipList = Ips.Where(i => i.Value == true).ToList();
|
||
// if (ipList.Count == 0)
|
||
// return null;
|
||
// else
|
||
// return ipList[0].Key;
|
||
//}
|
||
|
||
//static DateTime lastRefresh { get; set; } = DateTime.Now.AddMinutes(-1);
|
||
//static bool isRefresh { get; set; } = false;
|
||
/// <summary>
|
||
/// 获取代理
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
//private WebProxy GetProxy()
|
||
//{
|
||
// try
|
||
// {
|
||
// string proxyIP = AgentProductBuild.GetRandomProxyIP();
|
||
|
||
// if (!string.IsNullOrEmpty(proxyIP))
|
||
// {
|
||
// string[] ipArr = proxyIP.Split(':');
|
||
// if (ipArr.Length == 2)
|
||
// {
|
||
// WebProxy proxy = new WebProxy(ipArr[0], ipArr[1].ParseToInt());
|
||
// return proxy;
|
||
// }
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// }
|
||
|
||
// return null;
|
||
//}
|
||
|
||
|
||
///// <summary>
|
||
///// 微店类目缓存写入
|
||
///// </summary>
|
||
///// <param name="prod"></param>
|
||
///// <param name="vdCateId"></param>
|
||
///// <returns></returns>
|
||
//private string SaveToVDCateCache(ProductMappingImportParam prod, string vdCateId)
|
||
//{
|
||
// string url = BaseClass.BuildObjString("weidian_cache&act=product_add");
|
||
// string fromStr = "";
|
||
// if (prod.From == "淘宝")
|
||
// fromStr = "tb-";
|
||
// else if (prod.From == "阿里巴巴")
|
||
// fromStr = "al-";
|
||
// else if (prod.From == "拼多多" || prod.From == "搜款网")
|
||
// fromStr = "pd-";
|
||
// long Id = Convert.ToInt64(prod.RealProductId);
|
||
// fromStr = "cid-";
|
||
// Id = Convert.ToInt64(prod.CatId);
|
||
// var table = Id % 128;
|
||
|
||
// string data = "&product_id=" + fromStr + Id
|
||
// + "&category_id=" + vdCateId
|
||
// + "&number=" + table
|
||
// + "&" + UserLogin.GetSignaturex();
|
||
// string html = GetHtml.PostUtf8(url, data);
|
||
// return html;
|
||
//}
|
||
|
||
/// <summary>
|
||
/// 根据sku title和sku value获取sku id
|
||
/// </summary>
|
||
/// <param name="skuTitle_Value"></param>
|
||
/// <returns></returns>
|
||
//private string GetVDSkuCache(string skuTitle_Value)
|
||
//{
|
||
// var skuMod = Math.Abs(BaseClass.GetLong(skuTitle_Value));
|
||
// var table = skuMod % 128;
|
||
|
||
// string url = BaseClass.BuildObjString("weidian_cache&act=sku_get");
|
||
|
||
// string data = "&sku_title=" + skuMod
|
||
// + "&number=" + table
|
||
// + "&" + UserLogin.GetSignaturex();
|
||
// string html = GetHtml.PostUtf8(url, data);
|
||
// return html;
|
||
//}
|
||
|
||
/// <summary>
|
||
/// 微店skuId缓存写入
|
||
/// </summary>
|
||
/// <param name="skuTitle_Value"></param>
|
||
/// <param name="skuId"></param>
|
||
/// <returns></returns>
|
||
//private string SaveToVDSkuCache(string skuTitle_Value, long skuId, bool isUpdate = false)
|
||
//{
|
||
// var skuMod = Math.Abs(BaseClass.GetLong(skuTitle_Value));
|
||
// var table = skuMod % 128;
|
||
|
||
// string url = BaseClass.BuildObjString("weidian_cache&act=sku_add");
|
||
// if (isUpdate)
|
||
// url = BaseClass.BuildObjString("weidian_cache&act=sku_update");
|
||
|
||
// string data = "&sku_title=" + skuMod
|
||
// + "&sku_id=" + skuId
|
||
// + "&number=" + table
|
||
// + "&" + UserLogin.GetSignaturex();
|
||
// string html = GetHtml.PostUtf8(url, data);
|
||
// return html;
|
||
//}
|
||
|
||
/// <summary>
|
||
/// 微店上传访问受限
|
||
/// </summary>
|
||
/// <param name="result"></param>
|
||
/// <returns></returns>
|
||
private static bool IsUploadLimitedFailed(string result)
|
||
{
|
||
return result.Contains("无法连接到远程服务器") || result.Contains("操作超时") || result.Contains("基础连接已经关闭")
|
||
|| result.Contains("远程主机强迫关闭") || result.Contains("Unable to write data") || result.Contains("现在人太多了, 请稍后重试");
|
||
}
|
||
}
|
||
}
|