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,30 +34,30 @@ public sealed class GenerateAiProductImageStep : WxProductPublishStepBase
|
||||
|
||||
protected override Task ExecuteProvider(WXPublishContext context, CancellationToken cancellationToken)
|
||||
{
|
||||
if (chkAiImage.Checked)
|
||||
if (context.Parameters.IsAiImage)
|
||||
{
|
||||
int imgCount = 1;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (cell != null)
|
||||
cell.Value = "正在Ai生图";
|
||||
imgCount = txtAiImgCount.Text.Trim().ParseToInt();
|
||||
if (context.Progress != null)
|
||||
context.Progress.Report("正在Ai生图");
|
||||
imgCount = context.Parameters.AiImageCount;
|
||||
if (imgCount == 0)
|
||||
imgCount = 1;
|
||||
}));
|
||||
|
||||
List<Task> tList = new List<Task>();
|
||||
List<string> errStrLst = new List<string>();
|
||||
for (int n = 0; n < upProdParam.product.info.headImg.Count && n < imgCount; n++)
|
||||
for (int n = 0; n < context.Parameters.ProductParameter.product.info.headImg.Count && n < imgCount; n++)
|
||||
{
|
||||
while (tList.Count >= 10)
|
||||
{
|
||||
Thread.Sleep(500);
|
||||
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
|
||||
}
|
||||
var tt = Task.Run(() =>
|
||||
var tt = Task.Run(async () =>
|
||||
{
|
||||
var imgUrl = GetAiImg(upProdParam.product.info.headImg[n], upProdParam.product.info.shortTitle);
|
||||
var imgUrl = GetAiImg(context.Parameters.ProductParameter.product.info.headImg[n], context.Parameters.ProductParameter.product.info.shortTitle);
|
||||
if (imgUrl.StartsWith("生成Ai图片错误"))
|
||||
{
|
||||
errStrLst.Add(imgUrl);
|
||||
@@ -82,7 +82,7 @@ public sealed class GenerateAiProductImageStep : 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";
|
||||
@@ -91,24 +91,24 @@ public sealed class GenerateAiProductImageStep : WxProductPublishStepBase
|
||||
|
||||
var sTime = DateTime.Now;
|
||||
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
|
||||
if (cell != null)
|
||||
if (context.Progress != null)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
cell.Value = "正在上传Ai主图文件 " + (DateTime.Now - sTime).TotalMilliseconds.ParseToInt();
|
||||
context.Progress.Report("正在上传Ai主图文件 " + (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.headImg[n] = upImgUrl;
|
||||
context.Parameters.ProductParameter.product.info.headImg[n] = upImgUrl;
|
||||
//if (n == 0)
|
||||
// upProdParam.product.info.detail.detailImg.Insert(0, upImgUrl);
|
||||
}
|
||||
@@ -141,5 +141,6 @@ public sealed class GenerateAiProductImageStep : WxProductPublishStepBase
|
||||
throw new Exception(string.Join(",", errStrLst));
|
||||
}
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user