1商品json中有特殊字符情况处理 2商品类目导致不能上传问题处理(完成30%)

This commit is contained in:
wule committed 2025-08-19 19:06:20 +08:00
1 parent 8445ec1828
commit e73359e283
13 files changed
+618 -56

No files matched your search

@@ -86,6 +86,8 @@
this.splitContainer2 = new System.Windows.Forms.SplitContainer();
this.pbLoading = new System.Windows.Forms.PictureBox();
this.dgvSelectProduct = new TemuKJD.UserComponent.DataGridViewEx();
this.ucSplitPage1 = new TemuKJD.UserControls.UcSplitPage();
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
this.colSelect = new System.Windows.Forms.DataGridViewCheckBoxColumn();
this.colSelectId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colSupplierId = new System.Windows.Forms.DataGridViewTextBoxColumn();
@@ -99,7 +101,7 @@
this.colImgUrl = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colProductSkcPic = new System.Windows.Forms.DataGridViewImageColumn();
this.colProductName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colProductCat = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colProductCat = new System.Windows.Forms.DataGridViewLinkColumn();
this.colExtCode = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colStatus = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.colDraftId = new System.Windows.Forms.DataGridViewLinkColumn();
@@ -112,8 +114,6 @@
this.colEditNotes = new System.Windows.Forms.DataGridViewLinkColumn();
this.ColDelete = new System.Windows.Forms.DataGridViewLinkColumn();
this.colOpResult = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ucSplitPage1 = new TemuKJD.UserControls.UcSplitPage();
this.statusBar = new TemuKJD.UserControls.StatusBarUserControl();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
@@ -264,7 +264,7 @@
"全部",
"重上",
"已买"});
this.cmbUserNotes.Location = new System.Drawing.Point(1044, 8);
this.cmbUserNotes.Location = new System.Drawing.Point(1044, 5);
this.cmbUserNotes.Margin = new System.Windows.Forms.Padding(0);
this.cmbUserNotes.Name = "cmbUserNotes";
this.cmbUserNotes.Size = new System.Drawing.Size(65, 25);
@@ -281,7 +281,7 @@
"核价成功",
"核价成功(重复)",
"重复"});
this.cmbNotes.Location = new System.Drawing.Point(917, 8);
this.cmbNotes.Location = new System.Drawing.Point(917, 5);
this.cmbNotes.Margin = new System.Windows.Forms.Padding(0);
this.cmbNotes.Name = "cmbNotes";
this.cmbNotes.Size = new System.Drawing.Size(65, 25);
@@ -308,7 +308,7 @@
"已上传",
"草稿箱",
"全部"});
this.cmbStatus.Location = new System.Drawing.Point(814, 8);
this.cmbStatus.Location = new System.Drawing.Point(814, 5);
this.cmbStatus.Margin = new System.Windows.Forms.Padding(0);
this.cmbStatus.Name = "cmbStatus";
this.cmbStatus.Size = new System.Drawing.Size(65, 25);
@@ -864,6 +864,29 @@
this.dgvSelectProduct.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dgvSelectProduct_CellContentClick);
this.dgvSelectProduct.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dgvSelectProduct_Scroll);
//
// ucSplitPage1
//
this.ucSplitPage1.CurrentPage = 1;
this.ucSplitPage1.Dock = System.Windows.Forms.DockStyle.Right;
this.ucSplitPage1.Location = new System.Drawing.Point(1196, 0);
this.ucSplitPage1.Margin = new System.Windows.Forms.Padding(0);
this.ucSplitPage1.Name = "ucSplitPage1";
this.ucSplitPage1.Padding = new System.Windows.Forms.Padding(0, 0, 1, 0);
this.ucSplitPage1.Size = new System.Drawing.Size(362, 25);
this.ucSplitPage1.TabIndex = 6;
this.ucSplitPage1.TotalPage = 1;
//
// statusBar
//
this.statusBar.BackColor = System.Drawing.Color.White;
this.statusBar.Dock = System.Windows.Forms.DockStyle.Fill;
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, 0);
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1558, 25);
this.statusBar.TabIndex = 5;
//
// colSelect
//
this.colSelect.HeaderText = "选择";
@@ -977,6 +1000,8 @@
this.colProductCat.HeaderText = "商品类目";
this.colProductCat.Name = "colProductCat";
this.colProductCat.ReadOnly = true;
this.colProductCat.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.colProductCat.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
this.colProductCat.Width = 72;
//
// colExtCode
@@ -1075,29 +1100,6 @@
this.colOpResult.ReadOnly = true;
this.colOpResult.Width = 150;
//
// ucSplitPage1
//
this.ucSplitPage1.CurrentPage = 1;
this.ucSplitPage1.Dock = System.Windows.Forms.DockStyle.Right;
this.ucSplitPage1.Location = new System.Drawing.Point(1196, 0);
this.ucSplitPage1.Margin = new System.Windows.Forms.Padding(0);
this.ucSplitPage1.Name = "ucSplitPage1";
this.ucSplitPage1.Padding = new System.Windows.Forms.Padding(0, 0, 1, 0);
this.ucSplitPage1.Size = new System.Drawing.Size(362, 25);
this.ucSplitPage1.TabIndex = 6;
this.ucSplitPage1.TotalPage = 1;
//
// statusBar
//
this.statusBar.BackColor = System.Drawing.Color.White;
this.statusBar.Dock = System.Windows.Forms.DockStyle.Fill;
this.statusBar.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.statusBar.Location = new System.Drawing.Point(0, 0);
this.statusBar.Margin = new System.Windows.Forms.Padding(0);
this.statusBar.Name = "statusBar";
this.statusBar.Size = new System.Drawing.Size(1558, 25);
this.statusBar.TabIndex = 5;
//
// ProductThirdSelectListManageForm
//
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
@@ -1178,6 +1180,11 @@
private System.Windows.Forms.Label label11;
private UserComponent.UcCheckBox chkUploadProd;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.ComboBox cmbUserNotes;
private System.Windows.Forms.ComboBox cmbNotes;
private System.Windows.Forms.ComboBox cmbStatus;
private DevComponents.DotNetBar.PanelEx btnDel;
private System.Windows.Forms.DataGridViewCheckBoxColumn colSelect;
private System.Windows.Forms.DataGridViewTextBoxColumn colSelectId;
private System.Windows.Forms.DataGridViewTextBoxColumn colSupplierId;
@@ -1191,7 +1198,7 @@
private System.Windows.Forms.DataGridViewTextBoxColumn colImgUrl;
private System.Windows.Forms.DataGridViewImageColumn colProductSkcPic;
private System.Windows.Forms.DataGridViewTextBoxColumn colProductName;
private System.Windows.Forms.DataGridViewTextBoxColumn colProductCat;
private System.Windows.Forms.DataGridViewLinkColumn colProductCat;
private System.Windows.Forms.DataGridViewTextBoxColumn colExtCode;
private System.Windows.Forms.DataGridViewTextBoxColumn colStatus;
private System.Windows.Forms.DataGridViewLinkColumn colDraftId;
@@ -1204,10 +1211,5 @@
private System.Windows.Forms.DataGridViewLinkColumn colEditNotes;
private System.Windows.Forms.DataGridViewLinkColumn ColDelete;
private System.Windows.Forms.DataGridViewTextBoxColumn colOpResult;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.ComboBox cmbUserNotes;
private System.Windows.Forms.ComboBox cmbNotes;
private System.Windows.Forms.ComboBox cmbStatus;
private DevComponents.DotNetBar.PanelEx btnDel;
}
}
@@ -148,7 +148,7 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
prodSelect.main_img.Replace("https:", "http:"),
defaultBitmap,//prod.main_img,
prodSelect.fission_product_name,
prodSelect.cat_name,
string.IsNullOrWhiteSpace(prodSelect.change_cat_name) ? prodSelect.cat_name : prodSelect.change_cat_name,
prodSelect.ext_code,
prodSelect.status,
prodSelect.draft_id,
@@ -335,6 +335,8 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
case "认领":
//Task.Run(() => { SelectProduct(new TemuDBProduct[] { dbProduct }); });
break;
case "商品类目":
break;
case "草稿箱Id":
if (!string.IsNullOrEmpty(draftId))
{
@@ -620,9 +622,25 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
//var prodDetailJsonReplace = Regex.Replace(prodDetailJson, pattern, "\\$1");
string pattern = @"([^\\])(\\[^bfrnt\\/'\""])";
var prodDetailJsonReplace = Regex.Replace(prodDetailJson, pattern, "$1\\$2");
string pattern2 = @"([^\\,:""{\[])(""[^,:""}\]])";//希伯来文中的引号转义在数据库中有时候会丢失,回来发现了给配上\符号
string pattern2 = @"([^\\,:""{\[])(""[^,:""}\]])";//希伯来文等语言的引号转义在存入数据库时会因反转义丢失,回来发现了给配上\符号
var prodDetailJsonReplace2 = Regex.Replace(prodDetailJsonReplace, pattern2, "$1\\$2");
//总体替换后再把多国语言的每个标题替换一次
string productJsonTmp = prodDetailJsonReplace2.Substring(prodDetailJsonReplace.IndexOf("goodsI18nList"));
var matches = AllBase.BaseRegex.GetMatchRegex(productJsonTmp, "\"productName\":\"([\\s|\\S]*?)\"}");
foreach(Match match in matches)
{
var mStr = match.Groups[1].ParseToString();
if (!string.IsNullOrWhiteSpace(mStr) && mStr.Contains("\""))
{
string pattern3 = @"([^\\])("")";
string mStr2 = Regex.Replace(mStr, pattern3, "$1\\$2");
prodDetailJsonReplace2 = prodDetailJsonReplace2.Replace(mStr, mStr2);
}
}
temuDBProd.product_json = prodDetailJsonReplace2;
result = UploadProduct(shop, temuDBProd, prod, row.Cells["colOpResult"]); //将商品上传至草稿箱或直接上传到未发布
if (result.Contains("登录过期") || result.Contains("Invalid Login State"))
@@ -677,7 +695,7 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
Invoke(new Action(() =>
{
row.Cells["colDraftId"].Value = productDraftId; // 草稿箱id
row.Cells["colOpResult"].Value = prod.status == "已上传" ? "已成功上传" : "已上传草稿箱" + (" " + error).Trim(' ');
row.Cells["colOpResult"].Value = prod.status == "已上传" ? "已成功上传" : "已上传草稿箱" + (" " + error).TrimEnd(' ');
row.Cells["colStatus"].Value = prod.status;
}));
}
@@ -774,18 +792,73 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
prodParam.cat9Id = prodInfo.categories.cat9.catId;
prodParam.cat10Id = prodInfo.categories.cat10.catId;
long catId = prodParam.cat10Id.ParseToLong();
if (catId == 0) catId = prodParam.cat9Id.ParseToLong();
if (catId == 0) catId = prodParam.cat8Id.ParseToLong();
if (catId == 0) catId = prodParam.cat7Id.ParseToLong();
if (catId == 0) catId = prodParam.cat6Id.ParseToLong();
if (catId == 0) catId = prodParam.cat5Id.ParseToLong();
if (catId == 0) catId = prodParam.cat4Id.ParseToLong();
if (catId == 0) catId = prodParam.cat3Id.ParseToLong();
if (catId == 0) catId = prodParam.cat2Id.ParseToLong();
if (catId == 0) catId = prodParam.cat1Id.ParseToLong();
Dictionary<int, long> catIdDic = new Dictionary<int, long>();
catIdDic[10] = prodParam.cat10Id.ParseToLong();
catIdDic[9] = prodParam.cat9Id.ParseToLong();
catIdDic[8] = prodParam.cat8Id.ParseToLong();
catIdDic[7] = prodParam.cat7Id.ParseToLong();
catIdDic[6] = prodParam.cat6Id.ParseToLong();
catIdDic[5] = prodParam.cat5Id.ParseToLong();
catIdDic[4] = prodParam.cat4Id.ParseToLong();
catIdDic[3] = prodParam.cat3Id.ParseToLong();
catIdDic[2] = prodParam.cat2Id.ParseToLong();
catIdDic[1] = prodParam.cat1Id.ParseToLong();
long catId = 0;
int catLevel = 0;
for (int i = 10; i >= 1; i--)
{
catLevel = i;
catId = catIdDic[catLevel];
if (catId > 0)
break;
}
var html = AddDraft(shop, catId.ToString());
if (html.Contains("不合法的类目") && catLevel > 1)
{
catId = catIdDic[catLevel - 1];
//string catSearchStr = prodInfo.productName;
//int index = catSearchStr.IndexOf("PCS ");
//if (index > 0 && index < 5)
// catSearchStr = catSearchStr.Substring(index + 4).Trim();
var catSearchStr = selectProd.change_cat_name;
if (!string.IsNullOrWhiteSpace(catSearchStr))
{
html = SearchCategory(shop, catSearchStr);
try
{
var catObj = JObject.Parse(html)["result"]["categoryPaths"][0];
var catStr = JsonHelper.SerializeObject(catObj);
prodParam.cat1Id = catIdDic[1] = (catObj["cat1NodeVO"].IsNullOrEmpty() ? null : catObj["cat1NodeVO"]["catId"]).ParseToLong();
prodParam.cat2Id = catIdDic[2] = (catObj["cat2NodeVO"].IsNullOrEmpty() ? null : catObj["cat2NodeVO"]["catId"]).ParseToLong();
prodParam.cat3Id = catIdDic[3] = (catObj["cat3NodeVO"].IsNullOrEmpty() ? null : catObj["cat3NodeVO"]["catId"]).ParseToLong();
prodParam.cat4Id = catIdDic[4] = (catObj["cat4NodeVO"].IsNullOrEmpty() ? null : catObj["cat4NodeVO"]["catId"]).ParseToLong();
prodParam.cat5Id = catIdDic[5] = (catObj["cat5NodeVO"].IsNullOrEmpty() ? null : catObj["cat5NodeVO"]["catId"]).ParseToLong();
prodParam.cat6Id = catIdDic[6] = (catObj["cat6NodeVO"].IsNullOrEmpty() ? null : catObj["cat6NodeVO"]["catId"]).ParseToLong();
prodParam.cat7Id = catIdDic[7] = (catObj["cat7NodeVO"].IsNullOrEmpty() ? null : catObj["cat7NodeVO"]["catId"]).ParseToLong();
prodParam.cat8Id = catIdDic[8] = (catObj["cat8NodeVO"].IsNullOrEmpty() ? null : catObj["cat8NodeVO"]["catId"]).ParseToLong();
prodParam.cat9Id = catIdDic[9] = (catObj["cat9NodeVO"].IsNullOrEmpty() ? null : catObj["cat9NodeVO"]["catId"]).ParseToLong();
prodParam.cat10Id = catIdDic[10] = (catObj["cat10NodeVO"].IsNullOrEmpty() ? null : catObj["cat10NodeVO"]["catId"]).ParseToLong();
for (int i = 10; i >= 1; i--)
{
catLevel = i;
catId = catIdDic[catLevel];
if (catId > 0)
break;
}
}
catch (Exception ex)
{
catId = catIdDic[catLevel - 1];
}
}
html = AddDraft(shop, catId.ToString());
}
if (html.Contains("\"success\":true"))
prodParam.productDraftId = BaseRegex.GetLongJson(ref html, "productDraftId");
else
@@ -893,7 +966,23 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
// }
// centerWords += fissionTxt + ",";
//}
string centerName = dbProd.product_name + centerWords.ParseToString();
var prodName = dbProd.product_name;
var allTxt = headWords + prodName + centerWords + endWords;
byte[] bytes = Encoding.GetEncoding("gb2312").GetBytes(allTxt);
for (int i = 0; i < 100 && bytes.Length > 500; i++)
{
int pos1 = prodName.LastIndexOf(',');
int pos2 = prodName.LastIndexOf(' ');
if (pos1 > 0)
prodName = prodName.Substring(0, pos1 - 1);
else if (pos2>0)
prodName = prodName.Substring(0, pos2 - 1);
allTxt = headWords + prodName + centerWords + endWords;
bytes = Encoding.GetEncoding("gb2312").GetBytes(allTxt);
}
string centerName = prodName + centerWords.ParseToString();
// 标题完全打乱
//if (chkReFissionAllProdName.Checked)
@@ -1343,6 +1432,15 @@ namespace TemuKJD.KJDForms.ProductThirdSelectForms
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
}
private string SearchCategory(ShopLoginInfo shop, string searchStr)
{
string url = "https://agentseller.temu.com/anniston-agent-seller/category/search";
string body = @"{""searchText"":""" + searchStr + @"""}";
string refere = "https://agentseller.temu.com/goods/create/category";
return KJDHttpResponse.PostResponse2(shop, url, body, refere);
}
private void btnSetSubSa_Click(object sender, EventArgs e)
{
var lstProdId = dgvSelectProduct.Rows.Cast<DataGridViewRow>().Where(row