using AllBase; using System; using System.Collections.Generic; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Work.Api; using Work.ManageClass; namespace Work.CollectClass { public class ProductCheckControl { public string Name; public static int threadCount = 5; public static bool Running = false; public static int goodCount = 0; public static bool isCount = false; public static int start = 0; public static int end = 0; public static string pid = ""; public static List dicShopCount = new List(); public static List ShopProductCheckDetailList = new List(); public static List ShopProductCheckDetailList2 = new List(); public static List ProductStatusList = new List(); public ProductCheckControl(string name) { Name = name; } public void Get() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectProductCheck || shop.Message == "会话已过期") continue; var p = new ProductCheckDetailLogic(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.Get), threadCount); Thread.Sleep(1000); } Threadx.ThreadListWait(ref ts); } public void Off() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectProductCheck || shop.Message == "会话已过期") continue; var p = new ProductCheckDetailLogic(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.Off), threadCount); Thread.Sleep(1000); } Threadx.ThreadListWait(ref ts); } public void Del() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectProductCheck || shop.Message == "会话已过期") continue; var p = new ProductCheckDetailLogic(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.Del), threadCount); Thread.Sleep(1000); } Threadx.ThreadListWait(ref ts); } } public class ProductCheckDetailLogic { public string Name; public ShopChatBase Shop; public int count; public ProductCheckDetailLogic(string Name, ShopChatBase Shop) { this.Name = Name; this.Shop = Shop; } public void Off() { var api = new PinduoduoApiGetProduct(Shop); string html = api.SetOnline(long.Parse(ProductCheckControl.pid), false); if (!html.Contains("\"is_success\":true")) { Thread.Sleep(2000); html = api.SetOnline(long.Parse(ProductCheckControl.pid), false); } ProductStaus status = new ProductStaus(); status.goodId = ProductCheckControl.pid; if (html.Contains("\"is_success\":true")) { status.OffStatus = "下架成功"; ProductCheckControl.ProductStatusList.Add(status); LogSave.Add(Name, ProductCheckControl.pid + "下架成功"); } else { status.OffStatus = "下架失败"; ProductCheckControl.ProductStatusList.Add(status); LogSave.Add(Name, ProductCheckControl.pid + "下架失败"); } } public void Del() { string url = "https://mms.pinduoduo.com/plutus/api/plutus/bin/goods/delete/batch"; string refere = "http://mms.pinduoduo.com/Pdd.html"; string data = "{\"goods_ids\":[" + ProductCheckControl.pid + "],\"mall_id\":" + Shop.MallId + ",\"creator\":\"" + Shop.ShopName + "\",\"creator_id\":" + Shop.ReceiverId + "}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); if (html.Contains("商品仍在售")) { Off(); html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); } ProductStaus status = new ProductStaus(); status.goodId = ProductCheckControl.pid; if (html.Contains("\"success\":true")) { status.DelStatus = "删除成功"; ProductCheckControl.ProductStatusList.Add(status); LogSave.Add(Name, ProductCheckControl.pid + "删除成功"); } else { status.DelStatus = "删除失败"; ProductCheckControl.ProductStatusList.Add(status); LogSave.Add(Name, ProductCheckControl.pid + "删除失败"); } } public void Get() { GetAllOnlineCount(); int sub = ProductCheckControl.end - ProductCheckControl.start + 1; 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\",\"is_onsale\":1,\"size\":"+sub+",\"page\":#page#,\"mall_id\":" + Shop.MallId + "}"; string html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", "1"), CpsSetAllGoods.getAnti0aon()); //GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), Shop.Cookies); 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"); if (allCount< ProductCheckControl.start) { LogSave.Add(Name, "当前店铺最大在线商品数量为 " + allCount+",请停止操作下一步按钮"); return; } //int page = allCount / 100 + (allCount % 100 > 0 ? 1 : 0); //if (page > 1000) //{ // page = 1000; //} int i = ProductCheckControl.end / sub; if (i > 1) { html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data.Replace("#page#", (i).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).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).ToString()), CpsSetAllGoods.getAnti0aon()); } } var m = BaseRegex.GetMatchRegex(ref html, @"\{([\w\W]+?)\},[\w\W]+?\}"); for (int j = 0; m != null && j < m.Count; j++) { while (ProductCheckControl.Running) { Thread.Sleep(3000); continue; } string list = m[j].Groups[0].Value; ProductCheckDetail p = new ProductCheckDetail(); p.goodId = BaseRegex.GetStringJson(ref list, "id"); if (string.IsNullOrEmpty(p.goodId)) continue; p.goodName = BaseRegex.GetStringJson(ref list, "goods_name"); string urlx = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/on_shop/detail"; string datax = "{\"goods_id\":" + p.goodId + "}"; string htmlx = GetPostTaobaoHtml.GetJsonPost(urlx, "", true, datax, Shop.Cookies); string temp = BaseRegex.GetMatchRegexString(ref htmlx, @"""carousel_gallery"":\[(.*?)\]"); var mc = BaseRegex.GetMatchRegex(ref temp, @"""url"":""([^""]+?)"""); for (int k = 0; k < mc.Count; k++) { string imgx = mc[k].Groups[1].Value.Replace("@750w_1l_50Q", ""); if (imgx.Contains("?")) imgx = imgx.Substring(0, imgx.IndexOf("?")); p.imgUrlList.Add(imgx); } for (int q = 0; q < p.imgUrlList.Count; q++) { byte[] img; try { GetPostTaobaoHtml.DownLoadImage(p.imgUrlList[q], out img); if (img==null) { Thread.Sleep(2000); GetPostTaobaoHtml.DownLoadImage(p.imgUrlList[q], out img); } using (Stream stream = new MemoryStream(img)) { p.imagePdd[q] = Image.FromStream(stream, true); stream.Close(); stream.Dispose(); //释放占用资源 } p.imglist.Add(img); } catch { } } System.GC.Collect();//垃圾回收 if (!ProductCheckControl.ShopProductCheckDetailList.Exists(pt => pt != null && pt.goodId == p.goodId)) { ProductCheckControl.ShopProductCheckDetailList.Add(p); ProductCheckControl.ShopProductCheckDetailList2.Add(p); count++; LogSave.Add(Name, "获取在线产品 " + p.goodId); } else { } } } public void GetAllOnlineCount() { 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:desc\",\"is_onsale\":1,\"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()); } int allCount = BaseRegex.GetIntJson(ref html, "total"); KeyValueBase pair = new KeyValueBase (Shop.ShopName,allCount.ToString()); ProductCheckControl.dicShopCount.Add(pair); } } public class ProductCheckDetail { public string goodId = ""; public string goodName = ""; public List imgUrlList = new List(); public List imglist=new List(); public Image[] imagePdd = new Image[10]; } public class ProductStaus { public string goodId = ""; public string OffStatus = ""; public string DelStatus = ""; } }