1微信用户采集店铺商品功能 2查询达人带货商品并联系达人功能

This commit is contained in:
wule committed 2026-06-09 18:11:32 +08:00
1 parent e1ee91dd03
commit 2759ff0f6d
33 files changed
+2464 -626

No files matched your search

@@ -52,6 +52,7 @@ namespace TemuKJD.WXForms.ProductForms
int PageEnd = 20;
string currentGetTalentParam = "";
List<WXFinderTalentInfo> lstWXFinderTalentInfo = new List<WXFinderTalentInfo>();
List<WXLiveObjectInfo> lstWXLiveObjectInfo = new List<WXLiveObjectInfo>();
public WXFinderSquareForm()
{
@@ -94,6 +95,10 @@ namespace TemuKJD.WXForms.ProductForms
this.dgvTalent.AddSelectorColumn("colCheck");
dgvTalent.AddImgColumn("colImg", "colImgUrl");
this.dgvDaRenProd.AddSelectorColumn("colDgvProdCheck");
dgvDaRenProd.AddImgColumn("colLiveObjectImg", "colLiveObjectImgUrl");
dgvDaRenProd.AddImgColumn("colDgvProdImg", "colDgvProdImgUrl");
InitCef();
Task.Run(() =>
{
@@ -154,6 +159,11 @@ namespace TemuKJD.WXForms.ProductForms
{
currentGetTalentParam = postData;
}
if (/*responseData.Contains("mpAppid") ||*/ responseData.Contains("wxb32c03106e812d73"))
{
}
}
private void MainLifeHandler_OnPop(object sender, PopData e)
{
@@ -1120,6 +1130,317 @@ namespace TemuKJD.WXForms.ProductForms
wxProdIdWithListingTimeLst = wxProdIdWithListingTimeLst.OrderByDescending(p => p.soldNum).ThenByDescending(p => p.listingTime).ToList().Take(30).ToList();
return string.Join(",", wxProdIdWithListingTimeLst.Select(p => p.spuId));
}
private void btnSearch_Click(object sender, EventArgs e)
{
var selectRows = dgvTalent.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
if (selectRows.Count == 0)
{
BaseMsgForm.ShowError("请在操作列表页选择要查询的达人");
return;
}
pictureBox1.Visible = true;
string prodIds = txtProductIds.Text.Trim();
this.btnSearchDaRenProd.Enabled = false;
Task.Run(() => {
Thread.Sleep(5000);
Invoke(new Action(() => { this.btnSearchDaRenProd.Enabled = true; }));
});
dgvDaRenProd.Rows.Clear();
lstWXLiveObjectInfo.Clear();
if (cancellationTokenSource != null)
cancellationTokenSource.Cancel();
cancellationTokenSource = new CancellationTokenSource();
Task.Run(() =>
{
{
int num = 0;
foreach (var row in selectRows)
{
num++;
Invoke(new Action(() =>
{
this.statusBar.lblTaskStatus.Text = "达人带货商品查询 第 " + num + " 位,共 " + selectRows.Count + " 位达人";
row.Cells["colOpResult"].Value = "";
}));
if (this.cancellationTokenSource.IsCancellationRequested)
break;
var shopId = row.Cells["colSupplierId"].Value.ParseToString();
var shop = GlobalConfig.ValidShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
if (chkReUse.Visible && chkReUse.Checked)
shop = currentShop;
var talentAppid = row.Cells["colTalentAppid"].Value.ParseToString();
var talent = this.lstWXFinderTalentInfo.FirstOrDefault(t => t.talentAppid == talentAppid);
if (shop != null && talent != null && talent.accountList != null)
{
var finderUser = talent.accountList.FirstOrDefault(a => !a.finderUsername.IsNullOrEmpty() && !a.mpAppid.IsNullOrEmpty());
finderUser = talent.accountList.FirstOrDefault(a => !a.finderUsername.IsNullOrEmpty());
var finderUsername = finderUser?.finderUsername;
var mpAppid = finderUser?.mpAppid;
var endMs = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date) - 1;
var startMs = BaseClass.DateTimeToTimestampMilliseconds(DateTime.Now.Date.AddDays(-7));
int page = 0;
int pageSize = 10;
while (true)
{
page++;
var getLiveObjectRst = WXFinderSquareBLL.GetDaRenLiveFeedList(shop, finderUsername, mpAppid, talent.talentAppid, startMs, endMs, 1, page, pageSize);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getLiveObjectRst.ParseToString().Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJsonByRegs(ref getLiveObjectRst, getLiveObjectRst, "errmsg");
if (error.ParseToString().Contains("biz magic invalid"))
{
shop.LoginStatus = "未登录";
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(r
=> r.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
error = "店铺掉线";
}
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "达人带货商品查询失败 " + error;
}));
break;
}
var wxLiveObjectInfoResult = JsonHelper.DeserializeJsonToObject<WXLiveObjectInfoResult>(getLiveObjectRst);
var liveList = wxLiveObjectInfoResult.list;
this.lstWXLiveObjectInfo.AddRange(liveList);
foreach (var live in liveList)
{
foreach (var prod in live.productList.list)
{
Invoke(new Action(() =>
{
if (prod.spuMonthSales.ParseToInt() >= txtSaleCount.Text.Trim().ParseToInt())
{
var startTimeStr = BaseClass.StampToDateTime(live.liveObjectStartTime.ParseToInt()).ToString("yy-MM-dd HH:mm");
var duration = new TimeSpan(live.liveObjectDuringTimeSecond.ParseToLong() * 10000000);
var durationStr = duration.Hours + "时" + (Math.Ceiling(duration.TotalMinutes).ParseToInt() - duration.Hours * 60) + "分";
var rowIndex = dgvDaRenProd.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
talent.talentAppid,
finderUser.finderUsername,
finderUser.nickname, // 达人昵称
live.objectId, // 达人活动ID
live.liveObjectImg,
DataGridViewExtension.defaultBitmap, // 直播标题图
live.liveObjectDescription, // 达人活动直播标题
startTimeStr + "\r\n" + durationStr + " " + "观看人数" + live.livediagnosisFinderuinxfeedidWatchUv.ParseToInt(),
prod.spuImgUrl,
DataGridViewExtension.defaultBitmap,
prod.spuAppid,
prod.spuShopNickname,
prod.spuId,
prod.spuName,
prod.spuPrice.ParseToInt() * 0.01m,
prod.spuMonthSales.ParseToInt(),
"联系达人"
);
dgvDaRenProd.Rows[rowIndex].Height = 60;
}
}));
}
if (live.productList.total > 10)
{
int prodPage = 1;
int prodPageSize = 10;
var prodTotalPage = Math.Ceiling(live.productList.total.ParseToInt() * 1m / prodPageSize).ParseToInt();
while (prodPage < prodTotalPage)
{
if (this.cancellationTokenSource.IsCancellationRequested)
break;
prodPage++;
var getProdRst = WXFinderSquareBLL.GetDaRenLiveProductList(shop, finderUsername, mpAppid, talentAppid, live.objectId, prodPage, prodPageSize);
Thread.Sleep(Randomx.GetId(300, 600));
if (!getProdRst.ParseToString().Contains("\"code\":0"))
{
var error = BaseRegex.GetStringJsonByRegs(ref getProdRst, getProdRst, "errmsg");
if (error.ParseToString().Contains("biz magic invalid"))
{
shop.LoginStatus = "未登录";
var selectIds = dgvShop.Rows.Cast<DataGridViewRow>().Where(r
=> r.Cells["colSelect"]?.Value.ParseToBool() == true).Select(r => r.Cells["colShopId"]?.Value.ToString()).ToList();
Invoke(new Action(() => { BindShop(shop, selectIds, "店铺掉线"); }));
error = "店铺掉线";
}
Invoke(new Action(() =>
{
row.Cells["colOpResult"].Value = "达人带货商品查询失败 " + error;
}));
break;
}
var darenProdLst = JsonHelper.DeserializeJsonToList<WXLiveProduct>(JsonHelper.JObjectParse(getProdRst)["list"].ParseToString());
live.productList.list.AddRange(darenProdLst);
foreach (var prod in darenProdLst)
{
Invoke(new Action(() =>
{
if (prod.spuMonthSales.ParseToInt() >= txtSaleCount.Text.Trim().ParseToInt())
{
var startTimeStr = BaseClass.StampToDateTime(live.liveObjectStartTime.ParseToInt()).ToString("yy-MM-dd HH:mm");
var duration = new TimeSpan(live.liveObjectDuringTimeSecond.ParseToLong() * 10000000);
var durationStr = duration.Hours + "时" + (Math.Ceiling(duration.TotalMinutes).ParseToInt() - duration.Hours * 60) + "分";
var rowIndex = dgvDaRenProd.Rows.Add(
false,
shop.ShopId,
shop.ShopAccount,
"登录",
"进店",
talent.talentAppid,
finderUser.finderUsername,
finderUser.nickname, // 达人昵称
live.objectId, // 达人活动ID
live.liveObjectImg,
DataGridViewExtension.defaultBitmap, // 直播标题图
live.liveObjectDescription, // 达人活动直播标题
startTimeStr + "\r\n" + durationStr + " " + "观看人数" + live.livediagnosisFinderuinxfeedidWatchUv.ParseToInt(),
prod.spuImgUrl,
DataGridViewExtension.defaultBitmap,
prod.spuAppid,
prod.spuShopNickname,
prod.spuId,
prod.spuName,
prod.spuPrice.ParseToInt() * 0.01m,
prod.spuMonthSales.ParseToInt(),
"联系达人"
);
dgvDaRenProd.Rows[rowIndex].Height = 60;
}
}));
}
}
}
}
var total = wxLiveObjectInfoResult.total.ParseToInt();
var totalPage = Math.Ceiling(total * 1m / pageSize).ParseToInt();
if (page >= totalPage)
break;
}
}
}
}
Invoke(new Action(() =>
{
pictureBox1.Visible = false;
this.statusBar.lblTaskStatus.Text += "达人带货商品查询操作结束";
BaseMsgForm.ShowInfo("达人带货商品查询操作结束");
}));
}, cancellationTokenSource.Token);
}
private void btnStopSearchTalentProd_Click(object sender, EventArgs e)
{
if (this.cancellationTokenSource != null)
this.cancellationTokenSource.Cancel();
}
private void dgvDaRenProd_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 0 || e.RowIndex < 0)
return;
string headerText = dgvDaRenProd.Columns[e.ColumnIndex].HeaderText;
var shopId = dgvDaRenProd.Rows[e.RowIndex].Cells["colDgvProdShopId"].Value.ParseToString();
var shop = GlobalConfig.ValidShopLoginList.FirstOrDefault(s => s.ShopId == shopId);
var talentAppid = dgvDaRenProd.Rows[e.RowIndex].Cells["colDgvProdTalentAppid"].Value.ParseToString();
var talent = this.lstWXFinderTalentInfo.FirstOrDefault(t => t.talentAppid == talentAppid);
switch (headerText)
{
case "删除":
break;
case "登录":
{
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
RefreshShopLogin();
}
break;
case "进店":
{
WXShopLoginForm shopLoginForm = new WXShopLoginForm(shop);
WXShopListForm.Instance.CheckShopLogin(new ShopLoginInfo[] { shop }, false);
if (shop.LoginStatus == "登录成功")
{
shopLoginForm.openType = EnumOpenType.manage;
shopLoginForm.WindowState = FormWindowState.Maximized;
shopLoginForm.InitUrl = "https://store.weixin.qq.com/shop/home";
shopLoginForm.Show();
}
else
{
shopLoginForm.openType = EnumOpenType.login;
shopLoginForm.ShowDialog();
RefreshShopLogin();
}
}
break;
case "商品图片":
{
ShowImgForm imgFrom = new ShowImgForm(dgvDaRenProd.Rows[e.RowIndex].Cells["colDgvProdImgUrl"].Value.ParseToString());
imgFrom.ShowDialog();
break;
}
case "直播题图":
{
ShowImgForm imgFrom = new ShowImgForm(dgvDaRenProd.Rows[e.RowIndex].Cells["colLiveObjectImgUrl"].Value.ParseToString());
imgFrom.ShowDialog();
break;
}
case "联系达人":
{
var finderUser = talent.accountList?.FirstOrDefault(a => !a.finderUsername.IsNullOrEmpty());
if (finderUser != null)
{
var createChatRst = WXFinderSquareBLL.userCreateChatRoom(shop, finderUser.finderUsername, finderUser.mpAppid, talentAppid);
//ShowImgForm imgFrom = new ShowImgForm(dgvDaRenProd.Rows[e.RowIndex].Cells["colLiveObjectImgUrl"].Value.ParseToString());
//imgFrom.ShowDialog();
var room_id = BaseRegex.GetStringJson(ref createChatRst, "room_id");
if (string.IsNullOrEmpty(room_id))
{
BaseMsgForm.ShowError("联系窗口打开失败,请重试");
}
else
{
WXShopLoginForm loginForm = new WXShopLoginForm(shop);
loginForm.openType = EnumOpenType.manage;
loginForm.InitUrl = "https://store.weixin.qq.com/shop/kf/collab/im?mode=business&roomId=" + room_id;
loginForm.Show();
}
}
break;
}
case "":
dgvDaRenProd.Rows[e.RowIndex].Cells["colDgvProdCheck"].Value = !(bool)dgvDaRenProd.Rows[e.RowIndex].Cells["colDgvProdCheck"].Value;
break;
default:
break;
}
}
}
public class WXFinderSquareBLL
@@ -1183,6 +1504,65 @@ namespace TemuKJD.WXForms.ProductForms
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
/// <summary>
///
/// </summary>
/// <param name="shop"></param>
/// <param name="finderUsername"></param>
/// <param name="mpAppid"></param>
/// <param name="talentAppid"></param>
/// <param name="liveOrFeed">直播或短视频带货 1直播 2短视频</param>
/// <param name="page"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
public static string GetDaRenLiveFeedList(ShopLoginInfo shop, string finderUsername, string mpAppid, string talentAppid, long startMs, long endMs, int liveOrFeed = 1, int page = 1, int pageSize = 10)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/finderSquare/cgi/GetSameIndustryDetailLiveFeedList?token=&lang=zh_CN";
//"https://store.weixin.qq.com/shop/findersquare/finder-detail?from=5&fromTab=all&finderUsername=v2_060000231003b20faec8c7e58110c3d5ca01ee32b077ca155bf8a7fb3c2469d6ba215af008d9@finder&mpAppid=wx0e6b9a6557b6c7a9&talentAppid=wx34b8353cf2e12005";
string referer = "https://store.weixin.qq.com/shop/findersquare/finder-detail?from=5&fromTab=all&finderUsername=" + finderUsername;
if (!mpAppid.IsNullOrEmpty())
referer += "&mpAppid=" + mpAppid;
referer += "&talentAppid=" + talentAppid;
//{"appid":"wx34b8353cf2e12005","liveOrFeed":1,"page":{"limit":10,"offset":0},"startMs":1778342400000,"endMs":1780934399999,"sortControl":null}
//{"appid":"wx34b8353cf2e12005","liveOrFeed":1,"page":{"limit":10,"offset":0},"startMs":1778342400000,"endMs":1780934399999,"sortControl":[{"sortColName":"livediagnosis_finderuinxfeedid_watch_uv","sortRule":1}]} //sortRule 1 降序
string body = @"{""appid"":""" + talentAppid + @""",""liveOrFeed"":" + liveOrFeed + @",""page"":{""limit"":" + pageSize + @",""offset"":" + (page - 1) * 10 +
@"},""startMs"":" + startMs + @",""endMs"":" + endMs + @",""sortControl"":null}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string GetDaRenLiveProductList(ShopLoginInfo shop, string finderUsername, string mpAppid, string talentAppid, string objectId, int page = 1, int pageSize = 10)
{
string url = "https://store.weixin.qq.com/shop-faas/mmchannelstradeleague/finderSquare/cgi/getLiveProductList?token=&lang=zh_CN";
//"https://store.weixin.qq.com/shop/findersquare/finder-detail?from=5&fromTab=all&finderUsername=v2_060000231003b20faec8c7e58110c3d5ca01ee32b077ca155bf8a7fb3c2469d6ba215af008d9@finder&mpAppid=wx0e6b9a6557b6c7a9&talentAppid=wx34b8353cf2e12005";
string referer = "https://store.weixin.qq.com/shop/findersquare/finder-detail?from=5&fromTab=all&finderUsername=" + finderUsername;
if (!mpAppid.IsNullOrEmpty())
referer += "&mpAppid=" + mpAppid;
referer += "&talentAppid=" + talentAppid;
string body = @"{""appid"":""" + talentAppid + @""",""objectId"":""" + objectId + @""",""limit"":" + pageSize + @",""offset"":" + (page - 1) * 10 + @"}";
var result = WXHttpResponseBLL.WeiXinPostResponse(shop, url, body, referer);
return result;
}
public static string userCreateChatRoom(ShopLoginInfo shop, string finderUsername, string mpAppid, string talentAppid)
{
string url = "https://store.weixin.qq.com/shop/commkf/user_room?action=user_create_room&token=&lang=zh_CN";
//"https://store.weixin.qq.com/shop/findersquare/finder-detail?from=5&fromTab=all&finderUsername=v2_060000231003b20faec8c7e58110c3d5ca01ee32b077ca155bf8a7fb3c2469d6ba215af008d9@finder&mpAppid=wx0e6b9a6557b6c7a9&talentAppid=wx34b8353cf2e12005";
string referer = "https://store.weixin.qq.com/shop/findersquare/finder-detail?from=1&fromTab=all&finderUsername=" + finderUsername;
if (!mpAppid.IsNullOrEmpty())
referer += "&mpAppid=" + mpAppid;
referer += "&talentAppid=" + talentAppid;
string body = @"{""open_account"":""" + talentAppid + @"""}";
var result = WXHttpResponseBLL.WeiXinTalentOpenKfPostResponse(shop, url, body, referer);
return result;
}
}
public class WXAddFinderParam