using AllBase; //using JavaScriptEngineSwitcher.Core; //using JavaScriptEngineSwitcher.V8; using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using Work.Api; using Work.CollectClass; namespace Work.ManageClass { public class VioProductGroup { public string Name; public ShopChatBase Shop; public string delTitle; bool isOnline = false; public List ids = new List(); public List pidList = new List(); /// /// 不包含销量 /// public static bool IsNoSold = false; /// /// 不包含访客 /// public static bool IsNoVisit = false; /// /// 不包含收藏 /// public static bool IsNoColl = false; /// /// 获取企业全部上家 /// public static Dictionary UpIdsList = new Dictionary(); public List ProductChangeDelTemp = new List(); public VioProductGroup(string name, ShopChatBase shop) { Name = name; Shop = shop; } public void GetVioKeyWordDel() { Shop.VioProduct.Clear(); if (IsNoVisit) GetOnOrOff(); int mallId = Shop.MallId; string temptitle = ""; if (!string.IsNullOrEmpty(delTitle)) { string[] idsx = delTitle.Split(new string[] { "\r", "\n", "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < idsx.Length; i++) { temptitle += idsx[i] + ","; } } string cookies = Shop.Cookies, shopName = Shop.ShopName; string url = "https://mms.pinduoduo.com/vodka/v2/mms/query/display/mall/goodsList"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = ""; if (!string.IsNullOrEmpty(temptitle)) data = "{\"order_by\":\"id:asc\",\"goods_name\":\"" + temptitle.Substring(0,temptitle.Length-1) + "\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; else data = "{\"order_by\":\"id:asc\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; string html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); } int allCount = BaseRegex.GetIntJson(ref html, "total"); int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); if (page > 1000) { page = 1000; } for (int i = 0; i < page; i++) { if (i != 0) { html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); } } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; TaobaoProductBase p = new TaobaoProductBase(); p.GoodsId = BaseRegex.GetLongJson(ref list, "id"); p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn"); p.Titlte = BaseRegex.GetStringJson(ref list, "goods_name"); if (p.GoodsId == 0 || string.IsNullOrEmpty(p.Titlte)) continue; p.CatId = BaseRegex.GetIntJson(ref list, "cat_id"); p.CatId = PinduoduoCatList.GetNewCat3(p.CatId); p.SaleCount = BaseRegex.GetIntJson(ref list, "sold_quantity"); p.ShopName = Shop.ShopName; p.UseShopName = Shop.Name; int fav_cnt = BaseRegex.GetIntJson(ref list, "fav_cnt"); string price = BaseRegex.GetMatchRegexString(ref list, @"""sku_group_price"":\[([\d]+),"); if (string.IsNullOrEmpty(price)) price = "1000"; p.Price = int.Parse(price) / 100m; if (PinduoduoCatList.CatIds.ContainsKey(p.CatId)) { var c = PinduoduoCatList.CatIds[p.CatId]; p.Cat1 = c.cat1; p.Cat2 = c.cat2; p.Cat3 = c.cat3; p.Cat4 = c.cat4; p.MainCatId = c.main_cat_id; } else { } if (!string.IsNullOrEmpty(delTitle)) { string[] ids = delTitle.Split(new string[] { "\r", "\n", "," }, StringSplitOptions.RemoveEmptyEntries); bool ishas = false; for (int k = 0; k < ids.Length; k++) { if (p.Titlte.Contains(ids[k])) { ishas = true; break; } } if (!ishas) continue; } var mc = BaseRegex.GetMatchRegex(ref list, @"""is_onsale"":([\w\W]+?),"); if (mc == null || mc.Count <= 0) continue; p.OffLine = !bool.Parse(mc[0].Groups[1].Value); if (IsNoSold && p.SaleCount > 0) { // 跳过有销量商品 LogSave.Add(Name, "跳过销量商品 " + p.GoodsId); continue; } if (IsNoColl && fav_cnt > 0) { // 跳过收藏商品 LogSave.Add(Name, "跳过收藏商品 " + p.GoodsId); continue; } var pid = pidList.Find(id => id == p.GoodsId); if (pid > 0) { // 跳过有访客商品 continue; } if (!Shop.VioProduct.Exists(pt => pt != null && pt.GoodsId == p.GoodsId)) { //if (!p.Titlte.Contains(delTitle)) // continue; Shop.VioProduct.Add(p); VioProductControl.ProductDelTemp.Add(p); } } Thread.Sleep(300); LogSave.Add(Name, "获取在线关键词产品 " + shopName + ",分页:" + i); } LogSave.Add(Name, "获取完成"); } public void GetFilterKeyWordDel() { Shop.VioProduct.Clear(); int mallId = Shop.MallId; string temptitle = ""; if (!string.IsNullOrEmpty(delTitle)) { string[] idsx = delTitle.Split(new string[] { "\r", "\n", "," }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < idsx.Length; i++) { temptitle += idsx[i] + ","; } } string cookies = Shop.Cookies, shopName = Shop.ShopName; string url = "https://mms.pinduoduo.com/vodka/v2/mms/query/display/mall/goodsList"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = ""; if (!string.IsNullOrEmpty(delTitle)) data = "{\"order_by\":\"id:asc\",\"goods_name\":\"" + temptitle.Substring(0,temptitle.Length-1) + "\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; else data = "{\"order_by\":\"id:asc\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; string html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon());// GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); } int allCount = BaseRegex.GetIntJson(ref html, "total"); int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); if (page > 1000) { page = 1000; } for (int i = 0; i < page; i++) { if (i != 0) { html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); } } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; TaobaoProductBase p = new TaobaoProductBase(); p.GoodsId = BaseRegex.GetLongJson(ref list, "id"); p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn"); p.Titlte = BaseRegex.GetStringJson(ref list, "goods_name"); if (p.GoodsId == 0 || string.IsNullOrEmpty(p.Titlte)) continue; p.CatId = BaseRegex.GetIntJson(ref list, "cat_id"); p.CatId = PinduoduoCatList.GetNewCat3(p.CatId); p.SaleCount = BaseRegex.GetIntJson(ref list, "sold_quantity"); p.ShopName = Shop.ShopName; p.UseShopName = Shop.Name; int fav_cnt = BaseRegex.GetIntJson(ref list, "fav_cnt"); string price = BaseRegex.GetMatchRegexString(ref list, @"""sku_group_price"":\[([\d]+),"); if (string.IsNullOrEmpty(price)) price = "1000"; p.Price = int.Parse(price) / 100m; if (PinduoduoCatList.CatIds.ContainsKey(p.CatId)) { var c = PinduoduoCatList.CatIds[p.CatId]; p.Cat1 = c.cat1; p.Cat2 = c.cat2; p.Cat3 = c.cat3; p.Cat4 = c.cat4; p.MainCatId = c.main_cat_id; } else { } if (!string.IsNullOrEmpty(delTitle)) { string[] ids = delTitle.Split(new string[] { "\r", "\n", "," }, StringSplitOptions.RemoveEmptyEntries); bool ishas = false; for (int k = 0; k < ids.Length; k++) { if (p.Titlte.Contains(ids[k])) { ishas = true; break; } } if (!ishas) continue; } var mc = BaseRegex.GetMatchRegex(ref list, @"""is_onsale"":([\w\W]+?),"); if (mc == null || mc.Count <= 0) continue; p.OffLine = !bool.Parse(mc[0].Groups[1].Value); if (IsNoSold && p.SaleCount > 0) { // 跳过有销量商品 LogSave.Add(Name, "跳过销量商品 " + p.GoodsId); continue; } if (IsNoColl && fav_cnt > 0) { // 跳过收藏商品 LogSave.Add(Name, "跳过收藏商品 " + p.GoodsId); continue; } var pid = pidList.Find(id => id == p.GoodsId); if (pid > 0) { // 跳过有访客商品 continue; } string md5title = GetMd5(p.Titlte); var exsitTitle = UploadPinduoduoMain.RuleTitles.Find(title => title == md5title); var fid = filPidlist.Find(id => id == p.GoodsId.ToString()); if (string.IsNullOrEmpty(fid)&& string.IsNullOrEmpty(exsitTitle)) { // 跳过正常商品 continue; } if (!Shop.VioProduct.Exists(pt => pt != null && pt.GoodsId == p.GoodsId)) { Shop.VioProduct.Add(p); VioProductControl.ProductDelTemp.Add(p); } } Thread.Sleep(300); LogSave.Add(Name, "获取违规关键词产品 " + shopName + ",分页:" + i); } LogSave.Add(Name, "获取完成"); } public static string GetMd5(string instring) { //try //{ byte[] result = Encoding.Default.GetBytes(instring.Trim()); MD5 md5 = new MD5CryptoServiceProvider(); byte[] output = md5.ComputeHash(result); return BitConverter.ToString(output).Replace("-", ""); //} //catch //{ //} //return ""; } public void GetVioKeyWordDel2() { List titles = new List(); var mt = BaseRegex.GetMatchRegex(ref delTitle, @"([\w\W]+?)[,|\r\n|\s{1,}]"); for (int j = 0; mt != null && j < mt.Count; j++) { string item = mt[j].Groups[1].Value.Trim(); if (string.IsNullOrEmpty(item)) continue; titles.Add(item); } Shop.VioProduct.Clear(); int mallId = Shop.MallId; string cookies = Shop.Cookies, shopName = Shop.ShopName; string url = "https://mms.pinduoduo.com/vodka/v2/mms/query/display/mall/goodsList"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"order_by\":\"id:asc\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); } int allCount = BaseRegex.GetIntJson(ref html, "total"); int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); if (page > 1000) { page = 1000; } for (int i = 0; i < page; i++) { if (i != 0) { html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); } } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; TaobaoProductBase p = new TaobaoProductBase(); p.GoodsId = BaseRegex.GetLongJson(ref list, "id"); p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn"); p.Titlte = BaseRegex.GetStringJson(ref list, "goods_name"); if (p.GoodsId == 0 || string.IsNullOrEmpty(p.Titlte)) continue; p.CatId = BaseRegex.GetIntJson(ref list, "cat_id"); p.CatId = PinduoduoCatList.GetNewCat3(p.CatId); p.SaleCount = BaseRegex.GetIntJson(ref list, "sold_quantity"); p.ShopName = Shop.ShopName; p.UseShopName = Shop.Name; string price = BaseRegex.GetMatchRegexString(ref list, @"""sku_group_price"":\[([\d]+),"); if (string.IsNullOrEmpty(price)) price = "1000"; p.Price = int.Parse(price) / 100m; if (PinduoduoCatList.CatIds.ContainsKey(p.CatId)) { var c = PinduoduoCatList.CatIds[p.CatId]; p.Cat1 = c.cat1; p.Cat2 = c.cat2; p.Cat3 = c.cat3; p.Cat4 = c.cat4; p.MainCatId = c.main_cat_id; } else { } var mc = BaseRegex.GetMatchRegex(ref list, @"""is_onsale"":([\w\W]+?),"); if (mc == null || mc.Count <= 0) continue; p.OffLine = !bool.Parse(mc[0].Groups[1].Value); if (!Shop.VioProduct.Exists(pt => pt != null && pt.GoodsId == p.GoodsId)) { bool ishas = false; foreach (string s in titles) { if (p.Titlte.Contains(s)) { ishas = true; break; } } if (!ishas) continue; Shop.VioProduct.Add(p); VioProductControl.ProductDelTemp.Add(p); } } Thread.Sleep(300); LogSave.Add(Name, "获取在线关键词产品 " + shopName + ",分页:" + i); } LogSave.Add(Name, "获取完成"); } public void GetVioAllWord() { Shop.VioProduct.Clear(); int mallId = Shop.MallId; string cookies = Shop.Cookies, shopName = Shop.ShopName; string url = "https://mms.pinduoduo.com/vodka/v2/mms/query/display/mall/goodsList"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"order_by\":\"id:asc\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), cookies); } int allCount = BaseRegex.GetIntJson(ref html, "total"); int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); if (page > 1000) { page = 1000; } for (int i = 0; i < page; i++) { if (i != 0) { html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#page#", (i + 1).ToString()), cookies); } } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; TaobaoProductBase p = new TaobaoProductBase(); p.GoodsId = BaseRegex.GetLongJson(ref list, "id"); p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn"); p.Titlte = BaseRegex.GetStringJson(ref list, "goods_name"); if (p.GoodsId == 0 || string.IsNullOrEmpty(p.Titlte)) continue; p.CatId = BaseRegex.GetIntJson(ref list, "cat_id"); p.CatId = PinduoduoCatList.GetNewCat3(p.CatId); p.SaleCount = BaseRegex.GetIntJson(ref list, "sold_quantity"); p.ShopName = Shop.ShopName; p.UseShopName = Shop.Name; string price = BaseRegex.GetMatchRegexString(ref list, @"""sku_group_price"":\[([\d]+),"); if (string.IsNullOrEmpty(price)) price = "1000"; p.Price = int.Parse(price) / 100m; if (PinduoduoCatList.CatIds.ContainsKey(p.CatId)) { var c = PinduoduoCatList.CatIds[p.CatId]; p.Cat1 = c.cat1; p.Cat2 = c.cat2; p.Cat3 = c.cat3; p.Cat4 = c.cat4; p.MainCatId = c.main_cat_id; } else { } var mc = BaseRegex.GetMatchRegex(ref list, @"""is_onsale"":([\w\W]+?),"); if (mc == null || mc.Count <= 0) continue; p.OffLine = !bool.Parse(mc[0].Groups[1].Value); if (!VioProductControl.UpIds.Exists(pt => pt != null && pt.GoodsId == p.GoodsId)) { VioProductControl.UpIds.Add(p); } } Thread.Sleep(300); LogSave.Add(Name, "获取在线关键词产品 " + shopName + ",分页:" + i); } LogSave.Add(Name, "获取完成"); } public void GetRepeatGoodOnline() { ids.Clear(); DelGetGroup(); DelOrder(); if(IsNoVisit) GetOnOrOff(); Shop.VioProduct.Clear(); int mallId = Shop.MallId; string cookies = Shop.Cookies, shopName = Shop.ShopName; string url = "https://mms.pinduoduo.com/vodka/v2/mms/query/display/mall/goodsList"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = "{\"order_by\":\"id:asc\",\"size\":100,\"page\":#page#,\"mall_id\":" + mallId + "}"; string html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); } int allCount = BaseRegex.GetIntJson(ref html, "total"); int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); if (page > 1000) { page = 1000; } for (int i = 0; i < page; i++) { if (i != 0) { html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); if (html.Contains("超过商品数量查询范围,请缩小筛选范围")) break; if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); } if (string.IsNullOrEmpty(html) || !html.Contains("total")) { Thread.Sleep(30 * 1000); html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, cookies, data.Replace("#page#", (i + 1).ToString()), CpsSetAllGoods.getAnti0aon()); } } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\},[\w\W]+?\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; TaobaoProductBase p = new TaobaoProductBase(); p.GoodsId = BaseRegex.GetLongJson(ref list, "id"); p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn"); p.Titlte = BaseRegex.GetMatchRegexString(list, @"[""]goods_name[""][\s]*:[\s]*[""]([^}]+?)[""]"); if (string.IsNullOrEmpty(p.Titlte)) continue; p.CatId = BaseRegex.GetIntJson(ref list, "cat_id"); p.CatId = PinduoduoCatList.GetNewCat3(p.CatId); p.SaleCount = BaseRegex.GetIntJson(ref list, "sold_quantity"); p.ShopName = Shop.ShopName; p.UseShopName = Shop.Name; string price = BaseRegex.GetMatchRegexString(ref list, @"""sku_group_price"":\[([\d]+),"); if (string.IsNullOrEmpty(price)) price = "1000"; p.Price = int.Parse(price) / 100m; if (PinduoduoCatList.CatIds.ContainsKey(p.CatId)) { var c = PinduoduoCatList.CatIds[p.CatId]; p.Cat1 = c.cat1; p.Cat2 = c.cat2; p.Cat3 = c.cat3; p.Cat4 = c.cat4; p.MainCatId = c.main_cat_id; } else { } var mc = BaseRegex.GetMatchRegex(ref list, @"""is_onsale"":([\w\W]+?),"); if (mc == null || mc.Count <= 0) continue; p.OffLine = !bool.Parse(mc[0].Groups[1].Value); ProductChangeDelTemp.Add(p); } Thread.Sleep(300); LogSave.Add(Name, "获取在线产品 " + shopName + ",分页:" + i); } for (int i = 0; i < ProductChangeDelTemp.Count; i++) { var p = ProductChangeDelTemp[i]; var shopname = Shop.ShopName; try { var px = ProductChangeDelTemp.FindAll(pt => pt.GoodsId != p.GoodsId && pt.Titlte == p.Titlte); int count = px.Count+1; if (ids.Contains(p.GoodsId)) continue; bool ishas = false; if (IsNoSold && p.SaleCount > 0) ishas = true; if (IsNoColl && p.favcnt > 0) ishas = true; var pid = pidList.Find(id => id == p.GoodsId); if (pid > 0) ishas = true; if (px.Count>0&&!ishas) { //string tempId = ""; //for (int j = 0; j < px.Count; j++) //{ // tempId += px[j].GoodsId.ToString() + ","; // ids.Add(px[j].GoodsId); //} //p.repeatTitltId = tempId.Substring(0, tempId.Length - 1); if (px.Count>1) { var pxt = ProductChangeDelTemp.FindAll(pt => pt.Titlte == p.Titlte); if (pxt[0].GoodsId == p.GoodsId) continue; } p.repeatTitltId = px[0].GoodsId.ToString(); Shop.VioProduct.Add(p); VioProductControl.ProductDelTemp.Add(p); } if (px.Count > 0 && ishas) { px[0].repeatTitltId = p.GoodsId.ToString(); if (IsNoSold && px[0].SaleCount > 0) continue; if (IsNoColl && px[0].favcnt > 0) continue; pid = pidList.Find(id => id == px[0].GoodsId); if (pid > 0) continue; Shop.VioProduct.Add(px[0]); VioProductControl.ProductDelTemp.Add(px[0]); } } catch { } } } public void DelOrder() { //30天订单量 string url = "https://mms.pinduoduo.com/mars/shop/recentOrderList"; string refere = "https://mms.pinduoduo.com/Pdd.html"; int confirmStartTime = BaseClass.GetTime(DateTime.Parse(DateTime.Now.AddDays(-30).ToString("yyyy-MM-dd 00:00:00"))); int confirmEndTime = BaseClass.GetTime(DateTime.Parse(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 23:59:59"))); int isLucky = -1; string afterSaleType = "1"; int pageNumber = 1; int remarkStatus = -1; int pageSize = 50; string source = "MMS"; string data = "{\"orderType\":0,\"afterSaleType\":" + afterSaleType + ",\"remarkStatus\":" + remarkStatus + ",\"groupStartTime\":" + confirmStartTime + ",\"groupEndTime\":" + confirmEndTime + ",\"pageNumber\":" + pageNumber + ",\"pageSize\":" + pageSize + ",\"source\":\"MMS\"}"; //第一页匹配结果 string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); //30天订单量 int allCount = BaseRegex.GetIntJson(ref html, "totalItemNum"); int page = allCount / 50 + (allCount % 50 > 0 ? 1 : 0); for (int i = 0; i < page; i++) { if (i != 0) { html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data.Replace("#pageNumber#", (i + 1).ToString()), Shop.Cookies); } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; long Id = BaseRegex.GetLongJson(ref list, "goods_id"); var pt = Shop.OnOrOffProduct.Find(op => op != null && op.GoodsId == Id); if (pt != null) { Shop.OnOrOffProduct.Remove(pt); LogSave.Add(Name, "移除有订单 " + pt.GoodsId); } Thread.Sleep(100); } } } public void GetOnOrOff() { if (string.IsNullOrEmpty(PinduoduoAuth.strContent)) { PinduoduoAuth.strContent = GetVisitProductNew.strJs;//FileBase.ReadAllText(path); } string NoCode = ""; string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000"; if (string.IsNullOrEmpty(NoCode)) { string htmlx = GetHtml.Gbk("http://nano.qixiaoke.com/nano.txt"); NoCode = BaseRegex.GetMatchRegexString(ref htmlx, @"([\w\W]+?)-----"); } string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, NoCode, ""); string codex = UploadPinduoduoSet.ExecuteScript(fun2, PinduoduoAuth.strContent); string cookies = Shop.Cookies; string url = "https://mms.pinduoduo.com/sydney/api/goodsDataShow/queryGoodsDetailVOList"; string refere = "https://mms.pinduoduo.com/sycm/goods_effect"; string data = "{\"goodsId\":\"\",\"cate1Id\":\"\",\"cate2Id\":\"\",\"cate3Id\":\"\",\"startDate\":\"" + BaseClass.GetServerTimeString().AddDays(-30).ToString("yyyy-MM-dd") + "\",\"endDate\":\"" + BaseClass.GetServerTimeString().AddDays(-1).ToString("yyyy-MM-dd") + "\",\"queryType\":2,\"sortCol\":0,\"sortType\":1,\"pageNum\":1,\"pageSize\":50,\"crawlerInfo\":\"" + codex + "\"}"; string html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies); int allCount = BaseRegex.GetIntJson(ref html, "totalNum"); int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); for (int i = 1; i <= page; i++) { strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000"; if (string.IsNullOrEmpty(NoCode)) { string htmlx = GetHtml.Gbk("http://nano.qixiaoke.com/nano.txt"); NoCode = BaseRegex.GetMatchRegexString(ref htmlx, @"([\w\W]+?)-----"); } fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, NoCode, ""); codex = UploadPinduoduoSet.ExecuteScript(fun2, PinduoduoAuth.strContent); if (i != 1) { data = "{\"goodsId\":\"\",\"cate1Id\":\"\",\"cate2Id\":\"\",\"cate3Id\":\"\",\"startDate\":\"" + BaseClass.GetServerTimeString().AddDays(-30).ToString("yyyy-MM-dd") + "\",\"endDate\":\"" + BaseClass.GetServerTimeString().AddDays(-1).ToString("yyyy-MM-dd") + "\",\"queryType\":2,\"sortCol\":0,\"sortType\":1,\"pageNum\":" + i + ",\"pageSize\":50,\"crawlerInfo\":\"" + codex + "\"}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); } var m = BaseRegex.GetMatchRegex(ref html, @"\{([^\}]+?)\}"); for (int j = 0; m != null && j < m.Count; j++) { string list = m[j].Groups[0].Value; long Id = BaseRegex.GetLongJson(ref list, "goodsId"); if (!pidList.Contains(Id)) { pidList.Add(Id); LogSave.Add(Name, "流量 " + Id); } } LogSave.Add(Name, "获取 " + Shop.ShopName + " 流量:" + i); Thread.Sleep(100); } } public void DelGetGroup() { GetGroupOrder(); GetGroupOrderWait(); } public void GetGroupOrder() { string url = "https://mms.pinduoduo.com/mars/shop/queryMallExpiredSoonOrders"; string refere = "https://mms.pinduoduo.com/Pdd.html"; string data = ""; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); if (string.IsNullOrEmpty(html) || !html.Contains("\"success\":true")) return; var m = BaseRegex.GetMatchRegex(ref html, @"\{([^\}]+?)\}"); for (int i = 0; i < m.Count; i++) { string list = m[i].Groups[0].Value; if (!list.Contains("goods_id")) continue; long Id = BaseRegex.GetLongJson(ref list, "goods_id"); if (!pidList.Contains(Id)) { pidList.Add(Id); LogSave.Add(Name, "订单 " + Id); } Thread.Sleep(100); } } public void GetGroupOrderWait() { string Cookies = Shop.Cookies; string url = "https://mms.pinduoduo.com/chats/ungroupOrders?pageNo=1&pageSize=20"; string refere = "https://mms.pinduoduo.com/assets/chats/dist/indexMain.html"; string html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, Cookies); if (string.IsNullOrEmpty(html) || !html.Contains("\"orders\"")) return; int all = BaseRegex.GetIntJson(ref html, "total"); int page = all / 20 + (all % 20 > 0 ? 1 : 0); for (int j = 0; j < page; j++) { if (j != 0) { string urlx = url.Replace("pageNo=1", "pageNo=" + (j + 1)); html = GetPostTaobaoHtml.UploadTaobao(urlx, refere, true, Cookies); if (string.IsNullOrEmpty(html) || !html.Contains("\"orders\"")) return; } var m = BaseRegex.GetMatchRegex(ref html, @"\{.*?\}([^\}]+?)\}"); for (int i = 0; i < m.Count; i++) { string list = m[i].Groups[0].Value; if (!list.Contains("goodsId")) continue; long Id = BaseRegex.GetLongJson(ref list, "goodsId"); if (!pidList.Contains(Id)) { pidList.Add(Id); LogSave.Add(Name, "订单 " + Id); } Thread.Sleep(100); } } } public void offGood() { List ids = new List(); if (string.IsNullOrEmpty(PinduoduoAuth.strContent)) { PinduoduoAuth.strContent = GetVisitProductNew.strJs;//FileBase.ReadAllText(path); } string NoCode = ""; string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000"; if (string.IsNullOrEmpty(NoCode)) { string htmlx = GetHtml.Gbk("http://nano.qixiaoke.com/nano.txt"); NoCode = BaseRegex.GetMatchRegexString(ref htmlx, @"([\w\W]+?)-----"); } string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, NoCode, ""); string codex = UploadPinduoduoSet.ExecuteScript(fun2, PinduoduoAuth.strContent); List idsx = new List(); for (int j = 0; j < Shop.VioProduct.Count; j++) { bool isOnline = !Shop.VioProduct[j].OffLine; if (isOnline) { idsx.Add(Shop.VioProduct[j].GoodsId); if (idsx.Count >= 15) { string html = OffShop(idsx); idsx.Clear(); if (html == "error") break; Thread.Sleep(10 * 1000); } } else { var good = Shop.VioProduct[j]; good.Message = "下架商品"; VioProductControl.ProductDelTemp.Add(good); } } if (idsx.Count > 0) { OffShop(idsx); idsx.Clear(); } } public string OffShop(List ids) { if (ids.Count == 0) return ""; StringBuilder pids = new StringBuilder(); for (int i = 0; i < ids.Count; i++) { pids.Append("," + ids[i]); } string GoodsId = pids.ToString(1, pids.Length - 1); string codex = ""; //using (IJsEngine jsEngine = new V8JsEngine()) //{ // jsEngine.Execute(GetProductOnlineClass.JsCodeGetSms); // codex = jsEngine.CallFunction("aaa", "").ToString(); //} string data = "{\"goodsIds\":[" + GoodsId + "],\"crawlerInfo\":\"" + codex + "\"}"; string urlx = "https://mms.pinduoduo.com/vodka/v2/mms/batchOffSale"; string refere = "https://mms.pinduoduo.com"; string html = CpsSetAllGoods.Request_mms_pinduoduo_com(urlx, refere, Shop.Cookies, data, CpsSetAllGoods.getAnti0aon()); if (html.Contains("{\"success\":true")) { string[] l = GoodsId.Split(','); foreach (string s in l) { var good = Shop.VioProduct.Find(p => p.GoodsId == long.Parse(s)); good.Message = "下架成功"; VioProductControl.ProductDelTemp.Add(good); LogSave.Add(Name, "下架产品成功:" + s); } return ""; } if (html.Contains("手速太快了")|| html.Contains("频繁")) { LogSave.Add(Name, Shop.ShopName + "接口调用频繁,请过段时间再操作。"); return "error"; } return ""; } public void DeleteUp() { List ids = new List(); if (string.IsNullOrEmpty(PinduoduoAuth.strContent)) { PinduoduoAuth.strContent = GetVisitProductNew.strJs;//FileBase.ReadAllText(path); } string NoCode = ""; string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000"; if (string.IsNullOrEmpty(NoCode)) { string htmlx = GetHtml.Gbk("http://nano.qixiaoke.com/nano.txt"); NoCode = BaseRegex.GetMatchRegexString(ref htmlx, @"([\w\W]+?)-----"); } string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, NoCode, ""); string codex = UploadPinduoduoSet.ExecuteScript(fun2, PinduoduoAuth.strContent); for (int j = 0; j < Shop.VioProduct.Count; j++) { ids.Add(Shop.VioProduct[j].GoodsId); Shop.VioProduct[j].Message = "删除成功"; if (ids.Count >= 100) { string html = DelGroupIds(ids); if (html.Contains("删除量上限")) { LogSave.Add(Name, "今日删除商品已达上限:" + Shop.ShopName); for (int i = 0; i < ids.Count; i++) { var p = Shop.VioProduct.Find(sp => sp.GoodsId == ids[i]); p.Message = "今日删除商品已达上限"; VioProductControl.ProductDelTemp.Add(p); } return; } for (int i = 0; i < ids.Count; i++) { var p = Shop.VioProduct.Find(sp => sp.GoodsId == ids[i]); VioProductControl.ProductDelTemp.Add(p); } ids.Clear(); LogSave.Add(Name, "删除成功:" + Shop.VioProduct[j].GoodsId); Thread.Sleep(3 * 1000); } } if (ids.Count > 0) { string html = DelGroupIds(ids); if (html.Contains("删除量上限")) { LogSave.Add(Name, "今日删除商品已达上限:" + Shop.ShopName); for (int i = 0; i < ids.Count; i++) { var p = Shop.VioProduct.Find(sp => sp.GoodsId == ids[i]); p.Message = "今日删除商品已达上限"; VioProductControl.ProductDelTemp.Add(p); } return; } for (int i = 0; i < ids.Count; i++) { var p = Shop.VioProduct.Find(sp => sp.GoodsId == ids[i]); VioProductControl.ProductDelTemp.Add(p); } } LogSave.Add(Name, "删除完成"); } public string DelGroupIds(List ids) { if (ids.Count == 0) return ""; StringBuilder pids = new StringBuilder(); for (int i = 0; i < ids.Count; i++) { pids.Append("," + ids[i]); } var d = new DownUpProductExploder("", false, pids.ToString(1, pids.Length - 1)); d.Cookies = Shop.Cookies; d.Name = Name; d.Shop = Shop; string html = d.Delete(); return html; } public void GetUpId() { GetVioAllWord(); for (int i = 0; i < lstgood.Count; i++) { LogSave.Add(Name, "在店铺中查找违规商品:" + lstgood[i]); var up = VioProductControl.UpIds.Find(u => u.GoodsId == lstgood[i]); if (up != null) { Shop.VioProduct.Add(up); VioProductControl.ProductDelTemp.Add(up); } } LogSave.Add(Name, "查找店铺"+Shop.ShopName+"违规商品完成"); } public static List lstgood = new List(); public static void GetUpIdGoodsId() { for (int i = 0; i < BaseClass.UpIds.Count; i++) { //if (BaseClass.UpIds[i] != "pd-1249754292") // continue; string url = BaseClass.LoginApiUrl + "?obj=upshopid/upid&act=get_to"; string data = "up_id=" + BaseClass.UpIds[i] + "" + "&" + UserLogin.GetSignaturex(); string html = GetHtml.PostUtf8(url, data); var m = BaseRegex.GetMatchRegex(ref html, @"{[\w\W]+?}"); LogSave.Add("违规排查", "云端违规上家" + BaseClass.UpIds.Count + "个,当前查找第:" + (i+1)+"个"); for (int j = 0; j < m.Count; j++) { string list = m[j].Groups[0].Value; long goodsId = BaseRegex.GetLongJson(ref list, "pdd_id"); LogSave.Add("违规排查", "从违规上家"+ BaseClass.UpIds[i] + "中,查找到违规商品:" + goodsId); lstgood.Add(goodsId); } Thread.Sleep(200); } } public static void GetUpIdAndGoodsId() { bool had = true; int page = 1; while (had) { string data = UserLogin.GetSignaturex() + ""; string url = BaseClass.BuildObjString("upid&act=getx&page=" + page); string html = GetHtml.PostUtf8(url, data); var m = BaseRegex.GetMatchRegex(ref html, @"({[\s\S]+?})"); LogSave.Add("违规排查", "云端违规获取企业上家Id,第"+page+"页数据"); for (int i = 0; i < m.Count; i++) { var item = m[i].Groups[0].Value; string pid = BaseRegex.GetStringJson(ref item, "product_id");//商品ID string upids = BaseRegex.GetStringJson(ref item, "up_ids");//自定义上家Id string upids2 = BaseRegex.GetStringJson(ref item, "up_ids2");//自定义上家Id2 if ((string.IsNullOrEmpty(upids) && string.IsNullOrEmpty(upids2)) || string.IsNullOrEmpty(pid)) continue; UpProId upProId = new UpProId(); upProId.upProIdOne = upids; upProId.upProIdTwo = upids2; if (UpIdsList.ContainsKey(pid))//如果dictionary 存在相同的key,remove后再添加。 { UpIdsList.Remove(pid); } UpIdsList.Add(pid, upProId); } had = m.Count > 2; page++; } LogSave.Add("违规排查", "云端违规获取企业上家Id数据完成"); } public static List filPidlist = new List(); public static void GetFiltersUpIdAndGoodsId() { filPidlist.Clear(); foreach (KeyValuePair up in UpIdsList) { LogSave.Add("违规排查", "正在过滤违规商品"+up.Key); string pid = UploadPinduoduoMain.RuleIds.Find(r => r == up.Key); if (!string.IsNullOrEmpty(pid)) { filPidlist.Add(pid); } string upProIdOne = UploadPinduoduoMain.RuleIds.Find(r => r == up.Value.upProIdOne); if (!string.IsNullOrEmpty(upProIdOne)) { filPidlist.Add(upProIdOne); filPidlist.Add(up.Key); } string upProIdTwo = UploadPinduoduoMain.RuleIds.Find(r => r == up.Value.upProIdTwo); if (!string.IsNullOrEmpty(upProIdTwo)) { filPidlist.Add(upProIdTwo); filPidlist.Add(up.Key); } } LogSave.Add("违规排查", "云端违规过滤违规商品完成。"); } } public class VioProductControl { public string Name; public ShopChatBase Shop; public int ShopThreadCount = 20; public string delTitle; public static List UpIds = new List(); public static List ProductDelTemp = new List(); public VioProductControl(string name) { Name = name; } public void GetVioKeyWordGoodOnline() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectVio || !shop.Showed) continue; var p = new VioProductGroup(Name, shop); p.delTitle = delTitle; Threadx.ThreadListWait(ref ts, new Thread(p.GetVioKeyWordDel), ShopThreadCount); Thread.Sleep(100); } Threadx.ThreadListWait(ref ts); } public void GetFilterKeyWordGoodOnline() { if (VioProductGroup.UpIdsList.Count == 0) { VioProductGroup.GetUpIdAndGoodsId(); VioProductGroup.GetFiltersUpIdAndGoodsId(); } List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectVio || !shop.Showed) continue; var p = new VioProductGroup(Name, shop); p.delTitle = delTitle; Threadx.ThreadListWait(ref ts, new Thread(p.GetFilterKeyWordDel), ShopThreadCount); Thread.Sleep(100); } Threadx.ThreadListWait(ref ts); } public void GetRepeatGoodOnline() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectVio || !shop.Showed) continue; var p = new VioProductGroup(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.GetRepeatGoodOnline), ShopThreadCount); Thread.Sleep(100); } Threadx.ThreadListWait(ref ts); } public void GetOffGoodOnline() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectVio || !shop.Showed) continue; var p = new VioProductGroup(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.offGood), ShopThreadCount); Thread.Sleep(100); } Threadx.ThreadListWait(ref ts); } public void GetDelGoodOnline() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectVio || !shop.Showed) continue; var p = new VioProductGroup(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.DeleteUp), ShopThreadCount); Thread.Sleep(100); } Threadx.ThreadListWait(ref ts); } public void GetUpId() { VioProductGroup.lstgood.Clear(); VioProductGroup.GetUpIdGoodsId(); List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectVio || !shop.Showed) continue; var p = new VioProductGroup(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.GetUpId), ShopThreadCount); Thread.Sleep(100); } Threadx.ThreadListWait(ref ts); } } }