修改云端数据 代码改为异步,导入成功提示

This commit is contained in:
chfei committed 2026-09-08 09:44:17 +08:00
1 parent de9cd4ae65
commit 4fdcc94a91
5 files changed
+120 -14

No files matched your search

+76
View File
@@ -1249,6 +1249,82 @@ Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrom
return "";
}
}
public static async Task<string> PostUtf8Async(string url, string postData, string contentType = "", int? timeOut = null)
{
bool isError = false;
string[] l = UserAgent.Split('\n');
reTry:
try
{
string codeType = "utf-8";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = l[new Random(Guid.NewGuid().GetHashCode()).Next(l.Length)].Trim();
byte[] byteData = Encoding.GetEncoding(codeType).GetBytes(postData);
request.Method = "POST";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Timeout = BaseClass.TimeOut * 1000;
request.ReadWriteTimeout = BaseClass.TimeOut * 1000;
if (timeOut != null)
{
request.Timeout = timeOut.Value * 1000;
request.ReadWriteTimeout = timeOut.Value * 1000;
}
request.Proxy = null;
request.ContentType = "application/x-www-form-urlencoded; charset=" + codeType;
//if(BaseClass.SaLevel > 0)
{
//260306 采用GZip/deflate压缩
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br, zstd");
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
}
if (url.StartsWith("https://openapi.jinritemai.com/"))
{
request.Headers.Add("X-USE-BOE", "1");
request.Headers.Add("Origin-From", "djt_prod");
request.Headers.Add("djt_prod", "boe_time_sku");
}
if (!string.IsNullOrEmpty(contentType))
{
request.ContentType = contentType;
}
request.ContentLength = byteData.Length;
request.Referer = url;
request.CookieContainer = new CookieContainer();
request.AllowAutoRedirect = false;
using (Stream requestStream = await request.GetRequestStreamAsync())
{
requestStream.Write(byteData, 0, byteData.Length);
}
HttpWebResponse response = (HttpWebResponse) await request.GetResponseAsync();
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.GetEncoding(codeType));
//if (BaseClass.SaLevel == 0)
//{
// return readStream.ReadToEnd().Trim();
//}
//else
{
//260306 超管采用GZip/deflate压缩
//Thread.Sleep(50);
return GetProxyHtml.ReadResponse(response);
}
}
catch (Exception e)
{
LogSave.Add(e.ToString());
//if (!isError)
//{
// isError = true;
// goto reTry;
//}
Thread.Sleep(50);
return "";
}
}
/// <summary>
/// post 数据
@@ -49,13 +49,21 @@ namespace TemuKJD.PDDForms.ProductSelectForms
ucSplitPage1.PageChange += UcSplitPage1_PageChange;
InitCategory();
InitBindingDataGridView();
txt_title.Text = "连衣裙";
num_minsold.Value = 0;
num_maxsold.Value = 999;
num_minprice.Value = 0;
num_maxprice.Value = 999;
cb_Platform.SelectedIndex = 0;
ucSplitPage1.TotalCount = 0;
if (EnvironmentHelper.IsDevelopment)
{
txt_title.Text = "连衣裙";
}
}
@@ -301,8 +309,13 @@ namespace TemuKJD.PDDForms.ProductSelectForms
{
btnSearch_Click(obj, null);
}
private void btnSearch_Click(object sender, EventArgs e)
private async void btnSearch_Click(object sender, EventArgs e)
{
try
{
this.pbLoading.Visible = true;
btnSearch.Enabled = false;
GoodsSearchRequest search = new GoodsSearchRequest();
search.Platform = cb_Platform.SelectedIndex == 1 ? PlatformType.PDD : cb_Platform.SelectedIndex == 2 ? PlatformType.WX : PlatformType.None;
@@ -328,6 +341,16 @@ namespace TemuKJD.PDDForms.ProductSelectForms
GetGoods(search);
}
catch (Exception ex)
{
BaseMsgForm.ShowError($"查询失败:{ex.Message}");
}
finally
{
this.pbLoading.Visible = false;
btnSearch.Enabled = true;
}
}
@@ -346,14 +369,11 @@ namespace TemuKJD.PDDForms.ProductSelectForms
}
public void GetGoods(GoodsSearchRequest request)
public async void GetGoods(GoodsSearchRequest request)
{
this.pbLoading.Visible = true;
dataList.Clear();
Task.Run(() =>
{
PageData<CloudGoods> ret = CloudGoodsService.GetGoods(request);
PageData<CloudGoods> ret = await CloudGoodsService.GetGoods(request);
Invoke(new Action(() =>
{
ret.List.ForEach(a => dataList.Add(a));
@@ -363,7 +383,6 @@ namespace TemuKJD.PDDForms.ProductSelectForms
// 异步加载商品缩略图(Column1 绑定 ThumbUrl)
ShowDgvImg();
}));
});
}
@@ -377,7 +396,11 @@ namespace TemuKJD.PDDForms.ProductSelectForms
/// <param name="e"></param>
private void bt_importUploadList_Click(object sender, EventArgs e)
{
int succ = 0;
int err = 0;
foreach (var item in dataList)
{
try
{
if (item.IsSelected == false) continue;
string catName = "";
@@ -401,8 +424,15 @@ namespace TemuKJD.PDDForms.ProductSelectForms
product_name = item.Title,
cat_name = catName,
});
succ++;
}
catch
{
err++;
}
}
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", WXDBProdUploadForm.Instance.lstTemuDBProductSelect);
BaseMsgForm.ShowInfo($"导入完成!{succ} 成功 {err} 失败");
}
}
+3 -3
View File
@@ -29,7 +29,7 @@
private void InitializeComponent()
{
System.Windows.Forms.TreeNode treeNode1 = new System.Windows.Forms.TreeNode("选品上传");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("云仓数据");
System.Windows.Forms.TreeNode treeNode2 = new System.Windows.Forms.TreeNode("云端数据");
System.Windows.Forms.TreeNode treeNode3 = new System.Windows.Forms.TreeNode("我的商品库");
System.Windows.Forms.TreeNode treeNode4 = new System.Windows.Forms.TreeNode("商品预售/下架");
System.Windows.Forms.TreeNode treeNode5 = new System.Windows.Forms.TreeNode("云仓退货地址");
@@ -149,8 +149,8 @@
this.tv.Name = "tv";
treeNode1.Name = "选品上传";
treeNode1.Text = "选品上传";
treeNode2.Name = "云仓数据";
treeNode2.Text = "云仓数据";
treeNode2.Name = "云端数据";
treeNode2.Text = "云端数据";
treeNode3.Name = "我的商品库";
treeNode3.Text = "我的商品库";
treeNode4.Name = "商品预售/下架";
@@ -98,7 +98,7 @@ namespace TemuKJD.WXForms.ProductForms
case "选品上传":
SetForm(userSelectDbProductForm.Value);
break;
case "云仓数据":
case "云端数据":
SetForm(cloudgoodsForm.Value);
break;
case "我的商品库":
+2 -2
View File
@@ -15,10 +15,10 @@ namespace Work.Services
public class CloudGoodsService
{
private const string ServerUrl = "http://119.45.4.202:14312";
public static PageData<CloudGoods> GetGoods(GoodsSearchRequest request)
public static async Task<PageData<CloudGoods>> GetGoods(GoodsSearchRequest request)
{
string data = JsonHelper.SerializeObject(request);
var html = GetHtml.PostUtf8(ServerUrl + "/Goods/SearchGoods", data, "application/json");
var html = await GetHtml.PostUtf8Async(ServerUrl + "/Goods/SearchGoods", data, "application/json");
var ret = JsonConvert.DeserializeObject<Result<PageData<CloudGoods>>>(html);
if (ret.Code != 200)