上货增加图片缓存 暂未开放
This commit is contained in:
1 parent
6e995a5bdb
commit
ab7bd36ba6
1 file changed
+179
-81
@@ -16,6 +16,7 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -1605,6 +1606,9 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
|
|
||||||
string UploadProduct(ShopLoginInfo shop, KJDDBProduct dbProd, TemuDBProductSelect selectProd, DataGridViewCell cell, DateTime startTime)
|
string UploadProduct(ShopLoginInfo shop, KJDDBProduct dbProd, TemuDBProductSelect selectProd, DataGridViewCell cell, DateTime startTime)
|
||||||
{
|
{
|
||||||
|
PlatformType Platform = (dbProd.product_get_type_text == "多多" ? PlatformType.PDD : PlatformType.None);
|
||||||
|
|
||||||
|
|
||||||
#region 初始化上传商品对象
|
#region 初始化上传商品对象
|
||||||
// 生成初始化上传商品对象
|
// 生成初始化上传商品对象
|
||||||
var upProdInitParam = new WXUploadProductInitParam();
|
var upProdInitParam = new WXUploadProductInitParam();
|
||||||
@@ -2261,26 +2265,31 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
var prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(dbProd.product_json);
|
||||||
|
|
||||||
#region 图片盗链映射生成字典(如果有)
|
#region 图片盗链映射生成字典(如果有)
|
||||||
|
Dictionary<string, ImageCache> wxImgMapDic = new Dictionary<string, ImageCache>(StringComparer.OrdinalIgnoreCase);
|
||||||
bool isChangeImgDic = false;
|
bool isChangeImgDic = false;
|
||||||
Dictionary<string, string> wxImgMapDic = new Dictionary<string, string>();
|
wxImgMapDic = GetImageCaches(prodInfo);
|
||||||
if (!string.IsNullOrEmpty(dbProd.wx_img_map_json))
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
//Dictionary<string, string> wxImgMapDic = new Dictionary<string, string>();
|
||||||
wxImgMapDic = JsonHelper.DeserializeJsonToObject<Dictionary<string, string>>(dbProd.wx_img_map_json);
|
//if (!string.IsNullOrEmpty(dbProd.wx_img_map_json))
|
||||||
}
|
//{
|
||||||
catch
|
// try
|
||||||
{
|
// {
|
||||||
isChangeImgDic = true;
|
// wxImgMapDic = JsonHelper.DeserializeJsonToObject<Dictionary<string, string>>(dbProd.wx_img_map_json);
|
||||||
wxImgMapDic = new Dictionary<string, string>();
|
// }
|
||||||
}
|
// catch
|
||||||
}
|
// {
|
||||||
|
// isChangeImgDic = true;
|
||||||
|
// wxImgMapDic = new Dictionary<string, string>();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 提取源商品详情,根据需要生成sku货号
|
#region 提取源商品详情,根据需要生成sku货号
|
||||||
var prodInfo = JsonHelper.DeserializeJsonToObject<PDDProductInfo>(dbProd.product_json);
|
|
||||||
|
|
||||||
// 如果没有货号或有相同货号无法区分sku,自定义货号
|
// 如果没有货号或有相同货号无法区分sku,自定义货号
|
||||||
if (dbProd.db_type == "云端数据")
|
if (dbProd.db_type == "云端数据")
|
||||||
{
|
{
|
||||||
@@ -2522,8 +2531,10 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
// 获取缓存盗链 主图
|
// 获取缓存盗链 主图
|
||||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||||||
{
|
{
|
||||||
upProdInitParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
Debug.WriteLine("主图:缓存");
|
||||||
upProdParam.product.info.headImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
var image = wxImgMapDic[BaseClass.GetMd5(gallery_item.url)];
|
||||||
|
upProdInitParam.product.info.headImg.Add(image.PlatformUrl);
|
||||||
|
upProdParam.product.info.headImg.Add(image.PlatformUrl);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2533,6 +2544,7 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("主图:上传");
|
||||||
// 使用接口链接传主图
|
// 使用接口链接传主图
|
||||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||||
var upDate = UserLogin.GetSignaturex();
|
var upDate = UserLogin.GetSignaturex();
|
||||||
@@ -2560,7 +2572,11 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
{
|
{
|
||||||
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
||||||
upProdParam.product.info.headImg.Add(upImgUrl);
|
upProdParam.product.info.headImg.Add(upImgUrl);
|
||||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache
|
||||||
|
{
|
||||||
|
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||||||
|
PlatformUrl = upImgUrl,
|
||||||
|
};
|
||||||
isChangeImgDic = true;
|
isChangeImgDic = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2615,7 +2631,12 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
{
|
{
|
||||||
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
upProdInitParam.product.info.headImg.Add(upImgUrl);
|
||||||
upProdParam.product.info.headImg.Add(upImgUrl);
|
upProdParam.product.info.headImg.Add(upImgUrl);
|
||||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache
|
||||||
|
{
|
||||||
|
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||||||
|
PlatformUrl = upImgUrl,
|
||||||
|
};
|
||||||
|
|
||||||
isChangeImgDic = true;
|
isChangeImgDic = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -2706,24 +2727,14 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#region 保存缓存盗链图片
|
#region 保存缓存盗链图片
|
||||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
|
||||||
{
|
{
|
||||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
SaveImageCaches(Platform, wxImgMapDic.Values);
|
||||||
var data = "";
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
data = UserLogin.GetSignaturex();
|
|
||||||
data += "&spu_id=" + dbProd.spu_id;
|
|
||||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
|
||||||
}));
|
|
||||||
var 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"))
|
|
||||||
html = GetHtml.PostUtf8(url, data);
|
|
||||||
isChangeImgDic = false;
|
isChangeImgDic = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 识别类目
|
#region 识别类目
|
||||||
@@ -3464,7 +3475,9 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
// 获取缓存盗链 详情图
|
// 获取缓存盗链 详情图
|
||||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||||||
{
|
{
|
||||||
upProdParam.product.info.detail.detailImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
Debug.WriteLine("详情图:缓存");
|
||||||
|
var image = wxImgMapDic[BaseClass.GetMd5(gallery_item.url)];
|
||||||
|
upProdParam.product.info.detail.detailImg.Add(image.PlatformUrl);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3474,6 +3487,7 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("详情图:上传");
|
||||||
// 使用接口链接传详情图
|
// 使用接口链接传详情图
|
||||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||||
var upDate = UserLogin.GetSignaturex();
|
var upDate = UserLogin.GetSignaturex();
|
||||||
@@ -3500,7 +3514,11 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||||
{
|
{
|
||||||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache
|
||||||
|
{
|
||||||
|
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||||||
|
PlatformUrl = upImgUrl,
|
||||||
|
};
|
||||||
isChangeImgDic = true;
|
isChangeImgDic = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -3554,7 +3572,11 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||||
{
|
{
|
||||||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = new ImageCache
|
||||||
|
{
|
||||||
|
Md5 = BaseClass.GetMd5(gallery_item.url),
|
||||||
|
PlatformUrl = upImgUrl,
|
||||||
|
};
|
||||||
isChangeImgDic = true;
|
isChangeImgDic = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -3584,21 +3606,8 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 保存缓存盗链图片
|
#region 保存缓存盗链图片
|
||||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
|
||||||
{
|
{
|
||||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
SaveImageCaches(Platform, wxImgMapDic.Values);
|
||||||
var data = "";
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
data = UserLogin.GetSignaturex();
|
|
||||||
data += "&spu_id=" + dbProd.spu_id;
|
|
||||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
|
||||||
}));
|
|
||||||
var 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"))
|
|
||||||
html = GetHtml.PostUtf8(url, data);
|
|
||||||
isChangeImgDic = false;
|
isChangeImgDic = false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -4531,12 +4540,15 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
// 获取缓存盗链 sku图
|
// 获取缓存盗链 sku图
|
||||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(sku.thumb_url)))
|
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(sku.thumb_url)))
|
||||||
{
|
{
|
||||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)], });
|
Debug.WriteLine("SKU图:缓存");
|
||||||
|
var image = wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)];
|
||||||
|
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = image.PlatformUrl, });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// 使用接口链接传sku图
|
// 使用接口链接传sku图
|
||||||
if (1 == 1 && !sku.thumb_url.Contains("wst.wxapp.tc.qq.com"))
|
if (1 == 1 && !sku.thumb_url.Contains("wst.wxapp.tc.qq.com"))
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("SKU图:上传");
|
||||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||||
var upDate = UserLogin.GetSignaturex();
|
var upDate = UserLogin.GetSignaturex();
|
||||||
upDate += "&token=" + token.accessToken;
|
upDate += "&token=" + token.accessToken;
|
||||||
@@ -4562,7 +4574,11 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||||
{
|
{
|
||||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
||||||
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl;
|
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = new ImageCache
|
||||||
|
{
|
||||||
|
Md5 = BaseClass.GetMd5(sku.thumb_url),
|
||||||
|
PlatformUrl = upImgUrl,
|
||||||
|
};
|
||||||
isChangeImgDic = true;
|
isChangeImgDic = true;
|
||||||
continue; // 传图成功跳过模拟上传
|
continue; // 传图成功跳过模拟上传
|
||||||
}
|
}
|
||||||
@@ -4612,7 +4628,11 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||||
{
|
{
|
||||||
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
attrParam.items.Add(new productSaleAttrItemParam() { value = spec.spec_name, imgUrl = upImgUrl, });
|
||||||
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = upImgUrl;
|
wxImgMapDic[BaseClass.GetMd5(sku.thumb_url)] = new ImageCache
|
||||||
|
{
|
||||||
|
Md5 = BaseClass.GetMd5(sku.thumb_url),
|
||||||
|
PlatformUrl = upImgUrl,
|
||||||
|
};
|
||||||
isChangeImgDic = true;
|
isChangeImgDic = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -4658,21 +4678,8 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 保存缓存盗链图片
|
#region 保存缓存盗链图片
|
||||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
|
||||||
{
|
{
|
||||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
SaveImageCaches(Platform, wxImgMapDic.Values);
|
||||||
var data = "";
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
data = UserLogin.GetSignaturex();
|
|
||||||
data += "&spu_id=" + dbProd.spu_id;
|
|
||||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
|
||||||
}));
|
|
||||||
var 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"))
|
|
||||||
html = GetHtml.PostUtf8(url, data);
|
|
||||||
isChangeImgDic = false;
|
isChangeImgDic = false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -5798,21 +5805,8 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 保存缓存盗链图片
|
#region 保存缓存盗链图片
|
||||||
if (isChangeImgDic && dbProd.db_type != "云端数据")
|
|
||||||
{
|
{
|
||||||
var url = BaseClass.BuildObjString("product/mdy_pdd_product");
|
SaveImageCaches(Platform, wxImgMapDic.Values);
|
||||||
var data = "";
|
|
||||||
Invoke(new Action(() =>
|
|
||||||
{
|
|
||||||
data = UserLogin.GetSignaturex();
|
|
||||||
data += "&spu_id=" + dbProd.spu_id;
|
|
||||||
data += "&wx_img_map_json=" + JsonHelper.SerializeObject(wxImgMapDic);
|
|
||||||
}));
|
|
||||||
var 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"))
|
|
||||||
html = GetHtml.PostUtf8(url, data);
|
|
||||||
isChangeImgDic = false;
|
isChangeImgDic = false;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -7363,6 +7357,101 @@ namespace TemuKJD.WXForms.ProductForms
|
|||||||
{
|
{
|
||||||
globalShopUploadCntLimitRetryTimes = numJumpCnt.Value.ParseToInt();
|
globalShopUploadCntLimitRetryTimes = numJumpCnt.Value.ParseToInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取图片缓存
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="product"></param>
|
||||||
|
private Dictionary<string, ImageCache> GetImageCaches(PDDProductInfo product)
|
||||||
|
{
|
||||||
|
Dictionary<string, ImageCache> wxImgMapDic = new Dictionary<string, ImageCache>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
if (EnvironmentHelper.IsProduction)
|
||||||
|
{
|
||||||
|
return wxImgMapDic;
|
||||||
|
}
|
||||||
|
List<string> imageUrls = new List<string>();
|
||||||
|
imageUrls.AddRange(product.detail.galleries.Where(g => g.type == 1).Take(9).Select(a => a.url));
|
||||||
|
var temp_detailGalleries = product.detail.galleries.Where(g => g.type == 2).ToList();
|
||||||
|
if (temp_detailGalleries.Count == 0)
|
||||||
|
temp_detailGalleries.Add(new gallery_item() { type = 2, url = product.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
|
||||||
|
imageUrls.AddRange(temp_detailGalleries.Select(a => a.url));
|
||||||
|
|
||||||
|
|
||||||
|
if (product.detail.sku.FirstOrDefault()?.spec?.Count > 0)
|
||||||
|
{
|
||||||
|
imageUrls.AddRange(product.detail.sku.Select(a => a.thumb_url));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
List<string> imageUrlMd5s = imageUrls.Select(a => BaseClass.GetMd5(a)).ToList();
|
||||||
|
|
||||||
|
var url = BaseClass.BuildObjString("ImageCache/GetImageCache");//获取缓存
|
||||||
|
var data = JsonConvert.SerializeObject(new
|
||||||
|
{
|
||||||
|
md5s = imageUrlMd5s
|
||||||
|
});
|
||||||
|
|
||||||
|
var html = GetHtml.PostUtf8(url, data, contentType: "application/json");
|
||||||
|
if (string.IsNullOrEmpty(html))
|
||||||
|
html = GetHtml.PostUtf8(url, data);
|
||||||
|
var ret = JsonConvert.DeserializeObject<Result<List<ImageCache>>>(html);
|
||||||
|
if (ret.Code == 200)
|
||||||
|
{
|
||||||
|
foreach (var item in ret.Data)
|
||||||
|
{
|
||||||
|
item.IsCache = true;
|
||||||
|
wxImgMapDic[item.Md5] = item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return wxImgMapDic;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 保存缓存图片
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="platform"></param>
|
||||||
|
/// <param name="images"></param>
|
||||||
|
private void SaveImageCaches(PlatformType platform, IEnumerable<ImageCache> images)
|
||||||
|
{
|
||||||
|
if (EnvironmentHelper.IsProduction)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var url = BaseClass.BuildObjString("ImageCache/AddOrUpdate");
|
||||||
|
var data = "";
|
||||||
|
data = JsonHelper.SerializeObject(images.Where(a => a.IsCache == false).Select(a =>
|
||||||
|
new
|
||||||
|
{
|
||||||
|
md5 = a.Md5,
|
||||||
|
Platform = platform,
|
||||||
|
PlatformUrl = a.PlatformUrl
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
var html = GetHtml.PostUtf8(url, data, contentType: "application/json");
|
||||||
|
if (string.IsNullOrEmpty(html))
|
||||||
|
html = GetHtml.PostUtf8(url, data);
|
||||||
|
var ret = JsonConvert.DeserializeObject<Result<JToken>>(html);
|
||||||
|
List<string> failed = new List<string>();
|
||||||
|
if (ret.Code == 500)
|
||||||
|
{
|
||||||
|
if (ret.Data is JArray jArray)
|
||||||
|
{
|
||||||
|
failed = jArray.ToObject<List<string>>() ?? new List<string>();
|
||||||
|
}
|
||||||
|
else if (ret.Data is JValue jValue && jValue.Value is string str)
|
||||||
|
{
|
||||||
|
failed.Add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (ImageCache item in images)
|
||||||
|
{
|
||||||
|
item.IsCache = !failed.Contains(item.Md5, StringComparer.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class WXUpload
|
public class WXUpload
|
||||||
@@ -7868,4 +7957,13 @@ Content-Type: application/octet-stream
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsUseShanghaiReturnOrderAddress { get; set; } = false;
|
public bool IsUseShanghaiReturnOrderAddress { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class ImageCache
|
||||||
|
{
|
||||||
|
public string Md5 { get; set; }
|
||||||
|
public int Platform { get; set; }
|
||||||
|
[JsonProperty("platform_url")]
|
||||||
|
public string PlatformUrl { get; set; }
|
||||||
|
public bool IsCache { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user