导入外部多多数据 增加新格式

修改文件格式检测函数
This commit is contained in:
chfei committed 2026-08-11 16:32:42 +08:00
1 parent a568c685ee
commit 7d07c83579
6 files changed
+662 -107

No files matched your search

+1
View File
@@ -233,6 +233,7 @@
<Compile Include="Model\Result\PDDResult\PddClientInfo.cs" /> <Compile Include="Model\Result\PDDResult\PddClientInfo.cs" />
<Compile Include="Model\Result\PDDResult\PDDFrontProductInfo2.cs" /> <Compile Include="Model\Result\PDDResult\PDDFrontProductInfo2.cs" />
<Compile Include="Model\Result\PDDResult\PDDFrontProductInfo3.cs" /> <Compile Include="Model\Result\PDDResult\PDDFrontProductInfo3.cs" />
<Compile Include="Model\Result\PDDResult\PDDFrontProductInfo4.cs" />
<Compile Include="Model\Result\VDianShopLoginInfo.cs" /> <Compile Include="Model\Result\VDianShopLoginInfo.cs" />
<Compile Include="Model\Result\WXResult\DSRShopScoreInfo.cs" /> <Compile Include="Model\Result\WXResult\DSRShopScoreInfo.cs" />
<Compile Include="Model\Result\WXResult\WxActivityData.cs" /> <Compile Include="Model\Result\WXResult\WxActivityData.cs" />
@@ -0,0 +1,73 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace AllBase.Model.Result.PDDResult
{
public class PDDFrontProductInfo4
{
[JsonProperty("商品编号")]
public string ProductId { get; set; }
[JsonProperty("商品链接")]
public string ProductUrl { get; set; }
[JsonProperty("标题")]
public string Title { get; set; }
[JsonProperty("描述")]
public string Description { get; set; }
[JsonProperty("视频链接")]
public string VideoUrl { get; set; }
[JsonProperty("类目")]
public string Category { get; set; }
[JsonProperty("链接")]
public string Link { get; set; }
[JsonProperty("评论")]
public string Comments { get; set; }
[JsonProperty("属性")]
public Dictionary<string,string> Attributes { get; set; }
[JsonProperty("主图")]
public List<string> MainImages { get; set; }
[JsonProperty("详情图")]
public List<string> DetailImages { get; set; }
[JsonProperty("规格")]
public Dictionary<string,List<string>> Specifications { get; set; }
[JsonProperty("价格与库存")]
public Dictionary<string, PriceStock> SKU { get; set; }
}
public class PriceStock
{
[JsonProperty("规格值组合")]
public string SpecValue { get; set; }
[JsonProperty("价格")]
public string Price { get; set; }
[JsonProperty("原价")]
public string OriginalPrice { get; set; }
[JsonProperty("库存")]
public int Stock { get; set; }
[JsonProperty("规格图")]
public string SpecImage { get; set; }
}
}
+407 -3
View File
@@ -30,7 +30,7 @@ namespace TemuKJD.BLL
{ {
frontProdInfo = JsonHelper.DeserializeJsonToObject<PDDFrontProductInfo>(outProdJson); frontProdInfo = JsonHelper.DeserializeJsonToObject<PDDFrontProductInfo>(outProdJson);
} }
catch(Exception ex) catch (Exception ex)
{ {
return "转换错误" + ex.Message; return "转换错误" + ex.Message;
} }
@@ -1248,6 +1248,410 @@ namespace TemuKJD.BLL
return ""; return "";
} }
/// <summary>
/// 外来格式 中文属性转拼多多格式
/// </summary>
/// <param name="outProdJson"></param>
/// <param name="UpdateOldData"></param>
/// <param name="specialProdType"></param>
/// <param name="IsCollectAuthorityUser"></param>
/// <returns></returns>
public string PddFrontToPddBackConvertV4(string outProdJson, bool UpdateOldData = true, string specialProdType = null, bool IsCollectAuthorityUser = false)
{
PDDFrontProductInfo4 frontProdInfo = null;
try
{
frontProdInfo = JsonHelper.DeserializeJsonToObject<PDDFrontProductInfo4>(outProdJson);
}
catch (Exception ex)
{
return "转换错误" + ex.Message;
}
if (frontProdInfo == null || frontProdInfo.ProductId == null)
{
return "商品数据信息为空";
}
long mallId = Randomx.GetId(10000000, 99999999);
if (!string.IsNullOrEmpty(frontProdInfo.ProductUrl))
{
mallId = Math.Abs(frontProdInfo.ProductUrl.GetHashCode());
}
string thumbUrl = frontProdInfo.MainImages.FirstOrDefault();
KJDDBProduct dbProd = new KJDDBProduct() { size_json = "{}" };
PDDProductInfo prodInfo = new PDDProductInfo()
{
//source_json = JsonHelper.JObjectParse(outProdJson),
source_json = null,
//sale_count = frontProdInfo.goods.sold_quantity.ParseToString(),
//sale_count_text = frontProdInfo.goods.side_sales_tip,
};
prodInfo.chance_id = null;
prodInfo.chance_refere = null;
prodInfo.chance_tab = null;
prodInfo.decoration = new PDDProductDecorationInfo() { floor_list = new List<PDDProdfloorItem>() };
// 商品详情
prodInfo.detail = new PDDProductDetailInfo();
prodInfo.detail.allergy_refund = 0;
prodInfo.detail.allowed_region = new List<object>();
//prodInfo.detail.appeal_status = null;
//prodInfo.detail.app_id = null;
//prodInfo.detail.app_name = null;
//prodInfo.detail.bad_claim_text = null;
prodInfo.detail.bad_fruit_claim = 0;
//prodInfo.detail.business_source_type = null;
prodInfo.detail.can_appeal = null;
prodInfo.detail.card_verification_list = null;
prodInfo.detail.cats = new List<string>();
prodInfo.detail.cat_id = frontProdInfo.Category.ParseToInt();
prodInfo.detail.cat_ids = new List<int?>();
prodInfo.detail.check_status = 9;
//prodInfo.detail.check_type = null;
//prodInfo.detail.client_id = null;
prodInfo.detail.commit_deleted = 0;
//prodInfo.detail.commit_extension = null;
//prodInfo.detail.community_group_buying = null;
prodInfo.detail.cost_template_id = 0;
//prodInfo.detail.country = null;
prodInfo.detail.country_id = 0;
//prodInfo.detail.created_at = null;
//prodInfo.detail.creator_name = null;
prodInfo.detail.customizable = 0;
prodInfo.detail.customs = "";
prodInfo.detail.damage_claim = 0;
prodInfo.detail.delivery_one_day = 0;
//prodInfo.detail.delivery_type = null;
//prodInfo.detail.elec_goods_attributes = null;
prodInfo.detail.estimate_quantity = 0;
prodInfo.detail.event_type = 0;
prodInfo.detail.extend_warranty_dto = new extend_warranty_dto_item() { extend_warranty = 0 };
//prodInfo.detail.fabric = null;
//prodInfo.detail.fabric_content = null;
prodInfo.detail.galleries = new List<gallery_item>();
int galleryIndex = 0;
foreach (var frontGallery in frontProdInfo.MainImages)
{
prodInfo.detail.galleries.Add(new gallery_item()
{
url = frontGallery,
type = 1,
width = 0,
height = 0,
});
galleryIndex++;
}
foreach (var frontGallery in frontProdInfo.DetailImages)
{
prodInfo.detail.galleries.Add(new gallery_item()
{
url = frontGallery,
type = 2,
width = 0,
height = 0,
});
galleryIndex++;
}
prodInfo.detail.gold_price_template_id = null;
prodInfo.detail.gold_price_type = null;
prodInfo.detail.goods_certificate = null;
prodInfo.detail.goods_commit_check = new List<object>();
prodInfo.detail.goods_desc = frontProdInfo.Description;
prodInfo.detail.goods_id = frontProdInfo.ProductId.ParseToLong();
prodInfo.detail.goods_name = frontProdInfo.Title;
prodInfo.detail.goods_name_prefix = "";
prodInfo.detail.goods_pattern = 8;
prodInfo.detail.goods_property_list = null;
prodInfo.detail.goods_sn = null;
prodInfo.detail.goods_srv_templates = new List<object>();
prodInfo.detail.goods_trade_attr = null;
prodInfo.detail.goods_travel_attr = null;
prodInfo.detail.goods_type = 1;
prodInfo.detail.groups = new group_item() { single_price = 0, group_price = 0, customer_num = 2, buy_limit = 999999, order_limit = 999999 };
prodInfo.detail.hd_thumb_url = "";
prodInfo.detail.id = 0; // 编辑id,随意填写
prodInfo.detail.image_url = frontProdInfo.MainImages?.FirstOrDefault() ?? "";
prodInfo.detail.instruction_vo = new instruction_vo_item() { template_status = -1 };
prodInfo.detail.invoice_mode = null;
prodInfo.detail.invoice_mode_sub_type = null;
prodInfo.detail.invoice_status = 0;
prodInfo.detail.is_all_weight_same = true;
prodInfo.detail.is_app = 0;
prodInfo.detail.is_bangdan = 0;
prodInfo.detail.is_card_secret = false;
prodInfo.detail.is_certificate_provide = 0;
prodInfo.detail.is_customized = 0;
prodInfo.detail.is_customs = 0;
prodInfo.detail.is_deposit = false;
prodInfo.detail.is_draft = false;
prodInfo.detail.is_folt = 0;
prodInfo.detail.is_general_trade = 0;
prodInfo.detail.is_gold_price_matched = null;
prodInfo.detail.is_goods_copy = null;
prodInfo.detail.is_goods_decoration = 1;
prodInfo.detail.is_group_pre_sale = 0;
prodInfo.detail.is_only_for_remote_area = false;
prodInfo.detail.is_pre_sale = 0;
prodInfo.detail.is_refundable = 1;
prodInfo.detail.is_refundable_fifteen_day = 0;
prodInfo.detail.is_shop = 1;
prodInfo.detail.is_size_change_casually = 0;
prodInfo.detail.is_sku_pre_sale = 0;
prodInfo.detail.is_sku_shipment = 0;
prodInfo.detail.is_small_group = null;
prodInfo.detail.is_spring_festival_open_tag = false;
prodInfo.detail.is_two_num_group = false;
prodInfo.detail.is_warranty_one_year = 0;
prodInfo.detail.is_wms = 0;
prodInfo.detail.is_wp_service = 0;
prodInfo.detail.lack_of_weight_claim = 0;
prodInfo.detail.last_commit_check_status = 2;
prodInfo.detail.list_desc = new List<object>();
prodInfo.detail.local_service_id_list = null;
prodInfo.detail.mai_jia_zi_ti = null;
prodInfo.detail.mall_id = mallId;
prodInfo.detail.mall_info = new mall_info_item() { mall_name = mallId.ToString() };
prodInfo.detail.must_check_type = 0;
prodInfo.detail.name_prefix = "";
prodInfo.detail.origin_country_id = 0;
prodInfo.detail.origin_country_name = "";
prodInfo.detail.out_goods_sn = "";
prodInfo.detail.out_source_goods_id = null;
prodInfo.detail.out_source_type = null;
prodInfo.detail.oversea_goods = null;
prodInfo.detail.oversea_type = 0;
prodInfo.detail.owner = "主账号";
prodInfo.detail.owner_name = "";
prodInfo.detail.paper_length = null;
prodInfo.detail.paper_net_weight = null;
prodInfo.detail.paper_plies_num = null;
prodInfo.detail.paper_width = null;
prodInfo.detail.pre_sale_time = 0;
prodInfo.detail.privacy_delivery = 0;
prodInfo.detail.processing_charges = null;
prodInfo.detail.processing_charges_type = null;
prodInfo.detail.promised_delivery_seconds = null;
prodInfo.detail.purchase_info_supply = 0;
prodInfo.detail.qualification_id_list = new List<object>();
prodInfo.detail.quan_guo_lian_bao = 0;
prodInfo.detail.quick_refund = 0;
prodInfo.detail.reason = null;
prodInfo.detail.region_limit = 1;
prodInfo.detail.reject_reason = null;
prodInfo.detail.reject_status = null;
prodInfo.detail.same_city_template_id = 0;
prodInfo.detail.schedule_sale = new schedule_sale_item() { sale_type = 0 };
prodInfo.detail.second_hand = 0;
prodInfo.detail.sf_markup_template_sn = null;
prodInfo.detail.shang_men_an_zhuang = null;
prodInfo.detail.share_desc = frontProdInfo.Description;
prodInfo.detail.shipment_limit_second = 172800;
prodInfo.detail.shoes_template_id = null;
prodInfo.detail.shop_group_id = null;
prodInfo.detail.shop_group_name = null;
prodInfo.detail.show_activity_price = false;
prodInfo.detail.size_parent_spec_id = null;
prodInfo.detail.size_spec_id = null;
prodInfo.detail.sku = new List<sku_item>();
int maxPrice = int.MinValue;
int minPrice = int.MaxValue;
foreach (KeyValuePair<string, PriceStock> frontSku in frontProdInfo.SKU)
{
sku_item skuInfo = new sku_item()
{
id = 0,
sku_id = null,
sku_sn = null,
carnival_price = 0,
init_quantity = 0,
is_onsale = 1,
limit_quantity = 999999,
multi_price = (int)(frontSku.Value.Price.ParseToDecimal() * 100),
multi_price_in_yuan = null,
price = (int)(frontSku.Value.Price.ParseToDecimal() * 100 + 100),
price_in_yuan = null,
quantity = 0,
reserve_quantity = 0,
weight = 0,
thumb_url = frontSku.Value.SpecImage,
thumb_url_file_id = null,
thumb_url_status = null,
thumb_url_is_deleted = null,
quantity_delta = frontSku.Value.Stock,
spec = new List<spec_item>(),
out_sku_sn = "",
batch_id = null,
priority = 1,
ware_id = 0,
ware_biz_type = null,
advice_price = null,
length = null,
oversea_sku = null,
cspu_id = null,
child_skus = null,
ref_sku_commit_id = 0,
start_time = null,
end_time = null,
sku_srv_templates = null,
calendar_rule_id = null,
hot_live_group = null,
pre_sale_time = 0,
out_source_sku_id = null,
dd_grocery_sku_params = null,
sku_extended_attribute_dtos = null,
sku_basic_property_dtos = null,
spec_note_map = null,
delivery_schedule_dtos = null,
shipment_limit_second_list = null,
sku69_code = "",
};
maxPrice = Math.Max(maxPrice, skuInfo.price.Value);
minPrice = Math.Min(minPrice, skuInfo.price.Value);
var specList = frontSku.Value.SpecValue.Split(',').ToList();
foreach (var specItem in specList)
{
string parentName = "";
foreach (var item in frontProdInfo.Specifications)
{
if (item.Value.Contains(specItem))
{
parentName = item.Key;
break;
}
}
skuInfo.spec.Add(new spec_item()
{
parent_name = parentName,
spec_name = specItem,
spec_id = null,
});
}
prodInfo.detail.sku.Add(skuInfo);
}
prodInfo.detail.market_price = maxPrice * 2;
prodInfo.detail.max_group_price = maxPrice;
prodInfo.detail.min_group_price = minPrice;
prodInfo.detail.sku_type = null;
prodInfo.detail.song_huo_an_zhuang = null;
prodInfo.detail.song_huo_ru_hu = null;
prodInfo.detail.source = 0;
prodInfo.detail.spu_id = null;
prodInfo.detail.spu_version = null;
prodInfo.detail.submit_time = 0;
prodInfo.detail.thawed_refund = 0;
prodInfo.detail.third_type = 0;
prodInfo.detail.thumb_url = thumbUrl;
prodInfo.detail.tiny_name = "";
prodInfo.detail.transport_type_list = null;
prodInfo.detail.two_pieces_discount = 99;
prodInfo.detail.user_source = 1;
prodInfo.detail.warehouse = "";
prodInfo.detail.warm_tips = "";
prodInfo.detail.zhi_huan_bu_xiu = 0;
prodInfo.size = null;
prodInfo.material1 = null;
prodInfo.material3 = null;
prodInfo.property = new PDDProductPropertyInfo();
prodInfo.property.sku_properties = new object();
prodInfo.property.goods_properties = new List<goods_propertie_item>();
foreach (var frontProp in frontProdInfo.Attributes)
{
goods_propertie_item propInfo = new goods_propertie_item();
propInfo.name = frontProp.Key;
propInfo.values = new List<value_item>();
string[] p_values = frontProp.Value.Split(',');
foreach (var frontPropValue in p_values)
{
propInfo.values.Add(new value_item() { value = frontPropValue, raw_value = frontPropValue, unit = "" });
}
prodInfo.property.goods_properties.Add(propInfo);
}
dbProd.main_img = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1).url;
dbProd.product_json = JsonHelper.SerializeObject(prodInfo);
// 商品采集权限用户采集的数据加上用户前缀(商品前缀显示给用户的时候隐藏)
string collectAuthorityTag = "";
if (IsCollectAuthorityUser)
collectAuthorityTag = "-" + BaseClass.UserName;
bool isExist = false;
var existUrl = BaseClass.BuildPDDObjString("product/get_product_spu_id_list");
string existData = UserLogin.GetSignaturex() + "&search_spu_ids=" + prodInfo.detail.goods_id + collectAuthorityTag;
string html = GetHtml.PostUtf8(existUrl, existData);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(existUrl, existData);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(existUrl, existData);
if (!string.IsNullOrEmpty(html) && html.Contains("\"code\":200"))
{
if (html.Contains("\"data\":[") && !html.Contains("\"data\":[]"))
isExist = true;
}
else
{
return "入库失败,产品数据库已存在商品查询失败";
}
var url = BaseClass.BuildPDDObjString("product/add_product");
if (isExist)
{
if (UpdateOldData)
{
url = BaseClass.BuildPDDObjString("product/mdy_product");
}
else
{
return "已存在相同id商品,跳过";
}
}
var data = Work.UserLogin.GetSignaturex() +
"&from_shop_id=" + mallId +
"&spu_id=" + prodInfo.detail.goods_id.ParseToString() + collectAuthorityTag +
"&skc_id=" + prodInfo.detail.goods_id.ParseToString() +
"&price_text=" + prodInfo.detail.sku.Min(s => s.multi_price).ParseToInt() * 0.01m + "-" + prodInfo.detail.sku.Max(s => s.multi_price).ParseToInt() * 0.01m +
"&main_cat_id=" + (prodInfo.detail.cat_ids?.FirstOrDefault(c => c != null)).ParseToString() +
"&main_cat_name=" + HttpUtility.UrlEncode((prodInfo.detail.cat_ids?.FirstOrDefault(c => c != null)).ParseToString(), Encoding.UTF8) + // 取不到catname直接用catid,上货时候再取
"&cat_id=" + prodInfo.detail.cat_id.ParseToString() +
"&cat_name=" + HttpUtility.UrlEncode(prodInfo.detail.cat_id.ParseToString(), Encoding.UTF8) + // 取不到catname直接用catid,上货时候再取
"&ext_code=" + HttpUtility.UrlEncode(prodInfo.detail.out_goods_sn, Encoding.UTF8) +
"&product_name=" + HttpUtility.UrlEncode(prodInfo.detail.goods_name, Encoding.UTF8) +
"&product_json=" + HttpUtility.UrlEncode(dbProd.product_json, Encoding.UTF8) +
"&size_json=" + HttpUtility.UrlEncode(dbProd.size_json, Encoding.UTF8) +
"&main_img=" + HttpUtility.UrlEncode(dbProd.main_img, Encoding.UTF8) +
"&sale_count=" + HttpUtility.UrlEncode(prodInfo.sale_count, Encoding.UTF8) +
"&sale_count_text=" + HttpUtility.UrlEncode(prodInfo.sale_count_text, Encoding.UTF8) +
"&product_get_type=" + HttpUtility.UrlEncode("多多外部数据", Encoding.UTF8);
if (!string.IsNullOrEmpty(specialProdType))
data += "&special_prod_type=" + HttpUtility.UrlEncode(specialProdType, Encoding.UTF8);
if (IsCollectAuthorityUser)
{
data += "&add_user_name=" + BaseClass.UserName;
data += "&group=用户" + BaseClass.UserName;
}
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
html = GetHtml.PostUtf8(url, data);
if (string.IsNullOrEmpty(html) || !html.Contains("\"code\":200"))
{
return "商品采集保存失败!请检查网络连接:" + BaseRegex.GetStringJson(ref html, "msg");
}
return "";
}
/// <summary> /// <summary>
/// 聚水潭转pdd格式 /// 聚水潭转pdd格式
/// </summary> /// </summary>
@@ -2243,7 +2647,7 @@ namespace TemuKJD.BLL
prodInfo.detail.origin_country_id = 0; prodInfo.detail.origin_country_id = 0;
prodInfo.detail.origin_country_name = ""; prodInfo.detail.origin_country_name = "";
// 货号 1688没有字段直接标明,可能存在属性里面 // 货号 1688没有字段直接标明,可能存在属性里面
prodInfo.detail.out_goods_sn = (_1688ClentProdInfo.offerDetail?.featureAttributes?.FirstOrDefault(s=>s.name == "货号")?.value).ParseToString(); prodInfo.detail.out_goods_sn = (_1688ClentProdInfo.offerDetail?.featureAttributes?.FirstOrDefault(s => s.name == "货号")?.value).ParseToString();
//if (prodInfo.detail.out_goods_sn.IsNullOrEmpty()) //if (prodInfo.detail.out_goods_sn.IsNullOrEmpty())
//{ //{
// convertRst = "货号不存在"; // convertRst = "货号不存在";
@@ -2738,7 +3142,7 @@ namespace TemuKJD.BLL
spec_id = 0, spec_id = 0,
spec_name = "默认", spec_name = "默认",
}); });
if(string.IsNullOrEmpty(skuInfo.thumb_url)) if (string.IsNullOrEmpty(skuInfo.thumb_url))
{ {
skuInfo.thumb_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url; skuInfo.thumb_url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url;
} }
@@ -1114,13 +1114,15 @@ namespace TemuKJD.WXForms.ProductForms
int failedNum = 0; int failedNum = 0;
foreach (var path in filePathLst) foreach (var path in filePathLst)
{ {
string sourceContent = "";
string content = ""; string content = "";
string rst = "商品未识别"; string rst = "商品未识别";
try try
{ {
using (StreamReader sr = new StreamReader(path, Work.Api.UploadPinduoduoMain.GetFileEncoding(path))) using (StreamReader sr = new StreamReader(path, Work.Api.UploadPinduoduoMain.GetFileEncoding(path)))
{ {
content = sr.ReadToEnd(); sourceContent = sr.ReadToEnd();
} }
content = JsonHelper.SerializeObject(JsonHelper.JObjectParse(content)); content = JsonHelper.SerializeObject(JsonHelper.JObjectParse(content));
@@ -1128,19 +1130,6 @@ namespace TemuKJD.WXForms.ProductForms
{ {
rst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true); rst = new PDDProdFormConverter().PddFrontToPddBackConvert(content, true, null, true);
} }
//else if (content.Contains("\"destination_url\"") && content.Contains("\"destination_type\"") && content.Contains("\"pre_render_url\""))
//{
// rst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true);
//}
//else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") &&
// content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"decoration\"") &&
// content.Contains("\"goods_property\"") && content.Contains("\"ref_pid\"") && content.Contains("\"sku_id\"") &&
// content.Contains("\"quantity\"") && content.Contains("\"specs\"") && content.Contains("\"spec_key\"") &&
// content.Contains("\"spec_value\"") && content.Contains("\"group_price\"") && content.Contains("\"sku_price\"") &&
// content.Contains("img.pddpic.com") )
//{
// rst = new PDDProdFormConverter().PddFrontToPddBackConvert2(content, true, null, true);
//}
else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") && else if (content.Contains("\"goods_id\"") && content.Contains("\"goods_name\"") && content.Contains("\"gallery\"") &&
content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"goods_property\"") && content.Contains("\"priority\"") && content.Contains("\"enable_share\"") && content.Contains("\"goods_property\"") &&
(content.Contains("\"ref_pid\"") || content.Contains("\"goods_property\":[]")) && content.Contains("\"sku_id\"") && content.Contains("\"quantity\"") && (content.Contains("\"ref_pid\"") || content.Contains("\"goods_property\":[]")) && content.Contains("\"sku_id\"") && content.Contains("\"quantity\"") &&
@@ -1157,6 +1146,10 @@ namespace TemuKJD.WXForms.ProductForms
{ {
rst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true); rst = new PDDProdFormConverter().PddFrontToPddBackConvert3(content, true, null, true);
} }
else if (sourceContent.Contains("\"商品编号\"") && sourceContent.Contains("\"商品链接\"") && sourceContent.Contains("\"标题\""))
{
rst = new PDDProdFormConverter().PddFrontToPddBackConvertV4(sourceContent, true, null, true);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -117,6 +117,39 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="btnEditNotes.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="btnBatchEditNotes.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>148, 17</value>
</metadata>
<metadata name="btnAITitleFission.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>311, 17</value>
</metadata>
<metadata name="btnOut1688ProdSaveDb.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>460, 17</value>
</metadata>
<metadata name="btnImportPddOutData.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>655, 17</value>
</metadata>
<metadata name="btnSelect.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>840, 17</value>
</metadata>
<metadata name="btnSearch.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>948, 17</value>
</metadata>
<metadata name="btnStopStop.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1061, 17</value>
</metadata>
<metadata name="btnEmpty.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1189, 17</value>
</metadata>
<metadata name="btnGetProdWxCate.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1299, 17</value>
</metadata>
<metadata name="btnDel.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 55</value>
</metadata>
<metadata name="colSelect.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="colSelect.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
+141 -90
View File
@@ -1174,119 +1174,170 @@ namespace Work.Api
public static System.Text.Encoding GetFileEncoding(string filename) public static System.Text.Encoding GetFileEncoding(string filename)
{ {
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read)) byte[] bytes = File.ReadAllBytes(filename);
using (var br = new System.IO.BinaryReader(fs)) return DetectEncoding(bytes);
{
var buffer = br.ReadBytes(2);
if (buffer[0] >= 0xEF)
{
if (buffer[0] == 0xEF && buffer[1] == 0xBB)
{
return System.Text.Encoding.UTF8;
}
if (buffer[0] == 0xFE && buffer[1] == 0xFF)
{
return System.Text.Encoding.BigEndianUnicode;
} }
/// <summary>
if (buffer[0] == 0xFF && buffer[1] == 0xFE) /// 检测字节数组的编码
/// </summary>
public static Encoding DetectEncoding(byte[] bytes)
{ {
return System.Text.Encoding.Unicode; if (bytes == null || bytes.Length == 0)
return Encoding.UTF8;
// ---------- 1. 优先判断 BOM ----------
Encoding bomEncoding = DetectByBom(bytes);
if (bomEncoding != null)
return bomEncoding;
// ---------- 2. 判断是否为合法 UTF-8(无 BOM) ----------
if (IsValidUtf8(bytes))
return new UTF8Encoding(false); // 无 BOM 的 UTF-8
// ---------- 3. 判断是否符合 GBK/GB2312 双字节规则 ----------
if (IsLikelyGbk(bytes))
{
// GB18030 兼容 GBK/GB2312,是更安全的选择
try
{
return Encoding.GetEncoding("GB18030");
}
catch
{
// 某些精简运行时(如未注册 CodePages Provider)可能取不到,
// 需要在项目里加 <PackageReference Include="System.Text.Encoding.CodePages" />
// 并在启动时调用 Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
} }
} }
return GetEncodingWithBomUtf8(fs, System.Text.Encoding.Default); // ---------- 4. 兜底 ----------
} return Encoding.Default; // 或者你想要的 fallback,比如 Encoding.UTF8
}
private static System.Text.Encoding GetEncodingWithBomUtf8(Stream fs, Encoding defaultEncoding)
{
byte[] unicode = new byte[] { 0xFF, 0xFE, 0x41 };
byte[] unicodeBig = new byte[] { 0xFE, 0xFF, 0x00 };
//带BOM
byte[] utf8 = new byte[] { 0xEF, 0xBB, 0xBF };
var reVal = defaultEncoding;
using (var r = new System.IO.BinaryReader(fs))
{
byte[] ss = r.ReadBytes(4);
if (ss[0] == 0xFE && ss[1] == 0xFF && ss[2] == 0x00)
{
reVal = Encoding.BigEndianUnicode;
}
else if (ss[0] == 0xFF && ss[1] == 0xFE && ss[2] == 0x41)
{
reVal = Encoding.Unicode;
}
else
{
if (ss[0] == 0xEF && ss[1] == 0xBB && ss[2] == 0xBF)
{
reVal = Encoding.UTF8;
}
else
{
int i;
int.TryParse(fs.Length.ToString(), out i);
ss = r.ReadBytes(i);
if (IsUtf8Bytes(ss))
{
reVal = Encoding.UTF8;
}
}
}
return reVal;
}
} }
/// <summary> /// <summary>
/// 判断是否是不带 BOM 的 UTF8 格式 /// 根据 BOM 判断编码,没有 BOM 返回 null
/// </summary> /// </summary>
/// <param name="data"></param> private static Encoding DetectByBom(byte[] bytes)
/// <returns></returns>
private static bool IsUtf8Bytes(byte[] data)
{ {
int charByteCounter = 1;  //计算当前正分析的字符应还有的字节数 if (bytes.Length >= 4 &&
for (int i = 0; i < data.Length; i++) bytes[0] == 0x00 && bytes[1] == 0x00 &&
{ bytes[2] == 0xFE && bytes[3] == 0xFF)
var curByte = data[i]; //当前分析的字节. return new UTF32Encoding(true, true); // UTF-32 BE
if (charByteCounter == 1)
{ if (bytes.Length >= 4 &&
if (curByte >= 0x80) bytes[0] == 0xFF && bytes[1] == 0xFE &&
{ bytes[2] == 0x00 && bytes[3] == 0x00)
//判断当前 return new UTF32Encoding(false, true); // UTF-32 LE
while (((curByte <<= 1) & 0x80) != 0)
{ if (bytes.Length >= 3 &&
charByteCounter++; bytes[0] == 0xEF && bytes[1] == 0xBB && bytes[2] == 0xBF)
return new UTF8Encoding(true); // UTF-8 with BOM
if (bytes.Length >= 2 &&
bytes[0] == 0xFE && bytes[1] == 0xFF)
return new UnicodeEncoding(true, true); // UTF-16 BE
if (bytes.Length >= 2 &&
bytes[0] == 0xFF && bytes[1] == 0xFE)
return new UnicodeEncoding(false, true); // UTF-16 LE
return null;
} }
//标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X 
if (charByteCounter == 1 || charByteCounter > 6) /// <summary>
/// 严格校验字节序列是否为合法 UTF-8
/// </summary>
private static bool IsValidUtf8(byte[] bytes)
{ {
int i = 0;
int len = bytes.Length;
bool hasMultiByteSequence = false;
while (i < len)
{
byte b = bytes[i];
if (b <= 0x7F) // 单字节 ASCII
{
i++;
continue;
}
int extraBytes;
if ((b & 0xE0) == 0xC0) extraBytes = 1; // 110xxxxx
else if ((b & 0xF0) == 0xE0) extraBytes = 2; // 1110xxxx
else if ((b & 0xF8) == 0xF0) extraBytes = 3; // 11110xxx
else return false; // 不合法的起始字节
if (i + extraBytes >= len)
return false; // 长度不够
for (int j = 1; j <= extraBytes; j++)
{
if ((bytes[i + j] & 0xC0) != 0x80) // 后续字节必须是 10xxxxxx
return false; return false;
} }
hasMultiByteSequence = true;
i += extraBytes + 1;
} }
// 纯 ASCII 内容严格来说 UTF-8/GBK/ASCII 都符合,
// 这里只有出现过合法多字节序列才更有把握判定为 UTF-8。
// 如果你希望纯 ASCII 也直接归为 UTF-8,可以把下面这行去掉判断直接 return true。
return hasMultiByteSequence || IsAllAscii(bytes);
} }
else
private static bool IsAllAscii(byte[] bytes)
{ {
//若是UTF-8 此时第一位必须为1 foreach (byte b in bytes)
if ((curByte & 0xC0) != 0x80)
{ {
return false; if (b > 0x7F) return false;
}
charByteCounter--;
}
}
if (charByteCounter > 1)
{
throw new Exception("非预期的byte格式!");
} }
return true; return true;
} }
/// <summary>
/// 启发式判断是否符合 GBK/GB2312 双字节编码规则
/// GBK: 首字节 0x81-0xFE,次字节 0x40-0xFE(不含 0x7F)
/// </summary>
private static bool IsLikelyGbk(byte[] bytes)
{
int i = 0;
int len = bytes.Length;
bool hasDoubleByte = false;
while (i < len)
{
byte b = bytes[i];
if (b <= 0x7F) // ASCII
{
i++;
continue;
}
if (b >= 0x81 && b <= 0xFE)
{
if (i + 1 >= len) return false;
byte b2 = bytes[i + 1];
if (b2 >= 0x40 && b2 <= 0xFE && b2 != 0x7F)
{
hasDoubleByte = true;
i += 2;
continue;
}
return false;
}
return false; // 不符合 GBK 规则的字节
}
return hasDoubleByte;
}
public void GetCat() public void GetCat()
{ {
int CatThreadCount = 20; int CatThreadCount = 20;