From 24f6dd6f72ed395a2bbfc2f33dd59ddf2f02419c Mon Sep 17 00:00:00 2001 From: shanj <18996038927@163.com> Date: Sun, 3 Dec 2023 22:40:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D1688=E7=88=AC=E8=99=AB?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BBWY.Client/APIServices/PurchaseProductAPIService.cs | 4 ++-- BBWY.Server.API/Startup.cs | 5 +++++ .../PurchaseScheme/PurchaseProductAPIService.cs | 9 +++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/BBWY.Client/APIServices/PurchaseProductAPIService.cs b/BBWY.Client/APIServices/PurchaseProductAPIService.cs index ab80e86d..647416c5 100644 --- a/BBWY.Client/APIServices/PurchaseProductAPIService.cs +++ b/BBWY.Client/APIServices/PurchaseProductAPIService.cs @@ -189,7 +189,7 @@ namespace BBWY.Client.APIServices if (_1688pageResult.StatusCode != System.Net.HttpStatusCode.OK) return null; - var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA=)(.*)(\r*\n*\s*)"); + var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA\s?=)(.*)(\r*\n*\s*)"); if (!match.Success) return null; @@ -238,7 +238,7 @@ namespace BBWY.Client.APIServices SkuId = skuId, PurchaseProductId = purchaseProductId, Price = skuPrice == 0M ? firstPrice : skuPrice, - Title = name, + Title = matchName, PurchaseSkuId = value.Value("skuId"), PurchaseSkuSpecId = value.Value("specId"), Logo = colorsProperty.FirstOrDefault(c => c.name == matchName)?.imageUrl ?? "pack://application:,,,/Resources/Images/defaultItem.png" diff --git a/BBWY.Server.API/Startup.cs b/BBWY.Server.API/Startup.cs index 84746551..ccdcc052 100644 --- a/BBWY.Server.API/Startup.cs +++ b/BBWY.Server.API/Startup.cs @@ -19,6 +19,7 @@ using System.Collections.Generic; using System.Configuration; using System.IO; using System.Linq; +using System.Net.Http; using System.Reflection; using System.Text; using Yitter.IdGenerator; @@ -65,6 +66,10 @@ namespace BBWY.Server.API services.AddControllers(); services.AddHttpContextAccessor(); services.AddHttpClient(); + services.AddHttpClient("gzip").ConfigurePrimaryHttpMessageHandler(handler => new HttpClientHandler() + { + AutomaticDecompression = System.Net.DecompressionMethods.GZip + }); services.AddCors(options => { options.AddPolicy("cors", p => diff --git a/BBWY.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs b/BBWY.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs index 3387715b..17413558 100644 --- a/BBWY.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs +++ b/BBWY.Server.Business/PurchaseScheme/PurchaseProductAPIService.cs @@ -40,7 +40,7 @@ namespace BBWY.Server.Business this.restApiService = restApiService; _1688ProductDetailRequestHeader = new Dictionary() { - { "Host","detail.1688.com"}, + //{ "Host","detail.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"}, @@ -193,12 +193,13 @@ namespace BBWY.Server.Business $"clickid={Guid.NewGuid().ToString().Md5Encrypt()}&sessionid={Guid.NewGuid().ToString().Md5Encrypt()}&sk={(request.PriceMode == Enums.PurchaseOrderMode.批发 ? "order" : "consign")}", _1688ProductDetailRequestHeader, HttpMethod.Get, - httpClientName: "gzip"); + httpClientName: "gzip", + getResponseHeader: true); if (_1688pageResult.StatusCode != System.Net.HttpStatusCode.OK) return null; - var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA=)(.*)(\r*\n*\s*)"); + var match = Regex.Match(_1688pageResult.Content, @"(window\.__INIT_DATA\s?=)(.*)(\r*\n*\s*)"); if (!match.Success) return null; @@ -246,7 +247,7 @@ namespace BBWY.Server.Business { PurchaseProductId = request.PurchaseProductId, Price = skuPrice == 0M ? firstPrice : skuPrice, - Title = name, + Title = matchName, //name PurchaseSkuId = value.Value("skuId"), PurchaseSkuSpecId = value.Value("specId"), Logo = colorsProperty.FirstOrDefault(c => c.name == matchName)?.imageUrl ?? "pack://application:,,,/Resources/Images/defaultItem.png"