店铺考核提供备注功能 微信带货助手采集功能
This commit is contained in:
1 parent
4fa1fc03ca
commit
119b2f4f3e
64 files changed
+7940
-908
No files matched your search
@@ -0,0 +1,775 @@
|
||||
using AllBase;
|
||||
using AllBase.Model.Result;
|
||||
using AllBase.Model.Result.PDDResult;
|
||||
using CefSharp;
|
||||
using CefSharp.WinForms;
|
||||
using NaiBa.CefHelper;
|
||||
using NaiBa.CefHelper.Handler;
|
||||
using NaiBa.Util;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using TemuKJD.BaseForms;
|
||||
using TemuKJD.BLL;
|
||||
using TemuKJD.Extension;
|
||||
using TemuKJD.Helper;
|
||||
using TemuKJD.PDDForms.ProductSelectForms;
|
||||
using TemuKJD.WXForms.ProductForms;
|
||||
using Work;
|
||||
|
||||
namespace TemuKJD.ToolForms
|
||||
{
|
||||
public partial class WXSaleAssistantForm : BaseForms.BaseForm
|
||||
{
|
||||
public bool isGetingProdWithCef = false;
|
||||
public CancellationTokenSource cancellationTokenSource { get; set; } = null;
|
||||
ConcurrentList<WXSaleAssistantSpuItemInfo> lstWxSaleAssistantSpuItemInfo = new ConcurrentList<WXSaleAssistantSpuItemInfo>();
|
||||
string InitUrl = "https://store.weixin.qq.com/talent/pool/home";
|
||||
public ChromiumWebBrowser cefWebBrowser = null;
|
||||
private string currentUrl = "";
|
||||
int pageStart = 1;
|
||||
int pageEnd = 9999;
|
||||
decimal getDetailWaitSeconds = 1;
|
||||
int filterMonthSaleCount = 100;
|
||||
int filterTotalSaleCount = 500;
|
||||
int searchPageCount = 0;
|
||||
|
||||
public WXSaleAssistantForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void GetJuShuitanProdForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
//this.ucTabControlMetro1.TabPages.Remove(tabPage3);
|
||||
|
||||
//this.splitContainer1.SplitterDistance = 472;
|
||||
this.dgvProduct.AddSelectorColumn("colCheck");
|
||||
this.dgvProduct.AddImgColumn("colImg", "colImgUrl");
|
||||
|
||||
|
||||
lstWxSaleAssistantSpuItemInfo = NaiBa.Util.Helper.ConfigHelper.LoadConfig<ConcurrentList<WXSaleAssistantSpuItemInfo>>("wx_sale_assistant_list_" + MainForm.ProcessCount);
|
||||
if (lstWxSaleAssistantSpuItemInfo == null)
|
||||
lstWxSaleAssistantSpuItemInfo = new ConcurrentList<WXSaleAssistantSpuItemInfo>();
|
||||
|
||||
pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
int id = 0;
|
||||
foreach (var prod in lstWxSaleAssistantSpuItemInfo)
|
||||
{
|
||||
id++;
|
||||
if (id % 50 == 0)
|
||||
Thread.Sleep(1);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var rowId = this.dgvProduct.Rows.Add(
|
||||
true,
|
||||
prod.shop.appId,
|
||||
prod.shop.name,
|
||||
prod.spu.id,
|
||||
prod.spu.headImage, //.Replace("https://", "http://"),
|
||||
DataGridViewExtension.defaultBitmap,
|
||||
prod.spu.name,
|
||||
prod.spu.sales.monthlySales,
|
||||
prod.spu.sales.cumulativeSales,
|
||||
"", // 没有类目信息,不填
|
||||
prod.spu.price.sellingPrice * 0.01m,
|
||||
"删除",
|
||||
prod.operateMsg
|
||||
);
|
||||
dgvProduct.Rows[rowId].Height = 60;
|
||||
}));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
pbLoading.Visible = false;
|
||||
}));
|
||||
});
|
||||
|
||||
InitCef();
|
||||
}
|
||||
|
||||
void InitCef()
|
||||
{
|
||||
if (cefWebBrowser == null)
|
||||
{
|
||||
cefWebBrowser = CEFBrowser.CreateChromiumWebBrowser(InitUrl, false);
|
||||
|
||||
CustomResourceRequestHandlerLocal resourceRequestHandler = new CustomResourceRequestHandlerLocal();
|
||||
resourceRequestHandler.ResourceLoadCompleteEvent += RequestHandler_ResourceLoadComplete;
|
||||
resourceRequestHandler.BeforeResourceLoadEvent += RequestHandler_BeforeResourceLoad;
|
||||
cefWebBrowser.RequestHandler = new CustomRequestHandler(resourceRequestHandler);
|
||||
var lifeSapnHandler = new LifeSpanHandlerLocal(PopWindowType.SelfWindow);
|
||||
cefWebBrowser.LifeSpanHandler = lifeSapnHandler;
|
||||
cefWebBrowser.KeyboardHandler = new KeyboardHandler();
|
||||
cefWebBrowser.FrameLoadEnd += CefWebBrowser_FrameLoadEnd;
|
||||
cefWebBrowser.AddressChanged += CefWebBrowser_AddressChanged;
|
||||
cefWebBrowser.LoadError += CefWebBrowser_LoadError;
|
||||
cefWebBrowser.Dock = DockStyle.Fill;
|
||||
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
splitContainer2.Panel2.Controls.Add(cefWebBrowser);
|
||||
//cefWebBrowser.Load(shopMainUrl);
|
||||
}));
|
||||
}
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
string serverCookie = "";
|
||||
var url = BaseClass.BuildWXObjString("user/get_wx_sale_assistant_cookie");
|
||||
var data = UserLogin.GetSignaturex();
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200"))
|
||||
result = GetHtml.PostUtf8(url, data);
|
||||
|
||||
List<Cookie> cookieLst = new List<Cookie>();
|
||||
try
|
||||
{
|
||||
serverCookie = JsonHelper.SerializeObject(JsonHelper.JObjectParse(result)["cookie"]);
|
||||
cookieLst = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(serverCookie);
|
||||
if (cookieLst == null)
|
||||
cookieLst = new List<Cookie>();
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// cef138必须init后方可设置或删除cookie
|
||||
while (!cefWebBrowser.IsBrowserInitialized || !cefWebBrowser.GetBrowser().MainFrame.IsValid)
|
||||
Thread.Sleep(20);
|
||||
CEFBrowser.DeleteCookie(cefWebBrowser.GetCookieManager(null));
|
||||
|
||||
//cef 138 如果没有设置RequestContext 可能为空,直接getCookieManager
|
||||
//if (this.openType != EnumOpenType.login)
|
||||
{
|
||||
//var t = CEFBrowser.SetCookieAsync(JsonHelper.SerializeObject(cookieLst), cefWebBrowser.GetCookieManager(null));
|
||||
foreach (var cook in cookieLst)
|
||||
{
|
||||
var t = CEFBrowser.SetCookieAsync(cook.Domain.Trim('.'), cook.Name + "=" + cook.Value + ";", cefWebBrowser.GetCookieManager(null));
|
||||
t.Wait(5000);
|
||||
}
|
||||
}
|
||||
cefWebBrowser.Load(InitUrl);
|
||||
});
|
||||
}
|
||||
|
||||
private void CefWebBrowser_FrameLoadEnd(object sender, CefSharp.FrameLoadEndEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void RequestHandler_ResourceLoadComplete(object sender, string url, string postData, string responseData, IRequest request)
|
||||
{
|
||||
var dataTmp = responseData;
|
||||
var postTmp = postData;
|
||||
if (isGetingProdWithCef && spuItemsBase == null && url.Contains("https://store.weixin.qq.com/shop-faas/mmeckolpoolnode/ecListSelectionSpuItems?token=&lang=zh_CN"))
|
||||
{
|
||||
getSpuItemsParams = JsonHelper.JObjectParse(postTmp);
|
||||
Task.Run(() =>
|
||||
{
|
||||
showGetSaleAssistantItems(dataTmp);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public string requestId = "";
|
||||
public string pageContext = "";
|
||||
List<WXSaleAssistantSpuItemInfo> spuItemsBase = null;
|
||||
JObject getSpuItemsParams = null;
|
||||
void showGetSaleAssistantItems(string spuItemsData)
|
||||
{
|
||||
try
|
||||
{
|
||||
searchPageCount++;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
statusBar.lblTaskStatus.Text = "当前翻页数:" + searchPageCount;
|
||||
}));
|
||||
if (searchPageCount % 10 == 0)
|
||||
{
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_sale_assistant_list_" + MainForm.ProcessCount, lstWxSaleAssistantSpuItemInfo);
|
||||
}
|
||||
if (searchPageCount >= pageEnd)
|
||||
{
|
||||
isGetingProdWithCef = false;
|
||||
}
|
||||
if (spuItemsData.Contains("\"hasNext\":false"))
|
||||
{
|
||||
isGetingProdWithCef = false;
|
||||
}
|
||||
pageContext = BaseRegex.GetStringJson(ref spuItemsData, "pageContext");
|
||||
requestId = BaseRegex.GetStringJson(ref spuItemsData, "requestId");
|
||||
|
||||
var jObj = JsonHelper.JObjectParse(spuItemsData)["spuItems"];
|
||||
var spuItems = JsonHelper.DeserializeJsonToList<WXSaleAssistantSpuItemInfo>(JsonHelper.SerializeObject(jObj));
|
||||
if (spuItemsBase == null)
|
||||
{
|
||||
spuItemsBase = spuItems;
|
||||
foreach (var spuItem in spuItems)
|
||||
{
|
||||
// 月销
|
||||
if (spuItem.spu.sales.monthlySales < filterMonthSaleCount)
|
||||
continue;
|
||||
// 总销
|
||||
if (spuItem.spu.sales.cumulativeSales < filterTotalSaleCount)
|
||||
continue;
|
||||
// 已加入橱窗
|
||||
if (chkSkipIsAddWindow.Checked && spuItem.shopWindow != null && spuItem.shopWindow.status == 1)
|
||||
continue;
|
||||
// 已存在
|
||||
if (lstWxSaleAssistantSpuItemInfo.Any(s => s.spu.id == spuItem.spu.id))
|
||||
continue;
|
||||
|
||||
lstWxSaleAssistantSpuItemInfo.Add(spuItem);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var rowId = this.dgvProduct.Rows.Add(
|
||||
true,
|
||||
spuItem.shop.appId,
|
||||
spuItem.shop.name,
|
||||
spuItem.spu.id,
|
||||
spuItem.spu.headImage, //.Replace("https://", "http://"),
|
||||
DataGridViewExtension.defaultBitmap,
|
||||
spuItem.spu.name,
|
||||
spuItem.spu.sales.monthlySales,
|
||||
spuItem.spu.sales.cumulativeSales,
|
||||
"", // 没有类目信息,不填
|
||||
spuItem.spu.price.sellingPrice * 0.01m,
|
||||
"删除",
|
||||
spuItem.operateMsg
|
||||
);
|
||||
dgvProduct.Rows[rowId].Height = 60;
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
//currentGetHotListParamData = "";
|
||||
//currentGetSupplierListParamData = postData;
|
||||
//currentSupplierId = BaseRegex.GetStringJson(ref postData, "supplierId");
|
||||
//currentSupplierName = BaseRegex.GetStringJson(ref responseData, "supplierName");
|
||||
}
|
||||
|
||||
private bool RequestHandler_BeforeResourceLoad(object sender, string url, string postData, IRequest request)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
private void CefWebBrowser_AddressChanged(object sender, CefSharp.AddressChangedEventArgs e)
|
||||
{
|
||||
if (this.Created && !this.Disposing && !this.IsDisposed)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
currentUrl = e.Address;
|
||||
txtAddress.Text = e.Address;
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void CefWebBrowser_LoadError(object sender, CefSharp.LoadErrorEventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
private void btnImportCookie_Click(object sender, EventArgs e)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
foreach (var cookie in txtCookie.Text.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries))
|
||||
{
|
||||
var t = CEFBrowser.SetCookieAsync("store.weixin.qq.com", cookie, cefWebBrowser.GetCookieManager(null));
|
||||
t.Wait(5000);
|
||||
}
|
||||
cefWebBrowser.Load(InitUrl);
|
||||
});
|
||||
}
|
||||
|
||||
private void btnSaveCookie_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList("store.weixin.qq.com", cefWebBrowser.GetCookieManager(null));
|
||||
|
||||
var url = BaseClass.BuildWXObjString("user/update_wx_sale_assistant_cookie");
|
||||
var data = UserLogin.GetSignaturex();
|
||||
data += "&cookie=" + GetHtml.UrlEncodeUtf8(JsonHelper.SerializeObject(cookieList));
|
||||
var result = GetHtml.PostUtf8(url, data);
|
||||
if (!result.Contains("\"code\":200"))
|
||||
result = GetHtml.PostUtf8(url, data);
|
||||
|
||||
if (result.Contains("\"code\":200"))
|
||||
BaseMsgForm.ShowInfo("保存成功");
|
||||
else
|
||||
BaseMsgForm.ShowInfo("保存失败,请重试");
|
||||
}
|
||||
|
||||
private void btnRefreshCookie_Click(object sender, EventArgs e)
|
||||
{
|
||||
InitCef();
|
||||
}
|
||||
|
||||
private void btnPrev_Click(object sender, EventArgs e)
|
||||
{
|
||||
cefWebBrowser.Back();
|
||||
}
|
||||
|
||||
private void btnNext_Click(object sender, EventArgs e)
|
||||
{
|
||||
cefWebBrowser.Forward();
|
||||
}
|
||||
|
||||
private void txtAddress_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyCode == Keys.Enter)
|
||||
{
|
||||
if (cefWebBrowser != null)
|
||||
{
|
||||
cefWebBrowser.Load(txtAddress.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void dgvProduct_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||||
return;
|
||||
string headerText = dgvProduct.Columns[e.ColumnIndex].HeaderText;
|
||||
var prodId = dgvProduct.Rows[e.RowIndex].Cells["colProductId"].Value.ParseToString();
|
||||
var prod = lstWxSaleAssistantSpuItemInfo.FirstOrDefault(p => p.spu.id == prodId);
|
||||
var row = dgvProduct.Rows[e.RowIndex];
|
||||
|
||||
switch (headerText)
|
||||
{
|
||||
case "删除":
|
||||
//if (BaseMsgForm.ShowConfirm("确定删除商品吗?删除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||||
// return;
|
||||
//DeleteProduct(dbId);
|
||||
dgvProduct.Rows.Remove(row);
|
||||
lstWxSaleAssistantSpuItemInfo.Remove(prod);
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_sale_assistant_list_" + MainForm.ProcessCount, lstWxSaleAssistantSpuItemInfo);
|
||||
break;
|
||||
case "图片":
|
||||
var imgUrl = dgvProduct.Rows[e.RowIndex].Cells["colImgUrl"].Value.ParseToString().Replace("?imageView2/2/w/90/h/90", "");
|
||||
Dictionary<string, string> dic = new Dictionary<string, string>();
|
||||
dic[imgUrl] = imgUrl;
|
||||
foreach (var imgPath in prod.spu.headImage)
|
||||
{
|
||||
//dic[imgPath.Replace("https", "http")] = imgPath.Replace("https", "http");
|
||||
}
|
||||
ShowImgForm imgFrom = new ShowImgForm(imgUrl, dic);
|
||||
imgFrom.ShowDialog();
|
||||
break;
|
||||
case "":
|
||||
dgvProduct.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvProduct.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void txtFilterSaleCount_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
filterMonthSaleCount = txtFilterMonthSaleCount.Text.Trim().ParseToInt();
|
||||
}
|
||||
|
||||
private void txtFilterTotalSaleCount_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
filterTotalSaleCount = txtFilterTotalSaleCount.Text.Trim().ParseToInt();
|
||||
}
|
||||
|
||||
private void txtPageStart_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
pageStart = txtPageStart.Text.Trim().ParseToInt();
|
||||
}
|
||||
|
||||
private void txtPageEnd_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
pageEnd = txtPageEnd.Text.Trim().ParseToInt();
|
||||
}
|
||||
|
||||
private void btnStopStop_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (cancellationTokenSource != null)
|
||||
cancellationTokenSource.Cancel();
|
||||
isGetingProdWithCef = false;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
if (cancellationTokenSource == null || cancellationTokenSource.IsCancellationRequested)
|
||||
pbLoading.Visible = false;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void btnSearchTitle_Click(object sender, EventArgs e)
|
||||
{
|
||||
pbLoading.Visible = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
foreach (DataGridViewRow row in dgvProduct.Rows)
|
||||
{
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
|
||||
row.Visible = (row.Cells["colGoodsName"].Value.ParseToString().Contains(txtTitle.Text.Trim()) || txtTitle.Text.Trim() == "");
|
||||
if (row.Visible == false)
|
||||
row.Cells["colCheck"].Value = false;
|
||||
|
||||
}));
|
||||
}
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
pbLoading.Visible = false;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void txtWaitSeconds_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
getDetailWaitSeconds = txtWaitSeconds.Text.ParseToDecimal();
|
||||
}
|
||||
|
||||
private void btnExportCookie_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList("store.weixin.qq.com", cefWebBrowser.GetCookieManager(null));
|
||||
var shop = new ShopLoginInfo();
|
||||
shop.Cookies = JsonHelper.SerializeObject(cookieList);
|
||||
|
||||
List<CefSharp.Cookie> cooks = null;
|
||||
try { cooks = JsonHelper.DeserializeJsonToList<CefSharp.Cookie>(shop.Cookies); } catch (Exception ex) { }
|
||||
if (cooks == null)
|
||||
cooks = new List<CefSharp.Cookie>();
|
||||
|
||||
string cookJs = "";
|
||||
var keys = new string[] { "device_id", "talent_magic", "talent_rand", "talent_token" };
|
||||
foreach (var shopCook in cooks)
|
||||
{
|
||||
var cookie = shopCook.Name + "=" + shopCook.Value;
|
||||
if (!keys.Any(k => cookie.StartsWith(k)))
|
||||
continue;
|
||||
cookJs += "\r\ndocument.cookie='" + cookie.Substring(0, Math.Max(0, cookie.IndexOf("="))) + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';";
|
||||
}
|
||||
foreach (var shopCook in cooks)
|
||||
{
|
||||
var cookie = shopCook.Name + "=" + shopCook.Value;
|
||||
if (!keys.Any(k => cookie.StartsWith(k)))
|
||||
continue;
|
||||
cookJs += "\r\ndocument.cookie='" + cookie + "; domain=store.weixin.qq.com; expires=" +
|
||||
DateTime.Now.AddMonths(1).ToUniversalTime().ToString("ddd, dd MMM yyyy HH:mm:ss 'UTC'", new DateTimeFormatInfo()) + "; path=/';";
|
||||
}
|
||||
cookJs += "\r\nsetTimeout(() => { window.location.href='" + InitUrl + "'; }, 200)";
|
||||
Clipboard.SetDataObject(cookJs);
|
||||
BaseMsgForm.ShowInfo("复制成功");
|
||||
}
|
||||
|
||||
private void btnGetWxProd_Click(object sender, EventArgs e)
|
||||
{
|
||||
isGetingProdWithCef = true;
|
||||
pbLoading.Visible = true;
|
||||
if (cancellationTokenSource != null)
|
||||
cancellationTokenSource.Cancel();
|
||||
cancellationTokenSource = new CancellationTokenSource();
|
||||
|
||||
dgvProduct.Rows.Clear();
|
||||
lstWxSaleAssistantSpuItemInfo.Clear();
|
||||
searchPageCount = 0;
|
||||
spuItemsBase = null;
|
||||
getSpuItemsParams = null;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
int top = 0;
|
||||
while (this.isGetingProdWithCef == true)
|
||||
{
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
top += Randomx.GetId(500, 900);
|
||||
Thread.Sleep((int)(getDetailWaitSeconds * 1000) - 100 + Randomx.GetId(101, 501));
|
||||
|
||||
if (cefWebBrowser.IsLoading)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
var jsStr = @"window.scroll({
|
||||
top: document.body.scrollHeight,
|
||||
left: 0,
|
||||
behavior: 'smooth' // 可选,使滚动平滑
|
||||
});";
|
||||
//jsStr = @"window.scroll({
|
||||
// top: " + top + @",
|
||||
// left: 0,
|
||||
// behavior: 'smooth' // 可选,使滚动平滑
|
||||
// });";
|
||||
var client = cefWebBrowser.GetDevToolsClient();
|
||||
if (client != null)
|
||||
{
|
||||
var result = client.Runtime.EvaluateAsync(jsStr, null, true, null, null, true, null, true);
|
||||
result.Wait(5000);
|
||||
}
|
||||
|
||||
if (getSpuItemsParams != null)
|
||||
break;
|
||||
}
|
||||
|
||||
while (spuItemsBase != null && getSpuItemsParams != null && searchPageCount < pageEnd)
|
||||
{
|
||||
|
||||
if (cancellationTokenSource.IsCancellationRequested)
|
||||
break;
|
||||
|
||||
int sleepTime = (int)(getDetailWaitSeconds * 1000) - 100 + Randomx.GetId(101, 501);
|
||||
Thread.Sleep(Math.Max(100, sleepTime));
|
||||
|
||||
searchPageCount++;
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
statusBar.lblTaskStatus.Text = "当前翻页数:" + searchPageCount;
|
||||
}));
|
||||
if (searchPageCount % 10 == 0)
|
||||
{
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_sale_assistant_list_" + MainForm.ProcessCount, lstWxSaleAssistantSpuItemInfo);
|
||||
}
|
||||
|
||||
List<Cookie> cookieList = CEFBrowser.GetCookieList("store.weixin.qq.com", cefWebBrowser.GetCookieManager(null));
|
||||
var cookieShop = new ShopLoginInfo();
|
||||
cookieShop.Cookies = JsonHelper.SerializeObject(cookieList);
|
||||
getSpuItemsParams["pageContext"]["pageContext"] = pageContext;
|
||||
getSpuItemsParams["requestContext"]["requestId"] = requestId;
|
||||
foreach (var item in spuItemsBase)
|
||||
{
|
||||
JObject jObjDisplaySpu = new JObject();
|
||||
jObjDisplaySpu["spuId"] = item.spu.id;
|
||||
(getSpuItemsParams["requestContext"]["displayedSpus"] as JArray).Add(jObjDisplaySpu);
|
||||
}
|
||||
|
||||
//{"code":0,"pageContextResp":{"hasNext":false},"requestId":"1778688044492"}
|
||||
var spuItemsData = GetAssistant.wxGetAssistant(cookieShop, getSpuItemsParams);
|
||||
if (!spuItemsData.Contains("\"code\":0") || spuItemsData.Contains("\"hasNext\":false"))
|
||||
spuItemsData = GetAssistant.wxGetAssistant(cookieShop, getSpuItemsParams);
|
||||
if (!spuItemsData.Contains("\"code\":0") || spuItemsData.Contains("\"hasNext\":false"))
|
||||
spuItemsData = GetAssistant.wxGetAssistant(cookieShop, getSpuItemsParams);
|
||||
if (!spuItemsData.Contains("\"code\":0") || spuItemsData.Contains("\"hasNext\":false"))
|
||||
spuItemsData = GetAssistant.wxGetAssistant(cookieShop, getSpuItemsParams);
|
||||
if (!spuItemsData.Contains("\"code\":0") || spuItemsData.Contains("\"hasNext\":false"))
|
||||
spuItemsData = GetAssistant.wxGetAssistant(cookieShop, getSpuItemsParams);
|
||||
if (!spuItemsData.Contains("\"code\":0"))
|
||||
{
|
||||
BaseMsgForm.ShowError(spuItemsData);
|
||||
break;
|
||||
}
|
||||
if (spuItemsData.Contains("\"hasNext\":false"))
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pageContext = BaseRegex.GetStringJson(ref spuItemsData, "pageContext");
|
||||
requestId = BaseRegex.GetStringJson(ref spuItemsData, "requestId");
|
||||
|
||||
var jObj = JsonHelper.JObjectParse(spuItemsData)["spuItems"];
|
||||
var spuItems = JsonHelper.DeserializeJsonToList<WXSaleAssistantSpuItemInfo>(JsonHelper.SerializeObject(jObj));
|
||||
spuItemsBase = spuItems;
|
||||
foreach (var spuItem in spuItems)
|
||||
{
|
||||
// 月销
|
||||
if (spuItem.spu.sales.monthlySales < filterMonthSaleCount)
|
||||
continue;
|
||||
// 总销
|
||||
if (spuItem.spu.sales.cumulativeSales < filterTotalSaleCount)
|
||||
continue;
|
||||
// 已加入橱窗
|
||||
if (chkSkipIsAddWindow.Checked && spuItem.shopWindow != null && spuItem.shopWindow.status == 1)
|
||||
continue;
|
||||
// 已存在
|
||||
if (lstWxSaleAssistantSpuItemInfo.Any(s => s.spu.id == spuItem.spu.id))
|
||||
continue;
|
||||
|
||||
lstWxSaleAssistantSpuItemInfo.Add(spuItem);
|
||||
Invoke(new Action(() =>
|
||||
{
|
||||
var rowId = this.dgvProduct.Rows.Add(
|
||||
true,
|
||||
spuItem.shop.appId,
|
||||
spuItem.shop.name,
|
||||
spuItem.spu.id,
|
||||
spuItem.spu.headImage, //.Replace("https://", "http://"),
|
||||
DataGridViewExtension.defaultBitmap,
|
||||
spuItem.spu.name,
|
||||
spuItem.spu.sales.monthlySales,
|
||||
spuItem.spu.sales.cumulativeSales,
|
||||
"", // 没有类目信息,不填
|
||||
spuItem.spu.price.sellingPrice * 0.01m,
|
||||
"删除",
|
||||
spuItem.operateMsg
|
||||
);
|
||||
dgvProduct.Rows[rowId].Height = 60;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (!cancellationTokenSource.IsCancellationRequested)
|
||||
BaseMsgForm.ShowInfo("查询结束");
|
||||
else
|
||||
BaseMsgForm.ShowInfo("查询中断");
|
||||
|
||||
Invoke(new Action(() => { pbLoading.Visible = false; }));
|
||||
|
||||
}, cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
private void btnClear_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (BaseMsgForm.ShowConfirm("确定清除选中商品吗?清除后不可恢复!").DialogResult == DialogResult.Cancel)
|
||||
return;
|
||||
|
||||
var rows = this.dgvProduct.Rows.Cast<DataGridViewRow>().ToList(); //Cast后Rows做foreach循环时仍会夹花跳过,所以要ToList转一个新的数组。
|
||||
foreach (var row in rows)
|
||||
{
|
||||
if (row.Cells["colCheck"].Value.ParseToBool() == true)
|
||||
{
|
||||
var spuId = row.Cells["colProductId"].Value.ParseToString();
|
||||
lstWxSaleAssistantSpuItemInfo.RemoveAll(p => p.spu.id.ParseToString() == spuId);
|
||||
this.dgvProduct.Rows.Remove(row);
|
||||
}
|
||||
}
|
||||
NaiBa.Util.Helper.ConfigHelper.SaveConfig("wx_sale_assistant_list_" + MainForm.ProcessCount, lstWxSaleAssistantSpuItemInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public class WXSaleAssistantSpuItemInfo
|
||||
{
|
||||
public string operateMsg;
|
||||
|
||||
public WXSaleAssistantSpuInfo spu { get; set; }
|
||||
public WXSaleAssistantPromoteInfo promote { get; set; }
|
||||
public WXSaleAssistantShopInfo shop { get; set; }
|
||||
public object localLife { get;set;}
|
||||
// 是否已加入橱窗,不为空切status为1表示已加入
|
||||
public WXSaleAssistantShopWindowInfo shopWindow { get; set; }
|
||||
}
|
||||
|
||||
public class WXSaleAssistantShopWindowInfo
|
||||
{
|
||||
public int? status { get; set; } // 1
|
||||
}
|
||||
|
||||
public class WXSaleAssistantShopInfo
|
||||
{
|
||||
public string name { get; set; } // "海阔文化云上图书",
|
||||
public string icon { get; set; } // "http://mmbiz.qpic.cn/sz_mmbiz_png/ZWUXBFWiasldM81seiaAjqom0sK2QKAkkD4hXX3iaWLeyKmUnyNfPy1iaZ774ia29lMIj1fVEtcZqqXrv4c66ROCgpQ/0?wx_fmt=png",
|
||||
public WXSaleAssistantDetailedSellerRating detailedSellerRating { get; set; }
|
||||
public string appId { get; set; } // "wx1517b163194b3eaa",
|
||||
public string flag { get; set; } // "3"
|
||||
}
|
||||
|
||||
public class WXSaleAssistantDetailedSellerRating
|
||||
{
|
||||
public WXSaleAssistantDetailedRating detailedRating { get; set; }
|
||||
public WXSaleAssistantDetailedRating detailedSpuRating { get; set; }
|
||||
public WXSaleAssistantDetailedRating detailedDeliverRating { get; set; }
|
||||
public WXSaleAssistantDetailedRating detailedServiceRating { get; set; }
|
||||
}
|
||||
|
||||
public class WXSaleAssistantDetailedRating
|
||||
{
|
||||
public int? score { get; set; } // 482,
|
||||
public int? level { get; set; } // 2,
|
||||
public int? abovePercent { get; set; } // 7122
|
||||
|
||||
}
|
||||
|
||||
public class WXSaleAssistantPromoteInfo
|
||||
{
|
||||
public WXSaleAssistantCommissionInfo commission { get; set; }
|
||||
}
|
||||
|
||||
public class WXSaleAssistantCommissionInfo
|
||||
{
|
||||
public int? commissionRate { get; set; } // 500000,
|
||||
public string commissionRateDesc { get; set; } // "佣金率50%",
|
||||
public int? commission { get; set; } // 1490,
|
||||
public string commissionType { get; set; } // 1
|
||||
|
||||
}
|
||||
|
||||
public class WXSaleAssistantSpuInfo
|
||||
{
|
||||
public string id { get; set; } // "10000666530619"
|
||||
public string name { get; set; } // "懒鸟效应:激发孩子的成长力 养成自律的好习惯 告别拖延与分心",
|
||||
public string headImage { get; set; } // "https://wst.wxapp.tc.qq.com/161/20304/snscosdownload/SH/reserved/69d774500008a8161a1689b6ab95b01e000000a000004f50",
|
||||
public WXSaleAssistantStockInfo stock { get; set; }
|
||||
public WXSaleAssistantSalesInfo sales { get; set; }
|
||||
public WXSaleAssistantPriceInfo price { get; set; }
|
||||
public string shortName { get; set; } // "点击购买【懒鸟三生教育】"
|
||||
public List<WXSaleAssistantGuaranteeShowInfo> guaranteeShows { get; set; }
|
||||
public List<WXSaleAssistantBenefitInfo> benefits { get; set; }
|
||||
}
|
||||
|
||||
public class WXSaleAssistantBenefitInfo
|
||||
{
|
||||
public int? benefits { get; set; } // 0,
|
||||
public string name { get; set; } // "限免服务费"
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class WXSaleAssistantGuaranteeShowInfo
|
||||
{
|
||||
public string desc { get; set; } // "7天无理由",
|
||||
public int? tag { get; set; } // 4
|
||||
}
|
||||
|
||||
public class WXSaleAssistantPriceInfo
|
||||
{
|
||||
public int? sellingPrice { get; set; } // 2980
|
||||
}
|
||||
|
||||
public class WXSaleAssistantStockInfo
|
||||
{
|
||||
public int? totalStock { get; set; } // 3929912
|
||||
}
|
||||
public class WXSaleAssistantSalesInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 月销量
|
||||
/// </summary>
|
||||
public int? monthlySales { get; set; } // 52421
|
||||
/// <summary>
|
||||
/// 总销量
|
||||
/// </summary>
|
||||
public int? cumulativeSales { get; set; } // 71960
|
||||
}
|
||||
|
||||
public class GetAssistant
|
||||
{
|
||||
public static string wxGetAssistant(ShopLoginInfo shop, JObject wxCateAuthParam)
|
||||
{
|
||||
string url = "https://store.weixin.qq.com/shop-faas/mmeckolpoolnode/ecListSelectionSpuItems?token=&lang=zh_CN";
|
||||
string referer = "https://store.weixin.qq.com/talent/pool/home";
|
||||
string data = JsonHelper.SerializeObject(wxCateAuthParam);
|
||||
var result = WXHttpResponseBLL.WeiXinAssistantPostResponse(shop, url, data, referer);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user