Files
2025-06-29 19:38:31 +08:00

946 lines
43 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AllBase;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Work.Api;
namespace Work.CollectClass
{
public class JinBaoSpread
{
public static int Rate = 0;
public static int ShopRate = 0;
public static string goodId = "";
public static string Name="多多推广";
public static ShopChatBase Shop;
public static List<ShopChatBase> tempShops = new List<ShopChatBase>();
public static List<GoodRate> tempGoodRate = new List<GoodRate>();
public static string couponStartTime = "";
public static string couponEndTime = "";
public static long discount = 0;
//public static long commissionRate = 0;
public static int couCount = 1;
public static int goodCount = 500;
public static bool stopping = false;
public static int couCountx = 1;
public static long discountx = 0;
public static string couponStartTimex = "";
public static string couponEndTimex = "";
public static void WriteSpread()
{
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
string url = "https://mms.pinduoduo.com/cps/api/edit/editMallUnit";
string refere = "https://mms.pinduoduo.com/exp/mallPromotion";
string data = "{\"rate\":\"" + ShopRate * 10 + "\" }";
//第一页匹配结果
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, shop.Cookies);
if (html.Contains("\"success\":true"))
{
LogSave.Add(Name, "店铺" + shop.ShopName + ",修改后的佣金比率将在第二天0点生效");
}
else
{
string errorMsg = BaseRegex.GetStringJson(ref html, "errorMsg");
LogSave.Add(Name, "店铺" + shop.ShopName+","+ errorMsg + ",修改佣金比率失败");
}
}
}
public static void GoodWriteSpread()
{
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
string html = api.UpdateExtension(goodId,Rate * 10);
if (html.Contains("{\"is_change_success\":true}"))
{
LogSave.Add(Name, "商品" + goodId + ",修改后的佣金比率将在第二天0点生效");
}
else
{
string errorMsg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add(Name, "商品" + goodId + "," + errorMsg + ",修改佣金比率失败");
}
}
public static void CreateWriteSpread()
{
string[] goodsId = goodId.Trim().Replace("\r", "").Split('\n');
string units = "[";
for (int j = 0; j < goodsId.Length; j++)
{
units += "{\"goods_id\":\"" + goodsId[j] + "\",\"rate\":" + Rate * 10 + "},";
}
units = units.Substring(0, units.Length - 1);
units +="]";
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
string html = api.CreateGoodExtension(units);
if (html.Contains("{\"failed_vos\":[]}"))
{
LogSave.Add(Name, "商品" + goodId.Replace("\r", "").Replace("\n", "") + ",开通佣金比率成功");
}
else
{
string errorMsg = BaseRegex.GetStringJson(ref html, "reason");
LogSave.Add(Name, "商品" + goodId.Replace("\r", "").Replace("\n", "") + "开通佣金比率失败,错误原因"+errorMsg);
}
}
public static void OpenSpread()
{
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
string url = "https://mms.pinduoduo.com/cps/api/edit/openMallUnit";
string refere = "https://mms.pinduoduo.com/exp/mallPromotion";
string data = "{\"rate\":\"" + Rate * 10 + "\" }";
//第一页匹配结果
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, shop.Cookies);
if (html.Contains("\"success\":true"))
{
LogSave.Add(Name, "店铺" + shop.ShopName + ",开通多多推广成功,修改后的佣金比率将在第二天0点生效");
Thread.Sleep(10*1000);
}
else
{
string errorMsg = BaseRegex.GetStringJson(ref html, "errorMsg");
LogSave.Add(Name, "店铺" + shop.ShopName + "," + errorMsg + ",开通多多推广失败");
}
}
ReadSpread();
}
public static void OpenGoodSpread()
{
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(shop);
string html = api.CreateJinBaoExtension(ShopRate * 10);
if (html.Contains("\"is_create_success\":true"))
{
LogSave.Add(Name, "店铺" + shop.ShopName + ",开通多多推广成功,修改后的佣金比率将在第二天0点生效");
Thread.Sleep(10 * 1000);
}
else
{
string errorMsg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add(Name, "店铺" + shop.ShopName + "," + errorMsg + ",开通多多推广失败");
}
}
ReadSpread();
}
public static void ReadSpread()
{
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
string url = "https://mms.pinduoduo.com/cps/api/query/queryMallUnit";
string refere = "https://mms.pinduoduo.com/exp/mallPromotion";
string html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, shop.Cookies);
decimal minRate = BaseRegex.GetDecimalJson(ref html, "rate") / 10M;
shop.commission = minRate + "%";
if (minRate==0)
{
shop.commission = "没有开通全店推广";
LogSave.Add(Name, "商铺" + shop.ShopName + ",没有开通全店推广");
}
else
{
LogSave.Add(Name, "商铺" + shop.ShopName + ",佣金比率:" + minRate + "%");
}
tempShops.Add(shop);
Thread.Sleep(1 * 1000);
}
}
public static void apiReadSpread()
{
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
string html=api.JinBaoExtension(goodId);
decimal minRate = BaseRegex.GetDecimalJson(ref html, "rate") / 10M;
string errorMsg = "";
if (minRate == 0)
{
errorMsg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add(Name, "商品" + goodId + ","+errorMsg);
return;
}
else
{
LogSave.Add(Name, "商品" + goodId + ",佣金比率:" + minRate + "%");
}
GoodRate goodRate = new GoodRate();
goodRate.shopName = Shop.ShopName;
goodRate.goodId = goodId;
goodRate.rate = minRate + "%";
goodRate.error = errorMsg;
tempGoodRate.Add(goodRate);
Thread.Sleep(1 * 1000);
}
public static void OpenGoodCoupon()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
JinBaoMarketing.couponStartTime = couponStartTime;
JinBaoMarketing.couponEndTime = couponEndTime;
JinBaoMarketing.discount = discount;
JinBaoMarketing.Rate = Rate;
JinBaoMarketing.couCount = couCount;
JinBaoMarketing.goodCount = goodCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetGoodCoupon), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void OpenSetGoodCoupon()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
JinBaoMarketing.couponStartTime = couponStartTimex;
JinBaoMarketing.couponEndTime = couponEndTimex;
JinBaoMarketing.discount = discountx;
//JinBaoMarketing.Rate = Rate;
JinBaoMarketing.couCount = couCountx;
//JinBaoMarketing.goodCount = goodCount;
Threadx.ThreadListWait(ref ts, new Thread(p.GetSetGoodCoupon), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void OpenShopGoodCoupon()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
JinBaoMarketing.couponStartTime = couponStartTime;
JinBaoMarketing.couponEndTime = couponEndTime;
JinBaoMarketing.discount = discount;
JinBaoMarketing.Rate = Rate;
JinBaoMarketing.couCount = couCount;
JinBaoMarketing.goodCount = goodCount;
JinBaoMarketing.goodId = goodId;
Threadx.ThreadListWait(ref ts, new Thread(p.GetShopGoodCoupon), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void GetGoodSpread()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
Threadx.ThreadListWait(ref ts, new Thread(p.GetGoods), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void GetNoGoodSpread()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
Threadx.ThreadListWait(ref ts, new Thread(p.GetNoGoods), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void GetNoDelGoodSpread()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
Threadx.ThreadListWait(ref ts, new Thread(p.GetNoDelGoods), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
public static void GetCouponSpread()
{
List<Thread> ts = new List<Thread>();
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
{
var shop = GetShopLoginInfo.Shops[i];
if (!shop.SelectPayOrder || !shop.Showed)
continue;
var p = new JinBaoMarketing(Name, shop);
Threadx.ThreadListWait(ref ts, new Thread(p.GetCouponGoods), 20);
Thread.Sleep(100);
}
Threadx.ThreadListWait(ref ts);
}
}
public class JinBaoMarketing
{
public string Name = "";
public ShopChatBase Shop;
public static string couponStartTime = "";
public static string couponEndTime = "";
public static long discount = 0;
public static int Rate = 0;
public static int couCount = 0;
public static int goodCount = 0;
public static string goodId = "";
public static List<TaobaoProductBase> jinBaoTempProduct = new List<TaobaoProductBase>();
//public static List<TaobaoProductBase> jinBaoDelProduct = new List<TaobaoProductBase>();
public static Dictionary<string, List<TaobaoProductBase>> jinBaoDelProduct = new Dictionary<string, List<TaobaoProductBase>>();
public static List<TaobaoProductBase> jinBaoTempDelProduct = new List<TaobaoProductBase>();
public JinBaoMarketing(string name,ShopChatBase shop)
{
this.Name = name;
this.Shop = shop;
}
public void GetGoods()
{
Shop.jinBaoProduct.Clear();
int mallId = Shop.MallId;
string cookies = Shop.Cookies, shopName = Shop.ShopName;
string url = "https://mms.pinduoduo.com/cps/api/mall/goods";
string refere = "https://mms.pinduoduo.com/jinbao/promotion/create?from=nogoods";
string data = "{\"pageNumber\":#page#,\"pageSize\":100}";
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 < 5; 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, "goodsId");
//p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn");
p.Titlte = BaseRegex.GetStringJson(ref list, "goodsName");
p.CatId = BaseRegex.GetIntJson(ref list, "cat_id");
p.ShopName = Shop.ShopName;
int price = BaseRegex.GetIntJson(ref list, "groupPrice");
p.Price = price / 100m;
p.favcnt = JinBaoSpread.Rate;
p.UseShopName = Shop.Name;
//p.jinbaoCount = JinBaoSpread.couCount;
//p.jinbaoAmount = JinBaoSpread.discount;
//商品已经被设置
int wipeOutReason = BaseRegex.GetIntJson(ref list, "wipeOutReason");
if (wipeOutReason == 1)
continue;
jinBaoTempProduct.Add(p);
if (!Shop.jinBaoProduct.Exists(pt => pt != null && pt.GoodsId == p.GoodsId))
Shop.jinBaoProduct.Add(p);
}
Thread.Sleep(300);
LogSave.Add(Name, "获取在线产品 " + shopName + ",分页:" + i);
}
LogSave.Add(Name, "获取完成");
}
public void GetNoGoods()
{
if (jinBaoDelProduct.ContainsKey(Shop.ShopName))
jinBaoDelProduct.Remove(Shop.ShopName);
List<TaobaoProductBase> jinbaolst = new List<TaobaoProductBase>();
int mallId = Shop.MallId;
string cookies = Shop.Cookies, shopName = Shop.ShopName;
string url = "https://mms.pinduoduo.com/cps/api/query/unitList";
string refere = "https://mms.pinduoduo.com/jinbao/promotion/index";
string data = "{\"pageSize\":100,\"pageNumber\":#page#,\"currentPage\":#page#}";
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, @"{""id"":[\w\W]+?""hasCoupon""");
for (int j = 0; m != null && j < m.Count; j++)
{
string list = m[j].Groups[0].Value;
TaobaoProductBase p = new TaobaoProductBase();
p.GoodsSn= BaseRegex.GetLongJson(ref list, "id");
p.GoodsId = BaseRegex.GetLongJson(ref list, "goodsId");
//p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn");
p.Titlte = BaseRegex.GetStringJson(ref list, "goodsName");
p.ShopName = Shop.ShopName;
p.UseShopName = Shop.Name;
int price = BaseRegex.GetIntJson(ref list, "groupPrice");
p.Price = price / 100m;
p.favcnt = BaseRegex.GetIntJson(ref list, "commissionRate")/10;
//商品已经被设置
int onSale = BaseRegex.GetIntJson(ref list, "onSale");
if (onSale == 1)
continue;
p.Message = "未达标";
jinBaoTempDelProduct.Add(p);
if (!jinbaolst.Exists(pt => pt != null && pt.GoodsId == p.GoodsId))
jinbaolst.Add(p);
}
Thread.Sleep(300);
LogSave.Add(Name, "获取在线产品 " + shopName + ",分页:" + i);
}
jinBaoDelProduct.Add(Shop.ShopName, jinbaolst);
LogSave.Add(Name, "获取完成");
}
public void GetCouponGoods()
{
if (jinBaoDelProduct.ContainsKey(Shop.ShopName))
jinBaoDelProduct.Remove(Shop.ShopName);
List<TaobaoProductBase> jinbaolst = new List<TaobaoProductBase>();
int mallId = Shop.MallId;
string cookies = Shop.Cookies, shopName = Shop.ShopName;
string url = "https://mms.pinduoduo.com/cps/api/query/unitList";
string refere = "https://mms.pinduoduo.com/jinbao/promotion/index";
string data = "{\"pageSize\":100,\"pageNumber\":#page#,\"currentPage\":#page#}";
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 < 2; 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]+?""hasCoupon""[^>]+?");
for (int j = 0; m != null && j < m.Count; j++)
{
string list = m[j].Groups[0].Value;
TaobaoProductBase p = new TaobaoProductBase();
p.GoodsSn = BaseRegex.GetLongJson(ref list, "id");
p.GoodsId = BaseRegex.GetLongJson(ref list, "goodsId");
//p.GoodsSn = BaseRegex.GetLongJson(ref list, "goods_sn");
p.Titlte = BaseRegex.GetStringJson(ref list, "goodsName");
p.ShopName = Shop.ShopName;
p.UseShopName = Shop.Name;
//p.jinbaoCount = JinBaoSpread.couCountx;
//p.jinbaoAmount = JinBaoSpread.discountx;
int price = BaseRegex.GetIntJson(ref list, "groupPrice");
p.Price = price / 100m;
p.favcnt = BaseRegex.GetIntJson(ref list, "commissionRate") / 10;
//商品已经被设置
int remainQuantity = BaseRegex.GetIntJson(ref list, "remainQuantity");
if (remainQuantity == 1)
continue;
p.Message = "添加优惠券";
jinBaoTempDelProduct.Add(p);
if (!jinbaolst.Exists(pt => pt != null && pt.GoodsId == p.GoodsId))
jinbaolst.Add(p);
}
Thread.Sleep(300);
LogSave.Add(Name, "获取在线产品 " + shopName + ",分页:" + i);
}
jinBaoDelProduct.Add(Shop.ShopName, jinbaolst);
LogSave.Add(Name, "获取完成");
}
public void GetNoDelGoods()
{
if (!jinBaoDelProduct.ContainsKey(Shop.ShopName))
return;
var jinbaolst = jinBaoDelProduct[Shop.ShopName];
for (int i = 0; i < jinbaolst.Count; i++)
{
string url = "https://mms.pinduoduo.com/cps/api/edit/delete";
string refere = "https://mms.pinduoduo.com/jinbao/promotion/index";
string data = "{\"id\":"+ jinbaolst[i].GoodsSn + ",\"goodsId\":"+ jinbaolst[i].GoodsId+ "}";
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data.Replace("#page#", "1"), Shop.Cookies);
LogSave.Add(Name, jinbaolst[i].GoodsId + "正在删除");
if (!html.Contains("\"success\":true"))
{
string errorMsg = BaseRegex.GetStringJson(ref html, "errorMsg");
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = jinbaolst[i].GoodsId;
p.Message = errorMsg;
jinBaoTempProduct.Add(p);
}
else
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = jinbaolst[i].GoodsId;
p.Message = "未达标删除成功";
jinBaoTempProduct.Add(p);
}
Thread.Sleep(1000);
}
}
public void GetGoodCoupon2()
{
string subtemp = "";
string temp = "";
int count = 0;
for (int i = 0; !JinBaoSpread.stopping && i < Shop.jinBaoProduct.Count; i++)
{
if (count >= goodCount)
{
count = 0;
break;
}
var product = Shop.jinBaoProduct[i];
if (product.Uped)
continue;
Shop.jinBaoProduct[i].Uped = true;
long goodsPrice = (long)product.Price;
long goodsId = product.GoodsId;
string url = "https://mms.pinduoduo.com/cps/api/coupon/queryGoodsCouponLimit";
string refere = "https://mms.pinduoduo.com/jinbao/promotion/create";
string data = "{\"goodsIds\":[" + goodsId + "],\"type\":1}";
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
{
Thread.Sleep(2 * 1000);
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
continue;
}
long maxCoupon = BaseRegex.GetLongJson(ref html, "maxCoupon") / 1000;
if (discount > maxCoupon)
discount = maxCoupon;
//Thread.Sleep(2 * 1000);
url = "https://mms.pinduoduo.com/cps/api/coupon/createCommonCoupon";
refere = "https://mms.pinduoduo.com/jinbao/promotion/create?from=nogoods";
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(000000, 999999);
data = "{\"minOrderAmount\":0,\"couponDesc\":\"" + randx + "\",\"couponStartTime\":\"" + couponStartTime
+ "\",\"couponEndTime\":\"" + couponEndTime
+ "\",\"discount\":" + discount * 1000 + ",\"initQuantity\":" + couCount + ",\"userLimit\":1,\"goodsPrice\":" + goodsPrice
+ ",\"goodsId\":" + goodsId + "}";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
{
Thread.Sleep(2 * 1000);
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
continue;
}
long couponId = BaseRegex.GetLongJson(ref html, "batchId");
url = "https://mms.pinduoduo.com/cps/api/coupon/checkCouponInfo";
refere = "https://mms.pinduoduo.com/jinbao/promotion/create?from=nogoods";
data = "{\"goodsId\":" + goodsId + ",\"couponId\":" + couponId + "}";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
{
Thread.Sleep(2 * 1000);
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
continue;
}
subtemp += ",{\"goodsId\":" + goodsId + ",\"commissionRate\":" + Rate * 10 + ",\"couponId\":" + couponId + ",\"isVerify\":true}";
temp += "," + goodsId;
LogSave.Add(Name, goodsId + "正在生成优惠券");
count++;
Thread.Sleep(2 * 1000);
}
string urlx = "https://mms.pinduoduo.com/cps/api/edit/createCommonUnit/twoConfirm";
string referex = "https://mms.pinduoduo.com/jinbao/promotion/create";
string datax = "{\"units\":[" + subtemp.Substring(1) + "]}";
string htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies);
if (!htmlx.Contains("\"success\":true"))
{
Thread.Sleep(2 * 1000);
htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies);
if (!htmlx.Contains("\"success\":true"))
return;
}
urlx = "https://mms.pinduoduo.com/cps/api/edit/createCommonUnit";
referex = "https://mms.pinduoduo.com/jinbao/promotion/create?from=nogoods";
datax = "{\"units\":[" + subtemp.Substring(1) + "],\"isVerifyRatePrice\":true,\"isVerifyMultiEvent\":true}";
htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies);
string[] goodData = temp.Substring(1).Split(',');
if (!htmlx.Contains("\"success\":true"))
{
Thread.Sleep(2 * 1000);
htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies);
}
if (!htmlx.Contains("\"success\":true"))
{
for (int i = 0; i < goodData.Length; i++)
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = long.Parse(goodData[i]);
p.Message = "推广失败";
jinBaoTempProduct.Add(p);
}
return;
}
for (int i = 0; i < goodData.Length; i++)
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = long.Parse(goodData[i]);
p.Message = "推广成功";
jinBaoTempProduct.Add(p);
}
}
public void GetShopGoodCoupon()
{
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
string[] goodsIdx = JinBaoSpread.goodId.Trim().Replace("\r", "").Split('\n');
for (int i = 0; i < goodsIdx.Length; i++)
{
if (string.IsNullOrEmpty(goodsIdx[i]))
continue;
long goodsId =long.Parse(goodsIdx[i]);
api.Data.Clear();
api.Data.Add("batch_desc", "设置优惠券");
api.Data.Add("batch_start_time", couponStartTime);
api.Data.Add("batch_end_time", couponEndTime);
api.Data.Add("discount", (discount * 100).ToString());
api.Data.Add("init_quantity", couCount.ToString());
api.Data.Add("user_limit", "1");
api.Data.Add("goods_id", goodsId.ToString());
string html = api.CreateProCoupon();
if (html.Contains("不可重复设置"))
continue;
LogSave.Add(Name, goodsId + "正在生成优惠券");
long batch_id = BaseRegex.GetLongJson(ref html, "batch_id");
if (batch_id <= 0)
continue;
api.Data.Clear();
string units = "[{\"goods_id\":" + goodsId + ",\"rate\":10,\"coupon_id\":" + batch_id
+ ",\"coupon_start_time\":\"" + couponStartTime + "\",\"coupon_end_time\":\""
+ couponEndTime + "\",\"discount\":" + discount * 100
+ ",\"init_quantity\":" + couCount + "}]";
html = api.CreateGoodExtension(units);
if (html.Contains("不可重复设置"))
continue;
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(2 * 1000);
html = api.CreateGoodExtension(units);
}
if (html.Contains("error_msg"))
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.UseShopName = Shop.Name;
p.GoodsId = goodsId;
p.jinbaoCount = JinBaoSpread.couCount;
p.jinbaoAmount = JinBaoSpread.discount;
p.Message = "推广失败";
jinBaoTempProduct.Add(p);
}
else
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.UseShopName = Shop.Name;
p.GoodsId = goodsId;
p.jinbaoCount = JinBaoSpread.couCount;
p.jinbaoAmount = JinBaoSpread.discount;
p.Message = "推广成功";
jinBaoTempProduct.Add(p);
}
}
}
public void GetGoodCoupon()
{
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
int count = 0;
for (int i = 0; !JinBaoSpread.stopping && i < Shop.jinBaoProduct.Count; i++)
{
if (count >= goodCount)
{
count = 0;
break;
}
var product = Shop.jinBaoProduct[i];
//long goodsPrice = (long)(product.Price * 1000);
long goodsId = product.GoodsId;
api.Data.Clear();
api.Data.Add("batch_desc", "设置优惠券");
api.Data.Add("batch_start_time", couponStartTime);
api.Data.Add("batch_end_time", couponEndTime);
api.Data.Add("discount", (discount * 100).ToString());
api.Data.Add("init_quantity", couCount.ToString());
api.Data.Add("user_limit", "1");
api.Data.Add("goods_id", goodsId.ToString());
string html = api.CreateProCoupon();
if (html.Contains("不可重复设置"))
continue;
LogSave.Add(Name, goodsId + "正在生成优惠券");
long batch_id = BaseRegex.GetLongJson(ref html, "batch_id");
if (batch_id <= 0)
continue;
api.Data.Clear();
string units = "[{\"goods_id\":"+ goodsId + ",\"rate\":10,\"coupon_id\":" + batch_id
+ ",\"coupon_start_time\":\"" + couponStartTime + "\",\"coupon_end_time\":\""
+ couponEndTime + "\",\"discount\":" + discount * 100
+ ",\"init_quantity\":" + couCount + "}]";
html = api.CreateGoodExtension(units);
if (html.Contains("不可重复设置"))
continue;
if (html.Contains("调用过于频繁"))
{
Thread.Sleep(3 * 1000);
html = api.CreateGoodExtension(units);
}
count++;
if (html.Contains("error_msg"))
{
string errorMsg = BaseRegex.GetStringJson(ref html, "error_msg");
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = goodsId;
p.jinbaoCount = JinBaoSpread.couCount;
p.jinbaoAmount = JinBaoSpread.discount;
p.Message = errorMsg;
jinBaoTempProduct.Add(p);
}
else
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = goodsId;
p.jinbaoCount = JinBaoSpread.couCount;
p.jinbaoAmount = JinBaoSpread.discount;
p.Message = "推广成功";
jinBaoTempProduct.Add(p);
}
//Thread.Sleep(10 * 1000);
}
}
public void GetSetGoodCoupon()
{
if (!jinBaoDelProduct.ContainsKey(Shop.ShopName))
return;
var jinbaolst = jinBaoDelProduct[Shop.ShopName];
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
for (int i = 0; i < jinbaolst.Count; i++)
{
//string url = "https://mms.pinduoduo.com/cps/api/coupon/createCommonCoupon";
//string refere = "https://mms.pinduoduo.com/jinbao/promotion/index";
//api.Data.Clear();
//api.Data.Add("batch_desc", "设置优惠券");
//api.Data.Add("batch_start_time", couponStartTime);
//api.Data.Add("batch_end_time", couponEndTime);
//api.Data.Add("discount", (discount * 100).ToString());
//api.Data.Add("init_quantity", couCount.ToString());
//api.Data.Add("user_limit", "1");
//api.Data.Add("goods_id", goodsId.ToString());
//string html = api.CreateProCoupon();
//if (html.Contains("不可重复设置"))
// continue;
//LogSave.Add(Name, goodsId + "正在生成优惠券");
//long batch_id = BaseRegex.GetLongJson(ref html, "batch_id");
//if (batch_id <= 0)
// continue;
long goodsId = jinbaolst[i].GoodsId;
long goodsPrice = (long)(jinbaolst[i].Price * 1000);
string url = "https://mms.pinduoduo.com/cps/api/coupon/createCommonCoupon";
string refere = "https://mms.pinduoduo.com/jinbao/promotion/create?from=nogoods";
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(000000, 999999);
string data = "{\"minOrderAmount\":0,\"couponDesc\":\"" + randx + "\",\"couponStartTime\":\"" + couponStartTime
+ "\",\"couponEndTime\":\"" + couponEndTime
+ "\",\"discount\":" + discount * 1000 + ",\"initQuantity\":" + couCount + ",\"userLimit\":1,\"goodsPrice\":" + goodsPrice
+ ",\"goodsId\":" + goodsId + "}";
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
{
Thread.Sleep(2 * 1000);
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
if (!html.Contains("\"success\":true"))
continue;
}
long couponId = BaseRegex.GetLongJson(ref html, "batchId");
url = "https://mms.pinduoduo.com/cps/api/coupon/use";
refere = "https://mms.pinduoduo.com/jinbao/promotion/index";
data = "{\"goodsId\":" + goodsId + ",\"couponId\":" + couponId + ",\"type\":1}";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
LogSave.Add(Name, jinbaolst[i].GoodsId + "正在设置优惠券");
if (!html.Contains("\"success\":true"))
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.UseShopName = Shop.Name;
p.jinbaoCount = JinBaoSpread.couCountx;
p.jinbaoAmount = JinBaoSpread.discountx;
p.GoodsId = jinbaolst[i].GoodsId;
p.Message = "设置优惠券失败";
jinBaoTempProduct.Add(p);
}
else
{
TaobaoProductBase p = new TaobaoProductBase();
p.ShopName = Shop.ShopName;
p.GoodsId = jinbaolst[i].GoodsId;
p.UseShopName = Shop.Name;
p.jinbaoCount = JinBaoSpread.couCountx;
p.jinbaoAmount = JinBaoSpread.discountx;
p.Message = "设置优惠券成功";
jinBaoTempProduct.Add(p);
}
Thread.Sleep(5*1000);
}
}
}
public class GoodRate
{
public string shopName = "";
public string UseShopName = "";
public string goodId = "";
public string rate = "";
public string error = "";
}
}