diff --git a/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs b/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs index 927269e..3d4ad13 100644 --- a/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs +++ b/BBWYB.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs @@ -26,10 +26,12 @@ namespace BBWYB.Server.Business //private ConcurrentDictionary purchaseSchemeProductSkus)> productChaches; private IDictionary _1688ProductDetailRequestHeader; + private IDictionary _1688FactoryCardRequestHeader; private List _1688ColorPropertyFieldIdList; private List locationIdList; private List priceIdList; + private List purchaserNameIdList; private IList invalidPurchaserNameList; @@ -46,6 +48,14 @@ namespace BBWYB.Server.Business { "Accept-Encoding","gzip, deflate, br"}, { "Accept-Language","zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"} }; + _1688FactoryCardRequestHeader = new Dictionary() + { + { "Host","sale.1688.com"}, + { "User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.5112.102 Safari/537.36 Edg/104.0.1293.70"}, + { "Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"}, + { "Accept-Encoding","gzip, deflate, br"}, + { "Accept-Language","zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"} + }; purchaseProductCacheTimeSpan = TimeSpan.FromDays(1); _1688ColorPropertyFieldIdList = new List() { 3216, 1627207, 1234, 3151, 7853, 446, 374, 404, 100019516, 3114, 2068 }; //jobject["data"]["1081181309101"] != null ? @@ -57,6 +67,8 @@ namespace BBWYB.Server.Business // jobject["data"]["1081181309582"]["data"]["priceModel"]["currentPrices"][0].Value("price") : // jobject["data"]["16347413030316"]["data"]["priceModel"]["currentPrices"][0].Value("price"); priceIdList = new List() { "1081181309582", "1081181309582", "16347413030316", "13772573013151" }; + + purchaserNameIdList = new List() { "38229149", "38229148", "38229150" }; } public PurchaseSkuBasicInfoResponse GetProductInfo(PurchaseSkuBasicInfoRequest request) @@ -241,9 +253,11 @@ namespace BBWYB.Server.Business var jsonStr = match.Groups[2].Value; var jobject = JObject.Parse(jsonStr); + var memberId = jobject["globalData"]?["tempModel"]?["sellerMemberId"]?.ToString(); + #region 验证purchaserName var purchaserName = jobject["globalData"]["tempModel"]["companyName"].ToString(); - if (invalidPurchaserNameList.Contains(purchaserName)) + if (invalidPurchaserNameList.Any(x => purchaserName.Contains(x))) { var storeDataMatch = Regex.Match(_1688pageResult.Content, @"(window\.__STORE_DATA=)(.*)(\r*\n*\s*)"); if (storeDataMatch.Success) @@ -252,16 +266,37 @@ namespace BBWYB.Server.Business { var jsonStr_storeData = storeDataMatch.Groups[2].Value; var jobject_storeData = JObject.Parse(jsonStr_storeData); - var purchaserName_storeData = jobject_storeData["components"]?["38229149"]?["moduleData"]?["companyName"].ToString(); - if (string.IsNullOrEmpty(purchaserName_storeData)) - purchaserName_storeData = jobject_storeData["components"]?["38229148"]?["moduleData"]?["companyName"].ToString(); - if (string.IsNullOrEmpty(purchaserName_storeData)) - purchaserName_storeData = jobject_storeData["components"]?["38229150"]?["moduleData"]?["companyName"].ToString(); - if (!string.IsNullOrEmpty(purchaserName_storeData)) - purchaserName = purchaserName_storeData; + foreach (var purchaserNodeId in purchaserNameIdList) + { + var purchaserTempName = jobject_storeData["components"]?[purchaserNodeId]?["moduleData"]?["companyName"].ToString(); + if (!string.IsNullOrEmpty(purchaserTempName)) + { + purchaserName = purchaserTempName; + break; + } + } } catch { } } + + if (invalidPurchaserNameList.Any(x => purchaserName.Contains(x)) && !string.IsNullOrEmpty(memberId)) + { + //https://sale.1688.com/factory/card.html?memberId=b2b-4204371240a61bf + var _1688FactoryCardResult = restApiService.SendRequest("https://sale.1688.com", + "factory/card.html", + $"memberId={memberId}", + _1688FactoryCardRequestHeader, + HttpMethod.Get, + httpClientName: "gzip"); + if (_1688FactoryCardResult.StatusCode == System.Net.HttpStatusCode.OK) + { + var titleMatch = Regex.Match(_1688FactoryCardResult.Content, @"(.*)-(.*)-(.*)"); + if (titleMatch.Success) + { + purchaserName = titleMatch.Groups[1].Value; + } + } + } } #endregion @@ -280,10 +315,12 @@ namespace BBWYB.Server.Business Id = jobject["globalData"]["tempModel"]["sellerUserId"].ToString(), Id2 = jobject["globalData"]["tempModel"]["sellerLoginId"]?.ToString(), Name = purchaserName, - MemberId = jobject["globalData"]?["tempModel"]?["sellerMemberId"]?.ToString(), + MemberId = memberId, Location = location, Platform = Enums.Platform.阿里巴巴 }; + + var fidJToken = jobject["globalData"]["skuModel"]["skuProps"].FirstOrDefault(j => _1688ColorPropertyFieldIdList.Contains(j.Value("fid"))); if (fidJToken == null) fidJToken = jobject["globalData"]["skuModel"]["skuProps"].FirstOrDefault(j => j.Value("prop").Contains("颜色"));