3578 lines
178 KiB
C#
3578 lines
178 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.IO;
|
||
using System.Threading;
|
||
using AllBase;
|
||
using Work.CollectClass;
|
||
using Work.ManageClass;
|
||
//using JavaScriptEngineSwitcher.V8;
|
||
//using JavaScriptEngineSwitcher.Core;
|
||
using System.Linq;
|
||
using System.Diagnostics;
|
||
using Newtonsoft.Json.Linq;
|
||
using System.Collections.Specialized;
|
||
using System.Net;
|
||
using System.Text;
|
||
using System.Text.RegularExpressions;
|
||
using System.IO.Compression;
|
||
using NaiBa.Util.Extension;
|
||
|
||
namespace Work.Api
|
||
{
|
||
public class UploadPinduoduoSet
|
||
{
|
||
/// <summary>
|
||
/// 是否对微店转换数据取整(尾数为1,2,3,4取5,尾数为6,7,8,9取10)
|
||
/// </summary>
|
||
public static bool IsRounding = false;
|
||
public static Dictionary<long, KeyValuesBase> CatTemp = new Dictionary<long, KeyValuesBase>();
|
||
public static Dictionary<string, ImageUrlBase> ImageTemp = new Dictionary<string, ImageUrlBase>();
|
||
public static Dictionary<long, string> picsTemp = new Dictionary<long, string>();
|
||
public ShopChatBase Shop;
|
||
public TaobaoProductBase t;
|
||
public TaobaoProductBase us = null;
|
||
public bool FullToday = false, Punish = false, Success = false;
|
||
/// <summary>
|
||
/// 上货时使用代理获取拼多多上家商品
|
||
/// </summary>
|
||
public static bool IsUseProxyCollectUp = true;
|
||
|
||
/// <summary>
|
||
/// 中间数据
|
||
/// </summary>
|
||
public ProductCollectBase pb = new ProductCollectBase();
|
||
public string Name;
|
||
public UploadPinduoduoSet(ShopChatBase shop, string name, TaobaoProductBase T)
|
||
{
|
||
Shop = shop;
|
||
Name = name;
|
||
t = T;
|
||
}
|
||
|
||
public void Get()
|
||
{
|
||
#if DEBUG
|
||
|
||
Getx();
|
||
Thread.Sleep(1000);
|
||
#else
|
||
try
|
||
{
|
||
Getx();
|
||
Thread.Sleep(2000);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogSave.Add(Name, "上传商品" + t.FromId + "错误:" + e.Message);
|
||
}
|
||
#endif
|
||
}
|
||
|
||
public byte[] imageByte = null;
|
||
public long goodsId = 0;
|
||
|
||
Dictionary<long, string> picUped = new Dictionary<long, string>();
|
||
public void Getx()
|
||
{
|
||
if (!string.IsNullOrEmpty(t.ViPrice) && string.IsNullOrEmpty(t.ViPriceMaxMin))
|
||
{
|
||
LogSave.Add(Name, Shop.Name + " 版本升级不支持老数据格式,请重新制作新格式数据,跳过 " + t.FromId + " ");
|
||
return;
|
||
}
|
||
string imageUrlx = "";
|
||
//if (ImgDic.Count == 0)
|
||
// new Thread(CutImage).Start();
|
||
string beforeTitle = "";
|
||
while (UploadPinduoduoMain.upRunning && UploadPinduoduoMain.Waiting)
|
||
Thread.Sleep(100);
|
||
//while (UploadPinduoduoMain.RunningReplace && UploadPinduoduoMain.ReplaceWaiting)
|
||
// Thread.Sleep(100);
|
||
t.FromType = t.FromType.Replace("\"", "");
|
||
if (t.FromType.Contains("搜款网") && t.FromId > 10)
|
||
{
|
||
char[] idc = t.FromId.ToString().ToCharArray();
|
||
if (t.FromId.ToString().Length < t.TolerantFormId.Length)
|
||
idc = t.TolerantFormId.ToString().ToCharArray();
|
||
string ld = idc[idc.Length - 1].ToString();
|
||
for (int i = 1; i < idc.Length - 1; i++)
|
||
{
|
||
ld += idc[i];
|
||
}
|
||
ld += idc[0];
|
||
t.FromIdBak = t.FromId;
|
||
t.FromId = long.Parse(ld);
|
||
pb.from_site_id = 2;
|
||
}
|
||
|
||
if (UploadPinduoduoMain.NoRuleIds && UploadPinduoduoMain.RuleIds.Contains(t.FromId.ToString()))
|
||
{
|
||
t.Message = "上传可能违规,跳过";
|
||
Error("可能违规,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (TaobaoMobileCollect.ProductTemp.ContainsKey(t.FromId))
|
||
{
|
||
pb = TaobaoMobileCollect.ProductTemp[t.FromId].Clone();
|
||
if (t.Cat3 == 0 && t.Cat4 == 0)
|
||
{
|
||
t.Cat1 = pb.cat1;
|
||
t.Cat2 = pb.cat2;
|
||
t.Cat3 = pb.cat3;
|
||
t.CatId = pb.cat_id;
|
||
t.Cat4 = pb.cat4;
|
||
t.MainCatId = pb.main_cid;
|
||
t.MainCatName = pb.main_cat_name;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
pb.cat1 = t.Cat1;
|
||
pb.cat2 = t.Cat2;
|
||
pb.cat3 = t.Cat3;
|
||
pb.cat4 = t.Cat4;
|
||
pb.cat_id = t.CatId;
|
||
pb.main_cid = t.MainCatId;
|
||
|
||
|
||
if (t.FromType == "拼多多" || t.FromType == "内部数据" || t.FromType == "搜款网" || t.FromType == "搜款网净化")
|
||
{
|
||
PinduoduoProductCollect pp = new PinduoduoProductCollect(Name, t, IsUseProxyCollectUp);
|
||
pp.isUseCache = UploadPinduoduoMain.isUseCache;
|
||
pp.Get();
|
||
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(t.FromId))
|
||
{
|
||
if (!pp.OnSale)
|
||
t.Message = pp.message;
|
||
else
|
||
t.Message = pp.message;//"IP或买手号被限制,请更换IP或检查买手号是否能正常浏览商品";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
if (!PinduoduoProductCollect.isProxyAvailable)
|
||
{
|
||
Error("采集失败" + t.FromId, PinduoduoProductCollect.proxymessage);
|
||
}
|
||
return;
|
||
}
|
||
}
|
||
else if (t.FromType == "阿里巴巴" || t.FromType == "1688" || t.FromType == "阿里巴巴净化")
|
||
{
|
||
pb.from_url = "https://detail.1688.com/offer/" + t.FromId + ".html";
|
||
pb.from_id = t.FromId;
|
||
AlibabaProductGet ali = new AlibabaProductGet(pb);
|
||
ali.IsPinduoduo = true;
|
||
ali.Get();
|
||
if (!ali.OnSale)
|
||
{
|
||
t.Message = "商品或已下架";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (t.FromType == "阿里巴巴净化")
|
||
{
|
||
string jhtml = ServerTemp.GetJinHuaCache(t.FromId.ToString());
|
||
ali.AslasyHtml(t, jhtml);
|
||
}
|
||
}
|
||
else if (t.FromType == "微店")
|
||
{
|
||
pb.from_url = "https://weidian.com/item.html?itemID=" + t.FromId + ".html";
|
||
pb.from_id = t.FromId;
|
||
WeiDianProductCollect wd = new WeiDianProductCollect(t);
|
||
wd.Get();
|
||
if (!wd.OnSale)
|
||
{
|
||
t.Message = "商品或已下架";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
else if (t.FromType == "淘集集")
|
||
{
|
||
pb.from_url = "https://api.tjjapp.com/Api2_24_0/goods/info?goods_id=" + t.FromId;
|
||
pb.from_id = t.FromId;
|
||
TaoJiJiProductGet tjj = new TaoJiJiProductGet(pb);
|
||
tjj.IsPinduoduo = true;
|
||
tjj.Get();
|
||
if (!tjj.OnSale)
|
||
{
|
||
t.Message = "商品或已下架";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
else if (t.FromType == "京喜") //by ttzhao 2020.6.11
|
||
{
|
||
pb.from_url = "https://item.m.jd.com/product/" + t.FromId + ".html";
|
||
pb.from_id = t.FromId;
|
||
JingXiCollect jx = new JingXiCollect(pb);
|
||
jx.Get();
|
||
if (jx.GoodsStatus == JingXiCollect.GoodsStatusEnum.NotExist)
|
||
{
|
||
t.Message = "商品或已下架";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
pb.from_url = "https://item.taobao.com/item.htm?id=" + t.FromId;
|
||
pb.from_id = t.FromId;
|
||
if (t.TaoKeId > 0)
|
||
{
|
||
pb.up_url = "http://www.dataoke.com/item?id=" + t.TaoKeId;
|
||
}
|
||
TaobaoMobileCollect tm = new TaobaoMobileCollect(pb);
|
||
tm.Pinduoduo = true;
|
||
tm.Name = Name;
|
||
tm.Get();
|
||
if (!tm.GetSuccess)
|
||
{
|
||
t.Message = "商品或已下架";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (t.FromType == "淘宝净化")
|
||
{
|
||
string jhtml = ServerTemp.GetJinHuaCache(t.FromId.ToString());
|
||
tm.AslasyHtml(t,jhtml);
|
||
}
|
||
}
|
||
if (TaobaoMobileCollect.ProductTemp.ContainsKey(t.FromId))
|
||
pb = TaobaoMobileCollect.ProductTemp[t.FromId].Clone();
|
||
else
|
||
{
|
||
t.Message = "商品或已下架";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
if (BaseClass.UpIds.Count > 0)
|
||
{
|
||
for (int i = 0; i < BaseClass.UpIds.Count; i++)
|
||
{
|
||
string rid = BaseRegex.GetMatchRegexString(BaseClass.UpIds[i], @"([\d]+)");
|
||
if (string.IsNullOrEmpty(rid))
|
||
continue;
|
||
long uid = long.Parse(rid);
|
||
if (pb.id == uid)
|
||
return;
|
||
}
|
||
}
|
||
if (pb.Props.Count>2 && UploadPinduoduoMain.isSpecCount)
|
||
{
|
||
t.Message = "此商品属性较多,官方只允许上传最多俩个属性";
|
||
Error("此商品属性较多,官方只允许上传最多俩个属性:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
if (pb.Props.Count > 2)
|
||
{
|
||
pb.Props = pb.Props.OrderBy(u => u.Values.Count).ToList();
|
||
int count = pb.Props.Count - 2;
|
||
pb.Props.RemoveRange(0, count);
|
||
pb.Props = pb.Props.OrderByDescending(u => u.sort).ToList();
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(pb.logisticsTime))
|
||
{
|
||
string daystr = BaseRegex.GetMatchRegexString(ref pb.logisticsTime, @"([\d]+)");
|
||
int day = 0;
|
||
int.TryParse(daystr, out day);
|
||
if (day/24>0)
|
||
day = day / 24;
|
||
if ((pb.logisticsTime.Contains("48小时") || pb.logisticsTime.Contains("72小时")
|
||
|| pb.logisticsTime.Contains("2天") || pb.logisticsTime.Contains("3天") || pb.logisticsTime.Contains("预售") || day >= 2)
|
||
&& UploadPinduoduoMain.isLogistics)
|
||
{
|
||
t.Message = "跳过发货超过24小时商品或预售商品";
|
||
Error("跳过发货超过24小时商品或预售商品:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(pb.logisticsTime))
|
||
{
|
||
string daystr = BaseRegex.GetMatchRegexString(ref pb.logisticsTime, @"([\d]+)");
|
||
int day = 0;
|
||
int.TryParse(daystr, out day);
|
||
if (day / 24 > 0)
|
||
day = day / 24;
|
||
if ((pb.logisticsTime.Contains("72小时")|| pb.logisticsTime.Contains("3天") || pb.logisticsTime.Contains("预售") || day >=3)
|
||
&& UploadPinduoduoMain.isFourLogistics)
|
||
{
|
||
t.Message = "跳过发货超过48小时商品或预售商品";
|
||
Error("跳过发货超过48小时商品或预售商品:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (UploadPinduoduoMain.JinUp)
|
||
{
|
||
bool ishas = false;
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
if (pb.SkuMaps[i].price < UploadPinduoduoMain.minPrice)
|
||
{
|
||
ishas = true;
|
||
break;
|
||
}
|
||
if (pb.SkuMaps[i].price> UploadPinduoduoMain.maxPrice)
|
||
{
|
||
ishas = true;
|
||
break;
|
||
}
|
||
}
|
||
if (pb.SkuMaps.Count==0)
|
||
{
|
||
if (pb.discountPrice < UploadPinduoduoMain.minPrice)
|
||
{
|
||
ishas = true;
|
||
}
|
||
if (pb.discountPrice > UploadPinduoduoMain.maxPrice)
|
||
{
|
||
ishas = true;
|
||
}
|
||
}
|
||
if (ishas)
|
||
{
|
||
t.Message = "上传商品价格超过价格区间";
|
||
Error("跳过上传商品价格超过价格区间:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
}
|
||
if (UploadPinduoduoMain.JustFree && pb.express_price > 0)
|
||
{
|
||
t.Message = "跳过非包邮商品";
|
||
Error("跳过非包邮商品:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (pb.name.Contains("订金") || pb.name.Contains("定金") || pb.name.Contains("预售"))
|
||
{
|
||
t.Message = "预售商品";
|
||
Error("预售商品:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (BaseClass.UserVersion == 99 && (t.FromType == "拼多多" || t.FromType == "内部数据"))//|| t.FromType == "搜款网"
|
||
{
|
||
t.Message = "临时关闭";
|
||
Error("临时关闭:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (BaseClass.UserVersion != 100 && (t.FromType == "拼多多" || t.FromType == "内部数据"))
|
||
{
|
||
t.Message = "临时关闭";
|
||
Error("临时关闭:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if (pb.Props.Count==3)
|
||
{
|
||
t.Message = "此商品属性较多,官方只允许上传最多俩个属性";
|
||
Error("此商品属性较多,官方只允许上传最多俩个属性:" + t.FromId, t.Message);
|
||
return;
|
||
}
|
||
if ((t.FromType == "拼多多" || t.FromType == "内部数据" || t.FromType == "其他") && pb.Images.Count >= 8)
|
||
imageUrlx = pb.Images[7];
|
||
if ((t.FromType == "淘宝" || t.FromType == "阿里巴巴") && pb.Images.Count >= 5)
|
||
imageUrlx = pb.Images[4];
|
||
if (t.FromType == "京喜") //by ttzhao 2020.6.11
|
||
imageUrlx = pb.image;
|
||
beforeTitle = pb.name;
|
||
if (!string.IsNullOrEmpty(t.TaoKeUrl))
|
||
{
|
||
t.Titlte = pb.name;
|
||
t.Title = pb.name;
|
||
}
|
||
int beforePriceMin = Int32.MaxValue;
|
||
int beforePriceMax = 0;
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
int price = (int)(pb.SkuMaps[i].price * 100);
|
||
if (beforePriceMin > price)
|
||
beforePriceMin = price;
|
||
if (beforePriceMax < price)
|
||
beforePriceMax = price;
|
||
}
|
||
if (pb.SkuMaps.Count <= 1)
|
||
{
|
||
beforePriceMin = (int)(pb.price * 100);
|
||
beforePriceMax = beforePriceMin;
|
||
}
|
||
if (UploadPinduoduoMain.Irregularities && UploadShopControl.IrregularitiesWordFun(t.Titlte))
|
||
{
|
||
LogSave.Add(Name, Shop.Name + " 遇到品牌数据,跳过 " + t.FromId + " 该产品...");
|
||
Thread.Sleep(1000);
|
||
return;
|
||
}
|
||
pb.cat1 = t.Cat1;
|
||
pb.cat2 = t.Cat2;
|
||
pb.cat3 = t.Cat3;
|
||
pb.cat_id = t.CatId;
|
||
pb.cat4 = t.Cat4;
|
||
pb.main_cid = t.MainCatId;
|
||
pb.main_cat_name = t.MainCatName;
|
||
if (t.Cat3==8524)
|
||
{
|
||
FromTitleToCat.UserApi = true;
|
||
FromTitleToCat.inShop = null;
|
||
FromTitleToCat ft = new FromTitleToCat();
|
||
ft.TaobaoProduct = new TaobaoProductBase();
|
||
ft.Title = pb.name;
|
||
ft.TaobaoProduct.Titlte = pb.name;
|
||
ft.TaobaoProduct.FromId = pb.from_id;
|
||
ft.TaobaoCatId = pb.from_cat_id;
|
||
ft.JustGetCat = true;
|
||
ft.Get();
|
||
if (!string.IsNullOrEmpty(ft.Cat1) && ft.Cat1 != "0")
|
||
{
|
||
t.Cat1 = pb.cat1 = int.Parse(ft.Cat1);
|
||
t.Cat2 = pb.cat2 = int.Parse(ft.Cat2);
|
||
t.Cat3 = pb.cat3 = int.Parse(ft.Cat3);
|
||
t.Cat4 = pb.cat4 = int.Parse(ft.Cat4);
|
||
}
|
||
}
|
||
pb.from = t.FromType;
|
||
pb.from_name = pb.name;
|
||
if (!string.IsNullOrEmpty(t.Titlte) && t.Titlte.Length > 15)
|
||
pb.name = t.Titlte;
|
||
pb.name = BaseClass.SubCharLength(pb.name, 60).Replace("✅", "").Replace("◆", "");
|
||
if (pb.name.Contains("?"))
|
||
{
|
||
t.Message = "标题中不允许出现问号(?)";
|
||
Error("题中不允许出现问号,跳过:" + t.FromId, t.Message);
|
||
Thread.Sleep(1 * 1000);
|
||
return;
|
||
}
|
||
if (pb.Images.Count < 1)
|
||
{
|
||
t.Message = "内容图片不足";
|
||
Error("采集失败,跳过:" + t.FromId, t.Message);
|
||
Thread.Sleep(10 * 1000);
|
||
return;
|
||
}
|
||
if (pb.content==null||!pb.content.Contains("<img"))
|
||
{
|
||
foreach (var s in pb.Images)
|
||
{
|
||
pb.content += "<img src='" + s + "'>";
|
||
}
|
||
}
|
||
//删除固定主图
|
||
if (UploadPinduoduoMain.DeleteMainImage && pb.Images.Count > 1 && pb.Images.Count > UploadPinduoduoMain.DeleteMainImageCut)
|
||
pb.Images.RemoveAt(UploadPinduoduoMain.DeleteMainImageCut);
|
||
if (UploadPinduoduoMain.RandDeleteImage && pb.Images.Count > 1)
|
||
pb.Images.RemoveAt(Randomx.GetId(pb.Images.Count - 1));
|
||
if (UploadPinduoduoMain.PropImageToMain)
|
||
{
|
||
List<string> imgs = new List<string>();
|
||
for (int i = 0; i < pb.Props.Count; i++)
|
||
{
|
||
for (int j = 0; j < pb.Props[i].Values.Count; j++)
|
||
{
|
||
//if (!string.IsNullOrEmpty(pb.Props[i].Values[j].image) && !imgs.Contains(pb.Props[i].Values[j].image) || string.IsNullOrEmpty(pb.Props[i].Values[j].image))
|
||
if (string.IsNullOrEmpty(pb.Props[i].Values[j].image) || imgs.Contains(pb.Props[i].Values[j].image))
|
||
continue;
|
||
imgs.Add(pb.Props[i].Values[j].image);
|
||
}
|
||
}
|
||
if (imgs.Count > 2)
|
||
pb.Images = imgs;
|
||
}
|
||
|
||
for (int i = 0; UploadPinduoduoMain.RandMainImage && i < 15 && t.MainImage == 0; i++)//随机主题
|
||
{
|
||
int i1 = new Random(Guid.NewGuid().GetHashCode()).Next(0, pb.Images.Count - 1);
|
||
int i2 = new Random(Guid.NewGuid().GetHashCode()).Next(0, pb.Images.Count - 1);
|
||
int go = new Random(Guid.NewGuid().GetHashCode()).Next(0, 100);
|
||
if (i1 == i2 || go < 60)
|
||
continue;
|
||
string imgRand1 = pb.Images[i1];
|
||
string imgRand2 = pb.Images[i2];
|
||
pb.Images[i1] = imgRand2;
|
||
pb.Images[i2] = imgRand1;
|
||
}
|
||
for (int i = 0; i < pb.Images.Count; i++)
|
||
{
|
||
if (string.IsNullOrEmpty(pb.Images[i]))
|
||
continue;
|
||
if (!pb.Images[i].Contains("http:") && !pb.Images[i].Contains("https:"))
|
||
pb.Images[i] = "http:" + pb.Images[i];
|
||
if (pb.Images[i].Contains(".src"))
|
||
pb.Images[i] = pb.Images[i].Replace(".src", "");
|
||
if (pb.Images[i].Contains("@"))
|
||
pb.Images[i] = pb.Images[i].Substring(0, pb.Images[i].IndexOf("@"));
|
||
if (pb.Images[i].Contains("?"))
|
||
pb.Images[i] = pb.Images[i].Substring(0, pb.Images[i].IndexOf("?"));
|
||
}
|
||
UpPinduoduoProduct up = new UpPinduoduoProduct(Shop, Name);
|
||
up.BuildSkuMapProps(ref pb);
|
||
|
||
//获取缓存的图片
|
||
|
||
string ids = "";
|
||
for (int i = 0; i < pb.Images.Count; i++)
|
||
{
|
||
string urlx = pb.Images[i];
|
||
if (string.IsNullOrEmpty(urlx))
|
||
continue;
|
||
if (urlx.Contains(".yangkeduo.com"))
|
||
continue;
|
||
long urlId = Math.Abs(BaseClass.GetLong(urlx));
|
||
if (UploadPinduoduoMain.MainImg && picsTemp.ContainsKey(urlId))
|
||
{
|
||
pb.Images[i] = picsTemp[urlId];
|
||
continue;
|
||
}
|
||
if (!string.IsNullOrEmpty(urlx))
|
||
ids += urlId + ",";
|
||
}
|
||
var mx = BaseRegex.GetMatchRegex(ref pb.content, @"<img [^>]*?src=[""'](.*?)[""']");
|
||
if (mx.Count == 0)
|
||
mx = BaseRegex.GetMatchRegex(ref pb.content, @"<img[^>]*?>(.*?)</img>");
|
||
for (int j = 0; j < mx.Count; j++)
|
||
{
|
||
string urlx = mx[j].Groups[1].Value.Replace(".src", "");
|
||
if (string.IsNullOrEmpty(urlx))
|
||
continue;
|
||
if (urlx.Contains("//") && !urlx.Contains("http:") && !urlx.Contains("https:"))
|
||
urlx = "http:" + urlx;
|
||
if (urlx.Contains("?"))
|
||
urlx = urlx.Substring(0, urlx.IndexOf("?"));
|
||
if (urlx.Contains("@"))
|
||
urlx = urlx.Substring(0, urlx.IndexOf("@"));
|
||
if (urlx.Contains(".yangkeduo.com"))
|
||
continue;
|
||
long urlId = Math.Abs(BaseClass.GetLong(urlx));
|
||
if (picsTemp.ContainsKey(urlId))
|
||
continue;
|
||
if (!string.IsNullOrEmpty(urlx))
|
||
ids += urlId + ",";
|
||
}
|
||
for (int j = 0; pb.Props.Count > 0 && j < pb.SkuMaps.Count; j++)
|
||
{
|
||
if (!string.IsNullOrEmpty(pb.SkuMaps[j].prop_image) && pb.SkuMaps[j].prop_image.Contains(".yangkeduo.com/"))
|
||
{
|
||
if (pb.SkuMaps[j].prop_image.Substring(0, 2) == "//")
|
||
pb.SkuMaps[j].prop_image = "http:" + pb.SkuMaps[j].prop_image;
|
||
if (string.IsNullOrEmpty(pb.SkuMaps[j].pinduoduo_image))
|
||
pb.SkuMaps[j].pinduoduo_image = pb.SkuMaps[j].prop_image;
|
||
continue;
|
||
}
|
||
string urlx = string.IsNullOrEmpty(pb.SkuMaps[j].pinduoduo_image) ? pb.SkuMaps[j].prop_image : pb.SkuMaps[j].pinduoduo_image;
|
||
if (string.IsNullOrEmpty(urlx))
|
||
continue;
|
||
urlx = urlx.Replace(".src", "");
|
||
if (urlx.Contains("//") && !urlx.Contains("http:") && !urlx.Contains("https:"))
|
||
urlx = "http:" + urlx;
|
||
if (urlx.Contains("?"))
|
||
urlx = urlx.Substring(0, urlx.IndexOf("?"));
|
||
if (urlx.Contains("@"))
|
||
urlx = urlx.Substring(0, urlx.IndexOf("@"));
|
||
pb.SkuMaps[j].prop_image = urlx;
|
||
if (urlx.Contains(".yangkeduo.com"))
|
||
continue;
|
||
long urlId = Math.Abs(BaseClass.GetLong(urlx));
|
||
if (picsTemp.ContainsKey(urlId))
|
||
{
|
||
pb.SkuMaps[j].prop_image = picsTemp[urlId];
|
||
pb.SkuMaps[j].pinduoduo_image = picsTemp[urlId];
|
||
continue;
|
||
}
|
||
if (!string.IsNullOrEmpty(urlx) && !ids.Contains(urlId.ToString()))
|
||
ids += urlId + ",";
|
||
}
|
||
if (!string.IsNullOrEmpty(ids))
|
||
{
|
||
ids = ids.Substring(0, ids.Length - 1);
|
||
string urlxt = BaseClass.LoginApiUrl + "?obj=upshopid/image_pinduoduo&act=get";
|
||
string dataxt = UserLogin.GetSignaturex() + "&ids=" + ids;
|
||
string htmlxt = GetHtml.PostUtf8(urlxt, dataxt);
|
||
var mg = BaseRegex.GetMatchRegex(ref htmlxt, @"([\d]+),([\w\W]+?);");
|
||
|
||
for (int i = 0; i < mg.Count; i++)
|
||
{
|
||
try
|
||
{
|
||
long id = long.Parse(mg[i].Groups[1].Value);
|
||
string urlx = mg[i].Groups[2].Value;
|
||
picsTemp.Add(id, urlx);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
}
|
||
byte[] img;
|
||
bool ok;
|
||
|
||
string imageString = "";
|
||
string apiImageString = "";
|
||
ImageBuild ib;
|
||
List<string> images = new List<string>();
|
||
for (int j = 0; j < pb.Images.Count && images.Count < 10; j++)
|
||
{
|
||
if (pb.Images[j].Length > 2 && pb.Images[j].Substring(0, 2) == "//")
|
||
pb.Images[j] = "http:" + pb.Images[j];
|
||
if (pb.Images[j].Contains("@"))
|
||
pb.Images[j] = pb.Images[j].Substring(0, pb.Images[j].IndexOf("@"));
|
||
string imgUrl = "";
|
||
string tempImage = pb.Images[j];
|
||
//图片缓存
|
||
if (UploadPinduoduoMain.MainImg && picsTemp.ContainsKey(Math.Abs(BaseClass.GetLong(tempImage))))
|
||
tempImage = picsTemp[Math.Abs(BaseClass.GetLong(tempImage))];
|
||
if (tempImage.Contains(".yangkeduo.com/"))
|
||
{
|
||
images.Add(tempImage);
|
||
imageString += ",{\"url\":\"" + tempImage + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
|
||
apiImageString += ",\"" + tempImage + "\"";
|
||
if (imageByte == null || j == 5)
|
||
{
|
||
GetPostTaobaoHtml.DownLoadImage(tempImage, out img);
|
||
imageByte = img;
|
||
}
|
||
continue;
|
||
}
|
||
|
||
if (ImageTemp.ContainsKey(tempImage) && ImageTemp[tempImage].Height == ImageTemp[tempImage].Width && ImageTemp[tempImage].Width > 480 && ImageTemp[tempImage].Width <= 800)
|
||
{
|
||
imgUrl = ImageTemp[tempImage].Url;
|
||
images.Add(imgUrl);
|
||
AddImage(tempImage, imgUrl, 640, 640);
|
||
imageString += ",{\"url\":\"" + imgUrl + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
|
||
apiImageString += ",\"" + imgUrl + "\"";
|
||
continue;
|
||
}
|
||
ok = GetPostTaobaoHtml.DownLoadImage(tempImage, out img);
|
||
if (!ok)
|
||
continue;
|
||
if (imageByte == null && j == 2)
|
||
{
|
||
imageByte = img;
|
||
}
|
||
ib = new ImageBuild(img);
|
||
if (tempImage.Contains(".yangkeduo.com") && ib.CanUser && ib.Width == ib.Height && ib.Width >= 480 && ib.Width <= 800 && img.Length < 100 * 1024 && images.Count < 2)
|
||
{
|
||
imgUrl = tempImage;
|
||
}
|
||
else
|
||
{
|
||
ImageCut.HandleImage(ref img, UploadPinduoduoMain.MainImg);
|
||
ib = new ImageBuild(img);
|
||
if (UploadPinduoduoMain.MainImg)
|
||
img = ib.BuildNewSize(640, 640, 100);
|
||
else
|
||
img = ib.BuildNewSizeCut(640, 640, 100);
|
||
imgUrl = UploadImg(tempImage, ref img, true);
|
||
}
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
continue;
|
||
images.Add(imgUrl);
|
||
AddImage(tempImage, imgUrl, 640, 640);
|
||
imageString += ",{\"url\":\"" + imgUrl + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
|
||
apiImageString += ",\"" + imgUrl + "\"";
|
||
}
|
||
if (images.Count == 0)
|
||
{
|
||
t.Message = "上传轮播图错误";
|
||
Error(t.Message, t.Message);
|
||
return;
|
||
}
|
||
|
||
string apiContentString = "";
|
||
List<string> contentImage = new List<string>();
|
||
var m = BaseRegex.GetMatchRegex(ref pb.content, @"<img [^>]*?src=[""'](.*?)[""']");
|
||
if (m.Count == 0)
|
||
m = BaseRegex.GetMatchRegex(ref pb.content, @"<img[^>]*?>(.*?)</img>");
|
||
if (m.Count == 0)
|
||
m = BaseRegex.GetMatchRegex(ref pb.content, @"<img[^>]+?>(.*?)</img>");
|
||
int maxImageCount = UploadPinduoduoMain.JustSaveContentImage ? UploadPinduoduoMain.JustSaveContentImageCount : 20;
|
||
//if (maxImageCount < m.Count&&!UploadPinduoduoMain.JustSaveContentImage)
|
||
// maxImageCount = m.Count;
|
||
for (int j = 0; j < m.Count && contentImage.Count < maxImageCount; j++)
|
||
{
|
||
if (j == 0 && m.Count > 3 && UploadPinduoduoMain.DeleteFirst)//不要第一张图
|
||
continue;
|
||
if (m.Count > 5 && j == m.Count - 1 && UploadPinduoduoMain.DeleteFirst)//最后一张
|
||
continue;
|
||
string urlImg = m[j].Groups[1].Value.Replace(".src", "");
|
||
if (string.IsNullOrEmpty(urlImg))
|
||
continue;
|
||
if (urlImg.Contains("//") && !urlImg.Contains("http:") && !urlImg.Contains("https:"))
|
||
urlImg = "http:" + urlImg;
|
||
if (urlImg.Contains("?"))
|
||
urlImg = urlImg.Substring(0, urlImg.IndexOf("?"));
|
||
|
||
//图片缓存
|
||
if (picsTemp.ContainsKey(Math.Abs(BaseClass.GetLong(urlImg))))
|
||
urlImg = picsTemp[Math.Abs(BaseClass.GetLong(urlImg))];
|
||
|
||
if (urlImg.Contains(".yangkeduo.com/"))
|
||
{
|
||
contentImage.Add(urlImg);
|
||
imageString += ",{\"url\":\"" + urlImg + "\",\"width\":640,\"height\":640,\"type\":\"2\"}";
|
||
apiContentString += ",\"" + urlImg + "\"";
|
||
continue;
|
||
}
|
||
//string exe = Path.GetExtension(urlImg).ToLower();
|
||
//if (exe != ".jpeg" && exe != ".jpg" && exe != ".png" && exe != ".gif")
|
||
// continue;
|
||
if (ImageTemp.ContainsKey(urlImg))
|
||
{
|
||
string imgUrl = ImageTemp[urlImg].Url;
|
||
contentImage.Add(imgUrl);
|
||
imageString += ",{\"url\":\"" + imgUrl + "\",\"width\":" + ImageTemp[urlImg].Width + ",\"height\":" + ImageTemp[urlImg].Height + ",\"type\":\"2\"}";
|
||
apiContentString += ",\"" + imgUrl + "\"";
|
||
continue;
|
||
}
|
||
ok = GetPostTaobaoHtml.DownLoadImage(urlImg, out img);
|
||
if (ok && img.Length < 1000 * 1024)
|
||
{
|
||
ib = new ImageBuild(img);
|
||
int width = ib.Width;
|
||
int height = ib.Height;
|
||
if (ib.Width < 480 || ib.Width > 2500 || ib.Height > 1500)
|
||
{
|
||
if (ib.Width > 480 && ib.Width < 2500 && ib.Height > 1500)//contentImage.Count < 2 &&
|
||
{
|
||
if (ib.Width > 640)
|
||
{
|
||
width = 640;
|
||
int per = width * 100 / ib.Width;
|
||
height = ib.Height * per / 100;
|
||
height = Math.Min(1000, height);
|
||
}
|
||
else
|
||
{
|
||
width = ib.Width;
|
||
height = 1500;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
continue;
|
||
}
|
||
}
|
||
else if (ib.Width > 640)//图片宽度太宽的压缩一下
|
||
{
|
||
width = 640;
|
||
int per = width * 100 / ib.Width;
|
||
height = ib.Height * per / 100;
|
||
}
|
||
if (height < 10)
|
||
continue;
|
||
string imgUrl = "";
|
||
if (urlImg.Contains(".yangkeduo.com") && ib.CanUser && ib.Width > 480 && ib.Width < 1200 && ib.Height > 10 && ib.Height < 1500)
|
||
{
|
||
imgUrl = urlImg;
|
||
}
|
||
else
|
||
{
|
||
img = ib.BuildNewSize(width, height, 950);//不管大小如何,都重新生成JPG图片
|
||
imgUrl = UploadImg(urlImg, ref img, true);
|
||
}
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
contentImage.Add(imgUrl);
|
||
imageString += ",{\"url\":\"" + imgUrl + "\",\"width\":" + width + ",\"height\":" + height + ",\"type\":\"2\"}";
|
||
apiContentString += ",\"" + imgUrl + "\"";
|
||
AddImage(urlImg, imgUrl, width, height);
|
||
}
|
||
}
|
||
}
|
||
if (contentImage.Count == 0)
|
||
{
|
||
t.Message = "上传内容图异常";
|
||
Error(t.Message, t.Message);
|
||
return;
|
||
}
|
||
//上传SKU图
|
||
string firstSkuImage = "";
|
||
imageString = imageString.Substring(1);
|
||
apiContentString = apiContentString.Substring(1);
|
||
for (int j = 0; pb.Props.Count > 0 && j < pb.SkuMaps.Count; j++)
|
||
{
|
||
long urlId = Math.Abs(BaseClass.GetLong(pb.SkuMaps[j].prop_image));
|
||
if (picsTemp.ContainsKey(urlId))
|
||
pb.SkuMaps[j].prop_image = picsTemp[urlId];
|
||
if (!string.IsNullOrEmpty(pb.SkuMaps[j].prop_image) && pb.SkuMaps[j].prop_image.Contains(".yangkeduo.com/"))
|
||
{
|
||
if (pb.SkuMaps[j].prop_image.Substring(0, 2) == "//")
|
||
pb.SkuMaps[j].prop_image = "http:" + pb.SkuMaps[j].prop_image;
|
||
if (string.IsNullOrEmpty(pb.SkuMaps[j].pinduoduo_image))
|
||
pb.SkuMaps[j].pinduoduo_image = pb.SkuMaps[j].prop_image;
|
||
continue;
|
||
}
|
||
|
||
if (ImageTemp.ContainsKey(pb.SkuMaps[j].prop_image) && ImageTemp[pb.SkuMaps[j].prop_image].Width > 480 && ImageTemp[pb.SkuMaps[j].prop_image].Width == ImageTemp[pb.SkuMaps[j].prop_image].Height)
|
||
{
|
||
pb.SkuMaps[j].pinduoduo_image = ImageTemp[pb.SkuMaps[j].prop_image].Url;
|
||
if (string.IsNullOrEmpty(firstSkuImage))
|
||
firstSkuImage = pb.SkuMaps[j].pinduoduo_image;
|
||
continue;
|
||
}
|
||
string urlx = pb.SkuMaps[j].prop_image;
|
||
if (string.IsNullOrEmpty(urlx))
|
||
continue;
|
||
if (!urlx.Contains("http:") && !urlx.Contains("https:"))
|
||
urlx = "http:" + urlx;
|
||
|
||
ok = GetHtml.DownloadFile(urlx, out img);
|
||
ib = new ImageBuild(img);
|
||
if (ImageTemp.ContainsKey(pb.SkuMaps[j].prop_image) && ib.Width == ib.Height && ib.Width > 480 && ImageTemp[pb.SkuMaps[j].prop_image].Url.Contains("http:"))//未找到尺寸
|
||
{
|
||
ImageTemp[pb.SkuMaps[j].prop_image].Width = ib.Width;
|
||
ImageTemp[pb.SkuMaps[j].prop_image].Height = ib.Height;
|
||
pb.SkuMaps[j].pinduoduo_image = ImageTemp[pb.SkuMaps[j].prop_image].Url;
|
||
if (string.IsNullOrEmpty(firstSkuImage))
|
||
firstSkuImage = pb.SkuMaps[j].pinduoduo_image;
|
||
continue;
|
||
}
|
||
string imgUrl = "";
|
||
img = ib.BuildNewSize(640, 640, 800);
|
||
if (urlx.Contains(".yangkeduo.com") && ib.CanUser && ib.Width == ib.Height && ib.Width > 480 && ib.Width <= 800)
|
||
{
|
||
imgUrl = urlx;
|
||
}
|
||
else
|
||
{
|
||
imgUrl = UploadImg(urlx, ref img, true);
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
Thread.Sleep(1000);
|
||
imgUrl = UploadImg(urlx, ref img, true);
|
||
}
|
||
AddImage(urlx, imgUrl, 640, 640);
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
t.Message = "上传属性图异常";
|
||
Error(t.Message, t.Message);
|
||
return;
|
||
}
|
||
if (string.IsNullOrEmpty(firstSkuImage))
|
||
firstSkuImage = imgUrl;
|
||
pb.SkuMaps[j].pinduoduo_image = imgUrl;
|
||
if (ImageTemp.ContainsKey(pb.SkuMaps[j].prop_image))
|
||
{
|
||
ImageTemp[pb.SkuMaps[j].prop_image].Url = imgUrl;
|
||
ImageTemp[pb.SkuMaps[j].prop_image].Width = 640;
|
||
ImageTemp[pb.SkuMaps[j].prop_image].Height = 640;
|
||
}
|
||
AddImage(pb.SkuMaps[j].prop_image, pb.SkuMaps[j].pinduoduo_image, 640, 640);
|
||
}
|
||
if (string.IsNullOrEmpty(firstSkuImage) && images.Count > 0)
|
||
firstSkuImage = images[0];
|
||
|
||
if (pb.Images.Count < 10)
|
||
{
|
||
int subCount = 10 - pb.Images.Count;
|
||
if (pb.SkuMaps.Count > subCount)
|
||
{
|
||
for (int i = 0; i < subCount; i++)
|
||
{
|
||
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(0, pb.SkuMaps.Count);
|
||
string imagex = pb.SkuMaps[randx].pinduoduo_image;
|
||
if (imagex.Contains("@"))
|
||
imagex = imagex.Substring(0, imagex.IndexOf("@"));
|
||
pb.Images.Add(imagex);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(0, pb.SkuMaps.Count);
|
||
string imagex = pb.SkuMaps[randx].pinduoduo_image;
|
||
if (string.IsNullOrEmpty(imagex))
|
||
continue;
|
||
if (imagex.Contains("@"))
|
||
imagex = imagex.Substring(0, imagex.IndexOf("@"));
|
||
pb.Images.Add(imagex);
|
||
}
|
||
//subCount = 8 - pb.Images.Count;
|
||
//for (int i = 0; i < subCount; i++)
|
||
//{
|
||
// int randx = new Random(Guid.NewGuid().GetHashCode()).Next(0, contentImage.Count);
|
||
// pb.Images.Add(contentImage[randx]);
|
||
//}
|
||
}
|
||
int start = images.Count;
|
||
for (int j = start; j < pb.Images.Count; j++)
|
||
{
|
||
string tempImage = pb.Images[j];
|
||
//if (tempImage.Contains(".yangkeduo.com/"))
|
||
//{
|
||
images.Add(tempImage);
|
||
//imageString += ",{\"url\":\"" + tempImage + "\",\"width\":640,\"height\":640,\"type\":\"1\"}";
|
||
apiImageString += ",\"" + tempImage + "\"";
|
||
//continue;
|
||
//}
|
||
}
|
||
}
|
||
string url, data, html, refere = "https://mms.pinduoduo.com/Pdd.html";
|
||
string skuString = "";
|
||
string skuApiString = "", upProductId;
|
||
string out_goods_id = EncryptionCode.GetCode(pb.from_id, pb.from_site_id, Shop.MallId, out upProductId);
|
||
out_goods_id = "";
|
||
|
||
decimal maxPriceNewx = 0, minPriceNewx = 1000000;
|
||
decimal maxPriceOnline = 0, maxPriceNew = 0;
|
||
|
||
string singlePrice = t.ViPrice;
|
||
decimal proPrice = 0M;
|
||
decimal proPos = 0M;
|
||
|
||
if (!string.IsNullOrEmpty(singlePrice))
|
||
{
|
||
proPrice = decimal.Parse(singlePrice.Split('+')[0].Replace("%", ""));
|
||
proPos = decimal.Parse(singlePrice.Split('+')[1]);
|
||
}
|
||
|
||
decimal expressPrcie = pb.express_price;
|
||
if (!UploadPinduoduoMain.isExpressPrice)
|
||
expressPrcie = 0.0M;
|
||
if (pb.Props.Count == 0 || pb.Props[0].Values.Count == 0)
|
||
{
|
||
if (pb.price == 0 && pb.SkuMaps.Count > 0)
|
||
pb.price = pb.SkuMaps[0].price;
|
||
int onsale = pb.price == 0 ? 0 : 1;
|
||
int multi_price = 0;
|
||
if (t.ViGoodsId <= 0 || string.IsNullOrEmpty(singlePrice))
|
||
{
|
||
multi_price = WhitePriceBuild(pb.price, UploadPinduoduoMain.MultiPrice, expressPrcie);
|
||
}
|
||
else
|
||
{
|
||
multi_price = WhitePriceBuild(pb.price, proPrice, proPos, expressPrcie);
|
||
}
|
||
// 微店转换数据对sku价格取整,尾数1,2,3,4的加到5,尾数6,7,8,9的加到10
|
||
if (t.ViGoodsId > 0 && IsRounding)
|
||
{
|
||
while (!multi_price.ToString().EndsWith("0") && !multi_price.ToString().EndsWith("5"))
|
||
{
|
||
multi_price++;
|
||
}
|
||
}
|
||
maxPriceNewx = multi_price;
|
||
minPriceNewx = multi_price;
|
||
maxPriceNew = multi_price;
|
||
maxPriceOnline = multi_price + UploadPinduoduoMain.SinglePrice * 100;
|
||
skuString = ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + UploadPinduoduoMain.LimitBuy +
|
||
",\"quantity_delta\":" + UploadPinduoduoMain.LimitBuy + ",\"thumb_url\":\"\"," +
|
||
"\"multi_price\":" + multi_price + ",\"price\":" +
|
||
(multi_price + UploadPinduoduoMain.SinglePrice * 100) + ",\"out_sku_sn\":\"" + out_goods_id + "\",\"id\":0,\"spec\":\"\",\"weight\":1000}";
|
||
skuApiString = ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + UploadPinduoduoMain.LimitBuy +
|
||
",\"price\":\"" + (multi_price + UploadPinduoduoMain.SinglePrice * 100) + "\",\"weight\":1000,\"multi_price\":\"" + multi_price
|
||
+ "\",\"thumb_url\":\"" + firstSkuImage + "\",\"out_sku_sn\":\"" + out_goods_id + "\",\"quantity\":" + UploadPinduoduoMain.LimitBuy + ",\"spec_id_list\":\"[]\"}";
|
||
out_goods_id = "";
|
||
}
|
||
string Cookies = Shop.Cookies;
|
||
//随机属性名称
|
||
bool begin = new Random(Guid.NewGuid().GetHashCode()).Next(0, 10) < 5;
|
||
//UploadPinduoduoMain.RandSku = false;//临时关闭随机SKU功能
|
||
for (int i = 0; UploadPinduoduoMain.RandSku && i < pb.Props.Count; i++)
|
||
{
|
||
for (int j = 0; j < pb.Props[i].Values.Count; j++)
|
||
{
|
||
if (pb.Props[i].name == "尺码")
|
||
break;
|
||
pb.Props[i].Values[j].name_pinduoduo = Randomx.GetNewProp(begin, pb.Props[i].Values[j].name);
|
||
url = "https://mms.pinduoduo.com/glide/v2/mms/query/spec/by/name";
|
||
data = "{\"parent_id\":" + pb.Props[i].pinduoduo_id + ",\"name\":\"" + pb.Props[i].Values[j].name_pinduoduo + "\"}";
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Cookies);
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||
{
|
||
Thread.Sleep(30 * 1000);
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Cookies);
|
||
}
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||
{
|
||
Thread.Sleep(30 * 1000);
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Cookies);
|
||
}
|
||
string propvid = BaseRegex.GetStringJson(ref html, "result");
|
||
if (string.IsNullOrEmpty(propvid))
|
||
{
|
||
Thread.Sleep(3000);
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Cookies);
|
||
propvid = BaseRegex.GetStringJson(ref html, "result");
|
||
}
|
||
pb.Props[i].Values[j].id = propvid;
|
||
}
|
||
}
|
||
if (t.Cat3 == 0)
|
||
{
|
||
foreach (KeyValuePair<int, CatBase> c3 in PinduoduoCatList.CatIds)
|
||
{
|
||
if (c3.Value.cat2 == t.Cat2 && c3.Value.cat3 > 0)
|
||
{
|
||
t.Cat3 = c3.Value.cat3;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (t.Cat4 == 0 && t.Cat3 > 0)
|
||
{
|
||
foreach (KeyValuePair<int, CatBase> c4 in PinduoduoCatList.CatIds)
|
||
{
|
||
if (c4.Value.cat3 == t.Cat3 && c4.Value.cat4 > 0)
|
||
{
|
||
t.Cat4 = c4.Value.cat4;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
int catId = t.Cat4 > 0 ? t.Cat4 : t.Cat3, maxEndPrice = 0;
|
||
if (catId == 0)
|
||
catId = t.CatId;
|
||
catId = PinduoduoCatList.GetNewCat3(catId);
|
||
|
||
// 低价sku
|
||
SkuMapBase skuMin = null;
|
||
// 生成新的价格
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
// 团购(拼团)
|
||
if (t.ViGoodsId <= 0 || string.IsNullOrEmpty(singlePrice))
|
||
{
|
||
if (UploadPinduoduoMain.isPriceModel)
|
||
{
|
||
for (int k = 0; k < UploadPinduoduoMain.PriceModelList.Count; k++)
|
||
{
|
||
var item = UploadPinduoduoMain.PriceModelList[k];
|
||
if (pb.SkuMaps[i].price >= item.MinPrice && pb.SkuMaps[i].price < item.MaxPrice)
|
||
{
|
||
UploadPinduoduoMain.Postage = item.CoupPrice;
|
||
UploadPinduoduoMain.MultiPrice = 0;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
pb.SkuMaps[i].new_price = WhitePriceBuild(pb.SkuMaps[i].price, UploadPinduoduoMain.MultiPrice, expressPrcie);
|
||
}
|
||
else
|
||
{
|
||
//if (UploadPinduoduoMain.isPriceModel)
|
||
//{
|
||
// for (int k = 0; k < UploadPinduoduoMain.PriceModelList.Count; k++)
|
||
// {
|
||
// var item = UploadPinduoduoMain.PriceModelList[k];
|
||
// if (pb.SkuMaps[i].price >= item.MinPrice && pb.SkuMaps[i].price < item.MaxPrice)
|
||
// {
|
||
// proPos = item.CoupPrice;
|
||
// proPrice = 0;
|
||
// break;
|
||
// }
|
||
// }
|
||
//}
|
||
pb.SkuMaps[i].new_price = WhitePriceBuild(pb.SkuMaps[i].price, proPrice, proPos, expressPrcie);
|
||
}
|
||
if (maxEndPrice < pb.SkuMaps[i].new_price)
|
||
maxEndPrice = pb.SkuMaps[i].new_price;
|
||
// 单买
|
||
pb.SkuMaps[i].online_price = (int)(pb.SkuMaps[i].new_price + UploadPinduoduoMain.SinglePrice * 100);
|
||
if (maxPriceNew < pb.SkuMaps[i].new_price)
|
||
maxPriceNew = pb.SkuMaps[i].new_price;
|
||
if (maxPriceOnline < pb.SkuMaps[i].online_price)
|
||
maxPriceOnline = pb.SkuMaps[i].online_price;
|
||
if (skuMin == null || skuMin.new_price > pb.SkuMaps[i].new_price)
|
||
skuMin = pb.SkuMaps[i];
|
||
}
|
||
int skuMinBackPrice = skuMin==null?0:skuMin.new_price;
|
||
string skuMinString = "";
|
||
if (UploadPinduoduoMain.LowPriceSku && pb.SkuMaps.Count > 1 && skuMin != null)
|
||
{
|
||
skuMin.new_price =
|
||
(int)((skuMin.price * UploadPinduoduoMain.LowPricePercent + UploadPinduoduoMain.LowPriceAdd+expressPrcie) * 100);
|
||
}
|
||
|
||
int market_price = (int)(maxPriceOnline * UploadPinduoduoMain.BeforePrice);
|
||
bool userShield = false;
|
||
//临时关闭价格护盾
|
||
decimal dd = PinduoduoCatList.GetPriceSpace(catId) * 10;
|
||
if (dd == 12)
|
||
dd = 10;
|
||
for (int i = 0; UploadPinduoduoMain.PriceShield && i < pb.SkuMaps.Count; i++) // 二级护盾
|
||
{
|
||
if (UploadPinduoduoMain.LowPriceSku && pb.SkuMaps[i].id == skuMin.id)
|
||
continue;
|
||
pb.SkuMaps[i].new_price = (int)(pb.SkuMaps[i].new_price) / 10 * 10;
|
||
if (pb.SkuMaps[i].new_price < maxPriceNew / dd * 10)
|
||
{
|
||
userShield = true;
|
||
pb.SkuMaps[i].new_price = (int)(maxPriceNew / dd * 10);
|
||
}
|
||
//单买
|
||
pb.SkuMaps[i].online_price = (int)(pb.SkuMaps[i].online_price);
|
||
if (pb.SkuMaps[i].online_price < maxPriceOnline / dd * 10)
|
||
{
|
||
userShield = true;
|
||
pb.SkuMaps[i].online_price = (int)(maxPriceOnline / dd * 10 + 100);
|
||
}
|
||
}
|
||
if (dd == 10)
|
||
{
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
if (UploadPinduoduoMain.LowPriceSku)
|
||
continue;
|
||
pb.SkuMaps[i].new_price = (int)(maxPriceNew / dd * 10);
|
||
pb.SkuMaps[i].online_price = (int)(maxPriceOnline / dd * 10 + 100);
|
||
}
|
||
}
|
||
for (int i = 0; i < pb.Props.Count; i++)//剔除过多的属性
|
||
{
|
||
while (pb.Props[i].Values.Count > 30 && pb.Props.Count > 1)
|
||
{
|
||
string[] li = skuMin.name.Split(';');
|
||
string n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim();
|
||
string n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim();
|
||
if (pb.Props[i].Values[30].name.Contains(n1) || pb.Props[i].Values[30].name.Contains(n2)
|
||
|| n1.Contains(pb.Props[i].Values[30].name) || n2.Contains(pb.Props[i].Values[30].name))
|
||
{
|
||
pb.Props[i].Values.RemoveAt(29);
|
||
continue;
|
||
}
|
||
pb.Props[i].Values.RemoveAt(30);
|
||
}
|
||
while (pb.Props[i].Values.Count > 40 && pb.Props.Count == 1)
|
||
{
|
||
if (pb.Props[i].Values[40].name.Contains(skuMin.name) || skuMin.name.Contains(pb.Props[i].Values[40].name))
|
||
{
|
||
pb.Props[i].Values.RemoveAt(39);
|
||
continue;
|
||
}
|
||
pb.Props[i].Values.RemoveAt(40);
|
||
}
|
||
}
|
||
decimal maxSkuPriceOnline = 0;
|
||
decimal maxSkuMultiPriceOnline = 0;
|
||
|
||
// 微店转换数据对sku价格取整,尾数1,2,3,4的加到5,尾数6,7,8,9的加到10
|
||
if (t.ViGoodsId > 0 && IsRounding)
|
||
{
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
var sk = pb.SkuMaps[i];
|
||
while (!sk.new_price.ToString().EndsWith("0") && !sk.new_price.ToString().EndsWith("5"))
|
||
{
|
||
sk.new_price++;
|
||
}
|
||
while (!sk.online_price.ToString().EndsWith("0") && !sk.online_price.ToString().EndsWith("5"))
|
||
{
|
||
sk.online_price++;
|
||
}
|
||
}
|
||
}
|
||
if (pb.Props.Count == 1)
|
||
{
|
||
for (int j = 0; j < pb.Props[0].Values.Count; j++)
|
||
{
|
||
var sku = new SkuMapBase();
|
||
for (int k = 0; k < pb.SkuMaps.Count; k++)
|
||
{
|
||
string[] li = pb.SkuMaps[k].name.Split(';');
|
||
string n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim();//pb.SkuMaps[k].nameLite
|
||
if (n1.Replace(" ", "+") == pb.Props[0].Values[j].name || n1 == pb.Props[0].Values[j].name)
|
||
{
|
||
sku = pb.SkuMaps[k];
|
||
break;
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(sku.pinduoduo_image))
|
||
{
|
||
sku.pinduoduo_image = firstSkuImage;
|
||
}
|
||
if (sku.new_price == 0)
|
||
{
|
||
//Error("价格错误,跳过上传" + t.FromId, "价格计算错误");
|
||
continue;
|
||
}
|
||
if (sku.new_price > sku.online_price - 100)
|
||
sku.online_price = sku.new_price + 100;
|
||
|
||
if (maxSkuPriceOnline < sku.online_price)
|
||
maxSkuPriceOnline = sku.online_price;
|
||
if (maxSkuMultiPriceOnline < sku.new_price)
|
||
maxSkuMultiPriceOnline = sku.new_price;
|
||
if (pb.Props[0].Values[j].id == null || pb.Props[0].Values[j].id.Contains("null"))
|
||
continue;
|
||
int onsale = sku.number == 0 || sku.price == 0 ? 0 : 1;
|
||
if (skuApiString.Contains(pb.Props[0].Values[j].id + "]"))
|
||
continue;
|
||
int quantity = UploadPinduoduoMain.LimitBuy;
|
||
if (!UploadPinduoduoMain.isDefaultQun)
|
||
{
|
||
quantity = sku.number;
|
||
}
|
||
skuString += ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"quantity_delta\":" + quantity + ",\"thumb_url\":\"" + sku.pinduoduo_image + "\"," +
|
||
"\"multi_price\":" + sku.new_price + ",\"price\":" +
|
||
sku.online_price +
|
||
",\"out_sku_sn\":\"" + out_goods_id + "\",\"id\":0,\"spec\":" +
|
||
"[{\"parent_name\":\"" + pb.Props[0].name + "\",\"parent_id\":" +
|
||
pb.Props[0].id + ",\"spec_name\":\"" + pb.Props[0].Values[j].name_pinduoduo + "\",\"spec_id\":" +
|
||
pb.Props[0].Values[j].id + "}],\"weight\":1000}";
|
||
if (UploadPinduoduoMain.LowPriceQ && skuMin != null && sku.id == skuMin.id)
|
||
{
|
||
skuApiString += ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"price\":\"" + sku.online_price + "\",\"weight\":1000,\"multi_price\":\"" + sku.new_price
|
||
+ "\",\"thumb_url\":\"" + sku.pinduoduo_image + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + UploadPinduoduoMain.LowPriceStock + ",\"spec_id_list\":\"[" + pb.Props[0].Values[j].id + "]\"}";
|
||
}
|
||
else
|
||
{
|
||
skuApiString += ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"price\":\"" + sku.online_price + "\",\"weight\":1000,\"multi_price\":\"" + sku.new_price
|
||
+ "\",\"thumb_url\":\"" + sku.pinduoduo_image + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + quantity + ",\"spec_id_list\":\"[" + pb.Props[0].Values[j].id + "]\"}";
|
||
}
|
||
if (UploadPinduoduoMain.LowPriceSku&&sku.id==skuMin.id)
|
||
{
|
||
skuMinString = "{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"price\":\"" + (skuMinBackPrice+100) + "\",\"weight\":1000,\"multi_price\":\"" + skuMinBackPrice
|
||
+ "\",\"thumb_url\":\"" + sku.pinduoduo_image + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + quantity + ",\"spec_id_list\":\"[" + pb.Props[0].Values[j].id + "]\"}";
|
||
}
|
||
pb.Props[0].Values[j].is_used = true;
|
||
out_goods_id = "";
|
||
}
|
||
// 临时关闭剪刀手
|
||
if (UploadPinduoduoMain.CutHand && maxEndPrice > 800 && !string.IsNullOrEmpty(UploadPinduoduoMain.CutHandPath) && !string.IsNullOrEmpty(UploadPinduoduoMain.CutHandName))//价格剪刀手
|
||
{
|
||
string imgUrl = UploadPinduoduoMain.CutHandImage;
|
||
if (string.IsNullOrEmpty(UploadPinduoduoMain.CutHandImage))
|
||
{
|
||
var imgx = File.ReadAllBytes(UploadPinduoduoMain.CutHandPath);
|
||
ib = new ImageBuild(imgx);
|
||
imgx = ib.BuildNewSize(640, 640, 100);
|
||
imgUrl = UploadImg(UploadPinduoduoMain.CutHandPath, ref imgx, false);
|
||
UploadPinduoduoMain.CutHandImage = imgUrl;
|
||
}
|
||
PinduoduoApiPropId apix = new PinduoduoApiPropId(Shop);
|
||
string htmlx = apix.GetPropId(pb.Props[0].pinduoduo_id, UploadPinduoduoMain.CutHandName);
|
||
string spec_id = BaseRegex.GetStringJson(ref htmlx, "spec_id");
|
||
if (!string.IsNullOrEmpty(spec_id) && !string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
int multi_price = (int)(maxEndPrice / dd * 10);
|
||
skuApiString += ",{\"is_onsale\":1,\"limit_quantity\":" + UploadPinduoduoMain.LimitBuy +
|
||
",\"price\":\"" + (multi_price + 100) + "\",\"weight\":1000,\"multi_price\":\"" + multi_price
|
||
+ "\",\"thumb_url\":\"" + imgUrl + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + UploadPinduoduoMain.CutHandStock + ",\"spec_id_list\":\"[" + spec_id + "]\"}";
|
||
}
|
||
}
|
||
}
|
||
if (pb.Props.Count == 2)
|
||
{
|
||
for (int j = 0; j < pb.Props[0].Values.Count; j++)
|
||
{
|
||
for (int k = 0; k < pb.Props[1].Values.Count; k++)
|
||
{
|
||
string sm =
|
||
"{\"parent_name\":\"" + pb.Props[0].pinduoduo_name + "\",\"parent_id\":" + pb.Props[0].pinduoduo_id
|
||
+ ",\"spec_name\":\"" + (string.IsNullOrEmpty(pb.Props[0].Values[j].name_pinduoduo) ? pb.Props[0].Values[j].name : pb.Props[0].Values[j].name_pinduoduo) + "\",\"spec_id\":" + pb.Props[0].Values[j].id
|
||
+ "},{\"parent_name\":\"" + pb.Props[1].pinduoduo_name + "\",\"parent_id\":\"" + pb.Props[1].pinduoduo_id
|
||
+ "\",\"spec_name\":\"" + (string.IsNullOrEmpty(pb.Props[1].Values[k].name_pinduoduo) ? pb.Props[1].Values[k].name : pb.Props[1].Values[k].name_pinduoduo) + "\",\"spec_id\":\"" + pb.Props[1].Values[k].id + "\"}";
|
||
var sku = new SkuMapBase();
|
||
for (int l = 0; l < pb.SkuMaps.Count; l++)
|
||
{
|
||
string[] li = pb.SkuMaps[l].name.Split(';');
|
||
if (li.Length == 2)
|
||
{
|
||
string n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim();
|
||
string n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim();
|
||
if (t.FromType == "微店")
|
||
{
|
||
n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
}
|
||
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1)
|
||
{
|
||
sku = pb.SkuMaps[l];
|
||
break;
|
||
}
|
||
}
|
||
if (li.Length == 3)
|
||
{
|
||
string n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim();
|
||
string n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim();
|
||
string n3 = li[2].Substring(li[2].IndexOf(":") + 1).Trim();
|
||
if (t.FromType == "微店")
|
||
{
|
||
n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
n3 = li[2].Substring(li[2].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
}
|
||
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|
||
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|
||
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
|
||
{
|
||
sku = pb.SkuMaps[l];
|
||
break;
|
||
}
|
||
}
|
||
if (li.Length == 4)
|
||
{
|
||
string n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim();
|
||
string n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim();
|
||
string n3 = li[2].Substring(li[2].IndexOf(":") + 1).Trim();
|
||
string n4 = li[3].Substring(li[3].IndexOf(":") + 1).Trim();
|
||
if (t.FromType == "微店")
|
||
{
|
||
n1 = li[0].Substring(li[0].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
n2 = li[1].Substring(li[1].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
n3 = li[2].Substring(li[2].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
n4 = li[3].Substring(li[3].IndexOf(":") + 1).Trim().Replace(" ", "+");
|
||
}
|
||
if (pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n2 || pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n1
|
||
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n1
|
||
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n3 || pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n2)
|
||
{
|
||
sku = pb.SkuMaps[l];
|
||
break;
|
||
}
|
||
if (pb.Props[0].Values[j].name == n3 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n3
|
||
|| pb.Props[0].Values[j].name == n1 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n1
|
||
|| pb.Props[0].Values[j].name == n2 && pb.Props[1].Values[k].name == n4 || pb.Props[0].Values[j].name == n4 && pb.Props[1].Values[k].name == n2)
|
||
{
|
||
sku = pb.SkuMaps[l];
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(sku.pinduoduo_image))
|
||
{
|
||
sku.pinduoduo_image = firstSkuImage;
|
||
}
|
||
if (sku.new_price == 0)
|
||
{
|
||
sku.new_price = (int)maxPriceNew;
|
||
sku.number = 0;
|
||
}
|
||
if (sku.new_price > sku.online_price - 100)
|
||
sku.online_price = sku.new_price + 100;
|
||
|
||
if (maxSkuPriceOnline < sku.online_price)
|
||
maxSkuPriceOnline = sku.online_price;
|
||
if (maxSkuMultiPriceOnline < sku.new_price)
|
||
maxSkuMultiPriceOnline = sku.new_price;
|
||
if (pb.Props[1].Values[k].id == null || pb.Props[0].Values[j].id == null || pb.Props[1].Values[k].id.Contains("null") || pb.Props[0].Values[j].id.Contains("null"))
|
||
continue;
|
||
int onsale = sku.number == 0 || sku.price == 0 ? 0 : 1;
|
||
if (skuApiString.Contains(pb.Props[0].Values[j].id + "," + pb.Props[1].Values[k].id + "]"))
|
||
continue;
|
||
int quantity = UploadPinduoduoMain.LimitBuy;
|
||
if (!UploadPinduoduoMain.isDefaultQun)
|
||
{
|
||
quantity = sku.number;
|
||
}
|
||
skuString += ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"quantity_delta\":" + quantity + ",\"thumb_url\":\"" + sku.pinduoduo_image + "\"," +
|
||
"\"multi_price\":" + sku.new_price + ",\"price\":" +
|
||
sku.online_price +
|
||
",\"out_sku_sn\":\"" + out_goods_id + "\",\"id\":0,\"spec\":" +
|
||
"[" + sm + "],\"weight\":1000}";
|
||
if (UploadPinduoduoMain.LowPriceQ && skuMin != null && sku.id == skuMin.id)
|
||
{
|
||
skuApiString += ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"price\":\"" + sku.online_price + "\",\"weight\":1000,\"multi_price\":\"" + sku.new_price
|
||
+ "\",\"thumb_url\":\"" + sku.pinduoduo_image + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + UploadPinduoduoMain.LowPriceStock + ",\"spec_id_list\":\"[" + pb.Props[0].Values[j].id + "," + pb.Props[1].Values[k].id + "]\"}";
|
||
}
|
||
else
|
||
{
|
||
skuApiString += ",{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"price\":\"" + sku.online_price + "\",\"weight\":1000,\"multi_price\":\"" + sku.new_price
|
||
+ "\",\"thumb_url\":\"" + sku.pinduoduo_image + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + quantity + ",\"spec_id_list\":\"[" + pb.Props[0].Values[j].id + "," + pb.Props[1].Values[k].id + "]\"}";
|
||
}
|
||
if (UploadPinduoduoMain.LowPriceSku && sku.id == skuMin.id)
|
||
{
|
||
skuMinString = "{\"is_onsale\":" + onsale + ",\"limit_quantity\":" + quantity +
|
||
",\"price\":\"" + (skuMinBackPrice + 100) + "\",\"weight\":1000,\"multi_price\":\"" + skuMinBackPrice
|
||
+ "\",\"thumb_url\":\"" + sku.pinduoduo_image + "\",\"out_sku_sn\":\"" + out_goods_id +
|
||
"\",\"quantity\":" + quantity + ",\"spec_id_list\":\"[" + pb.Props[0].Values[j].id + "," + pb.Props[1].Values[k].id + "]\"}";
|
||
}
|
||
pb.Props[0].Values[j].is_used = true;
|
||
pb.Props[1].Values[k].is_used = true;
|
||
out_goods_id = "";
|
||
}
|
||
}
|
||
}
|
||
if (maxSkuPriceOnline > 0 && maxSkuPriceOnline < maxPriceOnline)
|
||
market_price = (int)(maxSkuPriceOnline * UploadPinduoduoMain.BeforePrice);
|
||
|
||
if (!string.IsNullOrEmpty(skuString))
|
||
skuString = skuString.Substring(1);
|
||
if (!string.IsNullOrEmpty(skuApiString))
|
||
skuApiString = skuApiString.Substring(1);
|
||
string content = string.IsNullOrEmpty(pb.content_pinduoduo) ? pb.name : pb.content_pinduoduo;
|
||
if (pb.from_site_id == 1 || pb.from_site_id == 3 || pb.from_site_id == 4)
|
||
{
|
||
content = "";
|
||
for (int i = 0; i < pb.Prop.Count && content.Length < 450; i++)
|
||
{
|
||
if (pb.Prop[i].Key.Contains("生产") || pb.Prop[i].Key.Contains("联系") || pb.Prop[i].Key.Contains("厂名") || pb.Prop[i].Key.Contains("厂址") || pb.Prop[i].Key.Contains("生产") || pb.Prop[i].Key.Contains("保质期"))
|
||
continue;
|
||
if (pb.Prop[i].Key.Contains("价") || pb.Prop[i].Value.Contains("元") || pb.Prop[i].Value.Contains("预售") || pb.Prop[i].Value.Contains("品牌"))
|
||
continue;
|
||
if (pb.Prop[i].Key.Contains("主要下游平台"))
|
||
continue;
|
||
content += pb.Prop[i].Key + ":" + pb.Prop[i].Value.Replace("2016", "2019").Replace("2017", "2019").Replace("2018", "2019").Trim() + ";";
|
||
}
|
||
if (content.Length < 10)
|
||
content = pb.name;
|
||
content = content.Replace("\"", "\\\"").Replace("/", "\\/");
|
||
}
|
||
if (content.Length < 40)
|
||
content += pb.name;
|
||
int mallId = Shop != null ? Shop.MallId : BaseClass.MallId;
|
||
string addContent = UploadPinduoduoMain.AddType(ref pb, Shop.MainCatId, Cookies, mallId);
|
||
|
||
bool again = false;
|
||
string error_msg = "";
|
||
|
||
content += UploadPinduoduoMain.RandDesc ? Randomx.GetWord(1) + Randomx.GetNumber(1) : "";
|
||
if (pb.from_id == 0)
|
||
pb.from_id = t.FromId;
|
||
if (pb.from_id == 0)
|
||
{
|
||
t.Message = "上家编码异常,请联系管理员";
|
||
Error("上家编码异常:" + t.Titlte, t.Message);
|
||
return;
|
||
}
|
||
|
||
t.ShopName = Shop.Name;
|
||
bool replaceFrist = true;
|
||
string skuStringx = "", skuApiStringx = "";
|
||
|
||
//生成新的价格
|
||
for (int i = 0; i < pb.SkuMaps.Count; i++)
|
||
{
|
||
if (maxPriceNewx < pb.SkuMaps[i].new_price)
|
||
maxPriceNewx = pb.SkuMaps[i].new_price;
|
||
if (minPriceNewx > pb.SkuMaps[i].new_price)
|
||
minPriceNewx = pb.SkuMaps[i].new_price;
|
||
}
|
||
if (maxPriceNewx == 0)
|
||
{
|
||
maxPriceNewx = maxPriceNew;
|
||
minPriceNewx = maxPriceNew;
|
||
}
|
||
|
||
long upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10000, 99999);
|
||
content = content.Replace("阳台", "").Replace("运费险", "").Replace("QQ", "").Replace("限量", "").Replace("成人", "").Replace("货到付款", "").Replace("老人", "").Replace("定金", "").Replace("抽奖", "").Replace("VX", "").Replace("★", "").Replace("?", "").Replace("天猫", "").Replace("淘宝", "");
|
||
var mcontent = BaseRegex.GetMatchRegex(ref content, @"品牌[^>]+?[;|;]");
|
||
if (mcontent != null && mcontent.Count > 0)
|
||
content = content.Replace(mcontent[0].Groups[0].Value, "");
|
||
pb.name = ReplaceTitle(pb.name);
|
||
string startname = pb.name.Substring(0, 1);
|
||
if (startname == "@")
|
||
pb.name = pb.name.Substring(1);
|
||
string tiny_name = pb.name.Length <= 10 ? pb.name : pb.name.Substring(0, 10);
|
||
if (content.Length > 500)
|
||
content = content.Substring(0, 500);
|
||
//if (t.FromType == "拼多多" || t.FromType == "内部数据")
|
||
// goto UserMmc;
|
||
//API接口
|
||
PinduoduoApiGetProduct api = null;
|
||
//UploadPinduoduoMain.isDefaultMoni = true;//测试模拟接口使用,请勿提交 by ttzhao 2020.7.4
|
||
if (UploadPinduoduoMain.isDefaultMoni)
|
||
goto UserMmc;
|
||
api = new PinduoduoApiGetProduct(Shop);
|
||
if (us != null)
|
||
{
|
||
api.Data.Add("goods_id", us.GoodsId.ToString());
|
||
}
|
||
else if (UploadPinduoduoMain.isLowPriceApplied && !string.IsNullOrEmpty(skuApiString))
|
||
{
|
||
decimal times = GetCatTimes(catId);
|
||
if (times != 0)
|
||
{
|
||
var lowPriceSkus = string.Empty;
|
||
decimal lowPrice = maxSkuMultiPriceOnline / (times * 100);
|
||
var json = api.GetProductInfoByCatAndPrice(catId, lowPrice);
|
||
JObject jObj = JObject.Parse(json);
|
||
if (jObj["goods_search_response"] != null)
|
||
{
|
||
int retryTimes = 0;
|
||
//生成特定低价引流spec,名称为“1”
|
||
List<string> lowPriceSpecs = new List<string>();
|
||
for (int i = 0; i < pb.Props.Count; i++)
|
||
{
|
||
var specId = pb.Props[i].pinduoduo_id;
|
||
var generatedSpec = api.GetSpecId(specId, "1");
|
||
var generatedSpecId = BaseRegex.GetStringJson(ref generatedSpec, "spec_id");
|
||
if (!pb.Props[i].Values.Any(sp => sp.id == generatedSpecId))
|
||
{
|
||
lowPriceSpecs.Add(generatedSpecId);
|
||
}
|
||
}
|
||
if (lowPriceSpecs.Count > 0)
|
||
{
|
||
foreach (var item in jObj["goods_search_response"]["goods_list"])
|
||
{
|
||
if (retryTimes++ < 10 && lowPriceSkus == string.Empty)
|
||
{
|
||
var token = PinduoduoProductCollect.GetRandomPDDAccessToken(p => p.ProductDetailStatus == 1);
|
||
if (!string.IsNullOrEmpty(token))
|
||
{
|
||
lowPriceSkus = PinduoduoProductCollect.GenerateLowPriceSkus(item["goods_id"].ParseToLong(), lowPrice, pb.Props, lowPriceSpecs, token);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
break;
|
||
}
|
||
}
|
||
skuApiString += lowPriceSkus;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (UploadPinduoduoMain.isfruit)
|
||
api.Data.Add("bad_fruit_claim", "1");
|
||
api.Data.Add("goods_name", pb.name);
|
||
api.Data.Add("goods_type", "1");
|
||
api.Data.Add("goods_desc", content);
|
||
api.Data.Add("cat_id", catId.ToString());
|
||
api.Data.Add("tiny_name", tiny_name);
|
||
api.Data.Add("country_id", "0");
|
||
api.Data.Add("market_price", market_price.ToString());
|
||
if (UploadPinduoduoMain.isPreSale)
|
||
{
|
||
api.Data.Add("pre_sale_time", UploadPinduoduoMain.endAdvanceTimex.ToString());
|
||
api.Data.Add("is_pre_sale", "true");
|
||
}
|
||
else
|
||
{
|
||
api.Data.Add("is_pre_sale", "false");
|
||
}
|
||
api.Data.Add("shipment_limit_second", "172800");
|
||
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
|
||
api.Data.Add("customer_num", UploadPinduoduoMain.GroupCount.ToString()); //团购人数
|
||
if (!UploadPinduoduoMain.limitCount)
|
||
{
|
||
api.Data.Add("buy_limit", UploadPinduoduoMain.BuyLimit.ToString());
|
||
api.Data.Add("order_limit", UploadPinduoduoMain.OrderLimit.ToString());
|
||
}
|
||
if (UploadPinduoduoMain.isSevNoRea)
|
||
api.Data.Add("is_refundable", "true");
|
||
else
|
||
api.Data.Add("is_refundable", "false");
|
||
|
||
if(BaseClass.UserVersion == 110) // 特殊版本默认七天无理由退货
|
||
api.Data["is_refundable"] = "true";
|
||
|
||
if (catId == 18230 || catId == 18141 || catId == 18159 || UploadPinduoduoMain.isfolt)
|
||
api.Data.Add("is_folt", "false");
|
||
else
|
||
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());
|
||
}
|
||
if (UploadPinduoduoMain.isSecond)
|
||
{
|
||
api.Data.Add("second_hand", "true");
|
||
}
|
||
else
|
||
{
|
||
api.Data.Add("second_hand", "false");
|
||
}
|
||
if (Shop.MainCatName == "海淘进口" && (pb.main_cat_name == "海淘进口" || pb.main_cid == 8))
|
||
{
|
||
if (string.IsNullOrEmpty(Shop.bondedWarehouseName))
|
||
{
|
||
Shop.CanUpload = false;
|
||
error_msg = "没有获取到保税区信息";
|
||
Shop.Message = error_msg;
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (UploadPinduoduoMain.CountryList.Count == 0)
|
||
{
|
||
string urlx = "https://mms.pinduoduo.com/glide/v2/mms/query/country/list";
|
||
string htmlx = GetPostTaobaoHtml.GetJsonPost(urlx, urlx, true, "", Shop.Cookies);
|
||
var mxt = BaseRegex.GetMatchRegex(ref htmlx, "{[^}]+?}");
|
||
for (int j = 0; j < mxt.Count; j++)
|
||
{
|
||
string list = mxt[j].Groups[0].Value;
|
||
string country_id = BaseRegex.GetStringJson(ref list, "country_id");
|
||
string country_name = BaseRegex.GetStringJson(ref list, "country_name");
|
||
if (!UploadPinduoduoMain.CountryList.ContainsKey(country_id))
|
||
UploadPinduoduoMain.CountryList.Add(country_id, country_name);
|
||
}
|
||
}
|
||
var countryid = UploadPinduoduoMain.CountryList.FirstOrDefault(q => q.Value == t.country || t.country.Contains(q.Value)).Key;
|
||
if (string.IsNullOrEmpty(countryid))
|
||
countryid = "233";
|
||
api.Data.Remove("goods_type");
|
||
api.Data.Remove("country_id");
|
||
api.Data.Remove("shipment_limit_second");
|
||
api.Data.Add("goods_type", "3");
|
||
api.Data.Add("country_id", countryid);
|
||
api.Data.Add("origin_country_id", countryid);
|
||
api.Data.Add("shipment_limit_second", "432000");
|
||
api.Data.Add("oversea_goods", "{\"bonded_warehouse_key\":\"" + Shop.bondedWarehouseKey + "\",\"customs_broker\":null,\"hs_code\":null,\"value_added_tax_rate\":null,\"consumption_tax_rate\":null}");
|
||
}
|
||
api.Data.Add("sku_list",
|
||
"[" + (string.IsNullOrEmpty(skuApiStringx) ? skuApiString : skuApiStringx) + "]");
|
||
if (UploadPinduoduoMain.defaultPid)
|
||
{
|
||
string code = "";
|
||
if (pb.from_site_id == 1)
|
||
code = "tb-";
|
||
if (pb.from_site_id == 2)
|
||
code = "pd-";
|
||
if (pb.from_site_id == 3)
|
||
code = "al-";
|
||
code += pb.from_id;
|
||
api.Data.Add("out_goods_id", code);
|
||
}
|
||
else
|
||
{
|
||
api.Data.Add("out_goods_id", "");
|
||
}
|
||
//api.Data.Add("hd_thumb_url", img400);
|
||
//api.Data.Add("thumb_url", img200);
|
||
//api.Data.Add("image_url", mainImageUrl);
|
||
api.Data.Add("carousel_gallery", "[" + apiImageString.Substring(1) + "]");
|
||
api.Data.Add("detail_gallery", "[" + apiContentString + "]");
|
||
if (t.GoodsId < 0)
|
||
t.GoodsId = 0;
|
||
|
||
if (",983,".Contains("," + catId + ","))//卷纸
|
||
{
|
||
api.Data.Add("paper_net_weight", "100");
|
||
api.Data.Add("paper_length", "100");
|
||
api.Data.Add("paper_width", "100");
|
||
api.Data.Add("paper_plies_num", "1");
|
||
}
|
||
if (",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("," + t.Cat1 + ",")) //食品
|
||
{
|
||
api.Data.Add("shelf_life", "300");
|
||
api.Data.Add("start_production_date", BaseClass.GetTime(DateTime.Today).ToString());
|
||
api.Data.Add("end_production_date", BaseClass.GetTime(DateTime.Today).ToString());
|
||
}
|
||
string mustCode = "";
|
||
string properties = "";
|
||
if (UploadPinduoduoMain.ismaterial)
|
||
{
|
||
properties = UploadPinduoduoProperties.GetNew(catId, t.Cat1, ref pb, ref Shop, out mustCode, true);
|
||
}
|
||
else
|
||
{
|
||
//UploadPinduoduoProperties.GetGuoJian(0,"",Shop);
|
||
properties = UploadPinduoduoProperties.GetNew(catId, t.Cat1, ref pb, ref Shop, out mustCode, false);
|
||
}
|
||
if (!string.IsNullOrEmpty(properties))
|
||
{
|
||
//api.Data.Remove("goods_properties");
|
||
api.Data["goods_properties"] = "[" + properties.Substring(1) + "]";
|
||
}
|
||
api.Data["gallery"] = imageString;
|
||
//api.Data.Add("skus", "[" + (string.IsNullOrEmpty(skuStringx) ? skuString : skuStringx.Substring(1)) + "]");
|
||
|
||
t.Price = pb.price;
|
||
//==================================图片缓存========================
|
||
string temp = "";
|
||
foreach (KeyValuePair<long, string> item in picUped)
|
||
{
|
||
temp += Math.Abs(item.Key) + "," + item.Value + ";";
|
||
}
|
||
if (!string.IsNullOrEmpty(temp))
|
||
{
|
||
url = BaseClass.LoginApiUrl + "?obj=upshopid/image_pinduoduo&act=add";
|
||
data = UserLogin.GetSignaturex() + "&data=" + temp;
|
||
html = GetHtml.PostUtf8(url, data);
|
||
}
|
||
//==================================图片缓存 结束========================
|
||
|
||
if (BaseClass.UserApi)//是否启用API上传 BaseClass.UseApiFirst
|
||
{
|
||
try
|
||
{
|
||
if (us != null) //修改
|
||
{
|
||
t.GoodsId = us.GoodsId;
|
||
UploadPinduoduoDeleteSku upx = new UploadPinduoduoDeleteSku(Name, Shop, us, skuString, skuApiString);
|
||
upx.pb = pb;
|
||
upx.Cat1 = t.Cat1;
|
||
upx.MaxPrice = maxPriceNewx;
|
||
upx.MinPrice = minPriceNewx;
|
||
upx.NewUpId = upid;
|
||
upx.skus = "[" + (string.IsNullOrEmpty(skuStringx) ? skuString : skuStringx.Substring(1)) + "]";
|
||
foreach (KeyValuePair<string, string> key in api.Data)
|
||
{
|
||
upx.Data.Add(key.Key, key.Value);
|
||
}
|
||
bool success = upx.GetNew();
|
||
if (!upx.CanUpload)
|
||
{
|
||
Shop.CanUpload = false;
|
||
Shop.Message = "高风险店铺、惩罚中或需要设置运费模板";
|
||
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
|
||
}
|
||
if (!success)
|
||
{
|
||
t.Message = "替换审核失败";
|
||
Error("提交异常:" + t.Titlte, t.Message);
|
||
//setOffProduct(us.GoodsId);
|
||
//error_msg += " 自动下架成功";
|
||
return;
|
||
}
|
||
api.Data["cat_id"] = catId.ToString();
|
||
}
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
if (t.ViGoodsName == "6" || string.IsNullOrEmpty(t.ViGoodsName) && (pb.from_site_id == 1 || pb.from_site_id == 3 || pb.from_site_id == 4 || pb.from_site_id == 6) && UploadPinduoduoMain.MultiPrice <= 8 && UploadPinduoduoMain.Postage <= 0)
|
||
//if ((!string.IsNullOrEmpty(t.ViGoodsName)&&t.ViGoodsId>0&&t.ViPriceMin>0&&t.ViPriceMax>0) ||( string.IsNullOrEmpty(t.ViGoodsName) && (pb.from_site_id == 1 || pb.from_site_id == 3) && UploadPinduoduoMain.MultiPrice <= 8 && UploadPinduoduoMain.Postage <= 0))
|
||
api.FromWeiDian = true;
|
||
if (UploadPinduoduoMain.isPriceModel)
|
||
api.FromWeiDian = true;
|
||
if (us != null) //修改
|
||
{
|
||
t.GoodsId = us.GoodsId;
|
||
//if (api.Data.ContainsKey("skus"))
|
||
// api.Data.Remove("skus");
|
||
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
||
return;
|
||
html = api.Updata();
|
||
if (html.Contains("该类目商品不允许设置限购,请设置单次限量为999999"))
|
||
{
|
||
if (api.Data.ContainsKey("buy_limit"))
|
||
{
|
||
api.Data["buy_limit"] = "999999";
|
||
api.Data["order_limit"] = "999999";
|
||
}
|
||
else
|
||
{
|
||
api.Data.Add("buy_limit", "999999");
|
||
api.Data.Add("order_limit", "999999");
|
||
}
|
||
html = api.Updata();
|
||
}
|
||
if (html.Contains("存在多余或重复输入"))
|
||
{
|
||
api.Data["goods_desc"] = pb.name;
|
||
html = api.Updata();
|
||
}
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("\"is_success\""))
|
||
{
|
||
error_msg = "正在检测是否替换成功";
|
||
t.Message = error_msg;
|
||
Error("正在检测:" + t.Titlte, t.Message);
|
||
Thread.Sleep(1000);
|
||
long goods_commit_id = BaseRegex.GetLongJson(ref html, "goods_commit_id");
|
||
int goods_status = 1;
|
||
for (int i = 0; goods_commit_id > 0 && i < 300 && 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)
|
||
{
|
||
error_msg = "替换审核失败";
|
||
goto ErrorEnd;
|
||
}
|
||
api = new PinduoduoApiGetProduct(Shop);
|
||
SetUpProduct(t.GoodsId, upProductId);
|
||
int siteId = pb.from_site_id;
|
||
if (t.ViGoodsName == "4")
|
||
siteId = 4;
|
||
if (t.ViGoodsName == "5")
|
||
siteId = 5;
|
||
if (t.ViGoodsName == "6")
|
||
siteId = 6;
|
||
if (string.IsNullOrEmpty(t.ViGoodsName) && (pb.from_site_id == 2 || UploadPinduoduoMain.MultiPrice > 8 || UploadPinduoduoMain.Postage > 0))
|
||
{
|
||
new GetNewTaobaoUpId(Shop).Get(t.GoodsId, t.FromId, imageByte, (int)minPriceNewx, (int)maxPriceNewx, beforeTitle);
|
||
}
|
||
else
|
||
{
|
||
if (t.ViGoodsId <= 0)
|
||
{
|
||
if (beforePriceMin > beforePriceMax)
|
||
{
|
||
int tempPrice = beforePriceMin;
|
||
beforePriceMin = beforePriceMax;
|
||
beforePriceMax = tempPrice;
|
||
}
|
||
html = api.Relationx(t.GoodsId, t.FromId, beforePriceMin, beforePriceMax, expressPrcie, siteId);
|
||
}
|
||
else
|
||
{
|
||
if (t.ViPriceMin > t.ViPriceMax)
|
||
{
|
||
int tempPrice = t.ViPriceMin;
|
||
t.ViPriceMin = t.ViPriceMax;
|
||
t.ViPriceMax = tempPrice;
|
||
}
|
||
html = api.Relationx(t.GoodsId, t.ViGoodsId, t.ViPriceMin, t.ViPriceMax, t.ViExpressPrice, siteId);//4 京东 5苏宁
|
||
}
|
||
}
|
||
|
||
goto End;
|
||
}
|
||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||
ErrorEnd:
|
||
if (UploadPinduoduoMain.ErrorDown)
|
||
{
|
||
new PinduoduoApiGetProduct(Shop).SetOnline(us.GoodsId, false);
|
||
error_msg += " 自动下架成功";
|
||
}
|
||
t.Message = error_msg;
|
||
Error("提交异常:" + t.Titlte, t.Message);
|
||
if (UploadPinduoduoMain.EditDayTemp.ContainsKey(t.GoodsId))
|
||
UploadPinduoduoMain.EditDayTemp[t.GoodsId] = DateTime.Now;
|
||
else
|
||
UploadPinduoduoMain.EditDayTemp.Add(t.GoodsId, DateTime.Now);
|
||
string tempFile = "temp/upsame/" + Shop.ShopName + "edit.tjm";
|
||
temp = t.GoodsId + "," + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n";
|
||
FileBase.AppendAllText(tempFile, temp);
|
||
return;
|
||
}
|
||
//goto UserMmc;//使用第三方
|
||
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
||
return;
|
||
|
||
#region 非微店模拟上家的,比较加价前sku最高和最低价和加价后sku最高和最低价格,超过108%去取微店缓存,如果取不到就报错
|
||
if (t.ViGoodsId <= 0)
|
||
{
|
||
if (beforePriceMin > beforePriceMax)
|
||
{
|
||
int tempPrice = beforePriceMin;
|
||
beforePriceMin = beforePriceMax;
|
||
beforePriceMax = tempPrice;
|
||
}
|
||
// 上家商品高低价格
|
||
int minFromProductPrice = beforePriceMin;
|
||
int maxFromProcuctPrice = beforePriceMax;
|
||
|
||
int minAfterProductPrice = 999999;
|
||
int maxAfterProcuctPrice = 0;
|
||
// 加价后商品高低价格
|
||
if (pb.SkuMaps.Count > 0)
|
||
{
|
||
minAfterProductPrice = pb.SkuMaps.Min(s => s.new_price);
|
||
maxAfterProcuctPrice = pb.SkuMaps.Max(s => s.new_price);
|
||
}
|
||
else
|
||
{
|
||
minAfterProductPrice = maxAfterProcuctPrice = Convert.ToInt32(pb.price * 100);
|
||
}
|
||
|
||
if (minAfterProductPrice > minFromProductPrice * 1.08M + expressPrcie * 100 || maxAfterProcuctPrice > maxFromProcuctPrice * 1.08M + expressPrcie * 100)
|
||
{
|
||
var weidianCaches = ServerTemp.GetWeiDianCache(pb);
|
||
weidianCaches = ServerTemp.FilteWeiDianProducts(weidianCaches, minAfterProductPrice * 93 / 100, maxAfterProcuctPrice * 93 / 100);
|
||
if (weidianCaches.Count > 0)
|
||
{
|
||
t.ViGoodsName = "6";
|
||
t.ViGoodsId = Convert.ToInt64(weidianCaches[0].Item1);
|
||
t.ViPriceMin = weidianCaches[0].Item2;
|
||
t.ViPriceMax = weidianCaches[0].Item3;
|
||
t.ViExpressPrice = 0;
|
||
}
|
||
else
|
||
{
|
||
Error("提交异常:" + t.Titlte, "商品加价差超过平台允许");
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
//if (UploadPinduoduoMain.isDraft)
|
||
//{
|
||
// html = api.AddDraft();
|
||
//}
|
||
html = api.AddNew();
|
||
if (UploadPinduoduoMain.isMaxPrice&&html.Contains("价格"))
|
||
{
|
||
string skulist = api.Data["sku_list"];
|
||
long maxPrice = 0;
|
||
var maxitem = "";
|
||
var mc = BaseRegex.GetMatchRegex(ref skulist, @"[,]?\{[\w\W]+?\}");
|
||
for (int i = 0;mc!=null&&i < mc.Count; i++)
|
||
{
|
||
var item = mc[i].Groups[0].Value;
|
||
long multi= BaseRegex.GetLongJson(ref item, "multi_price");
|
||
if (multi > maxPrice)
|
||
{
|
||
maxPrice = multi;
|
||
maxitem = item;
|
||
}
|
||
}
|
||
skulist = skulist.Replace(maxitem,"");
|
||
api.Data["sku_list"] = skulist;
|
||
html = api.AddNew();
|
||
}
|
||
//if (!html.Contains("goods_id") &&UploadPinduoduoMain.LowPriceSku && UploadPinduoduoMain.isUpSku)
|
||
//{
|
||
// string skuStr = api.Data["sku_list"];//skuMinString
|
||
// string specid = BaseRegex.GetMatchRegexString(ref skuMinString, @"""spec_id_list"":""\[([^}]+)\]""");
|
||
// var mc = BaseRegex.GetMatchRegex(ref skuStr, @"{[^}]+""spec_id_list"":""\["+specid+@"\]""}");
|
||
// var item = mc[0].Groups[0].Value;
|
||
// skuStr = skuStr.Replace(item,skuMinString);
|
||
// api.Data["sku_list"] = skuStr;
|
||
// html = api.AddNew();
|
||
//}
|
||
if (html.Contains("协议"))
|
||
{
|
||
string urlAdd = "https://mms.pinduoduo.com/earth/api/protocol/signProtocol";
|
||
string dataAdd = "{\"type\":0,\"signedStatus\":1}";
|
||
string htmlAdd = GetPostTaobaoHtml.UploadTaobaoPost(urlAdd, "https://mms.pinduoduo.com/mallcenter/protocol/index", true, dataAdd, Shop.Cookies);
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("分类调整已失效"))
|
||
{
|
||
FromTitleToCat.UserApi = true;
|
||
FromTitleToCat.inShop = null;
|
||
FromTitleToCat ft = new FromTitleToCat();
|
||
ft.TaobaoProduct = new TaobaoProductBase();
|
||
ft.Title = pb.name;
|
||
ft.TaobaoProduct.Titlte = pb.name;
|
||
ft.TaobaoProduct.FromId = pb.from_id;
|
||
ft.TaobaoCatId = pb.from_cat_id;
|
||
ft.JustGetCat = true;
|
||
ft.AgainCat = true;
|
||
ft.Get();
|
||
if (!string.IsNullOrEmpty(ft.Cat1) && ft.Cat1 != "0")
|
||
{
|
||
pb.cat1 = int.Parse(ft.Cat1);
|
||
pb.cat2 = int.Parse(ft.Cat2);
|
||
pb.cat3 = int.Parse(ft.Cat3);
|
||
pb.cat4 = int.Parse(ft.Cat4);
|
||
int cat3 = int.Parse(ft.Cat3);
|
||
int cat4= pb.cat4 = int.Parse(ft.Cat4);
|
||
catId = cat4 > 0 ? cat4 : cat3;
|
||
//catId = PinduoduoCatList.GetNewCat3(catId);
|
||
api.Data["cat_id"] = catId.ToString();
|
||
api.Data.Remove("goods_properties");
|
||
string goods_properties = UploadPinduoduoProperties.GetNew(catId, pb.cat1, ref pb, ref Shop, out mustCode, true);
|
||
if (goods_properties.Length > 0) //by ttzhao 2020.6.29
|
||
api.Data.Add("goods_properties", "[" + goods_properties.Substring(1) + "]");
|
||
html = api.AddNew();
|
||
}
|
||
ft.AgainCat = false;
|
||
}
|
||
if (html.Contains("流行元素校验错误:最多可选1个"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("流行元素") || px.name_alias.Contains("流行元素"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
//if (!string.IsNullOrEmpty(html) && html.Contains("当前运费模板已绑定商品数超过限制,请更换运费模板"))
|
||
//增加"请选择配送地区"的条件 by ttzhao 2020.6.23
|
||
if (!string.IsNullOrEmpty(html) && (html.Contains("当前运费模板已绑定商品数超过限制,请更换运费模板") || html.Contains("请选择配送地区")))
|
||
{
|
||
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetRandx(Shop.Cookies, Shop.MallId, Shop);
|
||
if (Shop.ExpressId == 0)
|
||
{
|
||
Thread.Sleep(10000);
|
||
Shop.ExpressId = new UpdatePinduoduoExpressSet().GetRandx(Shop.Cookies, Shop.MallId, Shop);
|
||
}
|
||
if (Shop.ExpressId == 0)
|
||
{
|
||
LogSave.Add(Name, "未找到新运费模板");
|
||
Shop.Message = "运费模板超过商品数限制,请设置新的运费模板";
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
return;
|
||
}
|
||
api.Data.Remove("cost_template_id");
|
||
api.Data["cost_template_id"] = Shop.ExpressId.ToString();
|
||
html = api.AddNew();
|
||
}
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("对联分类因"))
|
||
{
|
||
api.Data["cat_id"] = "19511";
|
||
html = api.AddNew();
|
||
}
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("红包/利是封分类因"))
|
||
{
|
||
api.Data["cat_id"] = "19497";
|
||
html = api.AddNew();
|
||
}
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("该类目下假一罚十必选"))
|
||
{
|
||
api.Data["is_folt"] = "true";
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("请输入必填规格:电池容量"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("电池容量") || px.name_alias.Contains("电池容量"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var porps = pb.Props.Find(pr => pr.name.Contains("容量"));
|
||
var tempplaeItem= template.properties.Find(pr => pr.name.Contains("容量")|| pr.name_alias.Contains("容量"));
|
||
if (porps != null)
|
||
{
|
||
temp = "";
|
||
for (int i = 0; i < porps.Values.Count; i++)
|
||
{
|
||
var c = porps.Values[i];
|
||
var v = p.values.Find(vt => vt.spec_id == long.Parse(c.id));
|
||
temp += ",{\"template_pid\":"+ tempplaeItem.id+ ",\"vid\":" + v.vid + ",\"value\":\"\",\"value_unit\":\"\",\"parent_spec_id\":"+ tempplaeItem.spec_id+ ",\"spec_id\":" + c.id + "}";
|
||
}
|
||
properties = properties + temp;
|
||
api.Data.Add("goods_properties", "[" + properties.Substring(1) + "]");
|
||
html = api.AddNew();
|
||
}
|
||
}
|
||
if (html.Contains("属性净含量校验错误:无效单位"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("产品重量") || px.name_alias.Contains("净含量"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
var itemreplace = item.Replace("\"value_unit\":\"g\"", "\"value_unit\":\"mL\"");
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("属性生产日期校验错误") && html.Contains("不可选"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("生产日期"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
//html = ResetProp(catId,"生产日期",api);
|
||
}
|
||
if (html.Contains("属性保质期校验错误:属性值") && html.Contains("不可选"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("保质期"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("属性化妆品批准文号校验错误:该属性必须填写"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("批准文号"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
string lastitem = ",{\"template_pid\":" + p.id + ",\"vid\":0,\"value\":\"2018004353\",\"value_unit\":\"\"}";
|
||
goods_properties = goods_properties.Substring(0, goods_properties.Length - 1) + lastitem + "]";
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("属性化妆品批准文号校验错误:该属性必须填写"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("批准文号"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
string lastitem = ",{\"template_pid\":" + p.id + ",\"vid\":0,\"value\":\"2018004353\",\"value_unit\":\"\"}";
|
||
goods_properties = goods_properties.Substring(0, goods_properties.Length - 1) + lastitem + "]";
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("属性化妆品批准文号校验错误"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("是否为特殊用途化妆品"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
if (mc != null && mc.Count == 1)
|
||
{
|
||
var item = mc[0].Groups[0].Value;
|
||
string lastitem = ",{\"template_pid\":" + p.id + ",\"vid\":325891,\"value\":\"是\",\"value_unit\":\"\"}";
|
||
goods_properties = goods_properties.Replace(item, lastitem);
|
||
}
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("属性厂名不符合关联规则,不允许填写"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("厂名"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
if (mc != null && mc.Count == 1)
|
||
{
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
p = template.properties.Find(px => px.name.Contains("厂址"));
|
||
mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
}
|
||
if (mc != null && mc.Count == 1)
|
||
{
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
}
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (FromTitleToCat.MainCat[1].Value1.Contains(t.Cat1.ToString()) && (html.Contains("属性成分含量校验错误") || html.Contains("材质") || html.Contains("面料")))
|
||
{
|
||
api.Data.Remove("goods_properties");
|
||
string goods_properties = UploadPinduoduoProperties.GetNew(catId, t.Cat1, ref pb, ref Shop, out mustCode, true);
|
||
if (goods_properties.Length > 0) //by ttzhao 2020.6.29
|
||
api.Data.Add("goods_properties", "[" + goods_properties.Substring(1) + "]");
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("属性净含量校验错误:无效单位"))
|
||
{
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
goods_properties = goods_properties.Replace("克", "g");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("3C认证证书编号"))
|
||
{
|
||
error_msg = BaseRegex.GetMatchRegexString(ref html, @"""3C认证证书编号:([\w\W]+?),格式不正确""");
|
||
if (!string.IsNullOrEmpty(error_msg))
|
||
{
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
string[] scs = { "2018152203021070", "2013010717593387", "2016010717879090", "2017152204017993" };
|
||
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(0, scs.Length);
|
||
goods_properties = goods_properties.Replace(error_msg.Trim(), scs[randx]);
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
}
|
||
if (html.Contains("属性3C认证证书编号不符合关联规则"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("3C认证"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
|
||
}
|
||
if (html.Contains("属性工业产品生产许可证编号不符合关联规则"))
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains("工业"));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("该类目商品不允许设置限购,请设置单次限量为999999"))
|
||
{
|
||
if (api.Data.ContainsKey("buy_limit"))
|
||
{
|
||
api.Data["buy_limit"] = "999999";
|
||
api.Data["order_limit"] = "999999";
|
||
}
|
||
else
|
||
{
|
||
api.Data.Add("buy_limit", "999999");
|
||
api.Data.Add("order_limit", "999999");
|
||
}
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("存在多余或重复输入") && !string.IsNullOrEmpty(mustCode))
|
||
{
|
||
var str1 = api.Data["sku_list"];
|
||
api.Data["goods_properties"] = "[" + mustCode.Substring(1) + "]";
|
||
api.Data["sku_list"] = str1;
|
||
html = api.AddNew();
|
||
}
|
||
if (html.Contains("调用过于频繁"))
|
||
{
|
||
Thread.Sleep(2000);
|
||
html = api.AddNew();
|
||
Thread.Sleep(2000);
|
||
}
|
||
if (html.Contains("调用过于频繁"))
|
||
{
|
||
Thread.Sleep(2000);
|
||
html = api.AddNew();
|
||
Thread.Sleep(2000);
|
||
}
|
||
if (html.Contains("调用过于频繁"))
|
||
{
|
||
Thread.Sleep(5000);
|
||
html = api.AddNew();
|
||
Thread.Sleep(1000);
|
||
}
|
||
Thread.Sleep(200);
|
||
api.Data.Remove("goods_properties");
|
||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||
if (error_msg.Contains("该属性必须填写"))
|
||
{
|
||
}
|
||
//if (error_msg.Contains("access_token") || error_msg.Contains("client_id"))
|
||
//{
|
||
// Shop.CanUpload = false;
|
||
// Shop.Message = error_msg;
|
||
// UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
// Error("提交异常:", error_msg);
|
||
// return;
|
||
//}
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("\"goods_id\":"))
|
||
{
|
||
if (UploadPinduoduoMain.ShopTitles.ContainsKey(Shop.ShopName))
|
||
UploadPinduoduoMain.ShopTitles[Shop.ShopName].Add(t.Titlte);
|
||
t.GoodsId = BaseRegex.GetLongJson(ref html, "goods_id");
|
||
goodsId = t.GoodsId;
|
||
SetUpProduct(t.GoodsId, upProductId, true);
|
||
api = new PinduoduoApiGetProduct(Shop);
|
||
|
||
int siteId = pb.from_site_id;
|
||
if (t.ViGoodsName == "1")
|
||
siteId = 1;
|
||
if (t.ViGoodsName == "4")
|
||
siteId = 4;
|
||
if (t.ViGoodsName == "5")
|
||
siteId = 5;
|
||
if (t.ViGoodsName == "6")
|
||
siteId = 6;
|
||
|
||
if (string.IsNullOrEmpty(t.ViGoodsName) && (pb.from_site_id == 2 || UploadPinduoduoMain.MultiPrice > 8 || UploadPinduoduoMain.Postage > 0))
|
||
{
|
||
new GetNewTaobaoUpId(Shop).Get(t.GoodsId, t.FromId, imageByte, (int)minPriceNewx, (int)maxPriceNewx, beforeTitle);
|
||
}
|
||
else
|
||
{
|
||
if (t.ViGoodsId <= 0)
|
||
{
|
||
if (beforePriceMin > beforePriceMax)
|
||
{
|
||
int tempPrice = beforePriceMin;
|
||
beforePriceMin = beforePriceMax;
|
||
beforePriceMax = tempPrice;
|
||
}
|
||
html = api.Relationx(t.GoodsId, t.FromId, beforePriceMin, beforePriceMax, pb.express_price, siteId);
|
||
}
|
||
else
|
||
{
|
||
if (t.ViPriceMin > t.ViPriceMax)
|
||
{
|
||
int tempPrice = t.ViPriceMin;
|
||
t.ViPriceMin = t.ViPriceMax;
|
||
t.ViPriceMax = tempPrice;
|
||
}
|
||
html = api.Relationx(t.GoodsId, t.ViGoodsId, t.ViPriceMin, t.ViPriceMax, t.ViExpressPrice, siteId);//4 京东 5苏宁
|
||
}
|
||
int relationCount = 1;
|
||
Again:
|
||
if (!html.Contains("\"is_success\":true") && html.Contains("调用过于频繁"))
|
||
{
|
||
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(10, 20);
|
||
Thread.Sleep(randx * 1000);
|
||
html = api.Relationx(t.GoodsId, t.ViGoodsId, t.ViPriceMin, t.ViPriceMax, t.ViExpressPrice, siteId);//4 京东 5苏宁
|
||
}
|
||
if (!html.Contains("\"is_success\":true") && html.Contains("调用过于频繁"))
|
||
{
|
||
relationCount++;
|
||
if (relationCount < 10)
|
||
goto Again;
|
||
}
|
||
if (!html.Contains("\"is_success\":true"))
|
||
{
|
||
error_msg = "关联异常:" + BaseRegex.GetStringJson(ref html, "error_msg");
|
||
Error("关联异常:" + t.Titlte, error_msg);
|
||
}
|
||
}
|
||
|
||
|
||
if (UploadPinduoduoMain.WhiteBack && !string.IsNullOrEmpty(imageUrlx))
|
||
{
|
||
//if (UploadPinduoduoMain.imgList.Count > 100)
|
||
//{
|
||
// Thread.Sleep(3000);
|
||
// LogSave.Add(Name, "白底图队列已满,等待3秒继续");
|
||
//}
|
||
UploadPinduoduoMain.imgList.Add(Shop.ShopName + "@" + goodsId + "@" + imageUrlx);
|
||
}
|
||
goto End;
|
||
}
|
||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("上限"))
|
||
{
|
||
FullToday = true;
|
||
Shop.CanUpload = false;
|
||
Shop.Message = error_msg;
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("分类调整"))
|
||
{
|
||
Error("分类失效:" + catId + ":" + error_msg, error_msg);
|
||
return;
|
||
}
|
||
if (!string.IsNullOrEmpty(error_msg) &&
|
||
(error_msg.Contains("惩罚") || error_msg.Contains("新协议") || error_msg.Contains("店铺资质") && !error_msg.Contains("出于监管要求") ||
|
||
error_msg.Contains("通过审核")))
|
||
{
|
||
Punish = true;
|
||
Shop.CanUpload = false;
|
||
Shop.Message = error_msg;
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (error_msg.Contains("授权失败"))
|
||
{
|
||
Shop.CanUpload = false;
|
||
Shop.Message = error_msg;
|
||
if (us == null)
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
else
|
||
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
|
||
}
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
UserMmc:
|
||
//模拟接口
|
||
if (Shop.UpCount++ > 150)
|
||
{
|
||
LogSave.Add(Name, "店铺" + Shop.ShopName + ",上传数据已经达到上限");
|
||
return;
|
||
}
|
||
long pinId;
|
||
if (us != null)
|
||
{
|
||
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/create_by_sn";
|
||
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");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/create_new";
|
||
data = "{}";
|
||
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");
|
||
FullToday = true;
|
||
Shop.CanUpload = false;
|
||
Shop.Message = error_msg;
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (pinId == 0)
|
||
{
|
||
Error("创建异常:" + t.Titlte + " 无法获取编辑ID ", "无法获取编辑ID");
|
||
return;
|
||
}
|
||
if (",2,6586,6785,6883,6758,6536,6630,6398,".Contains("," + t.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 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 = "";
|
||
//using (IJsEngine jsEngine = new V8JsEngine())
|
||
//{
|
||
// jsEngine.Execute(GetProductOnlineClass.JsCodeGetSms);
|
||
// codex = jsEngine.CallFunction("aaa", "").ToString();
|
||
//}
|
||
string goodProperties = UploadPinduoduoProperties.GetNew(catId, t.Cat1, ref pb, ref Shop, out mustCode);
|
||
if (!string.IsNullOrEmpty(goodProperties))
|
||
goodProperties = "[" + goodProperties.Substring(1) + "]";
|
||
else
|
||
goodProperties = "[]";
|
||
long limit = 999999;//UploadPinduoduoMain.BuyLimit UploadPinduoduoMain.OrderLimit
|
||
//content = content.Replace("阳台", "").Replace("成人", "").Replace("老人", "").Replace("定金", "").Replace("抽奖", "").Replace("VX", "").Replace("★", "").Replace("?", "");
|
||
string dataUp = "{\"cat_id\":" + catId + ",\"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\":\"" + tiny_name + "\",\"market_price\":" + market_price +
|
||
",\"share_desc\":\"" + content + ":\",\"goods_desc\":\"" + content + "\"," +
|
||
"\"image_url\":\"\"," +
|
||
"\"gallery\":[" + imageString + "],\"cost_template_id\":\"" + Shop.ExpressId.ToString() + "\",\"weight\":\"1.00\",\"warm_tips\":\"\"," +
|
||
"\"skus\":[" + (string.IsNullOrEmpty(skuStringx) ? skuString : skuStringx.Substring(1)) + "],\"out_goods_sn\":\"" + out_goods_id + "\",\"groups\":{\"customer_num\":" + UploadPinduoduoMain.GroupCount + "," +
|
||
"\"buy_limit\":" + limit + ",\"order_limit\":" + limit
|
||
+ "},\"production_license\":\"\",\"production_standard_number\":\"\"" + addContent + ",\"goods_commit_id\":\"" + pinId + "\",\"goods_properties\":" + goodProperties + "}";
|
||
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/update";
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, 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("保存异常:" + t.Titlte + " " + error_msg, error_msg);
|
||
return;
|
||
}
|
||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("过于频繁"))
|
||
{
|
||
LogSave.Add(Name, "太快了,休眠1分钟");
|
||
Thread.Sleep(100 * 1000);
|
||
}
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, dataUp, 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, 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("保存异常:" + t.Titlte + " " + error_msg, error_msg);
|
||
return;
|
||
}
|
||
url = "https://mms.pinduoduo.com/glide/v2/mms/query/goods/is_commit_available/" + pinId;
|
||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true, 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, 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("保存异常,校验失败:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/detail/" + pinId;
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", Cookies);
|
||
t.GoodsId = BaseRegex.GetLongJson(ref html, "goods_id");
|
||
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, 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("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("敏感词"))
|
||
{
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
//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("数量上限"))
|
||
{
|
||
FullToday = true;
|
||
Shop.CanUpload = false;
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (!string.IsNullOrEmpty(error_msg) && (error_msg.Contains("二级惩罚") || error_msg.Contains("店铺资质") || error_msg.Contains("通过审核")))
|
||
{
|
||
Punish = true;
|
||
Shop.CanUpload = false;
|
||
Error("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
|
||
Thread.Sleep(10 * 1000);
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, 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("提交异常:" + t.Titlte, error_msg);
|
||
return;
|
||
}
|
||
if (UploadPinduoduoMain.SingleThreadCount > 1 || !BaseClass.UserApi)
|
||
Thread.Sleep(10 * 1000);
|
||
else
|
||
Thread.Sleep(5 * 1000);
|
||
|
||
End:
|
||
try
|
||
{
|
||
if (UploadPinduoduoMain.EditDayTemp.ContainsKey(t.GoodsId))
|
||
UploadPinduoduoMain.EditDayTemp[t.GoodsId] = DateTime.Now;
|
||
else
|
||
UploadPinduoduoMain.EditDayTemp.Add(t.GoodsId, DateTime.Now);
|
||
string shopName = string.IsNullOrEmpty(BaseClass.ShopName) && Shop != null ? Shop.Name : BaseClass.ShopName;
|
||
if (UploadProductAllShop.UpToDown)
|
||
{
|
||
if (!UploadProductAllShop.JustUpload.ContainsKey(shopName))
|
||
UploadProductAllShop.JustUpload.Add(shopName, new List<long>());
|
||
if (!UploadProductAllShop.JustUpload[shopName].Contains(t.GoodsId))
|
||
UploadProductAllShop.JustUpload[shopName].Add(t.GoodsId);
|
||
}
|
||
string tempFile = "temp/upsame/" + shopName + "edit.tjm";
|
||
temp = t.GoodsId + "," + DateTime.Now.ToString("yyyy-MM-dd") + "\r\n";
|
||
FileBase.AppendAllText(tempFile, temp);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
|
||
Shop.UpCount++;
|
||
if (us == null)
|
||
UploadPinduoduoMain.ShopTemp.Add(Shop);
|
||
else
|
||
UploadPinduoduoMain.ShopReplaceTemp.Add(Shop);
|
||
t.Message = "提交成功";
|
||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("关联异常"))
|
||
{
|
||
UploadPinduoduoMain.RelErrorMessage = "";
|
||
if (UploadPinduoduoMain.RelErrorCount > 10)
|
||
{
|
||
UploadPinduoduoMain.RelErrorMessage = "平台服务出现异常,\r\n"+ Md5Base.EncryptEncode(Shop.ClientId);
|
||
}
|
||
UploadPinduoduoMain.RelErrorCount++;
|
||
if (!UploadPinduoduoMain.isDefaultMoni)
|
||
{
|
||
if (api == null)
|
||
api = new PinduoduoApiGetProduct(Shop);
|
||
html = api.SetOnline(t.GoodsId, false);
|
||
Thread.Sleep(3000);
|
||
html = api.DelGoods("[" + t.GoodsId + "]");
|
||
}
|
||
Error("提交异常:" + t.Titlte, "关联异常:" + error_msg);
|
||
}
|
||
else
|
||
{
|
||
Error("提交成功:" + t.Titlte, t.Message);
|
||
}
|
||
Success = true;
|
||
}
|
||
public string ResetProp(int catId, string propname, PinduoduoApiGetProduct api)
|
||
{
|
||
var template = UploadPinduoduoProperties.CatTemplate[catId].open_api_response;
|
||
var p = template.properties.Find(px => px.name.Contains(propname));
|
||
string goods_properties = api.Data["goods_properties"];
|
||
api.Data.Remove("goods_properties");
|
||
var mc = BaseRegex.GetMatchRegex(ref goods_properties, @",{""template_pid"":" + p.id + @",[\w\W]+?}");
|
||
var item = mc[0].Groups[0].Value;
|
||
goods_properties = goods_properties.Replace(item, "");
|
||
api.Data["goods_properties"] = goods_properties;
|
||
string html = api.AddNew();
|
||
return html;
|
||
}
|
||
public decimal GetCatTimes(int cat)
|
||
{
|
||
decimal times = 0;
|
||
string url = BaseClass.LoginApiUrl + "?obj=pinbaobao/cat&act=getCatTimes&cat_id=" + cat.ToString();
|
||
string data = UserLogin.GetSignaturex();
|
||
string html = GetHtml.PostUtf8(url, data);
|
||
decimal.TryParse(html, out times);
|
||
if (PinduoduoCatList.NewPriceSpaceCatIdx.ContainsKey(cat))
|
||
times = PinduoduoCatList.NewPriceSpaceCatIdx[cat];
|
||
return times;
|
||
}
|
||
|
||
//public static void CutImage()
|
||
//{
|
||
// List<Thread> ts = new List<Thread>();
|
||
// while (true)
|
||
// {
|
||
// if (ImgDic.Count == 0)
|
||
// {
|
||
// Thread.Sleep(2000);
|
||
// continue;
|
||
// }
|
||
// var p = ImgDic.FirstOrDefault();
|
||
// ImgDic.Remove(p.Key);
|
||
// CutImage cutImage = new CutImage(Name, Shop);
|
||
// cutImage.CurrentImage = p;
|
||
// Threadx.ThreadListWait(ref ts, new Thread(cutImage.CutImageVaule), 20);
|
||
// Thread.Sleep(200);
|
||
// }
|
||
// Threadx.ThreadListWait(ref ts);
|
||
//}
|
||
|
||
//public static void CutImage()
|
||
//{
|
||
// try
|
||
// {
|
||
// GetPostTaobaoHtml.DownLoadImage(imageUrlx, out imageByte);
|
||
// ImageBuild ib = new ImageBuild(imageByte);
|
||
// bool isflag = ib.ImageCuteNoLogo(ref imageByte);
|
||
// if (!isflag)
|
||
// return;
|
||
// string html = UploadImgCut(ref imageByte, goodsId);
|
||
// if (html.Contains("false"))
|
||
// LogSave.Add(Name, goodsId + "上传白底图失败");
|
||
// else
|
||
// LogSave.Add(Name, goodsId + "上传白底图成功");
|
||
// }
|
||
// catch
|
||
// {
|
||
|
||
// }
|
||
//}
|
||
|
||
|
||
public bool SetUpProduct(long pid, string upProductId, bool add = false)
|
||
{
|
||
string url = BaseClass.LoginApiUrl + "?obj=upshopid/upid&act=insert";
|
||
string data = "&pdd_id=" + pid + "&up_id=" + upProductId + "&table=" + (pid % 1024);
|
||
data += add ? "&add=1" : "";
|
||
string html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex(Shop.ShopId, Shop.ShopName) + data);
|
||
if (html != "ok")
|
||
{
|
||
Thread.Sleep(30 * 1000);
|
||
html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex(Shop.ShopId, Shop.ShopName) + data);
|
||
}
|
||
if (html != "ok")
|
||
{
|
||
LogSave.Add(Name, "服务器记录" + pid + "上家ID异常,请联系客服");
|
||
Thread.Sleep(30 * 1000);
|
||
}
|
||
return html == "ok";
|
||
}
|
||
|
||
|
||
/// 执行JS
|
||
/// </summary>
|
||
/// <param name="sExpression">参数体</param>
|
||
/// <param name="sCode">JavaScript代码的字符串</param>
|
||
/// <returns></returns>
|
||
public static string ExecuteScript(string sExpression, string sCode)
|
||
{
|
||
try
|
||
{
|
||
MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
|
||
scriptControl.UseSafeSubset = true;
|
||
scriptControl.Language = "JScript";
|
||
scriptControl.AddCode(sCode);
|
||
string str = scriptControl.Eval(sExpression).ToString();
|
||
return str;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
string str = ex.Message;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public Dictionary<string, int> PriceTemp = new Dictionary<string, int>();
|
||
|
||
/// <summary>
|
||
/// 白名单加价算法
|
||
/// </summary>
|
||
/// <param name="price"></param>
|
||
/// <param name="addPrice"></param>
|
||
/// <param name="postFree"></param>
|
||
/// <returns></returns>
|
||
public int WhitePriceBuild(decimal price, decimal addPrice, decimal postage, decimal postFree)
|
||
{
|
||
decimal addPricex = addPrice + UploadPinduoduoMain.MultiPricex;
|
||
decimal free = postage + postFree;
|
||
if (Shop == null)//|| !Shop.Explode
|
||
{
|
||
free = 0;
|
||
if (addPricex > 8)
|
||
addPricex = 8;
|
||
}
|
||
int p = (int)(price * (100 + addPricex) + free * 100);
|
||
if (UploadPinduoduoMain.RandPrice)
|
||
p -= Randomx.GetId(0, 10);
|
||
if (UploadPinduoduoMain.SubCoupon > 0 && !string.IsNullOrEmpty(t.youHuei))
|
||
{
|
||
decimal yh;
|
||
if (decimal.TryParse(t.youHuei, out yh))
|
||
{
|
||
p -= (int)(yh * 100 * UploadPinduoduoMain.SubCoupon / 100);
|
||
}
|
||
}
|
||
return p;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 白名单加价算法
|
||
/// </summary>
|
||
/// <param name="price"></param>
|
||
/// <param name="addPrice"></param>
|
||
/// <param name="postFree"></param>
|
||
/// <returns></returns>
|
||
public int WhitePriceBuild(decimal price, decimal addPrice, decimal postFree)
|
||
{
|
||
decimal addPricex = addPrice + UploadPinduoduoMain.MultiPricex;
|
||
decimal free = UploadPinduoduoMain.Postage + postFree;
|
||
if (Shop == null)//|| !Shop.Explode
|
||
{
|
||
free = 0;
|
||
if (addPricex > 8)
|
||
addPricex = 8;
|
||
}
|
||
int p = (int)(price * (100 + addPricex) + free * 100);
|
||
if (UploadPinduoduoMain.RandPrice)
|
||
p -= Randomx.GetId(0, 10);
|
||
if (UploadPinduoduoMain.SubCoupon > 0 && !string.IsNullOrEmpty(t.youHuei))
|
||
{
|
||
decimal yh;
|
||
if (decimal.TryParse(t.youHuei, out yh))
|
||
{
|
||
p -= (int)(yh * 100 * UploadPinduoduoMain.SubCoupon / 100);
|
||
}
|
||
}
|
||
return p;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 设置错误信息
|
||
/// </summary>
|
||
/// <param name="messageShow"></param>
|
||
/// <param name="message"></param>
|
||
public void Error(string messageShow, string message)
|
||
{
|
||
t.Message = message;
|
||
if (us == null)
|
||
{
|
||
UploadPinduoduoMain.ProductTemp.Add(t);
|
||
}
|
||
else
|
||
{
|
||
UploadPinduoduoMain.ProductReplaceTemp.Add(t);
|
||
}
|
||
LogSave.Add(Name, messageShow);
|
||
}
|
||
public string UploadImg(string beforUrl, ref byte[] img, bool hadUp)
|
||
{
|
||
if (img == null || img.Length == 0)
|
||
return "";
|
||
if (ImageTemp.ContainsKey(beforUrl))
|
||
return ImageTemp[beforUrl].Url;
|
||
string imgUrl = "", html;
|
||
long urlId = Math.Abs(BaseClass.GetLong(beforUrl));
|
||
if (BaseClass.UseApiFirst)
|
||
{
|
||
PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("频繁"))
|
||
Thread.Sleep(3000);
|
||
Thread.Sleep(1000);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
}
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
if (hadUp)
|
||
{
|
||
if (!picUped.ContainsKey(urlId))
|
||
picUped.Add(urlId, imgUrl);
|
||
if (!picsTemp.ContainsKey(urlId))
|
||
{
|
||
try
|
||
{
|
||
picsTemp.Add(urlId, imgUrl);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return imgUrl;
|
||
}
|
||
string url = "https://mms.pinduoduo.com/galerie/business/get_signature";
|
||
string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=5146155709&type=edit";
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{\"bucket_tag\":\"mms-material-img\"}", Shop.Cookies);//"{\"bucket_tag\":\"pdd_goods\"}" {\"bucket_tag\":\"pdd_mms\"}
|
||
//if (html.Contains("非法请求"))
|
||
//{
|
||
// url = "https://mms.pinduoduo.com/galerie/business/get_signature";
|
||
// refere = "https://mms.pinduoduo.com/goods/goods_materials";
|
||
// string data = "{\"bucket_tag\":\"mms-material-img\"}";
|
||
// html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, Shop.Cookies);
|
||
// string sign = BaseRegex.GetStringJson(ref html, "signature");
|
||
// url = "https://file.pinduoduo.com/v3/store_image";
|
||
// refere = "https://mms.pinduoduo.com/goods/goods_materials";
|
||
// try
|
||
// {
|
||
// string fileName = Randomx.GetId(100000) + ".jpg";
|
||
// html = HttpPostDataImage(url, 30000, "image", fileName, img, sign, refere);
|
||
// imgUrl = BaseRegex.GetStringJson(ref html, "url");
|
||
// if (imgUrl.Contains("null"))
|
||
// imgUrl = "";
|
||
// }
|
||
// catch
|
||
// {
|
||
// }
|
||
//}
|
||
//if (html.Contains("非法请求"))
|
||
//{
|
||
// string urlx = "https://aid.pinduoduo.com/api/banner-intelligent/material/upload";
|
||
// string referex = "https://aid.pinduoduo.com/tools/matting?origin=goods_material";
|
||
// try
|
||
// {
|
||
// string fileName = Randomx.GetId(100000) + ".jpg";
|
||
// html = HttpPostData(urlx, 30000, "file", fileName, img, referex);
|
||
// imgUrl = BaseRegex.GetStringJson(ref html, "result");
|
||
// if (imgUrl.Contains("null"))
|
||
// imgUrl = "";
|
||
// }
|
||
// catch
|
||
// {
|
||
// return "";
|
||
// }
|
||
//}
|
||
//if (html.Contains("非法请求"))//上传图片到客服chat文件夹里面了,可以用暂时不用
|
||
//{
|
||
// url = "https://mms.pinduoduo.com/chats/malls/" + Shop.MallId + "/get_upload_sign";
|
||
// refere = "https://mms.pinduoduo.com/chat-merchant/index.html";
|
||
// html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", Shop.Cookies);
|
||
// //url = "https://mms.pinduoduo.com/plateau/file/pre_upload";
|
||
// //html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{\"chat_type_id\":1,\"file_usage\":1}", Shop.Cookies);//upload_signature
|
||
//}
|
||
if (html.Contains("signature"))
|
||
{
|
||
string sign = BaseRegex.GetStringJson(ref html, "signature");
|
||
if (string.IsNullOrEmpty(sign))
|
||
{
|
||
return "";
|
||
}
|
||
string data =
|
||
"{\"upload_sign\":\"" + sign + "\",\"image\":\"data:image/jpeg;base64," +
|
||
Convert.ToBase64String(img) + "\"}";
|
||
url = "https://file.yangkeduo.com/v2/store_image";
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "url");
|
||
}
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("频繁"))
|
||
Thread.Sleep(3000);
|
||
Thread.Sleep(1000);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
if (hadUp)
|
||
{
|
||
if (!picUped.ContainsKey(urlId))
|
||
picUped.Add(urlId, imgUrl);
|
||
if (!picsTemp.ContainsKey(urlId))
|
||
{
|
||
try
|
||
{
|
||
picsTemp.Add(urlId, imgUrl);
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
}
|
||
}
|
||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
return imgUrl;
|
||
}
|
||
|
||
|
||
private string HttpPostDataImage(string url, int timeOut, string fileKeyName, string fileName, byte[] file, string sign, string referer)
|
||
{
|
||
string responseContent = "";
|
||
string cookie = Shop.Cookies;
|
||
if (string.IsNullOrEmpty(cookie))
|
||
{
|
||
return "";
|
||
}
|
||
var memStream = new MemoryStream();
|
||
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||
// 边界符
|
||
var boundary = "----WebKitFormBoundary2yjyehYBjxWIyeiH";
|
||
// 边界符
|
||
var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
|
||
// 边界符
|
||
var secondBoundary = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");
|
||
// 最后的结束符
|
||
var endBoundary = Encoding.ASCII.GetBytes("--" + boundary + "--");
|
||
|
||
// 设置属性
|
||
webRequest.Method = "POST";
|
||
webRequest.KeepAlive = true;
|
||
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
|
||
webRequest.Referer = referer;
|
||
webRequest.Accept = "*/*";
|
||
webRequest.UserAgent = BaseClass.ChromeUserAgent;
|
||
webRequest.Headers.Add("Cookie", cookie);
|
||
webRequest.Headers.Add("Origin", @"https://mms.pinduoduo.com");
|
||
webRequest.Headers.Add("Sec-Fetch-Site", @"same-site");
|
||
webRequest.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||
webRequest.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||
webRequest.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||
webRequest.Headers.Set(HttpRequestHeader.Cookie, cookie);
|
||
webRequest.ServicePoint.Expect100Continue = false;
|
||
|
||
|
||
string first =
|
||
"Content-Disposition: form-data; name=\"{0}\";\r\n\r\n" + sign + "\r\n";
|
||
var firstheader = string.Format(first, "upload_sign");
|
||
var firstheaderbytes = Encoding.UTF8.GetBytes(firstheader);
|
||
|
||
|
||
|
||
string filePartHeader =
|
||
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
||
"Content-Type: image/jpeg\r\n\r\n";
|
||
var header = string.Format(filePartHeader, fileKeyName, fileName);
|
||
|
||
//string temp = "--" + boundary+"\r\n"+ firstheader +"--" + boundary + "\r\n"+ header;
|
||
var headerbytes = Encoding.UTF8.GetBytes(header);
|
||
|
||
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
||
memStream.Write(firstheaderbytes, 0, firstheaderbytes.Length);
|
||
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
||
memStream.Write(headerbytes, 0, headerbytes.Length);
|
||
|
||
// 写入文件
|
||
memStream.Write(file, 0, file.Length);
|
||
|
||
|
||
// 写入文件
|
||
string endPartHeader =
|
||
"Content-Disposition: form-data; name=\"pic_operations\"\r\n\r\n";
|
||
var endheaderbytes = Encoding.UTF8.GetBytes(endPartHeader);
|
||
|
||
memStream.Write(secondBoundary, 0, secondBoundary.Length);
|
||
memStream.Write(endheaderbytes, 0, endheaderbytes.Length);
|
||
|
||
var stringKeyHeader2 = "{\"rules\":[{\"rule\":\"imageMogr2/format/jpeg/quality/80|imageView2/2/w/2000/h/2000\"}]}\r\n";
|
||
byte[] formbytes = Encoding.UTF8.GetBytes(stringKeyHeader2);
|
||
memStream.Write(formbytes, 0, formbytes.Length);
|
||
|
||
|
||
// 写入最后的结束边界符
|
||
memStream.Write(endBoundary, 0, endBoundary.Length);
|
||
|
||
webRequest.ContentLength = memStream.Length;
|
||
using (Stream stream = webRequest.GetRequestStream())
|
||
{
|
||
memStream.WriteTo(stream);
|
||
}
|
||
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
||
if (httpWebResponse != null)
|
||
{
|
||
if (string.IsNullOrEmpty(responseContent))
|
||
responseContent = ReadResponsex(httpWebResponse);
|
||
httpWebResponse.Close();
|
||
}
|
||
return responseContent;
|
||
}
|
||
/// <summary>
|
||
/// 发送post请求
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="timeOut"></param>
|
||
/// <param name="fileKeyName"></param>
|
||
/// <param name="filePath"></param>
|
||
/// <param name="stringDict"></param>
|
||
/// <returns></returns>
|
||
private string HttpPostData(string url, int timeOut, string fileKeyName, string fileName, byte[] file, NameValueCollection stringDict, string referer)
|
||
{
|
||
string responseContent;
|
||
string cookie = Shop.Cookies;// BaseClass.CookiesAllString.ContainsKey("taobao.com") ? BaseClass.CookiesAllString["taobao.com"] : "";
|
||
if (string.IsNullOrEmpty(cookie))
|
||
{
|
||
return "";
|
||
}
|
||
var memStream = new MemoryStream();
|
||
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||
// 边界符
|
||
var boundary = "----WebKitFormBoundaryHnaq59TH4KqN8876";
|
||
// 边界符
|
||
var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n");
|
||
//var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||
// 最后的结束符
|
||
var endBoundary = Encoding.ASCII.GetBytes("--" + boundary + "--\r\n");
|
||
|
||
// 设置属性
|
||
webRequest.Method = "POST";
|
||
webRequest.Timeout = timeOut;
|
||
webRequest.Proxy = null;
|
||
webRequest.ReadWriteTimeout = timeOut;
|
||
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
|
||
if (string.IsNullOrEmpty(referer))
|
||
referer = "https://tadget.taobao.com/redaction/manager.htm";
|
||
webRequest.Referer = referer;
|
||
webRequest.UserAgent = BaseClass.ChromeUserAgent;
|
||
//webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko";
|
||
webRequest.Headers.Add("Cookie", cookie);
|
||
//webRequest.Headers.Add("Cookie", "v=0; cookie2=19bb7096a84354a4c14f57b3b139b358; _tb_token_=371a6e3e53673; existShop=MTQ5NTA4NzEwNQ%3D%3D; skt=07be2c7a4d43d4e3; publishItemObj=Ng%3D%3D; t=cdd5be62cd6b4e78434311371fbd7ff9; uc3=sg2=UtABdWdeGfXD%2FQkzzQhDSLQGa8sMw6MWHGmZA5%2Fz1oY%3D&nk2=G4mgLCefCRJZu5RKow%3D%3D&id2=W8nWsIU9pmPl&vt3=F8dARVDUXtcYdighsV4%3D&lg2=VFC%2FuZ9ayeYq2g%3D%3D; tracknick=xiaotui930904; _cc_=UIHiLt3xSw%3D%3D; tg=0; thw=cn; ali_ab=36.7.115.240.1486373819164.2; miid=805014732159802464; mt=np=&ci=1_1&cyk=2_0; hng=CN%7Czh-CN%7CCNY; cna=FBaXEKHXWGsCASQ5jXreM7Bn; l=Alpa9EIFIfaqKZPIW3nvwNBw6g58A95l; isg=AoGB_EtuvM235dDxcXm4k6uxmM2obfWgjhNWjuPW9AjnyqCcK_uCcC2I-ody; lgc=xiaotui930904; uss=BxExuOuBMGTSmmLusncTQzrc54qNGyvc44m3KpvMw%2FDqvz12lH2jkCfx; _m_user_unitinfo_=unit|unsz; _m_h5_tk=0e98a920393ab7ef74949cb428e8cbf8_1495072723582; _m_h5_tk_enc=c01cbddf709302868d28a398ddc7a464; _m_unitapi_v_=1492572565585; uc1=cookie14=UoW%2BvfobS%2FYyFQ%3D%3D&lng=zh_CN&cookie16=UtASsssmPlP%2Ff1IHDsDaPRu%2BPw%3D%3D&existShop=true&cookie21=UIHiLt3xSixwH1aenGUFEQ%3D%3D&tag=8&cookie15=WqG3DMC9VAQiUQ%3D%3D&pas=0; sg=482; cookie1=AVZ7NzilkILAckSZh3aH1rY3cLn%2F1CTS%2FTys%2FR09hPk%3D; unb=802158228; _l_g_=Ug%3D%3D; _nk_=xiaotui930904; cookie17=W8nWsIU9pmPl; JSESSIONID=3667ED995D0FA3DF2C4B9D2848FBECFB; apushcff39d705ee654f2389a8c5fb80067dd=%7B%22ts%22%3A1495087171963%2C%22parentId%22%3A1495087120835%7D");
|
||
//webRequest.Headers.Add("X-Requested-With", "ShockwaveFlash/23.9.9.999");
|
||
//webRequest.Headers.Add("x-flash-version", "25,0,0,148");
|
||
|
||
|
||
//if (string.IsNullOrEmpty(ShopName))
|
||
// ShopName = BaseClass.ShopName;
|
||
//if (string.IsNullOrEmpty(ShopName))
|
||
//{
|
||
// ShopName = BaseRegex.GetMatchRegexString(ref cookie, "_nk_=([^;]+);");
|
||
//}
|
||
// 写入文件
|
||
string filePartHeader =
|
||
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
||
"Content-Type: image/jpeg\r\n\r\n";
|
||
if (url.Contains("s.taobao.com/image"))
|
||
{
|
||
filePartHeader =
|
||
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
||
"Content-Type: image/jpeg\r\n\r\n";
|
||
}
|
||
var header = string.Format(filePartHeader, fileKeyName, fileName);
|
||
var headerbytes = Encoding.UTF8.GetBytes(header);
|
||
|
||
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
||
memStream.Write(headerbytes, 0, headerbytes.Length);
|
||
|
||
//while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
|
||
//{
|
||
// memStream.Write(buffer, 0, bytesRead);
|
||
//}
|
||
memStream.Write(file, 0, file.Length);
|
||
|
||
// 写入字符串的Key
|
||
var stringKeyHeader = "\r\n--" + boundary +
|
||
"\r\nContent-Disposition: form-data; name=\"{0}\"" +
|
||
"\r\n\r\n\r\n";
|
||
|
||
foreach (byte[] formitembytes in from string key in stringDict.Keys
|
||
select string.Format(stringKeyHeader, key, stringDict[key])
|
||
into formitem
|
||
select Encoding.UTF8.GetBytes(formitem))
|
||
{
|
||
memStream.Write(formitembytes, 0, formitembytes.Length);
|
||
}
|
||
|
||
//var stringKeyHeader2 = "{\"rules\":[{\"rule\":\"imageMogr2/format/jpeg/quality/80|imageView2/2/w/2000/h/2000\"}]}";
|
||
//byte[] formbytes = Encoding.UTF8.GetBytes(stringKeyHeader2);
|
||
//memStream.Write(formbytes, 0, formbytes.Length);
|
||
|
||
|
||
// 写入最后的结束边界符
|
||
memStream.Write(endBoundary, 0, endBoundary.Length);
|
||
|
||
webRequest.ContentLength = memStream.Length;
|
||
|
||
var requestStream = webRequest.GetRequestStream();
|
||
|
||
memStream.Position = 0;
|
||
var tempBuffer = new byte[memStream.Length];
|
||
memStream.Read(tempBuffer, 0, tempBuffer.Length);
|
||
memStream.Close();
|
||
|
||
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
|
||
requestStream.Close();
|
||
|
||
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
||
|
||
using (var httpStreamReader = new StreamReader(httpWebResponse.GetResponseStream(),
|
||
Encoding.GetEncoding("utf-8")))
|
||
{
|
||
responseContent = httpStreamReader.ReadToEnd();
|
||
}
|
||
|
||
httpWebResponse.Close();
|
||
webRequest.Abort();
|
||
|
||
return responseContent;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 发送post请求
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="timeOut"></param>
|
||
/// <param name="fileKeyName"></param>
|
||
/// <param name="filePath"></param>
|
||
/// <param name="stringDict"></param>
|
||
/// <returns></returns>
|
||
private string HttpPostData(string url, int timeOut, string fileKeyName, string fileName, byte[] file, string referer)
|
||
{
|
||
string pjtoken;
|
||
if (WhiteBaseMap.ShopToken.ContainsKey(Shop.ShopName))
|
||
{
|
||
pjtoken = WhiteBaseMap.ShopToken[Shop.ShopName];
|
||
}
|
||
else
|
||
{
|
||
pjtoken = GetToken();
|
||
}
|
||
bool falg = true;
|
||
Again:
|
||
string cookie = Shop.Cookies;// BaseClass.CookiesAllString.ContainsKey("taobao.com") ? BaseClass.CookiesAllString["taobao.com"] : "";
|
||
cookie += "ptj_token="+ pjtoken + "";
|
||
if (string.IsNullOrEmpty(cookie))
|
||
{
|
||
return "";
|
||
}
|
||
var webRequest = (HttpWebRequest)WebRequest.Create(url);
|
||
// 边界符
|
||
var boundary = "----WebKitFormBoundaryPVCVkeltmosCsFhB";
|
||
// 设置属性
|
||
webRequest.KeepAlive = true;
|
||
webRequest.Method = "POST";
|
||
webRequest.ContentType = "multipart/form-data; boundary=" + boundary;
|
||
webRequest.Referer = referer;
|
||
webRequest.UserAgent = BaseClass.ChromeUserAgent;
|
||
webRequest.Accept = "*/*";
|
||
webRequest.Headers.Add("Anti-Content", CpsSetAllGoods.getAnti0aon());
|
||
webRequest.Headers.Add("Origin", @"https://aid.pinduoduo.com");
|
||
webRequest.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
||
webRequest.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||
webRequest.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||
webRequest.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||
webRequest.Headers.Set(HttpRequestHeader.Cookie, cookie);
|
||
webRequest.ServicePoint.Expect100Continue = false;
|
||
|
||
|
||
var memStream = new MemoryStream();
|
||
// 边界符
|
||
var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary+"\r\n");
|
||
// 最后的结束符
|
||
var endBoundary = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--");
|
||
// 写入文件
|
||
string filePartHeader =
|
||
"Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" +
|
||
"Content-Type: image/jpeg\r\n\r\n";
|
||
|
||
var header = string.Format(filePartHeader, fileKeyName, fileName);
|
||
var headerbytes = Encoding.UTF8.GetBytes(header);
|
||
memStream.Write(beginBoundary, 0, beginBoundary.Length);
|
||
memStream.Write(headerbytes, 0, headerbytes.Length);
|
||
memStream.Write(file, 0, file.Length);
|
||
// 写入最后的结束边界符
|
||
memStream.Write(endBoundary, 0, endBoundary.Length);
|
||
webRequest.ContentLength = memStream.Length;
|
||
using (Stream stream = webRequest.GetRequestStream())
|
||
{
|
||
memStream.WriteTo(stream);
|
||
}
|
||
//memStream.Position = 0;
|
||
//var tempBuffer = new byte[memStream.Length];
|
||
//memStream.Read(tempBuffer, 0, tempBuffer.Length);
|
||
//memStream.Close();
|
||
|
||
//requestStream.Write(tempBuffer, 0, tempBuffer.Length);
|
||
//requestStream.Close();
|
||
string responseText = "";
|
||
var httpWebResponse = (HttpWebResponse)webRequest.GetResponse();
|
||
|
||
if (httpWebResponse != null)
|
||
{
|
||
if (string.IsNullOrEmpty(responseText))
|
||
responseText = ReadResponsex(httpWebResponse);
|
||
httpWebResponse.Close();
|
||
}
|
||
if (responseText.Contains("\"success\":false") &&falg)
|
||
{
|
||
falg = false;
|
||
pjtoken = GetToken();
|
||
goto Again;
|
||
}
|
||
return responseText;
|
||
}
|
||
public string GetToken()
|
||
{
|
||
string urlxm = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
||
string referem = "https://mms.pinduoduo.com/goods/goods_materials?tab=0";
|
||
string dataxm = "{\"mallId\":" + Shop.MallId + ",\"redirectUrl\":\"https://aid.pinduoduo.com\"}";
|
||
string htmlxm = WhiteBaseMapInstance.Request_mms_pinduoduo_com(urlxm, urlxm, Shop.Cookies, dataxm, WhiteBaseMapInstance.getAnti0aon()); //GetPostTaobaoHtml.GetJsonPost(urlxm, referem, true, dataxm, Shop.Cookies);
|
||
string accessToken = BaseRegex.GetStringJson(ref htmlxm, "accessToken");
|
||
string cookies = "ptj_token=" + accessToken + ";";
|
||
htmlxm = WhiteBaseMapInstance.GetJsonPostURL("https://aid.pinduoduo.com/auth?redirectUrl=https%3A%2F%2Faid.pinduoduo.com%2Ftools%2Fmatting%3Forigin%3Dgoods_material&accessToken=" + accessToken, "", true, "", cookies);
|
||
string pjtoken = BaseRegex.GetMatchRegexString(ref htmlxm, "ptj_token=([^;]+?);");
|
||
if (WhiteBaseMap.ShopToken.ContainsKey(Shop.ShopName))
|
||
{
|
||
WhiteBaseMap.ShopToken[Shop.ShopName] = pjtoken;
|
||
}
|
||
else
|
||
{
|
||
WhiteBaseMap.ShopToken.Add(Shop.ShopName, pjtoken);
|
||
}
|
||
return pjtoken;
|
||
}
|
||
public static string ReadResponsex(HttpWebResponse response)
|
||
{
|
||
using (Stream responseStream = response.GetResponseStream())
|
||
{
|
||
Stream streamToRead = responseStream;
|
||
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
||
{
|
||
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
|
||
}
|
||
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
||
{
|
||
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
|
||
}
|
||
|
||
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8))
|
||
{
|
||
return streamReader.ReadToEnd();
|
||
}
|
||
}
|
||
}
|
||
|
||
public string UploadImgCut(ref byte[] img, long goodId)
|
||
{
|
||
if (img == null || img.Length == 0)
|
||
return "";
|
||
//if (ImageTemp.ContainsKey(beforUrl))
|
||
// return ImageTemp[beforUrl].Url;
|
||
string imgUrl = "", html;
|
||
if (BaseClass.UseApiFirst)
|
||
{
|
||
PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("频繁"))
|
||
Thread.Sleep(3000);
|
||
Thread.Sleep(1000);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
}
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
return imgUrl;
|
||
}
|
||
//string url = "https://mms.pinduoduo.com/earth/api/upload/getSignature";
|
||
//string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=5146155709&type=edit&from=category";
|
||
//html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{}", Shop.Cookies);
|
||
string url = "https://mms.pinduoduo.com/galerie/business/get_signature";
|
||
string refere = "https://mms.pinduoduo.com/goods/goods_materials";
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{\"bucket_tag\":\"pdd_goods\"}", Shop.Cookies);
|
||
|
||
string sign = BaseRegex.GetStringJson(ref html, "signature");
|
||
if (string.IsNullOrEmpty(sign))
|
||
{
|
||
return "";
|
||
}
|
||
string data =
|
||
"{\"upload_sign\":\"" + sign + "\",\"image\":\"data:image/jpeg;base64," +
|
||
Convert.ToBase64String(img) + "\"}";
|
||
url = "https://file.yangkeduo.com/v2/store_image";
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("频繁"))
|
||
Thread.Sleep(3000);
|
||
Thread.Sleep(1000);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
}
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
return imgUrl;
|
||
}
|
||
//LogSave.Add(Name, "上传白底图:" + imgUrl);
|
||
string upUrl = BaseRegex.GetStringJson(ref html, "url");
|
||
url = "https://mms.pinduoduo.com/giraffe/mms/material/create";
|
||
data = "{\"content\":\"" + upUrl + "\",\"goods_id\":" + goodId + ",\"type\":1}";
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
|
||
return html;
|
||
}
|
||
/// <summary>
|
||
///
|
||
/// 添加到缓存
|
||
/// </summary>
|
||
/// <param name="key"></param>
|
||
/// <param name="value"></param>
|
||
public static void AddImage(string key, string url, int width, int height)
|
||
{
|
||
if (string.IsNullOrEmpty(url))
|
||
return;
|
||
if (ImageTemp.ContainsKey(key) && url.Contains("http:"))
|
||
ImageTemp[key] = new ImageUrlBase(url, width, height);
|
||
if (ImageTemp.ContainsKey(key) || string.IsNullOrEmpty(key) || string.IsNullOrEmpty(url))
|
||
return;
|
||
try
|
||
{
|
||
ImageTemp.Add(key, new ImageUrlBase(url, width, height));
|
||
}
|
||
catch
|
||
{
|
||
}
|
||
}
|
||
|
||
public static string ReplaceTitle(string title)
|
||
{
|
||
string[] l = @"([\d\.]+[\s*]+元)
|
||
qq
|
||
预售
|
||
限量
|
||
".Split('\n');
|
||
foreach (string s in l)
|
||
{
|
||
if (string.IsNullOrEmpty(s))
|
||
continue;
|
||
string m = s.Trim();
|
||
if (m.Contains("("))
|
||
BaseRegex.Relpace(ref title, m, "");
|
||
else
|
||
title = title.Replace(m, "");
|
||
}
|
||
return title;
|
||
}
|
||
|
||
}
|
||
public class CutImage
|
||
{
|
||
public long goodsId;
|
||
public string url;
|
||
public string Name;
|
||
public ShopChatBase Shop;
|
||
public CutImage(string name, ShopChatBase shop)
|
||
{
|
||
Name = name;
|
||
Shop = shop;
|
||
}
|
||
public void CutImageVaule()
|
||
{
|
||
try
|
||
{
|
||
byte[] imageByte = new byte[0];
|
||
GetPostTaobaoHtml.DownLoadImage(url, out imageByte);
|
||
ImageBuild ib = new ImageBuild(imageByte);
|
||
if (ib.Width < 480 || ib.Width > 1500 || ib.Height < 480 || ib.Height > 1500)
|
||
{
|
||
LogSave.Add(Name, goodsId + "白底图大小不合适,跳过");
|
||
return;
|
||
}
|
||
bool isflag = ib.ImageCuteNoLogo();
|
||
if (!isflag)
|
||
return;
|
||
if (ib.Width != 480 || ib.Height != 480)
|
||
imageByte = ib.BuildNewSize(480, 480, 500, 100);
|
||
string html = UploadImgCut(ref imageByte, goodsId);
|
||
if (html.Contains("false"))
|
||
LogSave.Add(Name, goodsId + "上传白底图失败");
|
||
else
|
||
LogSave.Add(Name, goodsId + "上传白底图成功");
|
||
}
|
||
catch
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
public string UploadImgCut(ref byte[] img, long goodId)
|
||
{
|
||
if (img == null || img.Length == 0)
|
||
return "";
|
||
//if (ImageTemp.ContainsKey(beforUrl))
|
||
// return ImageTemp[beforUrl].Url;
|
||
string imgUrl = "", html;
|
||
//if (BaseClass.UseApiFirst)
|
||
//{
|
||
// PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||
// html = p.UploadImage(img);
|
||
// imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
// if (string.IsNullOrEmpty(imgUrl))
|
||
// {
|
||
// if (!string.IsNullOrEmpty(html) && html.Contains("频繁"))
|
||
// Thread.Sleep(3000);
|
||
// Thread.Sleep(1000);
|
||
// html = p.UploadImage(img);
|
||
// imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
// }
|
||
// if (!string.IsNullOrEmpty(imgUrl))
|
||
// LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
// return imgUrl;
|
||
//}
|
||
//string url = "https://mms.pinduoduo.com/earth/api/upload/getSignature";
|
||
//string refere = "https://mms.pinduoduo.com/goods/goods_add/index?id=5146155709&type=edit&from=category";
|
||
//html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{}", Shop.Cookies);
|
||
string url = "https://mms.pinduoduo.com/galerie/business/get_signature";
|
||
string refere = "https://mms.pinduoduo.com/goods/goods_materials";
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "{\"bucket_tag\":\"mms-material-img\"}", Shop.Cookies);//"{\"bucket_tag\":\"pdd_goods\"}"
|
||
|
||
string sign = BaseRegex.GetStringJson(ref html, "signature");
|
||
if (string.IsNullOrEmpty(sign))
|
||
{
|
||
return "";
|
||
}
|
||
string data =
|
||
"{\"upload_sign\":\"" + sign + "\",\"image\":\"data:image/jpeg;base64," +
|
||
Convert.ToBase64String(img) + "\"}";
|
||
url = "https://file.yangkeduo.com/v2/store_image";
|
||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
PinduoduoApiGetProduct p = new PinduoduoApiGetProduct(Shop);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
if (string.IsNullOrEmpty(imgUrl))
|
||
{
|
||
if (!string.IsNullOrEmpty(html) && html.Contains("频繁"))
|
||
Thread.Sleep(3000);
|
||
Thread.Sleep(1000);
|
||
html = p.UploadImage(img);
|
||
imgUrl = BaseRegex.GetStringJson(ref html, "image_url");
|
||
}
|
||
if (!string.IsNullOrEmpty(imgUrl))
|
||
LogSave.Add(Name, "上传图片:" + imgUrl);
|
||
}
|
||
string pjtoken = "";
|
||
if (WhiteBaseMap.ShopToken.ContainsKey(Shop.ShopName))
|
||
{
|
||
pjtoken = WhiteBaseMap.ShopToken[Shop.ShopName];
|
||
}
|
||
else
|
||
{
|
||
pjtoken = GetToken();
|
||
}
|
||
|
||
string cookie = Shop.Cookies;// BaseClass.CookiesAllString.ContainsKey("taobao.com") ? BaseClass.CookiesAllString["taobao.com"] : "";
|
||
cookie += "ptj_token=" + pjtoken + "";
|
||
string temp = ",{\"imageUrl\":\"" + imgUrl + "\",\"goodsId\":\"" + goodId + "\"}";
|
||
url = "https://aid.pinduoduo.com/api/banner-intelligent/matting/save";
|
||
data = "{\"images\":[" + temp.Substring(1, temp.Length - 1) + "],\"white\":true}";
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, url, true, data, cookie);
|
||
if (!html.Contains("\"success\":true,"))
|
||
{
|
||
pjtoken = GetToken();
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, url, true, data, cookie);
|
||
}
|
||
if (!html.Contains("\"success\":true,"))
|
||
return "false";
|
||
|
||
url = "https://mms.pinduoduo.com/garner/mms/file/list";
|
||
refere = "https://mms.pinduoduo.com/goods/goods_materials";
|
||
data = "{\"file_type_desc\":\"pic\",\"file_name\":\"" + goodId + "\",\"order_by\":\"create_time desc\",\"page\":1,\"page_size\":10,\"check_status_list\":[2]}";
|
||
html = GetPostTaobaoHtml.GetJsonPost(url, url, true, data, Shop.Cookies);
|
||
|
||
string upUrl = BaseRegex.GetStringJson(ref html, "url");
|
||
string id = BaseRegex.GetStringJson(ref html, "id");
|
||
url = "https://mms.pinduoduo.com/giraffe/mms/material/create";
|
||
data = "{\"content\":\"" + upUrl + "\",\"goods_id\":" + goodId + ",\"type\":1,\"mall_file_id\":"+id+",\"source\":4}"; //"{\"content\":\"" + upUrl + "\",\"goods_id\":" + goodId + ",\"type\":1}";
|
||
html = CpsSetAllGoods.Request_mms_pinduoduo_com(url, refere, Shop.Cookies, data, CpsSetAllGoods.getAnti0aon()); //GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies);
|
||
return html;
|
||
}
|
||
public string GetToken()
|
||
{
|
||
string urlxm = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
||
string referem = "https://mms.pinduoduo.com/goods/goods_materials?tab=0";
|
||
string dataxm = "{\"mallId\":" + Shop.MallId + ",\"redirectUrl\":\"https://aid.pinduoduo.com\"}";
|
||
string htmlxm = WhiteBaseMapInstance.Request_mms_pinduoduo_com(urlxm, urlxm, Shop.Cookies, dataxm, WhiteBaseMapInstance.getAnti0aon()); //GetPostTaobaoHtml.GetJsonPost(urlxm, referem, true, dataxm, Shop.Cookies);
|
||
string accessToken = BaseRegex.GetStringJson(ref htmlxm, "accessToken");
|
||
string cookies = "ptj_token=" + accessToken + ";";
|
||
htmlxm = WhiteBaseMapInstance.GetJsonPostURL("https://aid.pinduoduo.com/auth?redirectUrl=https%3A%2F%2Faid.pinduoduo.com%2Ftools%2Fmatting%3Forigin%3Dgoods_material&accessToken=" + accessToken, "", true, "", cookies);
|
||
string pjtoken = BaseRegex.GetMatchRegexString(ref htmlxm, "ptj_token=([^;]+?);");
|
||
if (WhiteBaseMap.ShopToken.ContainsKey(Shop.ShopName))
|
||
{
|
||
WhiteBaseMap.ShopToken[Shop.ShopName] = pjtoken;
|
||
}
|
||
else
|
||
{
|
||
WhiteBaseMap.ShopToken.Add(Shop.ShopName, pjtoken);
|
||
}
|
||
return pjtoken;
|
||
}
|
||
}
|
||
}
|