From cafdbbd95d970aaa795ebf43d0f788ecb80fd66a Mon Sep 17 00:00:00 2001 From: wule_5900x Date: Sun, 12 Apr 2026 11:12:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E5=BA=97=E6=A8=A1=E6=8B=9F=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20=20=E5=85=B6=E4=BB=96=E4=B8=80=E4=BA=9B=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AllBase/AllBase.csproj | 2 + AllBase/BaseClass.cs | 2 +- AllBase/GetHtml.cs | 5 + AllBase/GetProxyHtml.cs | 6 +- .../ToolsManage/ProductMappingImportParam.cs | 5 + AllBase/Model/Param/VDianManage/VDianParam.cs | 298 +++ AllBase/Model/Result/VDianShopLoginInfo.cs | 89 + AllBase/Randomx.cs | 2 +- .../BLL/BXX/BXXProductManage.cs | 26 +- .../KJD_WebService/KJD_WebService.csproj.user | 2 +- TEMUKJD/BLL/VDian/MappingVDianApiBLL.cs | 35 + TEMUKJD/BLL/VDian/MappingVDianBLL.cs | 1665 +++++++++++++++++ TEMUKJD/KJD.csproj | 6 +- .../PDDGetChanceProdByImgForm.cs | 2 +- .../PDDGetChanceProdForm.Designer.cs | 126 +- .../PDDGetChanceProdForm.cs | 72 +- .../ProductForms/WXDBProdUploadForm.cs | 9 +- .../WXForms/TalkForms/BuyerOrderListForm.cs | 24 +- .../WXForms/TalkForms/WxTalkForm.Designer.cs | 24 +- TEMUKJD/WXForms/TalkForms/WxTalkForm.cs | 46 +- 20 files changed, 2343 insertions(+), 103 deletions(-) create mode 100644 AllBase/Model/Param/VDianManage/VDianParam.cs create mode 100644 AllBase/Model/Result/VDianShopLoginInfo.cs create mode 100644 TEMUKJD/BLL/VDian/MappingVDianApiBLL.cs create mode 100644 TEMUKJD/BLL/VDian/MappingVDianBLL.cs diff --git a/AllBase/AllBase.csproj b/AllBase/AllBase.csproj index fe29a8d..3484139 100644 --- a/AllBase/AllBase.csproj +++ b/AllBase/AllBase.csproj @@ -206,6 +206,7 @@ + @@ -217,6 +218,7 @@ + diff --git a/AllBase/BaseClass.cs b/AllBase/BaseClass.cs index ef95fc7..6768ab1 100644 --- a/AllBase/BaseClass.cs +++ b/AllBase/BaseClass.cs @@ -27,7 +27,7 @@ namespace AllBase /// /// 版本ID /// - public static int VersionCount = 970; + public static int VersionCount = 976; //public static int VersionCount = 613; /// diff --git a/AllBase/GetHtml.cs b/AllBase/GetHtml.cs index 01d37db..03e0526 100644 --- a/AllBase/GetHtml.cs +++ b/AllBase/GetHtml.cs @@ -2044,5 +2044,10 @@ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom { return new Regex(@"\\u([0-9A-F]{4})", RegexOptions.IgnoreCase | RegexOptions.Compiled).Replace(source, x => Convert.ToChar(Convert.ToUInt16(x.Result("$1"), 16)).ToString()); } + + public static string ReadResponse(HttpWebResponse response, Encoding encoding = null) + { + return GetProxyHtml.ReadResponse(response, encoding); + } } } diff --git a/AllBase/GetProxyHtml.cs b/AllBase/GetProxyHtml.cs index 6bc9f4f..c5a0254 100644 --- a/AllBase/GetProxyHtml.cs +++ b/AllBase/GetProxyHtml.cs @@ -760,7 +760,7 @@ namespace AllBase } return webProxy; } - public static string ReadResponse(HttpWebResponse response) + public static string ReadResponse(HttpWebResponse response, Encoding encoding = null) { using (Stream responseStream = response.GetResponseStream()) { @@ -773,8 +773,8 @@ namespace AllBase { streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress); } - - using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8)) + if (encoding == null) encoding = Encoding.UTF8; + using (StreamReader streamReader = new StreamReader(streamToRead, encoding)) { return streamReader.ReadToEnd(); } diff --git a/AllBase/Model/Param/ToolsManage/ProductMappingImportParam.cs b/AllBase/Model/Param/ToolsManage/ProductMappingImportParam.cs index da5bc6b..2100036 100644 --- a/AllBase/Model/Param/ToolsManage/ProductMappingImportParam.cs +++ b/AllBase/Model/Param/ToolsManage/ProductMappingImportParam.cs @@ -88,5 +88,10 @@ namespace AllBase.Model.Param.ToolsManage /// 转换成功来源 未知,Api,模拟,缓存等 统计用 /// public string MappingResourceType { get; set; } + + /// + /// 转换重试次数 + /// + public int retryTimes { get; set; } } } diff --git a/AllBase/Model/Param/VDianManage/VDianParam.cs b/AllBase/Model/Param/VDianManage/VDianParam.cs new file mode 100644 index 0000000..79f7253 --- /dev/null +++ b/AllBase/Model/Param/VDianManage/VDianParam.cs @@ -0,0 +1,298 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AllBase.Model.Param.VDianManage +{ + + public class VDianParam + { + /// + /// + /// + public class VDianItemAddParam + { + /// + /// 偏远地区是否包邮:1包邮,0不包邮只有在free_delivery为1时候有效,否则不包邮 + /// + public byte remote_free_delivery { get; set; } + + /// + /// 商品描述 + /// + public string item_comment { get; set; } + + /// + /// 商品编号 + /// + public string merchant_code { get; set; } + + /// + /// status=1或不传为在架商品,status=2为下架商品,4表示下架和在架商品 + /// + public byte status { get; set; } + + /// + /// 商品图片 + /// + public List bigImgs { get; set; } + + /// + /// 商品图片描述 + /// + public List titles { get; set; } + + /// + /// 库存 + /// + public int stock { get; set; } + + /// + /// 是否包邮:0不包邮,1包邮 + /// + public byte free_delivery { get; set; } + + /// + /// 商品采购价(单位:分) + /// + public int purchase_fee { get; set; } + + /// + /// 商品详情 + /// + public List item_detail_list { get; set; } + + /// + /// 商品sku + /// + public List sku { get; set; } + + /// + /// 商品属性图片列表 + /// + public List attr_list { get; set; } + + public List attrList { get; set; } + + /// + /// 价格 + /// + public string price { get; set; } + + /// + /// 商品描述 + /// + public string item_name { get; set; } + } + + /// + /// 微店接口参数定义 + /// public={"access_token": "xxxxx", "version": "1.4", "method": "vdian.item.add", "format": "json","auth_userid":"923284842"} + /// + public class VDianPublicParam + { + public string access_token { get; set; } + public const string version = "1.4"; + public string method { get; set; } // "method": "vdian.item.add" + public const string format = "json"; + public string auth_userid { get; set; } // "auth_userid": "923284842" + } + + public class VDianItemDetail + { + /// + /// type =1 文字模块,type =2 图片 + /// + public byte type { get; set; } + + /// + /// 商品图片URL + /// + public string url { get; set; } + + /// + /// 详情文本(type=1填写此字段) + /// + public string text { get; set; } + } + + public class VDianSku + { + /// + /// sku采购价格(单位:分) + /// + //public int purchaseFee { get; set; } + + /// + /// sku编码 + /// + //public string sku_merchant_code { get; set; } + + /// + /// sku图片 + /// + public string img { get; set; } + + /// + /// sku库存 + /// + public int stock { get; set; } + + /// + /// sku价格 + /// + public string price { get; set; } + + /// + /// sku标题 + /// + public string title { get; set; } + + /// + /// sku对应的属性id列表 + /// + public List attr_ids { get; set; } + + /// + /// sku特殊编码 + /// + public string sku_merchant_code { get; set; } + } + + public class VDianProductBase + { + public VDianProductBase() + { + price = ""; + isPointPrice = 0; + vpoint_limit_count = ""; + pointPrice = new PointPrice(); + point_price_range = 3; + stock = ""; + weight = ""; + merchantCode = ""; + catePropList = new List(); + expressFeeTemplateId = 0; + freeDelivery = 0; + remoteFreeDelivery = 0; + isWeightTemplate = 0; + cateIds = ""; + purchase_limit = false; + purchase_limit_num = ""; + isNeedIdNo = ""; + isHiddenSetting = false; + itemStatus = 1; + areaTemplateId = ""; + areaTemplateFlag = 0; + isFutureSold = false; + futureSoldTime = ""; + submitWithLimitWords = false; + submitWithSensitiveWord = false; + isCheckQualification = true; + } + + public string shopId { get; set; } + public string shopName { get; set; } + public string itemId { get; set; } + public List imgs { get; set; } + public string itemName { get; set; } + public string price { get; set; } + public int isPointPrice { get; set; } + public string vpoint_limit_count { get; set; } + public PointPrice pointPrice { get; set; } + public int point_price_range { get; set; } + public string stock { get; set; } + public string weight { get; set; } + public string merchantCode { get; set; } + public long bgCateId { get; set; } + public List catePropList { get; set; } + public string tmpDetailId { get; set; } + public List attrList { get; set; } + public List sku { get; set; } + public int expressFeeTemplateId { get; set; } + public int freeDelivery { get; set; } + public int remoteFreeDelivery { get; set; } + public int isWeightTemplate { get; set; } + public string cateIds { get; set; } + public bool purchase_limit { get; set; } + public string purchase_limit_num { get; set; } + public string isNeedIdNo { get; set; } + public bool isHiddenSetting { get; set; } + public int itemStatus { get; set; } + public string areaTemplateId { get; set; } + public int areaTemplateFlag { get; set; } + public bool isFutureSold { get; set; } + public string futureSoldTime { get; set; } + public bool submitWithLimitWords { get; set; } + public bool submitWithSensitiveWord { get; set; } + public bool isCheckQualification { get; set; } + } + + public class VDianBigImg + { + public string url { get; set; } + public string title { get; set; } + } + + public class PointPrice + { + public string price { get { return _price; } set { _price = value; } } + public string point { get { return _point; } set { _point = value; } } + string _point = ""; + string _price = ""; + } + + public class VDianAttr + { + public string attr_title { get; set; } + public List attr_values { get; set; } + } + + public class VDianAttrValue + { + public long attr_id { get; set; } + public string attr_value { get; set; } + public string attr_title { get; set; } + } + + public class VDianAttrValuePic + { + public long attr_id { get; set; } + public List attr_values { get; set; } + public string attr_title { get; set; } + public string img { get; set; } + } + + public class VDianSkuProp + { + public List attrIds { get; set; } + public string price { get; set; } + public string stock { get; set; } + public string merchantCode { get; set; } = ""; + } + + // 微店佣金 + public class VDianCommission + { + public string itemIds { get; set; } + public bool isDownPrice { get; set; } + public bool isUpPrice { get; set; } + public int priceUpLimit { get; set; } + public VDianCommissionRate commissionRate { get; set; } + public string specifyRetailSellerIds { get; set; } + public string specifyCommissionRate { get; set; } + } + + // 微店佣金级别 + public class VDianCommissionRate + { + public string L1 { get; set; } + public string L2 { get; set; } + public string L3 { get; set; } + public string L4 { get; set; } + public string L5 { get; set; } + } + } +} diff --git a/AllBase/Model/Result/VDianShopLoginInfo.cs b/AllBase/Model/Result/VDianShopLoginInfo.cs new file mode 100644 index 0000000..11fe3c8 --- /dev/null +++ b/AllBase/Model/Result/VDianShopLoginInfo.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AllBase.Model.Result +{ + public class VDianShopLoginInfo + { + public string ShopName { get; set; } + public string ShopId { get; set; } + public string Cookies { get; set; } + public string Wdtoken { get; set; } + /// + /// 店铺登录状态 1为登录成功 2为掉线 + /// + public int LoginStatus { get; set; } + public string Phone { get; set; } + public string Password { get; set; } + public string UpGoodAuth { get; set; } + /// + /// 主体认证 + /// + public string MainAuth { get; set; } + public string ApiAuth { get; set; } + //public string WdApiToken { get; set; } + public string Api2Auth { get; set; } + public string WdApi2Token { get; set; } + public string WdApi2RefreshToken { get; set; } + public List LstWdApiToken { get; set; } + public VDianApiToken MultiImgApiToken { get; set; } + public VDianApiToken MultiAttrApiToken { get; set; } + public VDianApiToken MultiProductApiToken { get; set; } + /// + /// 是否开通分成推广金 + /// + //public string IsCPSable { get; set; } + } + + public class VDianApiToken + { + /// + /// Token对应的AppKey + /// + public VDianAppKey AppKey { get; set; } + + /// + /// AccessToken值 + /// + public string ApiAccessToken { get; set; } + + /// + /// 最后刷新日期,发现不是当日,立即刷新一次 + /// + public string LastRefreshDate { get; set; } + + public string RefreshToken { get; set; } + + /// + /// 是否已过期或者未授权 + /// + public string ApiAuth { get; set; } + } + + public class VDianAppKey + { + /// + /// 微店的AppKey + /// + public string AppKey { get; set; } + /// + /// 上货是否达到数量上限,未达上限为ok,达到上限为error + /// + public string Status { get; set; } + /// + /// 图片上传数量限制,未达上限为ok,达到上限为error + /// + public string ImgsCountStatus { get; set; } + /// + /// 上货数量限制,未达上限为ok,达到上限为error + /// + public string GoodsCountStatus { get; set; } + /// + /// 上传属性数量限制,未达上限为ok,达到上限为error + /// + public string PropCountStatus { get; set; } + } +} diff --git a/AllBase/Randomx.cs b/AllBase/Randomx.cs index 4ee1b18..3521036 100644 --- a/AllBase/Randomx.cs +++ b/AllBase/Randomx.cs @@ -40,7 +40,7 @@ namespace AllBase } return s.ToString(); } - public static string GetWordNumber(int len) + public static string GetWordWithNumber(int len) { StringBuilder s = new StringBuilder(); for (int i = 0; i < len; i++) diff --git a/KJDService/KJD_WebService/BLL/BXX/BXXProductManage.cs b/KJDService/KJD_WebService/BLL/BXX/BXXProductManage.cs index 18a9fd5..11aed81 100644 --- a/KJDService/KJD_WebService/BLL/BXX/BXXProductManage.cs +++ b/KJDService/KJD_WebService/BLL/BXX/BXXProductManage.cs @@ -250,6 +250,11 @@ namespace KJD_Web.BLL.BXX return "{\"code\":19999,\"msg\":\"输入为空\"}"; } + /// + /// 违规商品 + /// + /// + /// public string MdyViolationProd(string inputData) { if (!string.IsNullOrEmpty(inputData)) @@ -334,6 +339,11 @@ namespace KJD_Web.BLL.BXX return "{\"code\":19999,\"msg\":\"输入为空\"}"; } + /// + /// 获取商品SpuId(快速查询) + /// + /// + /// public string GetProductSpuIdLst(string inputData) { var timeCalc = DateTime.Now; @@ -409,6 +419,12 @@ namespace KJD_Web.BLL.BXX return "{\"code\":19999,\"msg\":\"输入为空\"}"; } + /// + /// 查询商品列表 + /// + /// + /// + /// public string GetProductList(string inputData, bool isDetail = false) { var timeCalc = DateTime.Now; @@ -509,7 +525,15 @@ namespace KJD_Web.BLL.BXX if (!string.IsNullOrWhiteSpace(search_ext_code)) where += " and p.ext_code like '%" + search_ext_code + "%'"; if (!string.IsNullOrWhiteSpace(search_prod_name)) - where += " and p.product_name like '%" + search_prod_name + "%'"; + { + var searchProdNameWords = search_prod_name.Split(new string[] { ",", ",", ";", ";", " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); + var multi_search_prod_name = ""; + foreach (var word in searchProdNameWords) + { + multi_search_prod_name += " or p.product_name like '%" + word + "%'"; + } + where += " and (" + multi_search_prod_name.Substring(4) + ")"; + } if (!string.IsNullOrWhiteSpace(search_group)) where += " and p.group like '%" + search_group + "%'"; if (!string.IsNullOrWhiteSpace(search_notes)) diff --git a/KJDService/KJD_WebService/KJD_WebService.csproj.user b/KJDService/KJD_WebService/KJD_WebService.csproj.user index 1b87364..4bcdc04 100644 --- a/KJDService/KJD_WebService/KJD_WebService.csproj.user +++ b/KJDService/KJD_WebService/KJD_WebService.csproj.user @@ -8,7 +8,7 @@ - Debug|Any CPU + Release|Any CPU ShowAllFiles diff --git a/TEMUKJD/BLL/VDian/MappingVDianApiBLL.cs b/TEMUKJD/BLL/VDian/MappingVDianApiBLL.cs new file mode 100644 index 0000000..307c3c9 --- /dev/null +++ b/TEMUKJD/BLL/VDian/MappingVDianApiBLL.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TemuKJD.BLL.VDian +{ + public class MappingVDianApiBLL + { + public static string GetFormattedImgFileName(string oldName) + { + if (oldName == null) + return ""; + var imgStr = oldName; + 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.Contains("?") && !imgStr.ToLower().EndsWith(".jpg") && !imgStr.ToLower().EndsWith(".jpeg") && !imgStr.ToLower().EndsWith(".bmp") + && !imgStr.ToLower().EndsWith(".png") && !imgStr.ToLower().EndsWith(".ss2") && !imgStr.ToLower().EndsWith(".gif")) + imgStr = imgStr.Substring(0, imgStr.LastIndexOf("?")); + if (!imgStr.StartsWith("http")) + imgStr = "https://" + imgStr.TrimStart('/'); + if (!imgStr.ToLower().EndsWith(".jpg") && !imgStr.ToLower().EndsWith(".jpeg") && !imgStr.ToLower().EndsWith(".png") && !imgStr.ToLower().EndsWith(".bmp") + && !imgStr.ToLower().EndsWith(".ss2") && !imgStr.ToLower().EndsWith(".gif")) + { + if (imgStr.Contains("gw.alicdn.com")) + return imgStr; + return ""; + } + return imgStr; + } + } +} diff --git a/TEMUKJD/BLL/VDian/MappingVDianBLL.cs b/TEMUKJD/BLL/VDian/MappingVDianBLL.cs new file mode 100644 index 0000000..3ff383b --- /dev/null +++ b/TEMUKJD/BLL/VDian/MappingVDianBLL.cs @@ -0,0 +1,1665 @@ +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 MappingVDianBLL + { + 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 listPurifyData = new List(); + /// + /// 上货时按上货拼多多上家93%需求适当减少的价格比例,如果是真实上货则不减少 + /// + decimal reduceRate = 0.96M; + + public MappingVDianBLL() + { + 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; + } + + /// + /// 将过多的sku attr属性拆分并模拟上传 + /// + /// + public bool upLoadAttrx(ProductMappingImportParam prod, VDianShopLoginInfo vDianShop, List wdAttrList, + List 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(); + 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>(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 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 bigImages = new List(); + List contentImages = new List(); + 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 lst = new List(); + 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 wdAttrList = new List(); + foreach (var prop in product.Props) + { + VDianParam.VDianAttr wdAttr = new VDianParam.VDianAttr(); + + wdAttr.attr_title = prop.name; + wdAttr.attr_values = new List(); + 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 wdAttrList_New = new List(); + + 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(); + } + + // 商品sku + vDianProduct.sku = new List(); + foreach (var sku in product.SkuMaps) + { + VDianParam.VDianSkuProp vDianSku = new VDianParam.VDianSkuProp(); + vDianSku.attrIds = new List(); + + 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(); + 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> FormatMainImages = new List>(); + foreach (var imgBaseStr in product.Images) + { + if (FormatMainImages.Count >= 5) + break; + + var imgStr = imgBaseStr; + imgStr = MappingVDianApiBLL.GetFormattedImgFileName(imgStr); + if (string.IsNullOrEmpty(imgStr)) + continue; + var imgMod = Math.Abs(BaseClass.GetLong(imgStr)); + imgModStr += imgMod + ","; + FormatMainImages.Add(new Tuple(imgStr, new KeyValue { Key = imgMod.ToString(), Value = "" })); + } + + // Mod详情图 + // + var matches = BaseRegex.GetMatchRegex(product.content, ""); + List> FormatContentImages = new List>(); + 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 = MappingVDianApiBLL.GetFormattedImgFileName(imgStr); + if (string.IsNullOrEmpty(imgStr)) + continue; + + var imgMod = Math.Abs(BaseClass.GetLong(imgStr)); + imgModStr += imgMod + ","; + FormatContentImages.Add(new Tuple(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(); + 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; + } + } + + /// + /// 获取图片 + /// + /// + /// + 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); + } + } + } + + /// + /// 提交商品图片 + /// + /// + /// 上传到服务器的图片路径 + 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"" + + +------WebKitFormBoundaryl8PNkxxP0AKTlrpf-- +"; + body = body.Replace("", 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; + } + + /// + /// 通过sku属性值获取sku属性编码,供上传使用 + /// + /// + /// + /// skuId + 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; + } + + /// + /// 微店商品详情模拟接口 + /// + /// + /// + private string request_vdian_good_detail_com(List 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; + } + + /// + /// 微店商品上传 + /// + /// + /// + 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; + } + + /// + /// 微店根据商品标题名称获取类目 + /// + /// + /// + 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; + } + + /// + /// 查询店铺销量信息,检测微店登录状态。 + /// + /// + /// + /// + 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; + } + + /// + /// 删除所有属性列表 + /// + /// + /// + private string request_vdian_hideAttr_com(List 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; + } + + /// + /// 获取所有属性列表 + /// + /// + 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; + } + + /// + /// 微店Request通用方法 + /// + /// + /// + /// + 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 Ips { get; set; } = new Dictionary(); + //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 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; + /// + /// 获取代理 + /// + /// + //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; + //} + + + ///// + ///// 微店类目缓存写入 + ///// + ///// + ///// + ///// + //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; + //} + + /// + /// 根据sku title和sku value获取sku id + /// + /// + /// + //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; + //} + + /// + /// 微店skuId缓存写入 + /// + /// + /// + /// + //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; + //} + + /// + /// 微店上传访问受限 + /// + /// + /// + private static bool IsUploadLimitedFailed(string result) + { + return result.Contains("无法连接到远程服务器") || result.Contains("操作超时") || result.Contains("基础连接已经关闭") + || result.Contains("远程主机强迫关闭") || result.Contains("Unable to write data") || result.Contains("现在人太多了, 请稍后重试"); + } + } +} diff --git a/TEMUKJD/KJD.csproj b/TEMUKJD/KJD.csproj index 504c416..571f4ca 100644 --- a/TEMUKJD/KJD.csproj +++ b/TEMUKJD/KJD.csproj @@ -129,6 +129,8 @@ + + @@ -1793,9 +1795,7 @@ Work - - - + False diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdByImgForm.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdByImgForm.cs index 13220bf..6c70b5e 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdByImgForm.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdByImgForm.cs @@ -379,7 +379,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms List fileNameLst = new List(); - string tempImgPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordNumber(8).ToLower(); + string tempImgPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower(); if (!Directory.Exists(tempImgPath)) Directory.CreateDirectory(tempImgPath); var imgUrlLst = this.txtImgUrl.Text.Split(new string[] { "\r", "\n", ";", " " }, StringSplitOptions.RemoveEmptyEntries); diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.Designer.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.Designer.cs index 465fecb..8ca6216 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.Designer.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.Designer.cs @@ -30,15 +30,16 @@ namespace TemuKJD.PDDForms.ProductSelectForms private void InitializeComponent() { this.components = new System.ComponentModel.Container(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle15 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle16 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle17 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle18 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle19 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle20 = new System.Windows.Forms.DataGridViewCellStyle(); - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle21 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle(); this.splitContainer1 = new System.Windows.Forms.SplitContainer(); this.ucGroupBoxEx1 = new TemuKJD.UserComponent.UcGroupBoxEx(this.components); + this.btnSelectNotGetDetail = new DevComponents.DotNetBar.PanelEx(); this.cmbFilterType = new System.Windows.Forms.ComboBox(); this.btnFilter = new DevComponents.DotNetBar.PanelEx(); this.txtFilter = new System.Windows.Forms.TextBox(); @@ -105,7 +106,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.chk = new TemuKJD.UserComponent.UcCheckBox(this.components); this.statusBar = new TemuKJD.UserControls.StatusBarUserControl(); this.ucSplitPage1 = new TemuKJD.UserControls.UcSplitPage(); - this.btnSelectNotGetDetail = new DevComponents.DotNetBar.PanelEx(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -197,17 +197,42 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.ucGroupBoxEx1.TabStop = false; this.ucGroupBoxEx1.Text = "操作"; // + // btnSelectNotGetDetail + // + this.btnSelectNotGetDetail.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.btnSelectNotGetDetail.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; + this.btnSelectNotGetDetail.Cursor = System.Windows.Forms.Cursors.Hand; + this.btnSelectNotGetDetail.DisabledBackColor = System.Drawing.Color.Empty; + this.btnSelectNotGetDetail.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + this.btnSelectNotGetDetail.Location = new System.Drawing.Point(1125, 30); + this.btnSelectNotGetDetail.Name = "btnSelectNotGetDetail"; + this.btnSelectNotGetDetail.Size = new System.Drawing.Size(153, 25); + this.btnSelectNotGetDetail.Style.Alignment = System.Drawing.StringAlignment.Center; + this.btnSelectNotGetDetail.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); + this.btnSelectNotGetDetail.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); + this.btnSelectNotGetDetail.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; + this.btnSelectNotGetDetail.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash; + this.btnSelectNotGetDetail.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None; + this.btnSelectNotGetDetail.Style.ForeColor.Color = System.Drawing.Color.White; + this.btnSelectNotGetDetail.Style.GradientAngle = 90; + this.btnSelectNotGetDetail.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center; + this.btnSelectNotGetDetail.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); + this.btnSelectNotGetDetail.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); + this.btnSelectNotGetDetail.TabIndex = 790; + this.btnSelectNotGetDetail.Text = "一键勾选未采集详情商品"; + this.btnSelectNotGetDetail.Click += new System.EventHandler(this.btnSelectNotGetDetail_Click); + // // cmbFilterType // this.cmbFilterType.FormattingEnabled = true; this.cmbFilterType.Items.AddRange(new object[] { - "过滤所有字段", + "过滤标题+SKU", "过滤标题"}); this.cmbFilterType.Location = new System.Drawing.Point(987, 58); this.cmbFilterType.Name = "cmbFilterType"; - this.cmbFilterType.Size = new System.Drawing.Size(102, 25); + this.cmbFilterType.Size = new System.Drawing.Size(108, 25); this.cmbFilterType.TabIndex = 1012; - this.cmbFilterType.Text = "过滤所有字段"; + this.cmbFilterType.Text = "过滤标题+SKU"; // // btnFilter // @@ -217,7 +242,7 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.btnFilter.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); this.btnFilter.Location = new System.Drawing.Point(987, 30); this.btnFilter.Name = "btnFilter"; - this.btnFilter.Size = new System.Drawing.Size(102, 25); + this.btnFilter.Size = new System.Drawing.Size(108, 25); this.btnFilter.Style.Alignment = System.Drawing.StringAlignment.Center; this.btnFilter.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); this.btnFilter.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); @@ -761,19 +786,19 @@ namespace TemuKJD.PDDForms.ProductSelectForms // this.dgvShop.AllowUserToAddRows = false; this.dgvShop.AllowUserToDeleteRows = false; - dataGridViewCellStyle15.BackColor = System.Drawing.Color.WhiteSmoke; - this.dgvShop.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle15; + dataGridViewCellStyle1.BackColor = System.Drawing.Color.WhiteSmoke; + this.dgvShop.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle1; this.dgvShop.AutoRowNumber = true; this.dgvShop.BackgroundColor = System.Drawing.Color.White; this.dgvShop.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); - dataGridViewCellStyle16.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle16.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle16.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle16.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle16.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle16.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle16.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.dgvShop.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle16; + dataGridViewCellStyle2.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle2.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle2.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle2.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle2.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle2.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle2.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dgvShop.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle2; this.dgvShop.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvShop.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.colSelect, @@ -894,20 +919,20 @@ namespace TemuKJD.PDDForms.ProductSelectForms // this.dgvChanceProduct.AllowUserToAddRows = false; this.dgvChanceProduct.AllowUserToDeleteRows = false; - dataGridViewCellStyle17.BackColor = System.Drawing.Color.WhiteSmoke; - this.dgvChanceProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle17; + dataGridViewCellStyle3.BackColor = System.Drawing.Color.WhiteSmoke; + this.dgvChanceProduct.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle3; this.dgvChanceProduct.AutoRowNumber = true; this.dgvChanceProduct.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; this.dgvChanceProduct.BackgroundColor = System.Drawing.Color.White; this.dgvChanceProduct.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); - dataGridViewCellStyle18.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; - dataGridViewCellStyle18.BackColor = System.Drawing.SystemColors.Control; - dataGridViewCellStyle18.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - dataGridViewCellStyle18.ForeColor = System.Drawing.SystemColors.WindowText; - dataGridViewCellStyle18.SelectionBackColor = System.Drawing.SystemColors.Highlight; - dataGridViewCellStyle18.SelectionForeColor = System.Drawing.SystemColors.HighlightText; - dataGridViewCellStyle18.WrapMode = System.Windows.Forms.DataGridViewTriState.False; - this.dgvChanceProduct.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle18; + dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; + dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; + dataGridViewCellStyle4.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); + dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; + dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; + dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; + dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.False; + this.dgvChanceProduct.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dgvChanceProduct.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dgvChanceProduct.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.colCheck, @@ -966,8 +991,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms // // colGoodsName // - dataGridViewCellStyle19.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.colGoodsName.DefaultCellStyle = dataGridViewCellStyle19; + dataGridViewCellStyle5.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.colGoodsName.DefaultCellStyle = dataGridViewCellStyle5; this.colGoodsName.FillWeight = 120F; this.colGoodsName.HeaderText = "商品名称"; this.colGoodsName.Name = "colGoodsName"; @@ -988,8 +1013,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms // // colPrice // - dataGridViewCellStyle20.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.colPrice.DefaultCellStyle = dataGridViewCellStyle20; + dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.colPrice.DefaultCellStyle = dataGridViewCellStyle6; this.colPrice.FillWeight = 70F; this.colPrice.HeaderText = "价格"; this.colPrice.Name = "colPrice"; @@ -1004,8 +1029,8 @@ namespace TemuKJD.PDDForms.ProductSelectForms // // colMsg // - dataGridViewCellStyle21.WrapMode = System.Windows.Forms.DataGridViewTriState.True; - this.colMsg.DefaultCellStyle = dataGridViewCellStyle21; + dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True; + this.colMsg.DefaultCellStyle = dataGridViewCellStyle7; this.colMsg.FillWeight = 200F; this.colMsg.HeaderText = "操作结果"; this.colMsg.Name = "colMsg"; @@ -1051,31 +1076,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms this.ucSplitPage1.TotalPage = 1; this.ucSplitPage1.PageChange += new System.Action(this.ucSplitPage1_PageChange); // - // btnSelectNotGetDetail - // - this.btnSelectNotGetDetail.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.btnSelectNotGetDetail.ColorSchemeStyle = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled; - this.btnSelectNotGetDetail.Cursor = System.Windows.Forms.Cursors.Hand; - this.btnSelectNotGetDetail.DisabledBackColor = System.Drawing.Color.Empty; - this.btnSelectNotGetDetail.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.btnSelectNotGetDetail.Location = new System.Drawing.Point(1125, 30); - this.btnSelectNotGetDetail.Name = "btnSelectNotGetDetail"; - this.btnSelectNotGetDetail.Size = new System.Drawing.Size(153, 25); - this.btnSelectNotGetDetail.Style.Alignment = System.Drawing.StringAlignment.Center; - this.btnSelectNotGetDetail.Style.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); - this.btnSelectNotGetDetail.Style.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(126)))), ((int)(((byte)(255))))); - this.btnSelectNotGetDetail.Style.BorderColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.PanelBorder; - this.btnSelectNotGetDetail.Style.BorderDashStyle = System.Drawing.Drawing2D.DashStyle.Dash; - this.btnSelectNotGetDetail.Style.BorderSide = DevComponents.DotNetBar.eBorderSide.None; - this.btnSelectNotGetDetail.Style.ForeColor.Color = System.Drawing.Color.White; - this.btnSelectNotGetDetail.Style.GradientAngle = 90; - this.btnSelectNotGetDetail.StyleMouseOver.Alignment = System.Drawing.StringAlignment.Center; - this.btnSelectNotGetDetail.StyleMouseOver.BackColor1.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); - this.btnSelectNotGetDetail.StyleMouseOver.BackColor2.Color = System.Drawing.Color.FromArgb(((int)(((byte)(25)))), ((int)(((byte)(102)))), ((int)(((byte)(255))))); - this.btnSelectNotGetDetail.TabIndex = 790; - this.btnSelectNotGetDetail.Text = "一键勾选未采集详情商品"; - this.btnSelectNotGetDetail.Click += new System.EventHandler(this.btnSelectNotGetDetail_Click); - // // PDDGetChanceProdForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; diff --git a/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.cs b/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.cs index 8c30d98..2dab4c0 100644 --- a/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.cs +++ b/TEMUKJD/PDDForms/ProductSelectForms/PDDGetChanceProdForm.cs @@ -1026,23 +1026,79 @@ namespace TemuKJD.PDDForms.ProductSelectForms private void btnFilter_Click(object sender, EventArgs e) { - var filters = txtFilter.Text.Trim().Split(new string[] { ",", ",", " ", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); + var filters = txtFilter.Text.Trim().Split(new string[] { ",", ",", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); // 含敏感词商品 - List filterChanceProdLst = null; + List filterChanceProdLst = new List(); if (cmbFilterType.Text.Trim() == "过滤标题") - filterChanceProdLst = lstChanceProductResult.Where(p => filters - .Any(f => (p?.dbProduct?.product_name).ParseToString().Contains(f) || (p?.keywords).ParseToString().Contains(f))).ToList(); + { + foreach(var chance in lstChanceProductResult) + { + if (filters.Any(f => chance.keywords.Contains(f))) + filterChanceProdLst.Add(chance); + if (filters.Any(f => (chance?.dbProduct?.product_name).ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + var prodInfo = JsonHelper.DeserializeJsonToObjectNullable(chance?.dbProduct?.product_json); + if (prodInfo == null) + continue; + try + { + if (filters.Any(f => prodInfo.detail.tiny_name.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + if (filters.Any(f => prodInfo.detail.goods_desc.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + if (filters.Any(f => prodInfo.detail.share_desc.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + } + catch + { + + } + } + } else - filterChanceProdLst = lstChanceProductResult.Where(p => filters.Any(f => JsonHelper.SerializeObject(p).Contains(f))).ToList(); + { + foreach (var chance in lstChanceProductResult) + { + if (filters.Any(f => chance.keywords.Contains(f))) + filterChanceProdLst.Add(chance); + if (filters.Any(f => (chance?.dbProduct?.product_name).ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + var prodInfo = JsonHelper.DeserializeJsonToObjectNullable(chance?.dbProduct?.product_json); + if (prodInfo == null) + continue; + try + { + if (filters.Any(f => prodInfo.detail.tiny_name.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + if (filters.Any(f => prodInfo.detail.goods_desc.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + if (filters.Any(f => prodInfo.detail.share_desc.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + foreach (var skuInfo in prodInfo.detail.sku) + { + foreach(var specInfo in skuInfo.spec) + { + if (filters.Any(f => specInfo.spec_name.ParseToString().Contains(f))) + filterChanceProdLst.Add(chance); + } + } + } + catch + { + } + } + } foreach (var chanceProd in filterChanceProdLst) { - var row = dgvChanceProduct.Rows.Cast().ToList().FirstOrDefault(r => r.Cells["colChanceId"].Value.ParseToString() == chanceProd.chance_id); lstChanceProductResult.Remove(chanceProd); - dgvChanceProduct.Rows.Remove(row); + + var row = dgvChanceProduct.Rows.Cast().ToList().FirstOrDefault(r => r.Cells["colChanceId"].Value.ParseToString() == chanceProd.chance_id); + if (row != null) + dgvChanceProduct.Rows.Remove(row); } - NaiBa.Util.Helper.ConfigHelper.SaveConfig("pdd_chance_product_list_" + MainForm.ProcessCount, lstChanceProductResult); + //NaiBa.Util.Helper.ConfigHelper.SaveConfig("pdd_chance_product_list_" + MainForm.ProcessCount, lstChanceProductResult); } private void btnSelectNotGetDetail_Click(object sender, EventArgs e) diff --git a/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs b/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs index 34c39d0..82317fa 100644 --- a/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs +++ b/TEMUKJD/WXForms/ProductForms/WXDBProdUploadForm.cs @@ -1988,7 +1988,7 @@ namespace TemuKJD.WXForms.ProductForms //------------------------------------------------------------------------------------------------------------------------------------- // ai识别类目暂存主图位置 int imgId = 0; - string tempImgPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordNumber(8).ToLower(); + string tempImgPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower(); List tempImgFullPathLst = new List(); //------------------------------------------------------------------------------------------------------------------------------------- // 生成ai识别类目所需图片 @@ -3391,7 +3391,7 @@ namespace TemuKJD.WXForms.ProductForms } } } - if (!prodInfo.detail.sku.Any(s => s.quantity.ParseToInt() > 0)) + if (dbProd.product_get_type_text == "厂商直采" && !prodInfo.detail.sku.Any(s => s.quantity.ParseToInt() > 0)) { return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"源商品库存为0\"}"; } @@ -3440,7 +3440,8 @@ namespace TemuKJD.WXForms.ProductForms skuParam.skuKey.productKey.outProductId = upProdParam.product.info.spuCode; // 库存 skuParam.productSkuInfo.stockInfo = new stockInfoParam() { stockNum = defaultAddPriceRule.StockNum }; - if (skuInfo.quantity.ParseToInt() == 0) + // 厂商直采上家库存为0则按0上架 + if (dbProd.product_get_type_text == "厂商直采" && skuInfo.quantity.ParseToInt() == 0) skuParam.productSkuInfo.stockInfo.stockNum = 0; skuParam.productSkuInfo.saleParam = new List(); foreach (var specInfo in skuInfo.spec) @@ -3961,7 +3962,7 @@ namespace TemuKJD.WXForms.ProductForms // 提交免审修改(实际生效接口) var listingAuditFreeRst = WXUpload.listingAuditFree(shop, productJson, upProdParam.product.productKey.productId, time1, time2); - string tempBlobPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordNumber(8).ToLower(); + string tempBlobPath = Path.GetTempPath().Trim('\\') + "\\" + Randomx.GetWordWithNumber(8).ToLower(); if (!Directory.Exists(tempBlobPath)) Directory.CreateDirectory(tempBlobPath); string blobFullPath = tempBlobPath + "\\blob"; // C:\Users\Administrator\AppData\Local\Temp\3mer3k21\blob diff --git a/TEMUKJD/WXForms/TalkForms/BuyerOrderListForm.cs b/TEMUKJD/WXForms/TalkForms/BuyerOrderListForm.cs index 6d3e76e..7332bae 100644 --- a/TEMUKJD/WXForms/TalkForms/BuyerOrderListForm.cs +++ b/TEMUKJD/WXForms/TalkForms/BuyerOrderListForm.cs @@ -61,6 +61,7 @@ namespace TemuKJD.WXForms.TalkForms dtpEndTime.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1); dgvBuyer.AddSelectorColumn("colSelect"); + InitCef(); lstPddBuyerOrderInfoLite = NaiBa.Util.Helper.ConfigHelper.LoadConfig> ("pdd_buyer_order"); if (lstPddBuyerOrderInfoLite == null) @@ -267,6 +268,11 @@ namespace TemuKJD.WXForms.TalkForms order = this.lstPddBuyerOrderInfoLite.FirstOrDefault(or => or.order_sn == o.order_sn); if (JsonHelper.SerializeObject(order) != JsonHelper.SerializeObject(o)) { + if(order.order_status_prompt.Contains("待发货") && !o.order_status_prompt.Contains("待发货")) + { + order.sendStatus = ""; + } + //order = JsonHelper.DeserializeJsonToObject(JsonHelper.SerializeObject(o)); order.activity_type = o.activity_type; order.discount_amount = o.discount_amount; @@ -490,16 +496,9 @@ namespace TemuKJD.WXForms.TalkForms try { - if (cefWebBrowser == null) + while (cefWebBrowser == null || !cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid) { - Invoke(new Action(() => - { - InitCef(); - })); - while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid) - { - Thread.Sleep(1); - } + Thread.Sleep(1); } CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null)); @@ -875,7 +874,7 @@ namespace TemuKJD.WXForms.TalkForms case "发送": Task.Run(() => { - SendOrderE57(order); + SendOrderE57(order, true); }); break; case "图片": @@ -891,8 +890,11 @@ namespace TemuKJD.WXForms.TalkForms } } - public void SendOrderE57(PddBuyerOrderInfoLite order) + public void SendOrderE57(PddBuyerOrderInfoLite order, bool resetSendStatus = false) { + if (resetSendStatus) + order.sendStatus = ""; + if (order.sendStatus == "已发送") { return; diff --git a/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs b/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs index 7fd63bd..90dc70b 100644 --- a/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs +++ b/TEMUKJD/WXForms/TalkForms/WxTalkForm.Designer.cs @@ -86,6 +86,7 @@ namespace TemuKJD.WXForms.TalkForms this.btnPrev = new DevComponents.DotNetBar.PanelEx(); this.txtAddress = new System.Windows.Forms.TextBox(); this.pnlTalk = new System.Windows.Forms.Panel(); + this.textBox1 = new System.Windows.Forms.TextBox(); this.lblAutoReplyStatus = new System.Windows.Forms.Label(); this.chkShowAutoReplyNum = new System.Windows.Forms.CheckBox(); this.chkShowShopStatistics = new System.Windows.Forms.CheckBox(); @@ -136,7 +137,7 @@ namespace TemuKJD.WXForms.TalkForms // lblVersionName // this.lblVersionName.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); - this.lblVersionName.Location = new System.Drawing.Point(32229, 33); + this.lblVersionName.Location = new System.Drawing.Point(32767, 33); // // panel3 // @@ -951,6 +952,7 @@ namespace TemuKJD.WXForms.TalkForms // // pnlTalk // + this.pnlTalk.Controls.Add(this.textBox1); this.pnlTalk.Controls.Add(this.lblAutoReplyStatus); this.pnlTalk.Controls.Add(this.chkShowAutoReplyNum); this.pnlTalk.Controls.Add(this.chkShowShopStatistics); @@ -962,16 +964,31 @@ namespace TemuKJD.WXForms.TalkForms this.pnlTalk.Size = new System.Drawing.Size(985, 544); this.pnlTalk.TabIndex = 1; // + // textBox1 + // + this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.textBox1.Location = new System.Drawing.Point(356, 61); + this.textBox1.Multiline = true; + this.textBox1.Name = "textBox1"; + this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both; + this.textBox1.Size = new System.Drawing.Size(555, 422); + this.textBox1.TabIndex = 208; + this.textBox1.Visible = false; + // // lblAutoReplyStatus // this.lblAutoReplyStatus.AutoSize = true; this.lblAutoReplyStatus.Dock = System.Windows.Forms.DockStyle.Bottom; this.lblAutoReplyStatus.Location = new System.Drawing.Point(0, 527); this.lblAutoReplyStatus.Name = "lblAutoReplyStatus"; - this.lblAutoReplyStatus.Size = new System.Drawing.Size(43, 17); + this.lblAutoReplyStatus.Size = new System.Drawing.Size(116, 17); this.lblAutoReplyStatus.TabIndex = 207; - this.lblAutoReplyStatus.Text = "label5"; + this.lblAutoReplyStatus.Text = "lblAutoReplyStatus"; this.lblAutoReplyStatus.Visible = false; + this.lblAutoReplyStatus.Click += new System.EventHandler(this.lblAutoReplyStatus_Click); + this.lblAutoReplyStatus.DoubleClick += new System.EventHandler(this.lblAutoReplyStatus_DoubleClick); // // chkShowAutoReplyNum // @@ -1242,5 +1259,6 @@ namespace TemuKJD.WXForms.TalkForms private System.Windows.Forms.Label lblProgress; private System.Windows.Forms.TabPage tabPage3; private System.Windows.Forms.Label lblAutoReplyStatus; + private System.Windows.Forms.TextBox textBox1; } } \ No newline at end of file diff --git a/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs b/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs index dfe77f4..25347a8 100644 --- a/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs +++ b/TEMUKJD/WXForms/TalkForms/WxTalkForm.cs @@ -242,7 +242,12 @@ namespace TemuKJD.WXForms.TalkForms if (chkIsAutoReply.Checked && 1==1) { - Invoke(new Action(() => { lblAutoReplyStatus.Visible = true; lblAutoReplyStatus.Text = "自动回复中... " + DateTime.Now.ToString("HH:mm:ss"); })); + Invoke(new Action(() => + { + lblAutoReplyStatus.Visible = true; + lblAutoReplyStatus.Text = "自动回复中... 待回复数:" + + lstAutoReplayParam.Select(rp => rp.nickName).Distinct().ToList().Count + "条 " + DateTime.Now.ToString("HH:mm:ss"); + })); if (lstAutoReplayParam.Count > 0) { @@ -281,7 +286,11 @@ namespace TemuKJD.WXForms.TalkForms if (response1.Result.Result.ParseToString() != "success") { Thread.Sleep(Randomx.GetId(500, 1000)); - Invoke(new Action(() => { lblAutoReplyStatus.Text = "当前用户获取失败,尝试获取全部用户 " + DateTime.Now.ToString("HH:mm:ss"); })); + Invoke(new Action(() => + { + lblAutoReplyStatus.Text = "当前用户获取失败,尝试获取全部用户 待回复数:" + + lstAutoReplayParam.Select(rp => rp.nickName).Distinct().ToList().Count + "条 " + DateTime.Now.ToString("HH:mm:ss"); + })); var jsStr2 = @"function clickAllUser() { var users = document.getElementsByClassName('tab-list-item'); for (i=0; i { lblAutoReplyStatus.Text = autoReplayParam.shopId + " 已尝试发送自动回复 " + DateTime.Now.ToString("HH:mm:ss"); })); + Invoke(new Action(() => + { + lblAutoReplyStatus.Text = autoReplayParam.shopId + " 已尝试发送自动回复 待回复数:" + + lstAutoReplayParam.Select(rp => rp.nickName).Distinct().ToList().Count + "条 " + DateTime.Now.ToString("HH:mm:ss"); + })); Thread.Sleep(Randomx.GetId(500, 600)); } } @@ -377,6 +390,32 @@ namespace TemuKJD.WXForms.TalkForms //_1688AddressForm.Show(); } + private void lblAutoReplyStatus_Click(object sender, EventArgs e) + { + + } + + int isDbClick = 0; + private void lblAutoReplyStatus_DoubleClick(object sender, EventArgs e) + { + isDbClick++; + Task.Run(() => + { + Thread.Sleep(5000); + if (isDbClick > 0) + isDbClick--; + }); + + if (textBox1.Visible == true) + textBox1.Visible = false; + + if (isDbClick > 3) + { + isDbClick = 0; + textBox1.Visible = true; + textBox1.Text = JsonHelper.SerializeObject(lstAutoReplayParam); + } + } void InitOrderForm() { @@ -1850,6 +1889,7 @@ namespace TemuKJD.WXForms.TalkForms //订单编号###亲,您的这笔订单已核实,请问是遇到什么问题了呢? //退款成功###亲,您的退款已办理成功,欢迎下次光临哦!"; + //https://store.weixin.qq.com/shop-faas/mmchannelstradeorder/list/cgi/orderSearch?token=&lang=zh_CN //https://store.weixin.qq.com/shop/order/list // 待发货