gx
This commit is contained in:
1 parent
0a3e5af6a9
commit
c2dcedd238
59 files changed
+2053
-1274
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using AllBase;
|
||||
using AllBase.Extension;
|
||||
using NaiBa.Util.Extension;
|
||||
using AllBase.Helper;
|
||||
using AllBase.Model.Config;
|
||||
using AllBase.Model.DBModel;
|
||||
@@ -20,7 +21,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Work;
|
||||
|
||||
namespace Store.Product.Publish.Steps.Wx;
|
||||
@@ -34,37 +34,37 @@ public sealed class UploadDetailImagesStep : WxProductPublishStepBase
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cell != null)
|
||||
if (context.Progress != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成商品详情";
|
||||
context.Progress.Report("正在生成商品详情");
|
||||
}));
|
||||
}
|
||||
Thread.Sleep(Randomx.GetId(100, 300));
|
||||
upProdParam.product.info.detail = new productDetailParam(); // 详情图
|
||||
detailGalleries = prodInfo.detail.galleries.Where(g => g.type == 2).ToList();
|
||||
if (detailGalleries.Count == 0)
|
||||
detailGalleries.Add(new gallery_item() { type = 2, url = prodInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
|
||||
context.Parameters.ProductParameter.product.info.detail = new productDetailParam(); // 详情图
|
||||
context.Parameters.DetailGalleries = context.Parameters.ProdInfo.detail.galleries.Where(g => g.type == 2).ToList();
|
||||
if (context.Parameters.DetailGalleries.Count == 0)
|
||||
context.Parameters.DetailGalleries.Add(new gallery_item() { type = 2, url = context.Parameters.ProdInfo.detail.galleries.FirstOrDefault(g => g.type == 1)?.url });
|
||||
|
||||
foreach (var gallery_item in detailGalleries)
|
||||
foreach (var gallery_item in context.Parameters.DetailGalleries)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (dbProd.product_get_type_text == "微信店采")
|
||||
if (context.Product.ProductGetTypeText == "微信店采")
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(gallery_item.url);
|
||||
context.Parameters.ProductParameter.product.info.detail.detailImg.Add(gallery_item.url);
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取缓存盗链 详情图
|
||||
if (wxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||||
if (context.Parameters.WxImgMapDic.ContainsKey(BaseClass.GetMd5(gallery_item.url)))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(wxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||||
context.Parameters.ProductParameter.product.info.detail.detailImg.Add(context.Parameters.WxImgMapDic[BaseClass.GetMd5(gallery_item.url)]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (needAddRandomBlock || wantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||||
if (context.Parameters.NeedAddRandomBlock || context.Parameters.WantAddRandomBlock || gallery_item.url.Contains("wst.wxapp.tc.qq.com"))
|
||||
{
|
||||
// 如果想打码或者需要打码,就走差异化详情图,不走api直传
|
||||
}
|
||||
@@ -73,31 +73,31 @@ public sealed class UploadDetailImagesStep : WxProductPublishStepBase
|
||||
// 使用接口链接传详情图
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
upDate += "&token=" + context.Parameters.Token.accessToken;
|
||||
upDate += "&post_data=" + GetHtml.UrlEncodeUtf8("{\"img_url\":\"" + gallery_item.url.Replace("https://", "http://") + "\"}");
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
if (context.Progress != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在生成商品详情图 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
context.Progress.Report("正在生成商品详情图 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt());
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 20 && upDateRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
context.Parameters.Token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
context.Parameters.Token = new WxApiBLL().GetRandomWxToken();
|
||||
upDateRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref upDateRst, "img_url");
|
||||
if (upDateRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
context.Parameters.ProductParameter.product.info.detail.detailImg.Add(upImgUrl);
|
||||
context.Parameters.WxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
context.Parameters.IsChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@@ -115,7 +115,7 @@ public sealed class UploadDetailImagesStep : WxProductPublishStepBase
|
||||
try
|
||||
{
|
||||
string errMsg = "";
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, gallery_item.url, needAddRandomBlock, wantAddRandomBlock);
|
||||
var imgBase64 = GetImgBase64ForApi(out errMsg, gallery_item.url, context.Parameters.NeedAddRandomBlock, context.Parameters.WantAddRandomBlock);
|
||||
if (!string.IsNullOrEmpty(errMsg))
|
||||
{
|
||||
throw new Exception(errMsg);
|
||||
@@ -123,7 +123,7 @@ public sealed class UploadDetailImagesStep : WxProductPublishStepBase
|
||||
|
||||
var urlImg = BaseClass.BuildWXImgObjString("product/wx_api_upload_image");
|
||||
var upDate = UserLogin.GetSignaturex();
|
||||
upDate += "&token=" + token.accessToken;
|
||||
upDate += "&token=" + context.Parameters.Token.accessToken;
|
||||
//upDate += "&is_file=true";
|
||||
//if (needAddRandomBlock || wantAddRandomBlock)
|
||||
// upDate += "&random_code=true";
|
||||
@@ -132,26 +132,26 @@ public sealed class UploadDetailImagesStep : WxProductPublishStepBase
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
if (context.Progress != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传商品详情图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
context.Progress.Report("正在上传商品详情图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt());
|
||||
}));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 5 && apiUpImgFileRst.Contains("access_token expired"); i++)
|
||||
{
|
||||
token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
token = new WxApiBLL().GetRandomWxToken();
|
||||
context.Parameters.Token.mdyTime = DateTime.Now.AddDays(-100);
|
||||
context.Parameters.Token = new WxApiBLL().GetRandomWxToken();
|
||||
apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
}
|
||||
var upImgUrl = BaseRegex.GetStringJson(ref apiUpImgFileRst, "img_url");
|
||||
if (apiUpImgFileRst.Contains("\"errcode\":0") && !string.IsNullOrEmpty(upImgUrl))
|
||||
{
|
||||
upProdParam.product.info.detail.detailImg.Add(upImgUrl);
|
||||
wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
isChangeImgDic = true;
|
||||
context.Parameters.ProductParameter.product.info.detail.detailImg.Add(upImgUrl);
|
||||
context.Parameters.WxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = upImgUrl;
|
||||
context.Parameters.IsChangeImgDic = true;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
@@ -166,16 +166,17 @@ public sealed class UploadDetailImagesStep : WxProductPublishStepBase
|
||||
|
||||
// 模拟上传图片
|
||||
bool randomDrawBlock = false;
|
||||
if (needAddRandomBlock || wantAddRandomBlock)
|
||||
if (context.Parameters.NeedAddRandomBlock || context.Parameters.WantAddRandomBlock)
|
||||
randomDrawBlock = true;
|
||||
var locationStr = UploadImg(shop, gallery_item.url, cell, randomDrawBlock);
|
||||
var locationStr = UploadImg(context.Parameters.Shop, gallery_item.url, randomDrawBlock);
|
||||
if (!locationStr.Contains("\"success\":true"))
|
||||
throw new Exception(locationStr);
|
||||
var location = BaseRegex.GetStringJson(ref locationStr, "Location");
|
||||
upProdParam.product.info.detail.detailImg.Add(location);
|
||||
context.Parameters.ProductParameter.product.info.detail.detailImg.Add(location);
|
||||
//wxImgMapDic[BaseClass.GetMd5(gallery_item.url)] = location;
|
||||
//isChangeImgDic = true;
|
||||
Thread.Sleep(Randomx.GetId(10, 50));
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user