Files
KJD_WebService/Work/Api/UploadPinduoduoDeleteSku.cs
T

1006 lines
61 KiB
C#

using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using AllBase;
using Work.CollectClass;
using System.IO;
namespace Work.Api
{
public class UploadPinduoduoDeleteSku
{
public ShopChatBase Shop;
public string Name;
public TaobaoProductBase Us;
public ProductCollectBase pb = null;
public string SkuString;
public string SkuStringApi;
public long NewUpId = 0;
public decimal MinPrice = 0, MaxPrice = 0;
public Dictionary<string, string> Data = new Dictionary<string, string>();
public bool CanUpload = true;
public int Cat1 = 0;
public long pid = 0;
public string title = "";
public string skus = "";
public UploadPinduoduoDeleteSku(string name, ShopChatBase shop, TaobaoProductBase us, string sku, string skuApi)
{
Name = name;
Shop = shop;
Us = us.Clone();
SkuString = sku;
SkuStringApi = skuApi;
}
public UploadPinduoduoDeleteSku()
{
}
public bool GetNew()
{
Us.FromId = Us.GoodsId;
GetProductDetail ge = new GetProductDetail(Shop, Name);
var r = ge.Get(Us.GoodsId);
if (r == null)
return false;
string apiImageString = "";
for (int i = 0; i < r.carousel_gallery_list.Count && i < 1; i++)
{
apiImageString += ",\"" + r.carousel_gallery_list[i] + "\"";
}
if (Data.ContainsKey("carousel_gallery") && !string.IsNullOrEmpty(Data["carousel_gallery"]) && Data["carousel_gallery"].Contains(",") && !string.IsNullOrEmpty(apiImageString))
{
string[] l = Data["carousel_gallery"].Replace("\"", "").Replace("[", "").Replace("]", "").Split(',');
for (int i = 0; i < l.Length && i < 9; i++)
{
apiImageString += ",\"" + l[i] + "\"";
}
Data["carousel_gallery"] = "[" + apiImageString.Substring(1) + "]";
}
Data["thumb_url"] = r.thumb_url;
Data["image_url"] = r.image_url;
Data["cat_id"] = r.cat_id.ToString();
string mustCode = "";
string properties = UploadPinduoduoProperties.GetNew(r.cat_id, 0, ref pb, ref Shop, out mustCode);
if (!Data.ContainsKey("goods_properties"))
Data.Add("goods_properties", "");
if (!string.IsNullOrEmpty(mustCode))
Data["goods_properties"] = "[" + mustCode.Substring(1) + "]";
else
Data["goods_properties"] = "";
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
api.Data = Data;
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return false;
string html = api.UpdataNew();
if (html.Contains("惩罚") || html.Contains("新协议") || html.Contains("协议已更新") || html.Contains("高风险店铺") || html.Contains("配送地区") || html.Contains("店铺资质") && !html.Contains("出于监管要求") ||
html.Contains("通过审核"))
{
string msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
MessageBox.Show("店铺:" + Shop.ShopName + " 错误:\r\n" + msg);
CanUpload = false;
return false;
}
if (!string.IsNullOrEmpty(BaseRegex.GetStringJson(ref html, "error_msg")))
return false;
long goods_commit_id = BaseRegex.GetLongJson(ref html, "goods_commit_id");
api = new PinduoduoApiGetProduct(Shop);
long upid = 0;
html = api.GetRelation(r.goods_id.ToString());
// 有获取到对应的上家id
if (html.Contains("out_goods_id") && html.Contains("out_goods_platform"))
upid = BaseRegex.GetLongJson(ref html, "out_goods_id");
else
upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10, 99999);
html = api.Relation(Us.GoodsId, upid, (int)(MinPrice * 0.96m), (int)(MaxPrice * 0.96m), 0, 0);
Thread.Sleep(500);
int goods_status = 1;
for (int i = 0; goods_commit_id > 0 && i < 600 && goods_status == 1; i++)
{
html = new PinduoduoApiGetProduct(Shop).GetCommitDetail(goods_commit_id);
goods_status = BaseRegex.GetIntJson(ref html, "goods_status");
if (goods_status == 1)
Thread.Sleep(1 * 1000);
}
if (goods_commit_id > 0)
new PinduoduoApiGetProduct(Shop).DeleteCommitDetail(goods_commit_id);
if (goods_status != 2 && goods_status != 4)
return false;
return true;
//模拟接口
if (Shop.UpCount++ > 150)
{
LogSave.Add(Name, "店铺" + Shop.ShopName + ",上传数据已经达到上限");
return false;
}
long pinId;
string error_msg;
string addContent = "";
string url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/create_by_sn";
string refere = "https://mms.pinduoduo.com/Pdd.html";
string data = "{\"goods_id\":" + Us.GoodsId + "}";
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
pinId = BaseRegex.GetLongJson(ref html, "goods_commit_id");
if (pinId == 0)
{
Thread.Sleep(30 * 1000);
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
pinId = BaseRegex.GetLongJson(ref html, "goods_commit_id");
}
if (!string.IsNullOrEmpty(html) && html.Contains("达到上限"))
{
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
Shop.CanUpload = false;
Shop.Message = error_msg;
UploadPinduoduoMain.ShopTemp.Add(Shop);
Error("提交异常:" + r.goods_name, error_msg);
return false;
}
if (pinId == 0)
{
Error("创建异常:" + r.goods_name + " 无法获取编辑ID ", "无法获取编辑ID");
return false;
}
if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + Cat1 + ","))//食品
{
addContent += ",\"shelf_life\":300,\"start_production_date\":" + BaseClass.GetTime(DateTime.Now.AddDays(-5)) + ",\"end_production_date\":" + BaseClass.GetTime(DateTime.Now);
}
else
{
addContent += ",\"shelf_life\":\"\",\"start_production_date\":\"\",\"end_production_date\":\"\"";
}
string propertiesx = UploadPinduoduoProperties.GetNew(pb.cat_id, Cat1, ref pb, ref Shop, out mustCode);
if (!string.IsNullOrEmpty(propertiesx))
{
propertiesx = "[" + propertiesx.Substring(1) + "]";
}
//string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000";
//string str = "";
//for (int i = 0; i < 16; i++)
//{
// str += new Random(Guid.NewGuid().GetHashCode()).Next(9);
//}
//string strToken = str + "-" + strTime;
//string strNumber = "";
//string temp2 = strTime + "," + strToken + "," + strNumber;
//string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, strToken, strNumber);
//string codex = ExecuteScript(fun2, strContent);
string codex = "";
//using (IJsEngine jsEngine = new V8JsEngine())
//{
// jsEngine.Execute(GetProductOnlineClass.JsCodeGetSms);
// codex = jsEngine.CallFunction("aaa", "").ToString();
//}
string dataUp = "{\"cat_id\":" + r.cat_id + ",\"crawlerInfo\":\"" + codex + "\",\"goods_type\":\"1\",\"country\":\"\",\"country_id\":\"\"," +
"\"warehouse\":\"\",\"customs\":\"\",\"is_customs\":0,\"is_pre_sale\":0,\"pre_sale_time\":\"\"," +
"\"is_refundable\":1,\"shipment_limit_second\":172800,\"event_type\":\"0\",\"is_folt\":\"1\"," +
"\"goods_name\":\"" + pb.name + "\",\"tiny_name\":\"" + Data["tiny_name"] + "\",\"market_price\":" + Data["market_price"] +
",\"share_desc\":\"" + Data["goods_desc"] + ":\",\"goods_desc\":\"" + Data["goods_desc"] + "\"," +
"\"image_url\":\"\",\"thumb_url\":\"" + Data["thumb_url"] + "\",\"hd_thumb_url\":\"" + Data["hd_thumb_url"] + "\"," +
"\"gallery\":[" + Data["gallery"] + "],\"cost_template_id\":\"" + Shop.ExpressId.ToString() + "\",\"weight\":\"1.00\",\"warm_tips\":\"\"," +
"\"skus\":" + skus + ",\"out_goods_sn\":\"" + Data["out_goods_id"] + "\",\"groups\":{\"customer_num\":" + UploadPinduoduoMain.GroupCount + "," +
"\"buy_limit\":" + UploadPinduoduoMain.BuyLimit + ",\"order_limit\":" + UploadPinduoduoMain.OrderLimit
+ "},\"production_license\":\"\",\"production_standard_number\":\"\"" + addContent + ",\"goods_commit_id\":\"" + pinId + "\"}";
if (!string.IsNullOrEmpty(propertiesx))
{
dataUp += ",\"goods_properties\":" + propertiesx + "";
}
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/update";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
error_msg += BaseRegex.GetStringJson(ref html, "sub_msg");
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":"))
{
Thread.Sleep(20 * 1000);
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("规格错误"))
{
Error("保存异常:" + r.goods_name + " " + error_msg, error_msg);
return false;
}
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("过于频繁"))
{
LogSave.Add(Name, "太快了,休眠1分钟");
Thread.Sleep(100 * 1000);
}
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
}
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":true"))
{
Thread.Sleep(20 * 1000);
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("过于频繁"))
Thread.Sleep(100 * 1000);
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
error_msg += BaseRegex.GetStringJson(ref html, "sub_msg");
}
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":true"))
{
Error("保存异常:" + r.goods_name + " " + error_msg, error_msg);
return false;
}
url = "https://mms.pinduoduo.com/glide/v2/mms/query/goods/is_commit_available/" + pinId;
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":true"))
{
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("过于频繁"))
Thread.Sleep(100 * 1000);
Thread.Sleep(10 * 1000);
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
}
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":true"))
{
Error("保存异常,校验失败:" + r.goods_name, error_msg);
return false;
}
url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/detail/" + pinId;
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", Shop.Cookies);
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/submit";
//using (IJsEngine jsEngine = new V8JsEngine())
//{
// jsEngine.Execute(GetProductOnlineClass.JsCodeGetSms);
// codex = jsEngine.CallFunction("aaa", "").ToString();
//}
data = "{\"goods_commit_id\":\"" + pinId + "\",\"crawlerInfo\":\"" + codex + "\"}";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":true"))
{
if (!string.IsNullOrEmpty(error_msg) && error_msg.ToLower().Contains("sku"))
{
Error("提交异常:" + r.goods_name, error_msg);
return false;
}
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("敏感词"))
{
Error("提交异常:" + r.goods_name, error_msg);
return false;
}
//if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("账号安全"))
//{
// FullToday = true;
// Shop.CanUpload = false;
// Error("提交异常:" + t.Titlte, error_msg);
// return;
//}
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("数量上限"))
{
Shop.CanUpload = false;
Error("提交异常:" + r.goods_name, error_msg);
return false;
}
if (!string.IsNullOrEmpty(error_msg) && (error_msg.Contains("二级惩罚") || error_msg.Contains("店铺资质") || error_msg.Contains("通过审核")))
{
Shop.CanUpload = false;
Error("提交异常:" + r.goods_name, error_msg);
return false;
}
Thread.Sleep(10 * 1000);
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (string.IsNullOrEmpty(error_msg))
error_msg = BaseRegex.GetStringJson(ref html, "errorMsg");
}
if (string.IsNullOrEmpty(html) || !html.Contains("{\"success\":true"))
{
Error("提交异常:" + r.goods_name, error_msg);
return false;
}
if (UploadPinduoduoMain.SingleThreadCount > 1)
Thread.Sleep(10 * 1000);
else
Thread.Sleep(5 * 1000);
return true;
}
/// <summary>
/// 设置错误信息
/// </summary>
/// <param name="messageShow"></param>
/// <param name="message"></param>
public void Error(string messageShow, string message)
{
LogSave.Add(Name, messageShow);
}
public bool Get()
{
Us.FromId = Us.GoodsId;
GetProductDetail ge = new GetProductDetail(Shop, Name);
var r = ge.Get(Us.GoodsId);
if (r == null)
return false;
//if (!",6586,6785,6883,6758,6536,6630,6398,2,,6785,1715,6883,13176,13177,13178,".Contains(Cat1.ToString()))
// Data["cat_id"] = "10780";
//else
Data["cat_id"] = PinduoduoCatList.GetNewCat3(int.Parse(Data["cat_id"])).ToString();
//Data["cat_id"] = "10795";//9706
string imageString = "", apiImageString = "", apiContentString = "";
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
apiImageString += ",\"" + r.carousel_gallery_list[i] + "\"";
}
if (!string.IsNullOrEmpty(Data["carousel_gallery"]) && Data["carousel_gallery"].Contains(",") && !string.IsNullOrEmpty(apiImageString))
{
Data["carousel_gallery"] = Data["carousel_gallery"].Substring(0, Data["carousel_gallery"].IndexOf(",")) +
apiImageString.Substring(0, apiImageString.LastIndexOf(",")) + "]";
}
Data["image_url"] = r.image_url;
//string skuString = "{\"is_onsale\":1,\"limit_quantity\":" + r.sku[0].limit_quantity +
// ",\"quantity_delta\":" + r.sku[0].quantity + ",\"thumb_url\":\"\"," +
// "\"multi_price\":" + r.sku[0].multi_price + ",\"price\":" +
// r.sku[0].price + ",\"out_sku_sn\":0,\"id\":0,\"spec\":\"\",\"weight\":1000}";
//string skuApiString = "{\"is_onsale\":1,\"limit_quantity\":" + UploadPinduoduoMain.LimitBuy +
// ",\"price\":\"" + r.sku[0].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku[0].multi_price
// + "\",\"thumb_url\":\"\",\"out_sku_sn\":\"\",\"quantity\":" + UploadPinduoduoMain.LimitBuy + ",\"spec_id_list\":\"[]\"}";
string skuApiStringNew = "";
int maxPrice = 0, minPrice = Int32.MaxValue;
for (int i = 0; i < r.sku_list.Count; i++)
{
if (maxPrice < r.sku_list[i].multi_price)
maxPrice = r.sku_list[i].multi_price;
if (minPrice > r.sku_list[i].multi_price)
minPrice = r.sku_list[i].multi_price;
string spec = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
spec += "," + r.sku_list[i].spec[j].spec_id;
if (!string.IsNullOrEmpty(spec))
spec = spec.Substring(1);
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn + "\",\"quantity\":1,\"spec_id_list\":\"[" + spec + "]\"}";
}
string catId = Data["cat_id"];
int market_price = r.market_price;
string addContent = ",\"fabric\":" + r.fabricx + ",\"fabric_content\":" + r.fabric_contentx;
Data["market_price"] = market_price.ToString();
//================移除附加属性处理===========================
if (Data.ContainsKey("shelf_life"))
Data.Remove("shelf_life");
if (Data.ContainsKey("start_production_date"))
Data.Remove("start_production_date");
if (Data.ContainsKey("end_production_date"))
Data.Remove("end_production_date");
if (Data.ContainsKey("goods_properties"))
Data.Remove("goods_properties");
if (Data.ContainsKey("fabric"))
Data.Remove("fabric");
if (Data.ContainsKey("fabric_content"))
Data.Remove("fabric_content");
int Cat1 = 0;
if (PinduoduoCatList.CatIds.ContainsKey(int.Parse(catId)))
Cat1 = PinduoduoCatList.CatIds[int.Parse(catId)].cat1;
if (Data.ContainsKey("goods_properties"))
Data.Remove("goods_properties");
string mustCode = "";
string goodsProperties = UploadPinduoduoProperties.GetNew(int.Parse(catId), Cat1, ref pb, ref Shop, out mustCode);
if (!string.IsNullOrEmpty(mustCode))
Data.Add("goods_properties", "[" + mustCode.Substring(1) + "]");
//电器
//if (!Data.ContainsKey("goods_properties") && ",14913,15540,14913,9647,9610,9559,9558,9551,6247,6167,6034,6028,6024,6006,5989,5982,5965,5963,5961,5959,5757,5671,5670,3030,657,".Contains("," + catId + ","))
//{
// Data.Add("goods_properties", "[{\"template_pid\":33050,\"template_module_id\":7185,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33051,\"template_module_id\":7185,\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33053,\"template_module_id\":7185,\"pid\":67,\"value\":\"\",\"value_unit\":\"\"}," +
// "{\"template_pid\":33052,\"template_module_id\":7185,\"pid\":59,\"vid\":0,\"value\":\"" + Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",983,".Contains("," + catId + ","))//卷纸
//{
// Data.Add("paper_net_weight", "100");
// Data.Add("paper_length", "100");
// Data.Add("paper_width", "100");
// Data.Add("paper_plies_num", "1");
//}
//if (!Data.ContainsKey("goods_properties") && ",3046,".Contains("," + catId + ","))//充电器
//{
// Data.Add("goods_properties", "[{\"template_pid\":33643,\"template_module_id\":7305,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33644,\"template_module_id\":7305,\"pid\":40,\"vid\":17130,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33646,\"template_module_id\":7305,\"pid\":63,\"value\":\"\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",3109,".Contains("," + catId + ","))//充电器2
//{
// Data.Add("goods_properties", "[{\"template_pid\":33110,\"template_module_id\":7198,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33111,\"template_module_id\":7198,\"pid\":2,\"vid\":0,\"value_unit\":\"mAh\"},{\"template_pid\":33112,\"template_module_id\":7198,\"pid\":89,\"vid\":0,\"value_unit\":\"mm\"},{\"template_pid\":33113,\"template_module_id\":7198,\"pid\":90,\"vid\":0,\"value_unit\":\"mm\"},{\"template_pid\":33114,\"template_module_id\":7198,\"pid\":91,\"vid\":0,\"value_unit\":\"mm\"},{\"template_pid\":33115,\"template_module_id\":7198,\"pid\":88,\"vid\":0,\"value_unit\":\"g\"},{\"template_pid\":33116,\"template_module_id\":7198,\"pid\":40,\"vid\":17130,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33117,\"template_module_id\":7198,\"pid\":16,\"value\":\"\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",6167,14913,".Contains("," + catId + ","))//充电器2
//{
// Data.Add("goods_properties", "[{\"template_pid\":33134,\"template_module_id\":7201,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33139,\"template_module_id\":7201,\"pid\":93,\"vid\":24044,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33145,\"template_module_id\":7201,\"pid\":67,\"vid\":0,\"value\":\"100\",\"value_unit\":\"W\"},{\"template_pid\":33135,\"template_module_id\":7201,\"pid\":40,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33136,\"template_module_id\":7201,\"pid\":142,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33137,\"template_module_id\":7201,\"pid\":49,\"value\":\"\",\"value_unit\":\"\"}," +
// "{\"template_pid\":33140,\"template_module_id\":7201,\"pid\":59,\"vid\":0,\"value\":\"" + Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",6169,9527,".Contains("," + catId + ","))//个人护理
//{
// Data.Add("goods_properties", "[{\"template_pid\":33120,\"template_module_id\":7199,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33122,\"template_module_id\":7199,\"pid\":7,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33123,\"template_module_id\":7199,\"pid\":40,\"vid\":57490,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33124,\"template_module_id\":7199,\"pid\":207,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33126,\"template_module_id\":7199,\"pid\":67,\"vid\":\"100\",\"value\":\"\",\"value_unit\":\"W\"}," +
// "{\"template_pid\":33125,\"template_module_id\":7199,\"pid\":59,\"vid\":0,\"value\":\"" + Randomx.GetId(2000, 2017) + "0" + Randomx.GetId(10000, 99999) + "" + Randomx.GetId(100000, 999999) + "\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",6248,".Contains("," + catId + ","))//电源方式
//{
// Data.Add("goods_properties", "[{\"template_pid\":30365,\"template_module_id\":6680,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":30366,\"template_module_id\":6680,\"pid\":67,\"vid\":0,\"value_unit\":\"W\"},{\"template_pid\":30367,\"template_module_id\":6680,\"pid\":40,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":30368,\"template_module_id\":6680,\"pid\":33,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":30369,\"template_module_id\":6680,\"pid\":133,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":30370,\"template_module_id\":6680,\"pid\":16,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":30371,\"template_module_id\":6680,\"pid\":96,\"vid\":28237,\"value\":\"\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",14932,".Contains("," + catId + ","))//纸尿片
//{
// Data.Add("goods_properties", "[{\"template_pid\":33590,\"template_module_id\":7294,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33591,\"template_module_id\":7294,\"pid\":9,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33592,\"template_module_id\":7294,\"pid\":55,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33594,\"template_module_id\":7294,\"pid\":316,\"vid\":0,\"value\":\"其他\",\"value_unit\":\"\"},{\"template_pid\":33595,\"template_module_id\":7294,\"pid\":317,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",14932,".Contains("," + catId + ","))//纸尿片
//{
// Data.Add("goods_properties", "[{\"template_pid\":33590,\"template_module_id\":7294,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33591,\"template_module_id\":7294,\"pid\":9,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33592,\"template_module_id\":7294,\"pid\":55,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":33594,\"template_module_id\":7294,\"pid\":316,\"vid\":0,\"value\":\"其他\",\"value_unit\":\"\"},{\"template_pid\":33595,\"template_module_id\":7294,\"pid\":317,\"vid\":0,\"value\":\"未知\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",15540,".Contains("," + catId + ","))//热水袋
//{
// Data.Add("goods_properties", "[{\"template_pid\":17018,\"template_module_id\":4030,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"},{\"template_pid\":16996,\"template_module_id\":4030,\"pid\":40,\"vid\":57495,\"value\":\"\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",6586,6785,6883,6758,6536,6630,6398,,".Contains("," + Cat1 + ",")) //食品
//{
// Data.Add("shelf_life", "300");
// Data.Add("start_production_date", BaseClass.GetTime(DateTime.Today).ToString());
// Data.Add("end_production_date", BaseClass.GetTime(DateTime.Today).ToString());
// Data.Add("goods_properties", "[{\"template_pid\":5876,\"template_module_id\":1385,\"pid\":57,\"vid\":0,\"value\":\"" +
// DateTime.Today.ToString("yyyy-MM-dd") +
// "\",\"value_unit\":\"\"},{\"template_pid\":5877,\"template_module_id\":1385,\"pid\":58,\"vid\":0,\"value\":\"300\",\"value_unit\":\"天\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",13176,".Contains("," + Cat1 + ","))//处方药
//{
// Data.Add("goods_properties", "[{\"template_pid\":9284,\"template_module_id\":2359,\"pid\":92,\"vid\":0,\"value\":\"Z" + Randomx.GetId(10000000, 99999999) + Randomx.GetId(1, 9) + "\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",13178,".Contains("," + Cat1 + ","))//非处方药
//{
// Data.Add("goods_properties", "[{\"template_pid\":21473,\"template_module_id\":4913,\"pid\":234,\"vid\":0,\"value\":\"ZC201" + Randomx.GetId(1000, 9999) + Randomx.GetId(1, 9) + "\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",2,6586,6785,6883,6758,6536,6630,6398,,63,64,65,92,95,99,101,3853,3862,3867,3872,3876,3900,898,897,3993,1079,".Contains("," + Cat1 + ",")) //食品
//{
// Data.Add("shelf_life", "300");
// Data.Add("start_production_date", BaseClass.GetTime(DateTime.Today).ToString());
// Data.Add("end_production_date", BaseClass.GetTime(DateTime.Today).ToString());
// Data.Add("goods_properties", "[{\"template_pid\":5876,\"template_module_id\":1385,\"pid\":57,\"vid\":0,\"value\":\"" +
// DateTime.Today.ToString("yyyy-MM-dd") +
// "\",\"value_unit\":\"\"},{\"template_pid\":5877,\"template_module_id\":1385,\"pid\":58,\"vid\":0,\"value\":\"300\",\"value_unit\":\"天\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",13176,".Contains("," + Cat1 + ",") && !",13184,13183,".Contains(Cat2.ToString()))
//{
// Data.Add("goods_properties", "[{\"template_pid\":9284,\"template_module_id\":2359,\"pid\":92,\"vid\":0,\"value\":\"Z" + Randomx.GetId(10000000, 99999999) + Randomx.GetId(1, 9) + "\",\"value_unit\":\"\"}]");
//}
//if (!Data.ContainsKey("goods_properties") && ",8439,".Contains("," + Cat1 + ","))
//{
// Data.Add("goods_properties", "[{\"template_pid\":35576,\"template_module_id\":7709,\"pid\":5,\"value\":\"\",\"value_unit\":\"\"}]");
//}
//===================================其他类目==========================================
//Data["cat_id"] = GetReplaceCat(Shop.MainCatId, oldId).ToString();
Data["sku_list"] = "[" + skuApiStringNew.Substring(1) + "]";
Data["customer_num"] = "2";
Data["goods_desc"] = r.goods_name;
string newName = Data["goods_name"];
Data["goods_name"] = BaseClass.SubCharLength(r.goods_name.Replace("✅", "").Replace("◆", ""), 60);
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
api.Data = Data;
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return false;
string html = api.Updata();
if (html.Contains("惩罚") || html.Contains("新协议") || html.Contains("协议已更新") || html.Contains("高风险店铺") || html.Contains("配送地区") || html.Contains("店铺资质") && !html.Contains("出于监管要求") ||
html.Contains("通过审核"))
{
string msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
MessageBox.Show("店铺:" + Shop.ShopName + " 错误:\r\n" + msg);
CanUpload = false;
return false;
}
if (!string.IsNullOrEmpty(BaseRegex.GetStringJson(ref html, "error_msg")))
return false;
long goods_commit_id = BaseRegex.GetLongJson(ref html, "goods_commit_id");
api = new PinduoduoApiGetProduct(Shop);
long upid = 0;
html = api.GetRelation(r.goods_id.ToString());
// 有获取到对应的上家id
if (html.Contains("out_goods_id") && html.Contains("out_goods_platform"))
{
upid = BaseRegex.GetLongJson(ref html, "out_goods_id");
html = api.Relation(r.goods_id, upid, (int)(MinPrice * 0.94m), (int)(MaxPrice * 0.94m), 0, 0);
}
else
{
upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10, 99999);
html = api.Relation(Us.GoodsId, upid, (int)(MinPrice * 0.96m), (int)(MaxPrice * 0.96m), 0, 0);
}
Thread.Sleep(500);
int goods_status = 1;
for (int i = 0; goods_commit_id > 0 && i < 600 && goods_status == 1; i++)
{
html = new PinduoduoApiGetProduct(Shop).GetCommitDetail(goods_commit_id);
goods_status = BaseRegex.GetIntJson(ref html, "goods_status");
if (goods_status == 1)
Thread.Sleep(1 * 1000);
}
if (goods_commit_id > 0)
new PinduoduoApiGetProduct(Shop).DeleteCommitDetail(goods_commit_id);
string url, data, refere;
if (goods_status != 2 && goods_status != 4)
return false;
return true;
//return true;
//Data["sku_list"] = "[" + skuApiStringNew.Substring(1) + "]";
//Data["goods_name"] = newName;
//api = new PinduoduoApiGetProduct(Shop);
//api.Data = Data;
//html = api.Updata();
//Thread.Sleep(10 * 1000);
//goods_commit_id = BaseRegex.GetLongJson(ref html, "goods_commit_id");
//goods_status = 1;
//for (int i = 0; goods_commit_id > 0 && i < 5 && goods_status == 1; i++)
//{
// html = new PinduoduoApiGetProduct(Shop).GetCommitDetail(goods_commit_id);
// goods_status = BaseRegex.GetIntJson(ref html, "goods_status");
// if (goods_status != 2)
// Thread.Sleep(10 * 1000);
//}
//if (goods_status != 2)
// return false;
//return true;
//r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
//api = new PinduoduoApiGetProduct(Shop);
//api.Data.Add("goods_id", Us.GoodsId.ToString());
//api.Data.Add("goods_name", r.goods_name);
//api.Data.Add("goods_type", "1");
//api.Data.Add("goods_desc", r.goods_desc);
//api.Data.Add("cat_id", r.cat_id.ToString());
//api.Data.Add("tiny_name", "");
//api.Data.Add("country_id", "0");
//api.Data.Add("market_price", market_price.ToString());
//api.Data.Add("is_pre_sale", "false");
//api.Data.Add("shipment_limit_second", "172800");
//api.Data.Add("cost_template_id", r.cost_template_id.ToString());
//api.Data.Add("customer_num", UploadPinduoduoMain.GroupCount.ToString());//团购人数
//api.Data.Add("buy_limit", UploadPinduoduoMain.LimitBuy.ToString());
//api.Data.Add("order_limit", UploadPinduoduoMain.LimitBuy.ToString());
//api.Data.Add("is_refundable", "true");
//api.Data.Add("second_hand", "false");
//api.Data.Add("is_folt", "true");
//if (!string.IsNullOrEmpty(addContent))
//{
// int fabric = BaseRegex.GetIntJson(ref addContent, "fabric");
// int fabric_content = BaseRegex.GetIntJson(ref addContent, "fabric_content");
// api.Data.Add("fabric", fabric.ToString());
// api.Data.Add("fabric_content", fabric_content.ToString());
//}
//api.Data.Add("sku_list", "[" + skuApiString + "]");
//api.Data.Add("out_goods_id", "");
//api.Data.Add("hd_thumb_url", r.hd_thumb_url);
//api.Data.Add("thumb_url", r.thumb_url);
//api.Data.Add("image_url", r.image_url);
//api.Data.Add("carousel_gallery", "[" + apiImageString.Substring(1) + "]");
//api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
//if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + Us.Cat1 + ","))//食品
//{
// api.Data.Add("shelf_life", "300");
// api.Data.Add("start_production_date", BaseClass.GetTime(DateTime.Now.AddDays(-5)).ToString());
// api.Data.Add("end_production_date", BaseClass.GetTime(DateTime.Now).ToString());
//}
//html = api.Updata();
//return;
//var ju = new JumpUpProductNew(Shop);
//ju.OutGoodId = r.commit_extension.out_goods_sn;
//ju.GetUrl(Us.GoodsId.ToString());
//int from = 7;
//api = new PinduoduoApiGetProduct(Shop);
//html = api.Relation(Us.GoodsId, ju.UpId.ProductIdFrom, (int)(r.sku[0].price * 93), (int)(r.sku[0].price * 93), 0, from);
//Thread.Sleep(10 * 1000);
//api = new PinduoduoApiGetProduct(Shop);
//api.Data.Add("goods_id", Us.GoodsId.ToString());
//api.Data.Add("goods_name", r.goods_name);
//api.Data.Add("goods_type", "1");
//api.Data.Add("goods_desc", r.goods_desc);
//api.Data.Add("cat_id", r.cat_id.ToString());
//api.Data.Add("tiny_name", "");
//api.Data.Add("country_id", "0");
//api.Data.Add("market_price", market_price.ToString());
//api.Data.Add("is_pre_sale", "false");
//api.Data.Add("shipment_limit_second", "172800");
//api.Data.Add("cost_template_id", r.cost_template_id.ToString());
//api.Data.Add("customer_num", UploadPinduoduoMain.GroupCount.ToString());//团购人数
//api.Data.Add("buy_limit", UploadPinduoduoMain.LimitBuy.ToString());
//api.Data.Add("order_limit", UploadPinduoduoMain.LimitBuy.ToString());
//api.Data.Add("is_refundable", "true");
//api.Data.Add("second_hand", "false");
//api.Data.Add("is_folt", "true");
//if (!string.IsNullOrEmpty(addContent))
//{
// int fabric = BaseRegex.GetIntJson(ref addContent, "fabric");
// int fabric_content = BaseRegex.GetIntJson(ref addContent, "fabric_content");
// api.Data.Add("fabric", fabric.ToString());
// api.Data.Add("fabric_content", fabric_content.ToString());
//}
//api.Data.Add("sku_list", "[" + SkuStringApi + "]");
//api.Data.Add("out_goods_id", "");
//api.Data.Add("hd_thumb_url", r.hd_thumb_url);
//api.Data.Add("thumb_url", r.thumb_url);
//api.Data.Add("image_url", r.image_url);
//api.Data.Add("carousel_gallery", "[" + apiImageString.Substring(1) + "]");
//api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
//if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + Us.Cat1 + ","))//食品
//{
// api.Data.Add("shelf_life", "300");
// api.Data.Add("start_production_date", BaseClass.GetTime(DateTime.Now.AddDays(-5)).ToString());
// api.Data.Add("end_production_date", BaseClass.GetTime(DateTime.Now).ToString());
//}
//from = 0;
//html = api.Updata();
//api = new PinduoduoApiGetProduct(Shop);
//html = api.Relation(Us.GoodsId, NewUpId, (int)(MinPrice * 95), (int)(MaxPrice * 95), 0, from);
//Thread.Sleep(10 * 1000);
//if (!string.IsNullOrEmpty(html) && html.Contains("\"is_success\":true"))
//{
// return;
//}
//return;
//Thread.Sleep(10 * 1000);
useSecond:
////二次编辑
string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000";
string str = "";
for (int i = 0; i < 16; i++)
{
str += new Random(Guid.NewGuid().GetHashCode()).Next(9);
}
string strToken = str + "-" + strTime;
string strNumber = "";
string temp2 = strTime + "," + strToken + "," + strNumber;
string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, strToken, strNumber);
string codex = "";
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/create_by_sn";
refere = "https://mms.pinduoduo.com/Pdd.html";
data = "{\"goods_id\":" + Us.GoodsId + "}";
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
long pinId = BaseRegex.GetLongJson(ref html, "goods_commit_id");
if (pinId == 0)
{
Thread.Sleep(30 * 1000);
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
pinId = BaseRegex.GetLongJson(ref html, "goods_commit_id");
}
if (pinId == 0)
return false;
string dataUp = "{\"cat_id\":" + r.cat_id + ",\"crawlerInfo\":\"" + codex + "\",\"goods_type\":\"1\",\"country\":\"\",\"country_id\":\"\"," +
"\"warehouse\":\"\",\"customs\":\"\",\"is_customs\":0,\"is_pre_sale\":0,\"pre_sale_time\":\"\"," +
"\"is_refundable\":1,\"shipment_limit_second\":172800,\"event_type\":\"0\",\"is_folt\":\"1\"," +
"\"goods_name\":\"" + r.goods_name + "\",\"tiny_name\":\"\",\"market_price\":" + market_price +
",\"share_desc\":\":\",\"goods_desc\":\"" + r.goods_desc + "\"," +
"\"image_url\":\"\",\"thumb_url\":\"" + r.thumb_url + "\",\"hd_thumb_url\":\"" + r.hd_thumb_url + "\"," +
"\"gallery\":[" + imageString.Substring(1) + "],\"cost_template_id\":\"" + r.cost_template_id + "\",\"weight\":\"1.00\",\"warm_tips\":\"\"," +
"\"skus\":[" + SkuString + "],\"out_goods_sn\":\"" + "\",\"groups\":{\"customer_num\":" + UploadPinduoduoMain.GroupCount + "," +
"\"buy_limit\":" + UploadPinduoduoMain.LimitBuy + ",\"order_limit\":" + UploadPinduoduoMain.LimitBuy
+ "},\"production_license\":\"\",\"production_standard_number\":\"\"" + addContent + ",\"goods_commit_id\":\"" + pinId + "\"}";
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/update";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, Shop.Cookies);
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (!string.IsNullOrEmpty(error_msg))
return false;
url = "https://mms.pinduoduo.com/glide/v2/mms/query/goods/is_commit_available/" + pinId;
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/submit";
data = "{\"goods_commit_id\":\"" + pinId + "\"}";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
return true;
//Thread.Sleep(10 * 1000);
//PinduoduoProductCollect pp = new PinduoduoProductCollect(Name, Us);
//pp.Get();
//if (!TaobaoMobileCollect.ProductTemp.ContainsKey(Us.FromId) || TaobaoMobileCollect.ProductTemp[Us.FromId].Images.Count==0)
// return;
//var product = TaobaoMobileCollect.ProductTemp[Us.FromId];
//string tempImage = product.Images[0];
//byte[] img;
//var ok = GetPostTaobaoHtml.DownLoadImage(tempImage, out img);
//if(!ok)
// return;
//var ib = new ImageBuild(img);
//img = ib.BuildNewSize(400, 400, 500);
//var up = new UploadPinduoduoSet(Shop, Name, null);
//string img400 =up.UploadImg(tempImage + "400*400", ref img);
//UploadPinduoduoSet.AddImage(tempImage + "400*400", img400, 400, 400);
//img = ib.BuildNewSize(200, 200, 500);
//var img200 = up.UploadImg(tempImage + "200*200", ref img);
//UploadPinduoduoSet.AddImage(tempImage + "200*200", img200, 200, 200);
//int catId = product.cat_id;
//string imageString = "";
//for (int i = 0; i < product.Images.Count; i++)
//{
// if (product.Images[i].Length > 2 && product.Images[i].Substring(0, 2) == "//")
// product.Images[i] = "http:" + product.Images[i];
// imageString += ",{\"url\":\"" + product.Images[i] + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
//}
//var m = BaseRegex.GetMatchRegex(ref product.content, @"<img [^>]*?src=[""'](.*?)[""']");
//for (int i = 0; i < m.Count; i++)
//{
// string imgUrl = m[i].Groups[1].Value;
// if (!imgUrl.Contains("http:") && !imgUrl.Contains("https:"))
// imgUrl = "http:" + imgUrl;
// string exe = Path.GetExtension(imgUrl).ToLower();
// if (exe != ".jpeg" && exe != ".jpg" && exe != ".png")
// continue;
// imageString += ",{\"url\":\"" + imgUrl + "\",\"width\":" + 750+ ",\"height\":" + 750 + ",\"type\":\"2\"}";
//}
//int multi_price = up.BuildNewPrice(product.price, 1, 0);
//string skuString = ",{\"is_onsale\":1,\"limit_quantity\":" + UploadPinduoduoMain.LimitBuy +
// ",\"quantity_delta\":" + UploadPinduoduoMain.LimitBuy + ",\"thumb_url\":\"\"," +
// "\"multi_price\":" + multi_price + ",\"price\":" +
// (multi_price + UploadPinduoduoMain.SinglePrice * 100) + ",\"out_sku_sn\":0,\"id\":0,\"spec\":\"\",\"weight\":1000}";
//int market_price = (int)(multi_price + UploadPinduoduoMain.SinglePrice * 100) * 2;
//string addContent = ",\"fabric\":" + r.fabric + ",\"fabric_content\":" + r.fabric_content;
//if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + product.cat1 + ","))//食品
//{
// addContent += ",\"shelf_life\":300,\"start_production_date\":" + BaseClass.GetTime(DateTime.Now.AddDays(-5)) + ",\"end_production_date\":" + BaseClass.GetTime(DateTime.Now);
//}
//else
//{
// addContent += ",\"shelf_life\":\"\",\"start_production_date\":\"\",\"end_production_date\":\"\"";
//}
//string url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/create_by_sn";
//string data = "{\"goods_id\":" + product.id + "}";
//string html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
//long pinId = BaseRegex.GetLongJson(ref html, "goods_commit_id");
//if (pinId == 0)
//{
// Thread.Sleep(30 * 1000);
// html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
// pinId = BaseRegex.GetLongJson(ref html, "goods_commit_id");
//}
//if(pinId==0)
// return;
//string dataUp = "{\"cat_id\":" + catId + ",\"goods_type\":\"1\",\"country\":\"\",\"country_id\":\"\"," +
// "\"warehouse\":\"\",\"customs\":\"\",\"is_customs\":0,\"is_pre_sale\":0,\"pre_sale_time\":\"\"," +
// "\"is_refundable\":1,\"shipment_limit_second\":172800,\"event_type\":\"0\",\"is_folt\":\"1\"," +
// "\"goods_name\":\"" + product.name + "\",\"tiny_name\":\"\",\"market_price\":" + market_price +
// ",\"share_desc\":\"" + product.content_pinduoduo + ":\",\"goods_desc\":\"" + product.content_pinduoduo + "\"," +
// "\"image_url\":\"\",\"thumb_url\":\"" + img200 + "\",\"hd_thumb_url\":\"" + img400 + "\"," +
// "\"gallery\":[" + imageString.Substring(1) + "],\"cost_template_id\":\"" + Shop.ExpressId + "\",\"weight\":\"1.00\",\"warm_tips\":\"\"," +
// "\"skus\":[" + skuString.Substring(1) + "],\"out_goods_sn\":\"" + "\",\"groups\":{\"customer_num\":" + UploadPinduoduoMain.GroupCount + "," +
// "\"buy_limit\":" + UploadPinduoduoMain.LimitBuy + ",\"order_limit\":" + UploadPinduoduoMain.LimitBuy
// + "},\"production_license\":\"\",\"production_standard_number\":\"\"" + addContent + ",\"goods_commit_id\":\"" + pinId + "\"}";
//url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/update";
//html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, Shop.Cookies);
//string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
//if(!string.IsNullOrEmpty(error_msg))
// return;
////url = "https://mms.pinduoduo.com/glide/v2/mms/query/goods/is_commit_available/" + pinId;
////html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, Shop.Cookies);
////error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
//url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/submit";
//data = "{\"goods_commit_id\":\"" + pinId + "\"}";
//html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
//error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
//Thread.Sleep(20*1000);
}
public bool UserUpdate(long pinId)
{
if (pinId == 0)
return false;
GetProductDetail ge = new GetProductDetail(Shop, Name);
var r = ge.Get(Us.GoodsId);
if (r == null)
return false;
string imageString = "";
for (int i = 0; i < r.detail_gallery_list.Count; i++)
{
imageString += ",{\"url\":\"" + r.detail_gallery_list[i] + "\", \"type\":2 }";
}
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
imageString += ",{\"url\":\"" + r.carousel_gallery_list[i] + "\", \"type\":1 }";
}
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000";
string str = "";
for (int i = 0; i < 16; i++)
{
str += new Random(Guid.NewGuid().GetHashCode()).Next(9);
}
string strToken = str + "-" + strTime;
string strNumber = "";
string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, strToken, strNumber);
string codex = "";
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
string dataUp = "{\"cat_id\":" + r.cat_id + ",\"crawlerInfo\":\"" + codex + "\",\"goods_type\":\"1\",\"country\":\"\",\"country_id\":\"\"," +
"\"warehouse\":\"\",\"customs\":\"\",\"is_customs\":0,\"is_pre_sale\":0,\"pre_sale_time\":\"\"," +
"\"is_refundable\":1,\"shipment_limit_second\":172800,\"event_type\":\"0\",\"is_folt\":\"1\"," +
"\"goods_name\":\"" + r.goods_name + "\",\"tiny_name\":\"\",\"market_price\":" + r.market_price +
",\"goods_desc\":\"" + r.goods_desc + "\"," +
"\"image_url\":\"" + r.image_url + "\",\"thumb_url\":\"" + r.thumb_url + "\",\"hd_thumb_url\":\"" + r.hd_thumb_url + "\"," +
"\"gallery\":[" + imageString.Substring(1) + "],\"cost_template_id\":\"" + r.cost_template_id + "\",\"weight\":\"1.00\",\"warm_tips\":\"\"," +
"\"skus\":[" + SkuString + "],\"out_goods_sn\":\"" + "\",\"groups\":{\"customer_num\":" + UploadPinduoduoMain.GroupCount + "," +
"\"buy_limit\":" + UploadPinduoduoMain.LimitBuy + ",\"order_limit\":" + UploadPinduoduoMain.LimitBuy
+ "},\"production_license\":\"\",\"production_standard_number\":\"\",\"goods_commit_id\":\"" + pinId + "\"}";
string refere = "https://mms.pinduoduo.com/";
string url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/update";
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, Shop.Cookies);
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (!string.IsNullOrEmpty(error_msg))
return false;
url = "https://mms.pinduoduo.com/glide/v2/mms/query/goods/is_commit_available/" + pinId;
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/submit";
string data = "{\"goods_commit_id\":\"" + pinId + "\",\"crawlerInfo\":\"" + codex + "\"}";
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
if (!string.IsNullOrEmpty(error_msg))
return false;
int goods_status = 1;
for (int i = 0; i < 10 && goods_status == 1; i++)
{
html = new PinduoduoApiGetProduct(Shop).GetCommitDetail(pinId);
goods_status = BaseRegex.GetIntJson(ref html, "goods_status");
if (goods_status != 2)
Thread.Sleep(10 * 1000);
}
if (goods_status != 2)
{
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/" + pinId + "/delete";
refere = "https://mms.pinduoduo.com/";
html = GetPostTaobaoHtml.JsonPinduoduoUpload(url, refere, true, "{}", Shop.Cookies);
return false;
}
return true;
}
public bool GetArrangeForm()
{
GetProductDetail ge = new GetProductDetail(Shop, "店铺整理");
var r = ge.Get(pid);
if (r == null)
return false;
string skuApiStringNew = "";
for (int i = 0; i < r.sku_list.Count; i++)
{
string spec = "";
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
spec += "," + r.sku_list[i].spec[j].spec_id;
if (!string.IsNullOrEmpty(spec))
spec = spec.Substring(1);
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn + "\",\"quantity\":1,\"spec_id_list\":\"[" + spec + "]\"}";
}
string addContent = ",\"fabric\":" + r.fabricx + ",\"fabric_content\":" + r.fabric_contentx;
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
api.Data.Add("goods_name", BaseClass.SubCharLength(title.Replace("✅", "").Replace("◆", ""), 60));
api.Data.Add("goods_type", "1");
api.Data.Add("goods_desc", r.goods_desc);
api.Data.Add("cat_id", r.cat_id.ToString());
api.Data.Add("tiny_name", "");
api.Data.Add("country_id", "0");
api.Data.Add("market_price", r.market_price.ToString());
api.Data.Add("is_pre_sale", "false");
api.Data.Add("shipment_limit_second", "172800");
api.Data.Add("cost_template_id", r.cost_template_id.ToString());
api.Data.Add("customer_num", UploadPinduoduoMain.GroupCount.ToString());//团购人数
if (!UploadPinduoduoMain.limitCount)
{
api.Data.Add("buy_limit", UploadPinduoduoMain.LimitBuy.ToString());
api.Data.Add("order_limit", UploadPinduoduoMain.LimitBuy.ToString());
}
api.Data.Add("is_refundable", "true");
api.Data.Add("second_hand", "false");
api.Data.Add("is_folt", "true");
if (!string.IsNullOrEmpty(addContent))
{
int fabric = BaseRegex.GetIntJson(ref addContent, "fabric");
int fabric_content = BaseRegex.GetIntJson(ref addContent, "fabric_content");
api.Data.Add("fabric", fabric.ToString());
api.Data.Add("fabric_content", fabric_content.ToString());
}
api.Data.Add("sku_list", "[" + skuApiStringNew.Substring(1) + "]");
api.Data.Add("out_goods_id", r.outer_goods_id);
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
api.Data.Add("thumb_url", r.thumb_url);
api.Data.Add("image_url", r.image_url);
api.Data["goods_desc"] = r.goods_desc;
//构造carousel_gallery 轮播图
string carousel_gallery = string.Empty;
if (r.carousel_gallery_list != null & r.carousel_gallery_list.Count > 0)
{
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
{
carousel_gallery += ",\"" + r.carousel_gallery_list[i] + "\"";
}
}
if (!string.IsNullOrEmpty(carousel_gallery))
carousel_gallery = carousel_gallery.Substring(1);
api.Data.Add("carousel_gallery", "[" + carousel_gallery + "]");
//构造detail_gallery商品详情图片
string detail_gallery = "";
for (int j = 0; j < r.detail_gallery_list.Count; j++)
{
if (r.detail_gallery_list.Count > 5 && j == 0 || r.detail_gallery_list.Count > 8 && j == r.detail_gallery_list.Count - 1)//不要第一张图和最后一张
{
continue;
}
string urlImg = r.detail_gallery_list[j];
if (!urlImg.Contains("http:"))
urlImg = "http:" + urlImg;
string exe = Path.GetExtension(urlImg).ToLower();
if (exe != ".jpeg" && exe != ".jpg" && exe != ".png")
continue;
detail_gallery += ",\"" + urlImg + "\"";
}
if (!string.IsNullOrEmpty(detail_gallery))
{
detail_gallery = detail_gallery.Substring(1);
}
api.Data.Add("detail_gallery", "[" + detail_gallery + "]");
if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + r.cat_id + ","))//食品
{
api.Data.Add("shelf_life", "300");
api.Data.Add("start_production_date", BaseClass.GetTime(DateTime.Now.AddDays(-5)).ToString());
api.Data.Add("end_production_date", BaseClass.GetTime(DateTime.Now).ToString());
}
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
return false;
string html = api.Add();
if (!string.IsNullOrEmpty(html) && html.Contains("\"error_msg\""))
{
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg");
LogSave.Add("店铺整理", "复制商品失败,原因:" + error_msg);
return false;
}
string goodsid = BaseRegex.GetStringJson(ref html, "goods_id");
LogSave.Add("店铺整理", "复制商品成功,生成商品ID:" + goodsid);
return true;
}
}
}