1.随机地址功能优化

2.商品随机主图遍框实现裂变
This commit is contained in:
wule_5900x committed 2026-05-31 01:01:11 +08:00
1 parent 898a739b65
commit 3f6a91c164
10 files changed
+3523 -214

No files matched your search

@@ -36,25 +36,34 @@ namespace TemuKJD.WXForms.ProductForms
{
public partial class WXDBProdUploadForm : BaseForm
{
public static WXDBProdUploadForm Instance { get; set; } = null;
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
public bool IsWxNotUseSoftwareDefaultAddressOnce { get; set; } = false;
public bool IsLoadComplate { get; set; } = false;
public ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new ConcurrentList<TemuDBProductSelect>();
ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
ConcurrentList<AddPriceRule> lstAddPriceRule = new ConcurrentList<AddPriceRule>();
bool isInit = false;
CheckBox chkSelectAll = null;
ConcurrentList<WXShopTokenInfo> lstWXShopTokenInfo = new ConcurrentList<WXShopTokenInfo>();
ConcurrentList<TemuDBProductSelect> lstTemuDBProductSelect = new ConcurrentList<TemuDBProductSelect>();
ConcurrentList<AddPriceRule> lstAddPriceRule = new ConcurrentList<AddPriceRule>();
AddPriceRule defaultAddPriceRule = null;
WXUploadRule wxUploadRule = null;
public Dictionary<string, bool> dicCheckedShopId = new Dictionary<string, bool>();
public string pdd_product_cates = "";
public List<string> forceFilteKeyWords = new List<string>()
{
"顶级", "之王", "二手", "亏本", "冲量", "白菜价", "跳楼价", "xxx", "xx", "最大", "最小", "低价", "降价", "成本", "赔钱", "甩卖",
"真丝", "蚕丝", "香云纱", "羊绒", "羊毛", "羊羔绒", "羊羔毛", "羽绒", "皮草"
};
string DefaultAdultBrandId = "";
// 微信带货助手cookie
List<Cookie> lstWxSaleAssistantCookie = new List<Cookie>();
@@ -65,6 +74,8 @@ namespace TemuKJD.WXForms.ProductForms
private void UserSelectDbProductForm_Load(object sender, EventArgs e)
{
Instance = this;
if (!BaseClass.UserAuthority.Contains("佣金上货"))
this.ucTabControlMetro1.TabPages.Remove(佣金上货);
else
@@ -131,6 +142,15 @@ namespace TemuKJD.WXForms.ProductForms
{
defaultAddPriceRule = new AddPriceRule() { AddPriceTimes = 1.3m, AddMorePrice = 1, SinglePriceAdd = 1 };
}
//this.txtFissionTitle.Text = NaiBa.Util.Helper.ConfigHelper.LoadConfig<string>("wx_prod_fission_title").ParseToString();
try
{
if (File.Exists("data\\config\\wx_prod_fission_title"))
this.txtFissionTitle.Text = File.ReadAllText("data\\config\\wx_prod_fission_title");
}
catch { }
txtAddTimes.TextChanged -= txtAddPrice_TextChanged;
txtAddMorePrice.TextChanged -= txtAddPrice_TextChanged;
txtSinglePriceAdd.TextChanged -= txtAddPrice_TextChanged;
@@ -155,6 +175,7 @@ namespace TemuKJD.WXForms.ProductForms
chkAddMorePriceFirst.CheckedChanged += chkAddMorePriceFirst_CheckedChanged;
chkStepAddPrice.CheckedChanged += chkStepAddPrice_CheckedChanged;
wxUploadRule = NaiBa.Util.Helper.ConfigHelper.LoadConfig<WXUploadRule>("wx_upload_rule");
if (wxUploadRule == null)
wxUploadRule = new WXUploadRule();
@@ -335,6 +356,10 @@ namespace TemuKJD.WXForms.ProductForms
cmbSourceType.Items.Insert(1, "1688商品");
cmbSourceType.Items.Insert(1, "多多商品");
}
if (!BaseClass.UserAuthority.Contains("商品裂变"))
{
ucTabControlMetro1.TabPages.Remove(商品裂变);
}
//#endif
if (BaseClass.SaLevel == 1)
{
@@ -1935,8 +1960,33 @@ namespace TemuKJD.WXForms.ProductForms
if (token == null || token.isExpire || string.IsNullOrEmpty(token.accessToken))
token = new WxApiBLL().GetRandomWxToken();
#region 设置标题
#region 设置标题
string prodTitle = dbProd.product_name.IsNullOrEmpty() ? prodInfo.detail.goods_name : dbProd.product_name;
// 裂变标题
if (BaseClass.UserAuthority.Contains("商品裂变") && chkFissionGoodsName.Checked)
{
bool isFinish = false;
Invoke(new Action(() => {
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
if (titles.Count == 0)
{
cancellationTokenSource.Cancel();
if (cell != null)
cell.Value = "裂变标题数量不足,将暂停上传";
BaseMsgForm.ShowError("裂变标题数量不足,将暂停上传");
isFinish = true;
}
prodTitle = titles[0];
titles.RemoveAt(0);
txtFissionTitle.Text = string.Join("\r\n", titles);
}));
if (isFinish)
{
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"裂变标题数量不足,将暂停上传\"}";
}
}
upProdInitParam.product.info.title = prodTitle;
upProdParam.product.info.title = prodTitle;
upProdParam.sessionInfo.sessionId = upProdInitParam.product.sessionId;
@@ -2422,7 +2472,7 @@ namespace TemuKJD.WXForms.ProductForms
#endregion
#region ai短标题 // ai获取短标题
if (wxUploadRule.IsAiShortTitle)
if (wxUploadRule.IsAiShortTitle || chkAiImage.Checked)
{
if (cell != null)
{
@@ -4129,6 +4179,249 @@ namespace TemuKJD.WXForms.ProductForms
}
#endregion
#region AI生成图片,用于商品裂变
if (chkAiImage.Checked)
{
int imgCount = 1;
Invoke(new Action(() =>
{
if (cell != null)
cell.Value = "正在Ai生图";
imgCount = txtAiImgCount.Text.Trim().ParseToInt();
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++)
{
while (tList.Count >= 10)
{
Thread.Sleep(500);
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
}
var tt = Task.Run(() =>
{
var imgUrl = GetAiImg(upProdParam.product.info.headImg[n], upProdParam.product.info.shortTitle);
if (imgUrl.StartsWith("生成Ai图片错误"))
{
errStrLst.Add(imgUrl);
return;
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"" + imgUrl + "\"}";
}
// api上传图片文件 Ai主图
if (1 == 1)
{
try
{
string errMsg = "";
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800);
if (!string.IsNullOrEmpty(errMsg))
{
errStrLst.Add(errMsg);
return;
//return errMsg;
}
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
var upDate = UserLogin.GetSignaturex();
upDate += "&token=" + token.accessToken;
//upDate += "&is_file=true";
//if (needAddRandomBlock || wantAddRandomBlock)
// upDate += "&random_code=true";
upDate += "&img_url=" + imgUrl;
upDate += "&img_base64=" + imgBase64;
var sTime = DateTime.Now;
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
if (cell != null)
{
Invoke(new Action(() =>
{
cell.Value = "正在上传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();
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;
//if (n == 0)
// upProdParam.product.info.detail.detailImg.Insert(0, upImgUrl);
}
else
{
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
errStrLst.Add("上传Ai图失败 " + upImgErrMsg);
return;
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"上传Ai图失败 " + upImgErrMsg + "\"}";
}
}
catch (Exception ex)
{
errStrLst.Add("上传Ai图失败 " + ex.Message);
return;
//return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"上传Ai图失败 " + ex.Message + "\"}";
}
}
});
tList.Add(tt);
}
while (tList.Count > 0)
{
Thread.Sleep(500);
tList.RemoveAll(t => t.IsCanceled || t.IsFaulted || t.IsCompleted);
}
// 错误超过一定数量直接报错返回
if (errStrLst.Count > 0 && errStrLst.Count >= imgCount / 3)
{
return string.Join(",", errStrLst);
}
}
#endregion
#region 添加图片随机外框,用于商品裂变
if (BaseClass.UserAuthority.Contains("商品裂变") && chkRandomImgBorder.Checked)
{
int mainCount = 9;
int detailCount = 1;
Invoke(new Action(() =>
{
mainCount = txtMainBorderImgCount.Text.Trim().ParseToInt();
detailCount = txtDetailBorderImgCount.Text.Trim().ParseToInt();
}));
// api上传图片文件 边框主图
if (1 == 1)
{
if (chkRandomMainImgOrder.Checked)
upProdParam.product.info.headImg = upProdParam.product.info.headImg.OrderBy(x => Guid.NewGuid()).Take(100).ToList();
for (int n = 0; n < upProdParam.product.info.headImg.Count && n < mainCount; n++)
{
var imgUrl = upProdParam.product.info.headImg[n];
try
{
string errMsg = "";
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800, true);
if (!string.IsNullOrEmpty(errMsg))
{
return errMsg;
}
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
var upDate = UserLogin.GetSignaturex();
upDate += "&token=" + token.accessToken;
//upDate += "&is_file=true";
//if (needAddRandomBlock || wantAddRandomBlock)
// upDate += "&random_code=true";
upDate += "&img_url=" + imgUrl;
upDate += "&img_base64=" + imgBase64;
var sTime = DateTime.Now;
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
if (cell != null)
{
Invoke(new Action(() =>
{
cell.Value = "正在优化主图文件 " + (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();
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;
}
else
{
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化主图失败 " + upImgErrMsg + "\"}";
}
}
catch (Exception ex)
{
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化主图失败 " + ex.Message + "\"}";
}
}
}
// api上传图片文件 边框详情图
if (1 == 1)
{
if (chkRandomDetailImgOrder.Checked)
upProdParam.product.info.detail.detailImg = upProdParam.product.info.detail.detailImg.OrderBy(x => Guid.NewGuid()).Take(100).ToList();
for (int n = 0; n < upProdParam.product.info.detail.detailImg.Count && n < detailCount; n++)
{
var imgUrl = upProdParam.product.info.detail.detailImg[n];
try
{
string errMsg = "";
//var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, needAddRandomBlock, wantAddRandomBlock, 800, 800);
var imgBase64 = GetImgBase64ForApi(out errMsg, imgUrl, false, false, 800, 800, true);
if (!string.IsNullOrEmpty(errMsg))
{
return errMsg;
}
var urlImg = BaseClass.BuildPDDObjString("product/wx_api_upload_image");
var upDate = UserLogin.GetSignaturex();
upDate += "&token=" + token.accessToken;
//upDate += "&is_file=true";
//if (needAddRandomBlock || wantAddRandomBlock)
// upDate += "&random_code=true";
upDate += "&img_url=" + imgUrl;
upDate += "&img_base64=" + imgBase64;
var sTime = DateTime.Now;
var apiUpImgFileRst = GetHtml.PostUtf8(urlImg, upDate);
if (cell != null)
{
Invoke(new Action(() =>
{
cell.Value = "正在优化详情图文件 " + (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();
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[n] = upImgUrl;
}
else
{
string upImgErrMsg = BaseRegex.GetStringJsonByRegs(ref apiUpImgFileRst, apiUpImgFileRst, "msg", "errMsg", "errorMsg", "err_msg", "error_msg");
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化详情图失败 " + upImgErrMsg + "\"}";
}
}
catch (Exception ex)
{
return "{\"success\":false,\"draftId\":0,\"status\":\"未上传\",\"errMsg\":\"优化详情图失败 " + ex.Message + "\"}";
}
}
}
}
#endregion
// 直接使用微信回采情趣商品品牌
if (BaseClass.UserAuthority.ParseToString().Contains("微信回采") && chkUseWXComplateProd.Checked &&
upProdParam.product.info.category.FirstOrDefault()?.name == "成人用品" && upProdParam.product.info.category[1].name != "情趣内衣")
@@ -4426,14 +4719,14 @@ namespace TemuKJD.WXForms.ProductForms
}
public static string GetImgBase64ForApi(out string errorMsg, string img_url, bool needAddRandomBlock, bool wantAddRandomBlock, int imgWidth = 0, int imgHeight = 0)
public static string GetImgBase64ForApi(out string errorMsg, string img_url, bool needAddRandomBlock, bool wantAddRandomBlock, int imgWidth = 0, int imgHeight = 0, bool wantAddRandomBorder = false)
{
errorMsg = "";
string imgBase64 = "";
//-------------------------------------------------------------------------------------------------------------------------------------
//生成主图base64字符串
string getImgError;
if (!img_url.Contains("wst.wxapp.tc.qq.com"))
if (!img_url.Contains("wst.wxapp.tc.qq.com") && !img_url.Contains("mmecimage.cn"))
img_url = img_url.Replace("https://", "http://");
var image = GetHtml.GetUrlImg(img_url, out getImgError);
if (image == null)
@@ -4459,6 +4752,14 @@ namespace TemuKJD.WXForms.ProductForms
g.FillRectangle(new SolidBrush(Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256))),
new Rectangle(Randomx.GetId(imageBg.Width - 30), Randomx.GetId(imageBg.Height - 30), 30, 30));
}
if (wantAddRandomBorder)
{
var borderColor = Color.FromArgb(Randomx.GetId(256), Randomx.GetId(256), Randomx.GetId(256));
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, 0, imageBg.Width, 20));
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, imageBg.Height - 20, imageBg.Width, 20));
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(0, 0, 20, imageBg.Height));
g.FillRectangle(new SolidBrush(borderColor), new Rectangle(imageBg.Width - 20, 0, 20, imageBg.Height));
}
}
using (MemoryStream memoryStream = new MemoryStream())
{
@@ -4504,7 +4805,6 @@ namespace TemuKJD.WXForms.ProductForms
}
public string UploadImg(ShopLoginInfo shop, Bitmap img, DataGridViewCell cell = null)
{
var upImgAuthRst = WXUpload.getUploadTempImgAuth(shop);
@@ -4586,6 +4886,24 @@ namespace TemuKJD.WXForms.ProductForms
}));
});
if (BaseClass.UserAuthority.Contains("商品裂变") && chkFissionGoodsName.Checked)
{
Invoke(new Action(() =>
{
var titles = txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList();
txtAddCount.Text = "" + titles.Count;
if (titles.Count == 0)
{
BaseMsgForm.ShowError("裂变标题数量不足");
return;
}
this.lstTemuDBProductSelect.Clear();
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
lblWaitToUp.Text = "待上传 " + lstTemuDBProductSelect.Count + " 件";
}));
}
pbSelectProd.Visible = true;
int addCount = txtAddCount.Text.Trim().ParseToInt();
if (getProdTokenSource != null)
@@ -4866,6 +5184,36 @@ namespace TemuKJD.WXForms.ProductForms
}
}
public string GetAiImg(string imgUrl, string imgWord)
{
string image_url = imgUrl;
string word = imgWord;
string secret = "sadhjufhe15c4fbvFBvcvds+5sdfds@#%$xsc";
string time = BaseClass.DateTimeToTimestampSeconds(DateTime.Now).ToString();
string code = BaseClass.GetMd5(secret + time).ToLower();
try
{
//string url = "http://ai-bs.jiaotian.vip:" + Randomx.GetId(20010, 20021) + "/index.php?obj=public/image";
//http://svn.jiaotian.vip:20010-20020/index.php?obj=public/image
string url = "http://svn.jiaotian.vip:" + Randomx.GetId(20010, 20021) + "/index.php?obj=public/image";
string data = "time=" + time + "&code=" + code + "&image_url=" + image_url + "&word=" + word;
string html = GetHtml.PostUtf8(url, data, "", 120);
if (!string.IsNullOrEmpty(html) && !html.Contains("error"))
{
return html;
}
else
{
return "生成Ai图片错误 " + html;
}
}
catch (Exception ex)
{
return "生成Ai图片错误 " + ex.Message;
}
}
private void btnClearUpload_Click(object sender, EventArgs e)
{
if (BaseMsgForm.ShowConfirm("确定清空待上传商品吗?清空后不可恢复!").DialogResult == DialogResult.Cancel)
@@ -5532,7 +5880,7 @@ namespace TemuKJD.WXForms.ProductForms
WXUserProdListForm.Instance.BringToFront();
}
private void dbProdList_SaveComplete(object obj)
public void dbProdList_SaveComplete(object obj)
{
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_db_prod_upload_list", this.lstTemuDBProductSelect);
Invoke(new Action(() =>
@@ -5565,6 +5913,13 @@ namespace TemuKJD.WXForms.ProductForms
if (lstWxSaleAssistantCookie == null)
lstWxSaleAssistantCookie = new List<Cookie>();
}
private void txtFissionTitle_TextChanged(object sender, EventArgs e)
{
if (this.IsLoadComplate)
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_prod_fission_title", txtFissionTitle.Text);
lblFissionTitleCount.Text = "标题数:" + txtFissionTitle.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).ToList().Count();
}
}
public class WXUpload