temu客户端程序
This commit is contained in:
commit
4aaf264e89
694 files changed
+263780
No files matched your search
@@ -0,0 +1,949 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
using Work.ManageClass;
|
||||
using Work.CollectClass;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
using NaiBa.Util.Extension;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class AlibabaProductGet
|
||||
{
|
||||
public ProductCollectBase Product;
|
||||
public bool IsPinduoduo = false;
|
||||
public bool OnSale = true;
|
||||
public AlibabaProductGet(ProductCollectBase p)
|
||||
{
|
||||
Product = p;
|
||||
}
|
||||
|
||||
public void Get()
|
||||
{
|
||||
if (TaobaoMobileCollect.ProductTemp.ContainsKey(Product.from_id))
|
||||
{
|
||||
Product = TaobaoMobileCollect.ProductTemp[Product.from_id].Clone();
|
||||
return;
|
||||
}
|
||||
string url = Product.from_url;
|
||||
string refere = "http://page.1688.com/";
|
||||
|
||||
bool canUse;
|
||||
string serverTempHtml = ServerTemp.Get(3, "main-" + Product.from_id.ToString(), out canUse);
|
||||
string html = serverTempHtml;
|
||||
|
||||
if (!string.IsNullOrEmpty(html) && !html.Contains("调用成功"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, false);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("currentTime"))
|
||||
{
|
||||
Thread.Sleep(60 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, false);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("currentTime"))
|
||||
{
|
||||
LogSave.Add("获取产品详细页面失败,请检查程序 " + url);
|
||||
OnSale = false;
|
||||
return;
|
||||
}
|
||||
if (html.Contains("no-price-txt"))
|
||||
{
|
||||
LogSave.Add("获取产品详细页面发现没有价格,跳过 " + url);
|
||||
OnSale = false;
|
||||
return;
|
||||
}
|
||||
if (!canUse)
|
||||
ServerTemp.Set(3, "main-" + Product.from_id.ToString(), html);
|
||||
Product.from_cat_id = BaseRegex.GetIntJson(ref html, @"catid");
|
||||
if (Product.from_cat_id == 0)
|
||||
{
|
||||
int.TryParse(BaseRegex.GetMatchRegexString(ref html, "catid:'([^}]+?)'"), out Product.from_cat_id);
|
||||
}
|
||||
Product.item_size = "";
|
||||
Product.item_weight = 1;
|
||||
Product.price = BaseRegex.GetDecimalJson(ref html, @"refPrice");
|
||||
if (Product.price == 0)
|
||||
{
|
||||
decimal.TryParse(BaseRegex.GetMatchRegexString(ref html, "refPrice:'([^}]+?)'"), out Product.price);
|
||||
}
|
||||
Product.discount = BaseRegex.GetDecimalJson(ref html, @"discount");
|
||||
Product.discountPrice = BaseRegex.GetDecimalJson(ref html, @"discountPrice");
|
||||
if (Product.discount == 0)
|
||||
{
|
||||
Product.discount = 1;
|
||||
Product.discountPrice = Product.price;
|
||||
}
|
||||
|
||||
Product.name = BaseRegex.GetMatchRegexString(html, "<h1[^>]*?>([^<]+)</h1>");
|
||||
foreach (string s in AlibabaShop.NoTitleWords)
|
||||
{
|
||||
Product.name = Product.name.Replace(s, "");
|
||||
}
|
||||
|
||||
Product.name = BaseRegex.Relpace(Product.name.Replace("2016", "2017").Replace("2015", "2017"), @"([a-zA-Z]{1,2}[\d]{1,5})", "").Trim();
|
||||
bool had2017 = Product.name.Contains("2017");
|
||||
Product.name = "'" + Product.name + "\"";
|
||||
Product.name = BaseRegex.Relpace(Product.name, @"([a-zA-Z0-9# -]{2,20}?)""", "").Replace("\"", "");//去掉结尾的数字和字母下划线
|
||||
Product.name = BaseRegex.Relpace(Product.name, @"'([a-zA-Z0-9# -]{2,20})", "").Replace("'", "");//去掉开始的数字和字母下划线
|
||||
if (had2017 && !Product.name.Contains("2017"))
|
||||
Product.name = "2017" + Product.name;
|
||||
|
||||
bool titleHad = false;
|
||||
//foreach (string s in AlibabaShop.TitleCantHad)
|
||||
//{
|
||||
// if (Product.name.Contains(s))
|
||||
// titleHad = true;
|
||||
//}
|
||||
if (Product.name.Length < 12 || titleHad)
|
||||
{
|
||||
LogSave.Add("获取产品详细页面发现标题 " + Product.name + " 异常,跳过 " + url);
|
||||
return;
|
||||
}
|
||||
Product.sell_pt = "";
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"data-imgs='{""preview"":""([^']+?)"",""original"":""([^']+?)""");
|
||||
if (m.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取图片为空,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
Product.Images.Add(m[i].Groups[2].Value);
|
||||
}
|
||||
Product.image = Product.Images[0];
|
||||
Product.image_from_url = Product.image;
|
||||
Product.image_path = "";
|
||||
SetSkuMap(ref html, url);
|
||||
string area = BaseRegex.GetMatchRegexString(ref html, @"<span class=""disc"">([^<]+)</span>");
|
||||
if (!string.IsNullOrEmpty(area) && area.Contains(" "))
|
||||
{
|
||||
Product.state = area.Substring(0, area.IndexOf(" "));
|
||||
Product.city = area.Substring(area.IndexOf(" ") + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Product.state = BaseRegex.GetMatchRegexString(ref html, "province=([^;]+?);");
|
||||
Product.city = BaseRegex.GetMatchRegexString(ref html, "city=([^;]+?)\"");
|
||||
}
|
||||
m = BaseRegex.GetMatchRegex(ref html,
|
||||
@"<td class=""de-feature"">([^<]+?)</td>[\s]+<td class=""de-value"">([^<]+?)</td>");
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string name = m[i].Groups[1].Value;
|
||||
string value = m[i].Groups[2].Value;
|
||||
bool had = false;
|
||||
foreach (string s in AlibabaShop.NoPropWords)
|
||||
{
|
||||
if (name.Contains(s))
|
||||
{
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (had)
|
||||
continue;
|
||||
if (name == "品牌")
|
||||
value = "十四楼";
|
||||
Product.Prop.Add(new KeyValueBase(name, value));
|
||||
}
|
||||
|
||||
string memberId = BaseRegex.GetMatchRegexString(ref html, @" data-tfs-url=""([^""]+)""");
|
||||
string desc =
|
||||
GetPostTaobaoHtml.UploadTaobao(memberId, Product.from_url, false);
|
||||
string content = BaseRegex.GetMatchRegexString(ref desc, @"""content"":""([\w\W]+?)""};");
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
LogSave.Add("获取描述异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
content = content.Replace("\\\"", "\"").Replace("\\\\", "\\");
|
||||
BaseRegex.Relpace(ref content, @"<table background=([\w\W]+?)>超级快车", "");
|
||||
string newContentx = BaseRegex.Relpace(content, @"<table ([\w\W]+)</table>", "");
|
||||
BaseRegex.Relpace(ref newContentx, @"(<[aA] [^>]+?>([\w\W]*?)</[aA]>)", "");
|
||||
if (string.IsNullOrEmpty(newContentx) || !newContentx.ToLower().Contains("<img "))
|
||||
newContentx = content;
|
||||
string newContent = "";
|
||||
m = BaseRegex.GetMatchRegex(ref newContentx, @"(<img [^>]+?>)");
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
if (!m[i].Groups[1].Value.Contains(".alicdn.com") || m[i].Groups[0].Value.Contains("display: none") || m[i].Groups[0].Value.Contains("display:none"))
|
||||
continue;
|
||||
newContent += m[i].Groups[1].Value + "<br /><br />";
|
||||
}
|
||||
if (string.IsNullOrEmpty(newContent))
|
||||
{
|
||||
LogSave.Add("描述正文为空,跳过 " + url);
|
||||
return;
|
||||
}
|
||||
html = GetPostTaobaoHtml.UploadTaobao(
|
||||
"https://laputa.1688.com/offer/ajax/widgetList.do?callback=jQuery172025158196459054927_1533388414900&blocks=&data=offerdetail_ditto" +
|
||||
"_title%2Cofferdetail_common_report%2Cofferdetail_ditto_serviceDesc%2Cofferdetail_ditto_preferential%2Cofferdetail_ditto_postage%2Coff" +
|
||||
"erdetail_ditto_offerSatisfaction%2Cofferdetail_w1190_guarantee%2Cofferdetail_w1190_tradeWay%2Cofferdetail_w1190_samplePromotion%2Coffer" +
|
||||
"detail_ditto_whosaleself&offerId=" + Product.from_id + "&pageId=laputa20140721212446", Product.from_url, false);
|
||||
Product.express_price = BaseRegex.GetDecimalJson(ref html, "totalCost");
|
||||
Product.content = newContent;
|
||||
Product.content_alibaba = newContent;
|
||||
Product.main_cid = 0;
|
||||
Product.from_title = Product.name;
|
||||
Product.from_site_id = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
string data = "{\"responseClass\":\"\\\"com.alibaba.wireless.detail.netdata.offerdatanet.OfferDetailDataResponse\\\"\",\"RESPONSE_DATA_KEY\":\"\",\"MOCK_DATA\":\"false\",\"offerId\":\"" + Product.from_id + "\"}";
|
||||
//先去取数据
|
||||
html = MakeRequestThroughTradeAscM(data);
|
||||
if (!html.Contains("调用成功"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
bool bo = AliBaBaModle(html);
|
||||
if (!bo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (Product.cat3 == 3109)
|
||||
{
|
||||
var pro = Product.Props.Where(s => s.name.Contains("容量")).FirstOrDefault();
|
||||
if (pro == null)
|
||||
{
|
||||
string mah = BaseRegex.GetMatchRegexString(ref Product.name, @"([\d]+)毫安");
|
||||
PropBase p = new PropBase();
|
||||
p.pinduoduo_id = "140871455";
|
||||
p.id = 140871455;
|
||||
p.name = "电池容量";
|
||||
PropValueBase pr = new PropValueBase();
|
||||
pr.id = PinduoduoCatList.GetDianYuanId(int.Parse(mah)).ToString();
|
||||
pr.value = pr.id;
|
||||
pr.name = mah + "毫安";
|
||||
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
|
||||
pr.image = "";
|
||||
pr.image_from_url = "";
|
||||
p.Values.Add(pr);
|
||||
Product.Props.Add(p);
|
||||
for (int i = 0; i < Product.SkuMaps.Count; i++)
|
||||
{
|
||||
var sku = Product.SkuMaps[i];
|
||||
sku.name = sku.name + ";" + mah + "毫安";
|
||||
sku.nameLite = sku.nameLite + mah + "毫安";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(pro.pinduoduo_id))
|
||||
{
|
||||
pro.pinduoduo_id = "140871455";
|
||||
pro.id = 140871455;
|
||||
}
|
||||
for (int i = 0; i < pro.Values.Count; i++)
|
||||
{
|
||||
var pr = pro.Values[i];
|
||||
string mah= BaseRegex.GetMatchRegexString(ref pr.name, @"([\d]+)毫安");
|
||||
pr.id= PinduoduoCatList.GetDianYuanId(int.Parse(mah)).ToString();
|
||||
pr.value = pr.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsPinduoduo)//如果是更新上家价格,则执行此代码
|
||||
{
|
||||
Product.main_cid = new FromTitleToCat().GetMainCatId(Product.cat1);
|
||||
if (Product.main_cid == 0)
|
||||
return;
|
||||
//url = BaseClass.BigDataApiUrl + "?obj=product/product";
|
||||
//string datax = "&act=update&site_id=3&shop_name=" + GetHtml.UrlEncodeUtf8(Product.from_shop_name) + "&json=" + GetHtml.UrlEncodeUtf8(JsonHelper.SerializeObject(Product));
|
||||
//html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex() + datax);
|
||||
try
|
||||
{
|
||||
if (TaobaoMobileCollect.ProductTemp.Count > 1000)
|
||||
{
|
||||
TaobaoMobileCollect.ProductTemp.Clear();
|
||||
}
|
||||
|
||||
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(Product.from_id))
|
||||
TaobaoMobileCollect.ProductTemp.Add(Product.from_id, Product);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
//后期加代码
|
||||
return;
|
||||
}
|
||||
if (Product.from_cat_id == 0)
|
||||
{
|
||||
Product.message = "分类识别错误:" + Product.name;
|
||||
LogSave.Add(Product.message);
|
||||
return;
|
||||
}
|
||||
LogSave.Add("获取成功:" + Product.name);
|
||||
}
|
||||
public void AslasyHtml(TaobaoProductBase t, string html)
|
||||
{
|
||||
if (string.IsNullOrEmpty(html) || html == "null")
|
||||
return;
|
||||
try
|
||||
{
|
||||
//string title = BaseRegex.GetStringJson(ref html, "fession_title");
|
||||
//string[] goodTitle = title.Split(';');
|
||||
//主图
|
||||
string mainPic = BaseRegex.GetStringJson(ref html, "main_pic");
|
||||
string[] images = mainPic.Split(';');
|
||||
Product.Images.Clear();
|
||||
for (int i = 0; i < images.Length; i++)
|
||||
{
|
||||
string img = images[i];
|
||||
if (img.Contains("?"))
|
||||
img = img.Substring(0, img.IndexOf("?"));
|
||||
Product.Images.Add(img);
|
||||
}
|
||||
//详情图
|
||||
string container_info = BaseRegex.GetMatchRegexString(ref html, @"""container_info"":""(.*?)""");
|
||||
string[] contentimage = container_info.Split(';');
|
||||
var m = BaseRegex.GetMatchRegex(ref container_info, @"<img([^""]+?)>");
|
||||
string content = "";
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string img = m[i].Groups[0].Value;
|
||||
if (img.Contains("?"))
|
||||
img = img.Substring(0, img.IndexOf("?"));
|
||||
content += img;
|
||||
}
|
||||
Product.content = content;
|
||||
Product.Props.Clear();
|
||||
string temp = "";
|
||||
m = BaseRegex.GetMatchRegex(ref html,
|
||||
@"\{""id"":([-\d]+),""name"":""([^}]+)"",""pinduoduo_name"":[^}]+?,""Values"":\[([\w\W]+?)\]\}");
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
PropBase p = new PropBase();
|
||||
p.id = long.Parse(m[i].Groups[1].Value);
|
||||
p.name = m[i].Groups[2].Value;
|
||||
p.name = BaseRegex.Relpace(p.name, "(&[a-zA-z0-9]+?;)", "");
|
||||
bool had = false;
|
||||
for (int j = 0; j < Product.Props.Count; j++)
|
||||
{
|
||||
if (Product.Props[j].name == p.name)
|
||||
{
|
||||
p = Product.Props[j];
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
temp = m[i].Groups[3].Value;
|
||||
var mm = BaseRegex.GetMatchRegex(ref temp, @"""value"":""([-\d]*?)"",""name"":""([^""]+?)""[^\}]*\}");
|
||||
for (int j = 0; j < mm.Count; j++)
|
||||
{
|
||||
string v = mm[j].Groups[1].Value;
|
||||
string vi = mm[j].Groups[0].Value;
|
||||
string image = BaseRegex.GetStringJson(ref vi, "image");
|
||||
if (image == "null")
|
||||
image = "";
|
||||
PropValueBase pr = new PropValueBase();
|
||||
pr.value = v;
|
||||
pr.name = mm[j].Groups[2].Value;
|
||||
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
|
||||
pr.image = image;
|
||||
pr.image_from_url = image;
|
||||
bool hadx = false;
|
||||
for (int k = 0; k < p.Values.Count; k++)
|
||||
{
|
||||
if (p.Values[k].name == pr.name)
|
||||
{
|
||||
hadx = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hadx)
|
||||
p.Values.Add(pr);
|
||||
}
|
||||
if (!had)
|
||||
{
|
||||
p.sort = i + 1;
|
||||
Product.Props.Add(p);
|
||||
}
|
||||
}
|
||||
//Product.name = goodTitle[0];
|
||||
|
||||
|
||||
//for (int i = 1; i < goodTitle.Length; i++)
|
||||
//{
|
||||
// var p = t.Clone();
|
||||
// t.Titlte = goodTitle[i];
|
||||
// t.FromType = "阿里巴巴";
|
||||
// t.Uped = false;
|
||||
// UploadPinduoduoMain.ProductStock.Insert(0, p);
|
||||
//}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private string MakeRequestThroughTradeAscM(string data)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
string url = "http://acs.m.taobao.com/gw/mtop.1688.wosc.cbu.offerdetailservice.queryofferdetail/1.0/?data=";
|
||||
try
|
||||
{
|
||||
string api = "mtop.1688.wosc.cbu.offerdetailservice.queryofferdetail";
|
||||
string v = "1.0";
|
||||
|
||||
var t = BaseClass.GetTime(BaseClass.GetServerTimeString()).ToString();
|
||||
string utdid = "XUEI6Cqy4UgDAHCsEH0z5one";
|
||||
string uid = "";
|
||||
string appKey = "25443018";
|
||||
string lat = "";
|
||||
string lng = "";
|
||||
string ttid = "219201@taobao_android_7.6.0";
|
||||
string sid = "";
|
||||
string deviceId = "AqjuNSqg5WtUMlGAgV2ZsudCBHdVINyeYYmyjrge4w2P";
|
||||
string features = "27";
|
||||
string x_pv = "5.1";
|
||||
string url_getSign = BaseClass.BuildObjString("get_taobao_sign&act=get_tb_sign");// "http://new.qixiaoke.com/?obj=littlecow/user&act=get_tb_sign";
|
||||
string url_data = UserLogin.GetSignaturex("", "");
|
||||
string sign = GetHtml.PostUtf8(url_getSign, url_data + "&t=" + t + "&api=" + api + "&v=" + v + "&data=" + data);
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + GetHtml.UrlEncodeUtf8(data));
|
||||
request.Headers.Add("x-features", features);
|
||||
request.UserAgent = "MTOPSDK%2F3.1.1.7+%28Android%3B5.1%3BOPPO%3BOPPO+R9m%29";
|
||||
request.Headers.Add("x-ttid", "219201@taobao_android_7.6.0");
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "no-cache");
|
||||
request.Headers.Add("x-appkey", appKey);
|
||||
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
request.Headers.Add("x-pv", x_pv);
|
||||
request.Headers.Add("x-t", t.ToString());
|
||||
request.Headers.Add("x-utdid", utdid);
|
||||
request.Headers.Add("x-devid", deviceId);
|
||||
request.Headers.Add("x-sign", sign);
|
||||
request.Headers.Add("x-uid", uid);
|
||||
request.Headers.Add("x-sid", sid);
|
||||
request.Headers.Add("x-page-url", "http%3A%2F%2Fitem.taobao.com%2Fitem.htm");
|
||||
request.Headers.Add("x-nettype", "WIFI");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "deflate");
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
bool flag = e.Status == WebExceptionStatus.ProtocolError;
|
||||
if (!flag)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
response = (HttpWebResponse)e.Response;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
bool flag2 = response != null;
|
||||
if (flag2)
|
||||
{
|
||||
response.Close();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
return ReadResponse(response);
|
||||
}
|
||||
private static string ReadResponse(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();
|
||||
}
|
||||
}
|
||||
}
|
||||
private bool AliBaBaModle(string html)
|
||||
{
|
||||
if (html.Contains("商品不存在或不可展示"))
|
||||
{
|
||||
//IsOnSale = false;
|
||||
return false;
|
||||
}
|
||||
Product.item_weight = 1;
|
||||
var priceInfo = BaseRegex.GetMatchRegexString(ref html, "\"currentPrices\":([\\w\\W]+?)],");
|
||||
if (priceInfo.Contains("price"))
|
||||
{
|
||||
var sPriceTemp = BaseRegex.GetMatchRegex(ref priceInfo, "\"price\":\"([\\w\\W]+?)\"");
|
||||
if (sPriceTemp.Count > 0)
|
||||
{
|
||||
string sPrice = "";
|
||||
foreach (var item in sPriceTemp)
|
||||
{
|
||||
var v = item.ToString();
|
||||
sPrice = BaseRegex.GetMatchRegexString(ref v, "\"price\":\"([\\w\\W]+?)\"");
|
||||
if (!string.IsNullOrEmpty(Product.price.ToString()) && sPrice.ParseToDecimal() > Product.price)
|
||||
{
|
||||
if (sPrice.IndexOf("-") > 0)
|
||||
{
|
||||
sPrice = sPrice.Substring(0, sPrice.IndexOf('-'));
|
||||
}
|
||||
Product.price = Convert.ToDecimal(sPrice);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
var saleCount = BaseRegex.GetMatchRegexString(ref html, "\"saledCount\":\"([\\w\\W]+?)\"");
|
||||
int iSaleCount = 0;
|
||||
int.TryParse(saleCount, out iSaleCount);
|
||||
Product.saleCount = iSaleCount;
|
||||
Product.discountPrice = Product.price;
|
||||
|
||||
|
||||
Product.name = BaseRegex.GetMatchRegexString(html, "\"subject\":\"([\\w\\W]+?)\"");
|
||||
foreach (string s in AlibabaShop.NoTitleWords)
|
||||
{
|
||||
Product.name = Product.name.Replace(s, "");
|
||||
}
|
||||
|
||||
Product.name = BaseRegex.Relpace(Product.name.Replace("2018", "2020").Replace("2019", "2020"), @"([a-zA-Z]{1,2}[\d]{1,5})", "").Trim();
|
||||
bool had2017 = Product.name.Contains("2019");
|
||||
//Product.name = "'" + Product.name + "\"";
|
||||
//Product.name = BaseRegex.Relpace(Product.name, @"([a-zA-Z0-9# -]{2,20}?)""", "").Replace("\"", "");//去掉结尾的数字和字母下划线
|
||||
//Product.name = BaseRegex.Relpace(Product.name, @"'([a-zA-Z0-9# -]{2,20})", "").Replace("'", "");//去掉开始的数字和字母下划线
|
||||
if (had2017 && !Product.name.Contains("2019"))
|
||||
Product.name = "2019" + Product.name;
|
||||
|
||||
if (Product.name.Length < 12)
|
||||
{
|
||||
LogSave.Add("获取产品详细页面发现标题 " + Product.name + " 异常,跳过 " + Product.from_url);
|
||||
return false;
|
||||
}
|
||||
Product.sell_pt = "";
|
||||
var m = BaseRegex.GetMatchRegex(ref html, "\"originalImageURI\":\"([\\w\\W]+?)\"");
|
||||
if (m.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取图片为空,请检查程序 " + Product.from_url);
|
||||
return false;
|
||||
}
|
||||
if (Product.Images.Count <= 0)//如果主图有了 则不需要从页面拿了(文本备份里面有了) updata by tl 20190716
|
||||
{
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
Product.Images.Add(m[i].Groups[1].Value);
|
||||
}
|
||||
}
|
||||
Product.image = Product.Images[0];
|
||||
Product.image_from_url = Product.image;
|
||||
Product.image_path = "";
|
||||
SetSkuMapMoble(ref html);
|
||||
|
||||
string area = BaseRegex.GetMatchRegexString(ref html, "\"location\":\"([\\w\\W]+?)\"");
|
||||
if (!string.IsNullOrEmpty(area) && area.Contains(" "))
|
||||
{
|
||||
Product.state = area.Substring(0, area.IndexOf(" "));
|
||||
Product.city = area.Substring(area.IndexOf(" ") + 1);
|
||||
}
|
||||
var prop = BaseRegex.GetMatchRegexString(ref html, "\"productFeatureList\":\\[([\\w\\W]+?)\\],");
|
||||
m = BaseRegex.GetMatchRegex(ref prop, "\"name\":\"([\\w\\W]+?)}");
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string name = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, "\"name\":\"([\\w\\W]+?)\"");
|
||||
string value = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, "\"value\":\"([\\w\\W]+?)\"");
|
||||
bool had = false;
|
||||
foreach (string s in AlibabaShop.NoPropWords)
|
||||
{
|
||||
if (name.Contains(s))
|
||||
{
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (had)
|
||||
continue;
|
||||
if (name == "品牌")
|
||||
value = "other/其他";
|
||||
Product.Prop.Add(new KeyValueBase(name, value));
|
||||
}
|
||||
|
||||
string contentUrl = BaseRegex.GetMatchRegexString(ref html, "\"detailUrl\":\"([\\w\\W]+?)\"");
|
||||
string desc =
|
||||
GetPostTaobaoHtml.UploadTaobao(contentUrl, Product.from_url, false);
|
||||
string content = BaseRegex.GetMatchRegexString(ref desc, "\"content\":\"([\\w\\W]+?)\"};");
|
||||
if (string.IsNullOrEmpty(content))
|
||||
{
|
||||
LogSave.Add("获取描述异常,请检查程序 " + Product.from_url);
|
||||
return false;
|
||||
}
|
||||
content = content.Replace("\\\"", "\"").Replace("\\\\", "\\");
|
||||
BaseRegex.Relpace(ref content, @"<table background=([\w\W]+?)>超级快车", "");
|
||||
string newContentx = content;
|
||||
BaseRegex.Relpace(ref newContentx, @"(<[aA] [^>]+?>([\w\W]*?)</[aA]>)", "");
|
||||
if (string.IsNullOrEmpty(newContentx) || !newContentx.ToLower().Contains("<img "))
|
||||
newContentx = content;
|
||||
string newContent = "";
|
||||
m = BaseRegex.GetMatchRegex(ref newContentx, @"(<img [^>]+?>)");
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
if (!m[i].Groups[1].Value.Contains(".alicdn.com") || m[i].Groups[0].Value.Contains("display: none") || m[i].Groups[0].Value.Contains("display:none"))
|
||||
continue;
|
||||
newContent += m[i].Groups[1].Value + "<br /><br />";
|
||||
}
|
||||
if (string.IsNullOrEmpty(newContent))
|
||||
{
|
||||
LogSave.Add("描述正文为空,跳过 " + Product.from_url);
|
||||
return false;
|
||||
}
|
||||
|
||||
string offerFare = BaseRegex.GetMatchRegexString(ref html, "\"offerFareModel\":{([\\w\\W]+?)}");
|
||||
string IsHasFare = BaseRegex.GetStringJson(ref html, "hasFare");
|
||||
if (IsHasFare == "true")
|
||||
{
|
||||
Product.express_price = BaseRegex.GetDecimalJson(ref html, "cost");
|
||||
}
|
||||
|
||||
Product.from_cat_id = BaseRegex.GetIntJson(ref html, @"topCategoryId");
|
||||
|
||||
|
||||
//Product.content = newContent;
|
||||
if (string.IsNullOrEmpty(Product.content))//加这个判断是为了有可能文件里面有了详情图 updata by tl 20190716
|
||||
{
|
||||
Product.content = newContent;
|
||||
}
|
||||
|
||||
Product.content_alibaba = newContent;
|
||||
Product.main_cid = 0;
|
||||
Product.from_title = Product.name;
|
||||
Product.from_site_id = 3;
|
||||
return true;
|
||||
}
|
||||
private string UnTransferred(string Meaning)
|
||||
{
|
||||
//转义字符变换成普通字符
|
||||
Meaning = Meaning.Replace("<", "<");
|
||||
Meaning = Meaning.Replace(">", ">");
|
||||
Meaning = Meaning.Replace("'", "'");
|
||||
Meaning = Meaning.Replace(""", "\"");
|
||||
Meaning = Meaning.Replace("&", "&");
|
||||
|
||||
return Meaning;
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置skumap
|
||||
/// </summary>
|
||||
/// <param name="product"></param>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="url"></param>
|
||||
public void SetSkuMapMoble(ref string html)
|
||||
{
|
||||
string prop = BaseRegex.GetMatchRegexString(ref html, "\"skuProps\":([\\w\\W]+?)],");
|
||||
string skuMap = string.Empty;
|
||||
System.Text.RegularExpressions.MatchCollection mc = System.Text.RegularExpressions.Regex.Matches(html, "\"skuInfoMap\":([\\w\\W]+?)}},", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
||||
if (mc.Count > 0)
|
||||
{
|
||||
skuMap = mc[0].Groups[0].Value.ToString();
|
||||
}
|
||||
skuMap = skuMap.Replace("\"skuInfoMap\":", "").Trim(',');
|
||||
if (string.IsNullOrEmpty(skuMap) || string.IsNullOrEmpty(prop))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var m = BaseRegex.GetMatchRegex(ref prop, @"""prop"":""([^""]+?)"",""value"":\[([\w\W]+?\})\]\}");
|
||||
if (m == null || m.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取Prop异常,请检查程序 " + Product.from_url);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
PropBase p = new PropBase();
|
||||
string values = m[i].Groups[2].Value;
|
||||
p.name = m[i].Groups[1].Value;
|
||||
p.name = BaseRegex.Relpace(p.name, "(&[a-zA-z0-9]+?;)", "");
|
||||
bool had = false;
|
||||
for (int j = 0; j < Product.Props.Count; j++)
|
||||
{
|
||||
if (Product.Props[j].name == p.name)
|
||||
{
|
||||
p = Product.Props[j];
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var mm = BaseRegex.GetMatchRegex(ref values, @"\{([^\}]+?)\}");
|
||||
if (mm.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取Prop数值异常,请检查程序 " + Product.from_url);
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < mm.Count; j++)
|
||||
{
|
||||
PropValueBase pr = new PropValueBase();
|
||||
string h = mm[j].Groups[1].Value;
|
||||
h = UnTransferred(h).Replace(";", "").Replace(",", "");
|
||||
//h = BaseRegex.Relpace(h, "(&[a-zA-z0-9]+?;)", "").Replace(";", "").Replace(",", "");
|
||||
pr.name = BaseRegex.GetStringJson(ref h, "name");
|
||||
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
|
||||
pr.image = BaseRegex.GetStringJson(ref h, "imageUrl").Replace("null",null);
|
||||
pr.image_from_url = BaseRegex.GetStringJson(ref h, "imageUrl").Replace("null", null);
|
||||
p.Values.Add(pr);
|
||||
}
|
||||
if (!had)
|
||||
{
|
||||
p.sort = i + 1;
|
||||
Product.Props.Add(p);
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
JObject ja = JObject.Parse(skuMap);
|
||||
string temp = ja.ToString();
|
||||
string price = Product.price.ToString();
|
||||
foreach (var item in ja)
|
||||
{
|
||||
string result = item.ToString();
|
||||
string pri = BaseRegex.GetStringJson(ref result, "discountPrice");
|
||||
if (string.IsNullOrEmpty(pri))
|
||||
pri = BaseRegex.GetStringJson(ref result, "price");
|
||||
if (!string.IsNullOrEmpty(pri))
|
||||
price = pri;
|
||||
string name = item.Key;
|
||||
|
||||
string sale_count = BaseRegex.GetStringJson(ref result, "saleCount");
|
||||
string number = BaseRegex.GetStringJson(ref result, "canBookCount");
|
||||
name = UnTransferred(name);
|
||||
name = BuildName(name);
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
LogSave.Add("获取SKUmap名称异常,请检查程序 " + Product.from_url);
|
||||
return;
|
||||
}
|
||||
SkuMapBase sm = new SkuMapBase();
|
||||
sm.name = name;
|
||||
sm.price = decimal.Parse(price);
|
||||
sm.number = int.Parse(number);
|
||||
sm.sale_count = int.Parse(sale_count);
|
||||
Product.SkuMaps.Add(sm);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
//m = BaseRegex.GetMatchRegex(ref skuMap, "\"([\\s\\S]+?\":\\{\"specId\":[\\s\\S]+?skuId\":\"[\\d]+?\")");
|
||||
//if (m.Count == 0)
|
||||
//{
|
||||
// LogSave.Add("获取skuMap异常,请检查程序 " + Product.from_url);
|
||||
// return;
|
||||
//}
|
||||
//string price = BaseRegex.GetMatchRegexString(ref html, @"""priceRangeOriginal"":\[\[[\d]+, ([\d\.]+)?\]");
|
||||
//if (string.IsNullOrEmpty(price))
|
||||
//{
|
||||
// price = Product.price.ToString();
|
||||
//}
|
||||
//for (int i = 0; i < m.Count; i++)
|
||||
//{
|
||||
// string pri = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, @"""discountPrice"":""([\d\.]+)""");
|
||||
// if (string.IsNullOrEmpty(pri))
|
||||
// pri = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, @"""price"":""([\d\.]+)""");
|
||||
// if (!string.IsNullOrEmpty(pri))
|
||||
// price = pri;
|
||||
// string name = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, "\"([\\w\\W]+?)\":{");
|
||||
|
||||
// string sale_count = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, "\"saleCount\":\"([\\w\\W]+?)\"");
|
||||
// string number = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, "\"canBookCount\":\"([\\w\\W]+?)\"");
|
||||
// name = UnTransferred(name);
|
||||
// name = BuildName(name);
|
||||
|
||||
// //name = BaseRegex.Relpace(name, "(&[a-zA-z0-9]+?;)", "").Replace(",", "");
|
||||
// if (string.IsNullOrEmpty(name))
|
||||
// {
|
||||
// LogSave.Add("获取SKUmap名称异常,请检查程序 " + Product.from_url);
|
||||
// return;
|
||||
// }
|
||||
// SkuMapBase sm = new SkuMapBase();
|
||||
// sm.name = name;
|
||||
// sm.price = decimal.Parse(price);
|
||||
// sm.number = int.Parse(number);
|
||||
// sm.sale_count = int.Parse(sale_count);
|
||||
// Product.SkuMaps.Add(sm);
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置skumap
|
||||
/// </summary>
|
||||
/// <param name="product"></param>
|
||||
/// <param name="html"></param>
|
||||
/// <param name="url"></param>
|
||||
public void SetSkuMap(ref string html, string url)
|
||||
{
|
||||
string prop = BaseRegex.GetMatchRegexString(ref html, "\"skuProps\":([^\n]+?)\n");
|
||||
if (string.IsNullOrEmpty(prop))
|
||||
{
|
||||
prop = BaseRegex.GetMatchRegexString(ref html, "skuProps:([^\n]+?)\n");
|
||||
}
|
||||
string skuMap = BaseRegex.GetMatchRegexString(ref html, "\"skuMap\":([^\n]+?)\n");
|
||||
if (string.IsNullOrEmpty(skuMap))
|
||||
{
|
||||
skuMap = BaseRegex.GetMatchRegexString(ref html, "skuMap:([^\n]+?)\n");
|
||||
}
|
||||
if (string.IsNullOrEmpty(skuMap) || string.IsNullOrEmpty(prop))
|
||||
{
|
||||
//LogSave.Add("获取Prop或者skuMap异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
var m = BaseRegex.GetMatchRegex(ref prop, @"""prop"":""([^""]+?)"",""value"":\[([\w\W]+?\})\]\}");
|
||||
if (m == null || m.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取Prop异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
PropBase p = new PropBase();
|
||||
string values = m[i].Groups[2].Value;
|
||||
p.name = m[i].Groups[1].Value;
|
||||
p.name = BaseRegex.Relpace(p.name, "(&[a-zA-z0-9]+?;)", "");
|
||||
bool had = false;
|
||||
for (int j = 0; j < Product.Props.Count; j++)
|
||||
{
|
||||
if (Product.Props[j].name == p.name)
|
||||
{
|
||||
p = Product.Props[j];
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var mm = BaseRegex.GetMatchRegex(ref values, @"\{([^\}]+?)\}");
|
||||
//var mmm = BaseRegex.GetMatchRegex(ref values, @"""imageUrl"":""([^""]+?)""");
|
||||
if (mm.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取Prop数值异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
for (int j = 0; j < mm.Count; j++)
|
||||
{
|
||||
PropValueBase pr = new PropValueBase();
|
||||
string h = mm[j].Groups[1].Value;
|
||||
h = BaseRegex.Relpace(h, "(&[a-zA-z0-9]+?;)", "").Replace(";", "").Replace(",", "");
|
||||
pr.name = BaseRegex.GetStringJson(ref h, "name");
|
||||
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
|
||||
pr.image = BaseRegex.GetStringJson(ref h, "imageUrl");
|
||||
pr.image_from_url = BaseRegex.GetStringJson(ref h, "imageUrl");
|
||||
p.Values.Add(pr);
|
||||
}
|
||||
if (!had)
|
||||
{
|
||||
p.sort = i + 1;
|
||||
Product.Props.Add(p);
|
||||
}
|
||||
}
|
||||
m = BaseRegex.GetMatchRegex(ref skuMap, @"""([^""]+?)"":{""price"":""([^""]+?)""");
|
||||
if (m.Count == 0)
|
||||
{
|
||||
m = BaseRegex.GetMatchRegex(ref skuMap, @"""([^""]+?)"":\{[^\}]*""canBookCount"":([\d]+),[^\}]+?""saleCount"":([\d]+)");
|
||||
if (m.Count == 0)
|
||||
{
|
||||
m = BaseRegex.GetMatchRegex(ref skuMap, @"""([^""]+?)"":[\w\W]+?,""saleCount"":([\d]+)[^\}]+?,""canBookCount"":([\d]+),[^\}]+?\}");
|
||||
}
|
||||
if (m.Count == 0)
|
||||
{
|
||||
m = BaseRegex.GetMatchRegex(ref skuMap, @"""([^""]+?)"":[\w\W]+?,""saleCount"":([\d]+),""canBookCount"":([\d]+),[^\}]+?\}");
|
||||
}
|
||||
if (m.Count == 0)
|
||||
{
|
||||
LogSave.Add("获取skuMap异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
string price = BaseRegex.GetMatchRegexString(ref html, @"""priceRangeOriginal"":\[\[[\d]+, ([\d\.]+)?\]");
|
||||
if (string.IsNullOrEmpty(price))
|
||||
{
|
||||
price = Product.price.ToString();
|
||||
//LogSave.Add("获取统一批发价异常,请检查程序 " + url);
|
||||
//return;
|
||||
}
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string pri = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, @"""discountPrice"":""([\d\.]+)""");
|
||||
if (string.IsNullOrEmpty(pri))
|
||||
pri = BaseRegex.GetMatchRegexString(m[i].Groups[0].Value, @"""price"":""([\d\.]+)""");
|
||||
if (!string.IsNullOrEmpty(pri))
|
||||
price = pri;
|
||||
string name = m[i].Groups[1].Value;
|
||||
string number = m[i].Groups[2].Value=="0"?"1": m[i].Groups[2].Value;
|
||||
string sale_count = m[i].Groups[3].Value;
|
||||
name = BuildName(name);
|
||||
name = BaseRegex.Relpace(name, "(&[a-zA-z0-9]+?;)", "").Replace(",", "");
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
LogSave.Add("获取SKUmap名称异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
SkuMapBase sm = new SkuMapBase();
|
||||
sm.name = name;
|
||||
sm.price = decimal.Parse(price);
|
||||
sm.number = int.Parse(number);
|
||||
sm.sale_count = int.Parse(sale_count);
|
||||
Product.SkuMaps.Add(sm);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string price = m[i].Groups[2].Value;
|
||||
string name = m[i].Groups[1].Value;
|
||||
name = BuildName(name);
|
||||
name = BaseRegex.Relpace(name, "(&[a-zA-z0-9]+?;)", "").Replace(",", "");
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
LogSave.Add("获取SKUmap名称异常,请检查程序 " + url);
|
||||
return;
|
||||
}
|
||||
SkuMapBase sm = new SkuMapBase();
|
||||
sm.name = name;
|
||||
sm.price = decimal.Parse(price);
|
||||
sm.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
|
||||
Product.SkuMaps.Add(sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成名称
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
private string BuildName(string name)
|
||||
{
|
||||
if (!name.Contains(">") && !name.Contains(">"))
|
||||
return Product.Props[0].name + ":" + name;
|
||||
name = name.Replace(">", ">");
|
||||
string[] l = name.Split('>');
|
||||
if (l.Length != Product.Props.Count)
|
||||
{
|
||||
return ""; //数量不匹配可能有错误
|
||||
}
|
||||
string temp = "";
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
temp += ";" + Product.Props[i].name + ":" + l[i];
|
||||
}
|
||||
return temp.Substring(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class AutoConfirmExpress
|
||||
{
|
||||
public static List<KeyValueBase> ExpressList = new List<KeyValueBase>();
|
||||
public int BuyType;
|
||||
public AutoConfirmExpress(int buyType)
|
||||
{
|
||||
BuyType = buyType;
|
||||
if (ExpressList.Count > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var m = BaseRegex.GetMatchRegex(ref ExpressNames, @"<a val=""([\d]+)"">([^<]+?)</a>");
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string key = m[i].Groups[1].Value;
|
||||
string value = m[i].Groups[2].Value;
|
||||
KeyValueBase k = new KeyValueBase(key, value);
|
||||
ExpressList.Add(k);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<string> TaobaoOrder = new List<string>();
|
||||
|
||||
public void GetTaobao(Dictionary<string, string> beforeOrder)
|
||||
{
|
||||
|
||||
//Dictionary<char,Dictionary< char,Dictionary < char,string>>> chars = new Dictionary<char, Dictionary<char, Dictionary<char, string>>>();
|
||||
|
||||
string url = "https://buyertrade.taobao.com/trade/itemlist/list_bought_items.htm";
|
||||
string refere = url;
|
||||
string html = GetPostTaobaoHtml.UploadTaobao(url, refere, false);
|
||||
html = GetHtml.Decode(html);
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
html = html.Replace("\\\"", "\"").Replace("\\/", "/");
|
||||
int page = BaseRegex.GetIntJson(ref html, "totalPage");
|
||||
for (int k = 1; k <= page; k++)
|
||||
{
|
||||
if (k != 1)
|
||||
{
|
||||
string data =
|
||||
"buyerNick=&dateBegin=0&dateEnd=0&lastStartRow=&logisticsService=&options=0&orderStatus=&pageNum=" + k
|
||||
+ "&pageSize=15&queryBizType=&queryOrder=desc&rateStatus=&refund=&sellerNick=&prePageNo=2";
|
||||
url =
|
||||
"https://buyertrade.taobao.com/trade/itemlist/asyncBought.htm?action=itemlist/BoughtQueryAction&event_submit_do_query=1&_input_charset=utf8";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data);
|
||||
Thread.Sleep(5 * 1000);
|
||||
}
|
||||
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"\{""extra"":([\w\W]+?)""quantity"":""([\d]+)""");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
string list = m[i].Groups[0].Value;
|
||||
string oid = BaseRegex.GetLongJson(ref list, "id").ToString();
|
||||
if (!beforeOrder.ContainsKey(oid))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string status = BaseRegex.GetStringJson(ref list, "tradeStatus");
|
||||
if (status != "WAIT_BUYER_CONFIRM_GOODS" && status != "TRADE_BUYER_SIGNED" && status != "TRADE_CLOSED" && status != "TRADE_FINISHED")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string sell = BaseRegex.GetMatchRegexString(ref list, @"""seller"":\{([^\}]+?)\}");
|
||||
long shopId = BaseRegex.GetLongJson(ref sell, "id");
|
||||
url = "https://wuliu.taobao.com/user/order_detail_new.htm?trade_id=" + oid + "&seller_id=" + shopId;
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, false);
|
||||
Thread.Sleep(3000);
|
||||
string no = BaseRegex.GetMatchRegexString(ref html,
|
||||
@"<label class=""label"">运单号码:</label>\s+<span class=""em"">([^<]+?)</span>");
|
||||
string company = BaseRegex.GetMatchRegexString(ref html,
|
||||
@"<label class=""label"">物流公司:</label>\s+<span class=""em"">([^<]+?)</span>");
|
||||
if (string.IsNullOrEmpty(no) || string.IsNullOrEmpty(company))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
no = no.Trim();
|
||||
company = company.Trim();
|
||||
var express = GetExpressId(company);
|
||||
if (express == null)
|
||||
{
|
||||
LogSave.Add("没有找到快递公司");
|
||||
continue;
|
||||
}
|
||||
company = express.Value;
|
||||
int companyId = int.Parse(express.Key);
|
||||
UpdateServer(beforeOrder[oid], company, no, companyId);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public KeyValueBase GetExpressId(string company)
|
||||
{
|
||||
for (int i = 0; i < ExpressList.Count; i++)
|
||||
{
|
||||
if (ExpressList[i].Value == company || ExpressList[i].Value.Replace("快递", "速递") == company || ExpressList[i].Value.Replace("快递", "速运") == company)
|
||||
return ExpressList[i];
|
||||
}
|
||||
for (int i = 0; i < ExpressList.Count; i++)
|
||||
{
|
||||
if (ExpressList[i].Value.Length > 1 && company.Length > 1 && ExpressList[i].Value.Substring(0, 2) == company.Substring(0, 2))
|
||||
return ExpressList[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Get()
|
||||
{
|
||||
int page = 1;
|
||||
string url, html;
|
||||
List<string> orders = new List<string>();
|
||||
Dictionary<string, string> beforeOrder = new Dictionary<string, string>();
|
||||
for (int p = 0; p < page; p++)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
string data = UserLogin.GetSignaturex();
|
||||
url = BaseClass.BuildObjString("pay_group_order&act=get_confirm_order&buy_type=" + BuyType + "&page=" + p);
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
page = BaseRegex.GetIntValue(html, "page");
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
//MessageBox.Show("获取订单列表网络异常,请稍后重试", "提示");
|
||||
LogSave.Add("拼单", "获取订单列表网络异常,请稍后重试");
|
||||
return;
|
||||
}
|
||||
var mm = BaseRegex.GetMatchRegex(ref html, "<order ([^>]+?)>");
|
||||
for (int i = 0; i < mm.Count; i++)
|
||||
{
|
||||
string list = mm[i].Groups[0].Value;
|
||||
string orderId = BaseRegex.GetStringJson(ref list, "order_id_buy");
|
||||
string orderIdb = BaseRegex.GetStringJson(ref list, "order_id");
|
||||
if (string.IsNullOrEmpty(orderId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
orders.Add(orderId);
|
||||
if (!beforeOrder.ContainsKey(orderId))
|
||||
beforeOrder.Add(orderId, orderIdb);
|
||||
}
|
||||
}
|
||||
|
||||
url = BaseClass.NewUrl+"/orders.html?type=3&refer_page_name=personal";
|
||||
string refere = BaseClass.NewUrl+"/";
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"\{""group_id"":([\w\W]+?)""order_sn"":([\w\W]+?)\}");
|
||||
if (m == null || m.Count == 0)
|
||||
m = BaseRegex.GetMatchRegex(ref html, @"\{""order_sn""(.*?)""biz_type"":[\d]+");
|
||||
string lastOrderId = "";
|
||||
string status = "6";
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
string list = m[i].Groups[0].Value;
|
||||
string oid = BaseRegex.GetStringJson(ref list, "order_sn");
|
||||
lastOrderId = oid;
|
||||
string pid = BaseRegex.GetLongJson(ref list, "goods_id").ToString();
|
||||
string statusDesc = BaseRegex.GetStringJson(ref list, "order_status_desc");
|
||||
long order_time = BaseRegex.GetLongJson(ref list, "order_time");
|
||||
if (!orders.Contains(oid))
|
||||
continue;
|
||||
if (BuyType == 1)
|
||||
{
|
||||
if (order_time > BaseClass.GetTime(DateTime.Now) - 5 * 84600)
|
||||
continue;
|
||||
ConfirmOrder(oid, pid);
|
||||
}
|
||||
|
||||
if (BuyType == 2)
|
||||
{
|
||||
url = BaseClass.NewUrl+"/order.html?order_sn=" + oid +
|
||||
"&refer_page_name=my_order&refer_page_id=my_order_1513009667550_P4xCgmERE6&refer_page_sn=10032";
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
||||
string shippingName = BaseRegex.GetStringJson(ref html, "shippingName");
|
||||
string trackingNumber = BaseRegex.GetStringJson(ref html, "trackingNumber");
|
||||
string temp = BaseRegex.GetMatchRegexString(ref html, @"""shipping"":\{(.*?)\}");
|
||||
int expressId = BaseRegex.GetIntJson(ref temp, "id");
|
||||
if (expressId > 0)
|
||||
{
|
||||
UpdateServer(beforeOrder[oid], shippingName, trackingNumber, expressId);
|
||||
}
|
||||
}
|
||||
}
|
||||
page = 0;
|
||||
while (m != null && m.Count > 0 && page < 100)
|
||||
{
|
||||
page++;
|
||||
url =
|
||||
"http://apiv4.yangkeduo.com/ordersv2/unreceived?size=10&offset=" + lastOrderId + "&pdduid=" + BaseClass.PddUid;
|
||||
refere =
|
||||
BaseClass.NewUrl+"/orders.html?type=3&refer_page_name=personal&refer_page_id=personal_1513007415720_UV8kas6VCW&refer_page_sn=10001";
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
||||
m = BaseRegex.GetMatchRegex(ref html, @"\{""group_id"":([\w\W]+?)""order_sn"":([\w\W]+?)\}");
|
||||
if (m == null || m.Count == 0)
|
||||
m = BaseRegex.GetMatchRegex(ref html, @"\{""order_sn""(.*?)""biz_type"":[\d]+");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
string list = m[i].Groups[0].Value;
|
||||
string oid = BaseRegex.GetStringJson(ref list, "order_sn");
|
||||
lastOrderId = oid;
|
||||
string pid = BaseRegex.GetLongJson(ref list, "goods_id").ToString();
|
||||
string statusDesc = BaseRegex.GetStringJson(ref list, "order_status_desc");
|
||||
long order_time = BaseRegex.GetLongJson(ref list, "order_time");
|
||||
if (oid == "180622-684676220032434")
|
||||
{
|
||||
}
|
||||
if (!orders.Contains(oid))
|
||||
continue;
|
||||
if (BuyType == 1)
|
||||
{
|
||||
if (order_time > BaseClass.GetTime(DateTime.Now) - 5 * 84600)
|
||||
continue;
|
||||
ConfirmOrder(oid, pid);
|
||||
}
|
||||
if (BuyType == 2)
|
||||
{
|
||||
url = BaseClass.NewUrl+"/order.html?order_sn=" + oid +
|
||||
"&refer_page_name=my_order&refer_page_id=my_order_1513009667550_P4xCgmERE6&refer_page_sn=10032";
|
||||
html = GetPostTaobaoHtml.UploadTaobao(url, refere, true);
|
||||
string shippingName = BaseRegex.GetStringJson(ref html, "shippingName");
|
||||
string trackingNumber = BaseRegex.GetStringJson(ref html, "trackingNumber");
|
||||
string temp = BaseRegex.GetMatchRegexString(ref html, @"""shipping"":\{(.*?)\}");
|
||||
int expressId = BaseRegex.GetIntJson(ref temp, "id");
|
||||
if (expressId > 0)
|
||||
{
|
||||
UpdateServer(beforeOrder[oid], shippingName, trackingNumber, expressId);
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
GetTaobao(beforeOrder);
|
||||
LogSave.Add("拼单", "自动确认收货全部完成");
|
||||
}
|
||||
|
||||
public void ConfirmOrder(string oid, string goods_id)
|
||||
{
|
||||
string url = "http://apiv4.yangkeduo.com/order/" + oid + "/received?pdduid=" + BaseClass.PddUid + "&is_back=1";
|
||||
string data = "{}";
|
||||
string refere = BaseClass.NewUrl+"/orders.html?refer_page_name=login&refer_page_id=login_1513005785399_B4Dxk8TYgA&type=3&order_index=0";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data);
|
||||
|
||||
refere = BaseClass.NewUrl+"/comments.html?order_sn=" + oid + "&goods_id=" + goods_id +
|
||||
"&page_el_sn=99664&type=3&refer_page_name=my_order&refer_page_id=my_order_1513006052449_n43miXeWuI&refer_page_sn=10032&refer_page_el_sn=99664";
|
||||
url = "http://apiv4.yangkeduo.com/v2/order/goods/review?pdduid=" + BaseClass.PddUid;
|
||||
data = "{\"goods_id\":" + goods_id + ",\"order_sn\":\"" + oid + "\",\"desc_score\":5,\"logistics_score\":5,\"service_score\":5,\"comment\":\"\",\"pictures\":[]}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data);
|
||||
if (html.Contains("rating_id"))
|
||||
{
|
||||
LogSave.Add("拼单", "确认收货成功:" + oid);
|
||||
}
|
||||
Thread.Sleep(300);
|
||||
}
|
||||
|
||||
public void UpdateServer(string order_id, string shippingName, string trackingNumber, int expressId)
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.Append("&status=" + 8);
|
||||
s.Append("&oid=" + order_id);
|
||||
s.Append("&express_name=" + shippingName);
|
||||
s.Append("&express_id=" + expressId);
|
||||
s.Append("&express_no=" + trackingNumber);
|
||||
s.Append("&get_time=1");
|
||||
string data = UserLogin.GetSignaturex();
|
||||
string url = BaseClass.BuildObjString("pay_group_order&act=update&buy_type=" + BuyType);
|
||||
string html = GetHtml.PostUtf8(url, data + s);
|
||||
if (html != "ok")
|
||||
{
|
||||
Thread.Sleep(10 * 1000);
|
||||
data = UserLogin.GetSignaturex();
|
||||
html = GetHtml.PostUtf8(url, data + s);
|
||||
}
|
||||
if (html != "ok")
|
||||
{
|
||||
Thread.Sleep(30 * 1000);
|
||||
data = UserLogin.GetSignaturex();
|
||||
html = GetHtml.PostUtf8(url, data + s);
|
||||
}
|
||||
if (html != "ok")
|
||||
LogSave.Add("拼单", "自动提交物流信息失败,请检查网络");
|
||||
else
|
||||
{
|
||||
LogSave.Add("拼单", "返回物流信息完成:" + order_id);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetErrorSend()
|
||||
{
|
||||
string data = UserLogin.GetSignaturex();
|
||||
string url = BaseClass.BuildObjString("pay_group_order&act=reset_status");
|
||||
string html = GetHtml.PostUtf8(url, data);
|
||||
if (html != "ok")
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public string ExpressNames = "<a val=\"1\">申通快递</a><a val=\"3\">百世快递</a><a val=\"44\">顺丰快递</a><a val=\"85\">圆通快递</a><a val=\"89\">赛澳递</a><a val=\"90\">晟邦物流</a><a val=\"115\">中通快递</a><a val=\"116\">全峰快递</a><a val=\"117\">优速快递</a><a val=\"118\">邮政EMS</a><a val=\"119\">天天快递</a><a val=\"120\">京东配送</a><a val=\"121\">韵达快递</a><a val=\"122\">快捷快递</a><a val=\"124\">国通快递</a><a val=\"129\">宅急送快递</a><a val=\"130\">如风达</a><a val=\"131\">德邦快递</a><a val=\"132\">邮政快递包裹</a><a val=\"133\">龙邦快递</a><a val=\"135\">联邦快递</a><a val=\"136\">九曳供应链</a><a val=\"140\">南京晟邦</a><a val=\"142\">万象物流</a><a val=\"143\">立即送</a><a val=\"144\">门对门</a><a val=\"148\">安达信</a><a val=\"149\">海外快递</a><a val=\"150\">飞远物流</a><a val=\"152\">汇文快递</a><a val=\"154\">黄马甲</a><a val=\"155\">速尔快递</a><a val=\"156\">亚马逊物流</a><a val=\"157\">黑猫宅急便</a><a val=\"161\">上海赛澳递</a><a val=\"162\">城市100</a><a val=\"163\">芝麻开门</a><a val=\"164\">顺捷丰达</a><a val=\"165\">汇通小红马</a><a val=\"180\">其他</a><a val=\"183\">跨越速递</a><a val=\"186\">usps</a><a val=\"187\">青岛安捷</a><a val=\"195\">贝海国际速递</a><a val=\"197\">环球速运</a><a val=\"201\">全一快递</a><a val=\"205\">远成快运</a><a val=\"209\">联众国际快运</a><a val=\"210\">天地华宇</a><a val=\"211\">中邮速递</a><a val=\"213\">EMS-国际件</a><a val=\"214\">中铁物流</a><a val=\"216\">新邦物流</a><a val=\"217\">Flash Express</a><a val=\"218\">新顺丰NSF</a><a val=\"221\">DCS GLOBAL</a><a val=\"227\">日日顺物流</a><a val=\"228\">苏宁快递</a><a val=\"229\">百世快运</a><a val=\"230\">德邦物流</a><a val=\"231\">微特派</a><a val=\"232\">AAE全球专递</a><a val=\"233\">Aramex</a><a val=\"234\">Asendia USA</a><a val=\"235\">City-Link</a><a val=\"236\">COE</a><a val=\"237\">DHL德国</a><a val=\"238\">DHL全球</a><a val=\"239\">DHL中国</a><a val=\"240\">EMS国际</a><a val=\"241\">FedEx美国</a><a val=\"242\">FedEx中国</a><a val=\"243\">OCS</a><a val=\"244\">OnTrac</a><a val=\"245\">TNT</a><a val=\"246\">UPS</a><a val=\"247\">阿尔巴尼亚邮政</a><a val=\"248\">阿根廷邮政</a><a val=\"249\">阿联酋邮政</a><a val=\"250\">爱沙尼亚邮政</a><a val=\"252\">奥地利邮政</a><a val=\"253\">澳大利亚邮政</a><a val=\"254\">巴基斯坦邮政</a><a val=\"255\">巴西邮政</a><a val=\"256\">白俄罗斯邮政</a><a val=\"257\">百福东方</a><a val=\"258\">包裹信件</a><a val=\"259\">保加利亚邮政</a><a val=\"260\">比利时邮政</a><a val=\"261\">波兰邮政</a><a val=\"262\">传喜物流</a><a val=\"263\">大田物流</a><a val=\"264\">递四方</a><a val=\"265\">俄速通</a><a val=\"266\">法国邮政</a><a val=\"267\">凡宇快递</a><a val=\"268\">飞豹快递</a><a val=\"269\">飞远(爱彼西)配送</a><a val=\"270\">芬兰邮政</a><a val=\"271\">哥伦比亚邮政</a><a val=\"272\">韩国邮政</a><a val=\"273\">恒路物流</a><a val=\"274\">华企快运</a><a val=\"275\">加运美</a><a val=\"276\">佳吉快运</a><a val=\"277\">佳怡物流</a><a val=\"278\">嘉里大通</a><a val=\"279\">捷克邮政</a><a val=\"280\">筋斗云物流</a><a val=\"281\">京广速递</a><a val=\"282\">克罗地亚邮政</a><a val=\"283\">拉脱维亚邮政</a><a val=\"284\">黎巴嫩邮政</a><a val=\"285\">联昊通</a><a val=\"286\">马耳他邮政</a><a val=\"287\">马其顿邮政</a><a val=\"288\">毛里求斯邮政</a><a val=\"289\">秘鲁邮政</a><a val=\"290\">民邦快递</a><a val=\"291\">民航快递</a><a val=\"292\">明亮物流</a><a val=\"293\">摩尔多瓦邮政</a><a val=\"294\">南非邮政</a><a val=\"295\">挪威邮政</a><a val=\"296\">葡萄牙邮政</a><a val=\"297\">全日通</a><a val=\"298\">日本邮政</a><a val=\"299\">瑞典邮政</a><a val=\"300\">瑞士邮政</a><a val=\"301\">塞尔维亚邮政</a><a val=\"302\">三态速递</a><a val=\"303\">沙特邮政</a><a val=\"304\">圣安物流</a><a val=\"305\">盛丰物流</a><a val=\"306\">盛辉物流</a><a val=\"307\">斯洛伐克邮政</a><a val=\"308\">斯洛文尼亚邮政</a><a val=\"309\">穗佳物流</a><a val=\"310\">泰国邮政</a><a val=\"311\">土耳其邮政</a><a val=\"312\">万家物流</a><a val=\"313\">乌克兰邮政</a><a val=\"314\">西班牙邮政</a><a val=\"315\">信丰物流</a><a val=\"316\">匈牙利邮政</a><a val=\"317\">亚风速递</a><a val=\"318\">亚美尼亚邮政</a><a val=\"319\">燕文物流</a><a val=\"320\">意大利邮政</a><a val=\"321\">银捷速递</a><a val=\"322\">印度邮政</a><a val=\"323\">英国皇家邮政</a><a val=\"324\">邮政标准快递</a><a val=\"325\">邮政国际包裹</a><a val=\"326\">越丰物流</a><a val=\"327\">运通中港快递</a><a val=\"328\">增益速递</a><a val=\"
Line truncated
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AllBase;
|
||||
using Work.CollectClass;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class BigDataCenter
|
||||
{
|
||||
public string Name;
|
||||
public static Dictionary<string,List<string>> Keywords = new Dictionary<string, List<string>>();
|
||||
public static List<string> KeywordTemp = new List<string>();
|
||||
public static int PriceBegin = 0, PriceEnd = 0, SoldBegin = 0, SoldEnd = 0,Count=0;
|
||||
public static bool Taobao = false, Alibaba = false, Pinduoduo = false;
|
||||
public static List<TaobaoProductBase> ProductTemp = new List<TaobaoProductBase>();
|
||||
public static List<string> KeywordString = new List<string>();
|
||||
|
||||
public BigDataCenter(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public void Get()
|
||||
{
|
||||
string url = "http://pcat.qixiaoke.com/taobao/pinduoduo_search.php";
|
||||
for (int i = 0; i < KeywordString.Count; i++)
|
||||
{
|
||||
string key = KeywordString[i];
|
||||
int count = Keywords.ContainsKey(key) ? Keywords[key].Count : Count;
|
||||
List<string> titles = Keywords.ContainsKey(key) ? Keywords[key] : new List<string>();
|
||||
string data = UserLogin.GetSignaturex();
|
||||
data += "&keyword=" + GetHtml.UrlEncodeUtf8(key) + "&count=" + count;
|
||||
data += "&pi=" + PriceBegin + "&pa=" + PriceEnd + "&si=" + SoldBegin + "&sa=" + SoldEnd;
|
||||
if (Taobao)
|
||||
{
|
||||
string html = GetHtml.PostUtf8(url, data + "&sid=1");
|
||||
Data(html, titles);
|
||||
}
|
||||
if (Alibaba)
|
||||
{
|
||||
string html = GetHtml.PostUtf8(url, data + "&sid=3");
|
||||
Data(html, titles);
|
||||
}
|
||||
if (Pinduoduo)
|
||||
{
|
||||
string html = GetHtml.PostUtf8(url, data + "&sid=2");
|
||||
Data(html, titles);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Data(string html, List<string> list)
|
||||
{
|
||||
html = GetHtml.Decode(html).Replace("\\/","/");
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""attrs"":\{([^\}]+?)\}");
|
||||
for (int j = 0; m != null && j < m.Count ; j++)
|
||||
{
|
||||
if(list.Count>0 && j>= list.Count)
|
||||
break;
|
||||
string li = m[j].Groups[1].Value;
|
||||
TaobaoProductBase t = new TaobaoProductBase();
|
||||
t.FromId = BaseRegex.GetLongJson(ref li, "product_id");
|
||||
int tp = BaseRegex.GetIntJson(ref li, "site_id");
|
||||
t.FromType = "淘宝";
|
||||
if (tp == 2)
|
||||
t.FromType = "内部数据";
|
||||
if (tp == 3)
|
||||
t.FromType = "阿里巴巴";
|
||||
t.Titlte = BaseRegex.GetStringJson(ref li, "name");
|
||||
t.Cat1 = BaseRegex.GetIntJson(ref li, "cat1");
|
||||
t.Cat2 = BaseRegex.GetIntJson(ref li, "cat2");
|
||||
t.Cat3 = BaseRegex.GetIntJson(ref li, "cat3");
|
||||
t.CatId = BaseRegex.GetIntJson(ref li, "cat_id");
|
||||
if (t.Cat3 != t.CatId)
|
||||
t.Cat4 = t.CatId;
|
||||
FromTitleToCat f = new FromTitleToCat();
|
||||
t.MainCatId = f.GetMainCatId(t.Cat1);
|
||||
t.MainCatName = f.MainCatName;
|
||||
if (list.Count > j)
|
||||
{
|
||||
t.Build = true;
|
||||
t.Titlte = list[j];
|
||||
}
|
||||
t.Price = BaseRegex.GetDecimalJson(ref li, "price_min");
|
||||
t.SaleCount = BaseRegex.GetIntJson(ref li, "sold_count");
|
||||
BigDataBuild.Product.Add(t);
|
||||
ProductTemp.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
public string Input(string dir)
|
||||
{
|
||||
string message = "无导入数据";
|
||||
string[] l = Directory.GetFiles(dir);
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
string name = Path.GetFileNameWithoutExtension(l[i]);
|
||||
if(string.IsNullOrEmpty(name))
|
||||
continue;
|
||||
List<string> keywords = new List<string>();
|
||||
string[] ll = FileBase.ReadAllLines(l[i]);
|
||||
for (int j = 0; j < ll.Length; j++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ll[j]) || ll[j].Length>32 || ll[j].Length<20)
|
||||
continue;
|
||||
string key = ll[j].Trim().Replace("\t", " ");
|
||||
if (keywords.Contains(key))
|
||||
continue;
|
||||
keywords.Add(key);
|
||||
}
|
||||
if (Keywords.ContainsKey(name))
|
||||
{
|
||||
Keywords[name] = keywords;
|
||||
continue;
|
||||
}
|
||||
Keywords.Add(name, keywords);
|
||||
KeywordTemp.Add(name);
|
||||
message = "导入成功";
|
||||
}
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,708 @@
|
||||
using AllBase;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Work.CollectClass;
|
||||
using Work.ManageClass;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class BuildNewTitle
|
||||
{
|
||||
public ShopChatBase Shop;
|
||||
public long Pid;
|
||||
public string Title,Name;
|
||||
public string[] NoWords = "✅,💯,★".Split(',');
|
||||
public bool SetNewTitle = false;
|
||||
public static bool BeforRand = false,KeepAll = false;
|
||||
public static long endAdvanceTime=0;
|
||||
public BuildNewTitle(ShopChatBase shop, long pid, string title, string name)
|
||||
{
|
||||
Shop = shop;
|
||||
Pid = pid;
|
||||
Title = title;
|
||||
Name = name;
|
||||
}
|
||||
public BuildNewTitle(ShopChatBase shop, long pid, string title, string name,bool setNewTitle)
|
||||
{
|
||||
Shop = shop;
|
||||
Pid = pid;
|
||||
Title = title;
|
||||
Name = name;
|
||||
SetNewTitle = setNewTitle;
|
||||
}
|
||||
|
||||
public void Set()
|
||||
{
|
||||
GetProductDetail ge = new GetProductDetail(Shop, Name);
|
||||
var r = ge.Get(Pid);
|
||||
if (r == null)
|
||||
{
|
||||
LogSave.Add(Name,"获取失败,店铺:"+Shop.ShopName +" ID:"+Pid);
|
||||
return;
|
||||
}
|
||||
string imageString = "", apiContentString = "";
|
||||
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
|
||||
{
|
||||
imageString += ",\"" + r.carousel_gallery_list[i] + "\"";
|
||||
}
|
||||
for (int i = 0; i < r.detail_gallery_list.Count; i++)
|
||||
{
|
||||
apiContentString += ",\"" + r.detail_gallery_list[i] + "\"";
|
||||
}
|
||||
string skuApiStringNew = "";
|
||||
int price = int.MaxValue;
|
||||
for (int i = 0; i < r.sku_list.Count; i++)
|
||||
{
|
||||
if (price > r.sku_list[i].multi_price)
|
||||
price = r.sku_list[i].multi_price;
|
||||
string spec = "";
|
||||
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
|
||||
spec += "," + r.sku_list[i].spec[j].spec_id;
|
||||
if (!string.IsNullOrEmpty(spec))
|
||||
spec = spec.Substring(1);
|
||||
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
|
||||
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
|
||||
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn +
|
||||
"\",\"quantity\":" + r.sku_list[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}";
|
||||
}
|
||||
if (SetNewTitle && !KeepAll)
|
||||
{
|
||||
string upTitle = BaseRegex.GetMatchRegexString(ref r.goods_desc, @"【【【([\w\W]{10,60})】】");
|
||||
if (string.IsNullOrEmpty(upTitle))
|
||||
{
|
||||
upTitle = r.goods_name;
|
||||
r.goods_desc += "【【【"+r.goods_name+"】】";
|
||||
}
|
||||
BigDataBuild bd = new BigDataBuild(Name);
|
||||
if (BeforRand)
|
||||
{
|
||||
Title = bd.GetRandTitle(upTitle);
|
||||
}
|
||||
else
|
||||
{
|
||||
string mainKey = bd.GetMainKeywords(upTitle);
|
||||
if (string.IsNullOrEmpty(mainKey))
|
||||
{
|
||||
LogSave.Add(Name, "没有找到主关键词");
|
||||
return;
|
||||
}
|
||||
Title = bd.GetAllTitle(mainKey);
|
||||
if (string.IsNullOrEmpty(Title)&& mainKey.Split(' ').Length>2)
|
||||
{
|
||||
string[] l = mainKey.Split(' ');
|
||||
string keyword = "";
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
keyword += l[i];
|
||||
}
|
||||
Title = bd.GetAllTitle(keyword);
|
||||
}
|
||||
if (string.IsNullOrEmpty(Title))
|
||||
{
|
||||
Title = bd.GetRandTitle(upTitle);
|
||||
}
|
||||
}
|
||||
Title = BaseClass.SubCharLength(Title, 60);
|
||||
|
||||
}
|
||||
if (KeepAll)
|
||||
Title = r.goods_name;
|
||||
|
||||
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
|
||||
foreach (string noWord in NoWords)
|
||||
{
|
||||
if (r.goods_name.Contains(noWord))
|
||||
r.goods_name = r.goods_name.Replace(noWord, "");
|
||||
if (r.goods_desc.Contains(noWord))
|
||||
r.goods_desc = r.goods_desc.Replace(noWord, "");
|
||||
}
|
||||
|
||||
r.goods_desc = BaseRegex.Clear(r.goods_desc, "");
|
||||
string title;
|
||||
if (!string.IsNullOrEmpty(Title))
|
||||
title = Title;
|
||||
else
|
||||
title = r.goods_name;
|
||||
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
|
||||
var api = new PinduoduoApiGetProduct(Shop);
|
||||
if (r.tiny_name.Length > 10)
|
||||
r.tiny_name = r.tiny_name.Substring(0, 10);
|
||||
api.Data.Add("goods_id", Pid.ToString());
|
||||
api.Data.Add("goods_name", title);
|
||||
api.Data.Add("goods_type", r.goods_type.ToString());
|
||||
api.Data.Add("goods_desc", r.goods_desc);
|
||||
api.Data.Add("cat_id", r.cat_id.ToString());
|
||||
api.Data.Add("tiny_name", r.tiny_name);
|
||||
api.Data.Add("country_id", r.country_id.ToString());
|
||||
api.Data.Add("market_price", r.market_price.ToString());
|
||||
api.Data.Add("is_pre_sale", "false");
|
||||
api.Data.Add("shipment_limit_second", r.shipment_limit_second.ToString());
|
||||
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
|
||||
api.Data.Add("customer_num", r.customer_num.ToString());//团购人数
|
||||
if (!UploadPinduoduoMain.limitCount)
|
||||
{
|
||||
api.Data.Add("buy_limit", r.buy_limit.ToString());
|
||||
api.Data.Add("order_limit", r.order_limit.ToString());
|
||||
}
|
||||
api.Data.Add("is_refundable", r.is_refundable==1? "true": "false");
|
||||
api.Data.Add("second_hand", r.second_hand == 1 ? "true" : "false");
|
||||
api.Data.Add("is_folt", r.is_folt == 1 ? "true" : "false");
|
||||
if (BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id")>0)
|
||||
{
|
||||
api.Data.Add("fabric", BaseRegex.GetIntJson(ref ge.Html, "fabric_id").ToString());
|
||||
api.Data.Add("fabric_content", BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id").ToString());
|
||||
}
|
||||
api.Data.Add("sku_list","[" + skuApiStringNew.Substring(1) + "]");
|
||||
api.Data.Add("out_goods_id", r.outer_goods_id);
|
||||
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
|
||||
api.Data.Add("thumb_url", r.thumb_url);
|
||||
api.Data.Add("image_url", r.image_url);
|
||||
api.Data.Add("carousel_gallery", "[" + imageString.Substring(1) + "]");
|
||||
api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
|
||||
if(r.shelf_life>0)
|
||||
{
|
||||
api.Data.Add("shelf_life", r.shelf_life.ToString());
|
||||
api.Data.Add("start_production_date", r.start_production_date.ToString());
|
||||
api.Data.Add("end_production_date", r.end_production_date.ToString());
|
||||
}
|
||||
if (BaseRegex.GetIntJson(ref ge.Html, "paper_width") > 0)
|
||||
{
|
||||
api.Data.Add("paper_net_weight", BaseRegex.GetIntJson(ref ge.Html, "paper_net_weight").ToString());
|
||||
api.Data.Add("paper_length", BaseRegex.GetIntJson(ref ge.Html, "paper_length").ToString());
|
||||
api.Data.Add("paper_width", BaseRegex.GetIntJson(ref ge.Html, "paper_width").ToString());
|
||||
api.Data.Add("paper_plies_num", BaseRegex.GetIntJson(ref ge.Html, "paper_plies_num").ToString());
|
||||
}
|
||||
if (r.goods_property_list.Count > 0)
|
||||
{
|
||||
string code = "";
|
||||
for (int i = 0; i < r.goods_property_list.Count; i++)
|
||||
{
|
||||
//var p =
|
||||
// UploadPinduoduoProperties.Properties.Find(
|
||||
// pp => pp.template_pid == r.goods_property_list[i].template_pid);
|
||||
//if(p==null)
|
||||
// continue;
|
||||
code +=
|
||||
",{\"template_pid\":" + r.goods_property_list[i].template_pid + ",\"template_module_id\":" + r.goods_property_list[i].vid
|
||||
+ ",\"pid\":" + r.goods_property_list[i].ref_pid + ",\"vid\":" + r.goods_property_list[i].vid
|
||||
+ ",\"value\":\"" + r.goods_property_list[i].vvalue + "\",\"value_unit\":\"" + r.goods_property_list[i].punit + "\"}";
|
||||
}
|
||||
api.Data.Add("goods_properties", "[" + code.Substring(1) + "]");
|
||||
}
|
||||
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
||||
return;
|
||||
string html = api.Updata();
|
||||
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
|
||||
{
|
||||
Thread.Sleep(6000);
|
||||
html = api.Updata();
|
||||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
}
|
||||
TaobaoProductBase t = new TaobaoProductBase();
|
||||
t.GoodsId = Pid;
|
||||
t.Titlte = title;
|
||||
t.Price = price/100m;
|
||||
if (string.IsNullOrEmpty(error_msg))
|
||||
{
|
||||
t.Message = "修改成功";
|
||||
SetRelation(Pid, ref r, ref Shop);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (KeepAll)
|
||||
{
|
||||
html = new PinduoduoApiGetProduct(Shop).SetOnline(r.goods_id, true);
|
||||
Thread.Sleep(5 * 1000);
|
||||
}
|
||||
t.Message = error_msg;
|
||||
|
||||
}
|
||||
UploadPinduoduoMain.ProductReplaceTemp.Add(t);
|
||||
}
|
||||
|
||||
|
||||
public void SetAdvanceSale()
|
||||
{
|
||||
GetProductDetail ge = new GetProductDetail(Shop, Name);
|
||||
var r = ge.Get(Pid);
|
||||
if (r == null)
|
||||
{
|
||||
LogSave.Add(Name, "获取失败,店铺:" + Shop.ShopName + " ID:" + Pid);
|
||||
return;
|
||||
}
|
||||
long pre_sale_time = BaseRegex.GetLongJson(ref ge.Html, "pre_sale_time");
|
||||
//if (pre_sale_time > BaseClass.GetTime(DateTime.Now))
|
||||
//{
|
||||
// LogSave.Add(Name, "已经设置跳过:" + Shop.ShopName + " ID:" + Pid);
|
||||
// TaobaoProductBase tt = new TaobaoProductBase();
|
||||
// tt.GoodsId = Pid;
|
||||
// tt.Titlte = Title;
|
||||
// tt.Message = "已设置跳过";
|
||||
// UploadPinduoduoMain.ProductReplaceTemp.Add(tt);
|
||||
// return;
|
||||
//}
|
||||
string imageString = "", apiContentString = "";
|
||||
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
|
||||
{
|
||||
imageString += ",\"" + r.carousel_gallery_list[i] + "\"";
|
||||
}
|
||||
for (int i = 0; i < r.detail_gallery_list.Count; i++)
|
||||
{
|
||||
apiContentString += ",\"" + r.detail_gallery_list[i] + "\"";
|
||||
}
|
||||
int maxPriceNew = 0, maxPriceOnline = 0;
|
||||
//生成新的价格
|
||||
for (int i = 0; i < r.sku_list.Count; i++)
|
||||
{
|
||||
if (maxPriceNew < r.sku_list[i].multi_price)
|
||||
maxPriceNew = r.sku_list[i].multi_price;
|
||||
if (maxPriceOnline < r.sku_list[i].price)
|
||||
maxPriceOnline = r.sku_list[i].price;
|
||||
}
|
||||
bool userShield = false;
|
||||
decimal dd = PinduoduoCatList.GetPriceSpace(r.cat_id) * 10;
|
||||
for (int i = 0; i < r.sku_list.Count; i++) // 二级护盾
|
||||
{
|
||||
if (r.sku_list[i].multi_price < maxPriceNew / dd * 10)
|
||||
{
|
||||
r.sku_list[i].multi_price = (int)(maxPriceNew / dd * 10);
|
||||
}
|
||||
if (r.sku_list[i].price < maxPriceOnline / dd * 10)
|
||||
{
|
||||
r.sku_list[i].price = (int)(maxPriceOnline / dd * 10 + 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
string skuApiStringNew = "";
|
||||
int price = int.MaxValue;
|
||||
for (int i = 0; i < r.sku_list.Count; i++)
|
||||
{
|
||||
if (price > r.sku_list[i].multi_price)
|
||||
price = r.sku_list[i].multi_price;
|
||||
string spec = "";
|
||||
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
|
||||
spec += "," + r.sku_list[i].spec[j].spec_id;
|
||||
if (!string.IsNullOrEmpty(spec))
|
||||
spec = spec.Substring(1);
|
||||
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
|
||||
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
|
||||
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn +
|
||||
"\",\"quantity\":" + r.sku_list[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}";
|
||||
}
|
||||
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
|
||||
foreach (string noWord in NoWords)
|
||||
{
|
||||
if (r.goods_name.Contains(noWord))
|
||||
r.goods_name = r.goods_name.Replace(noWord, "");
|
||||
if (r.goods_desc.Contains(noWord))
|
||||
r.goods_desc = r.goods_desc.Replace(noWord, "");
|
||||
}
|
||||
|
||||
r.goods_desc = BaseRegex.Clear(r.goods_desc, "");
|
||||
string title;
|
||||
if (!string.IsNullOrEmpty(Title))
|
||||
title = Title;
|
||||
else
|
||||
title = r.goods_name.Replace("\",\"", "");
|
||||
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
|
||||
var api = new PinduoduoApiGetProduct(Shop);
|
||||
if (BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id") > 0)
|
||||
{
|
||||
api.Data.Add("fabric", BaseRegex.GetIntJson(ref ge.Html, "fabric_id").ToString());
|
||||
api.Data.Add("fabric_content", BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id").ToString());
|
||||
}
|
||||
if (r.shelf_life > 0)
|
||||
{
|
||||
api.Data.Add("shelf_life", r.shelf_life.ToString());
|
||||
api.Data.Add("start_production_date", r.start_production_date.ToString());
|
||||
api.Data.Add("end_production_date", r.end_production_date.ToString());
|
||||
}
|
||||
if (BaseRegex.GetIntJson(ref ge.Html, "paper_width") > 0)
|
||||
{
|
||||
api.Data.Add("paper_net_weight", BaseRegex.GetIntJson(ref ge.Html, "paper_net_weight").ToString());
|
||||
api.Data.Add("paper_length", BaseRegex.GetIntJson(ref ge.Html, "paper_length").ToString());
|
||||
api.Data.Add("paper_width", BaseRegex.GetIntJson(ref ge.Html, "paper_width").ToString());
|
||||
api.Data.Add("paper_plies_num", BaseRegex.GetIntJson(ref ge.Html, "paper_plies_num").ToString());
|
||||
}
|
||||
if (r.goods_property_list.Count > 0)
|
||||
{
|
||||
string code = "";
|
||||
for (int i = 0; i < r.goods_property_list.Count; i++)
|
||||
{
|
||||
code +=
|
||||
",{\"template_pid\":" + r.goods_property_list[i].template_pid + ",\"template_module_id\":" + r.goods_property_list[i].vid
|
||||
+ ",\"pid\":" + r.goods_property_list[i].ref_pid + ",\"vid\":" + r.goods_property_list[i].vid
|
||||
+ ",\"value\":\"" + r.goods_property_list[i].vvalue + "\",\"value_unit\":\"" + r.goods_property_list[i].punit + "\"}";
|
||||
}
|
||||
api.Data.Add("goods_properties", "[" + code.Substring(1) + "]");
|
||||
}
|
||||
ProductCollectBase pb = new ProductCollectBase();
|
||||
int Cat1 = 0;
|
||||
if(PinduoduoCatList.CatIds.ContainsKey(r.cat_id))
|
||||
Cat1 = PinduoduoCatList.CatIds[r.cat_id].cat1;
|
||||
string mustCode = "";
|
||||
string properties = UploadPinduoduoProperties.GetNew(r.cat_id, Cat1, ref pb, ref Shop, out mustCode);
|
||||
|
||||
if (!string.IsNullOrEmpty(properties) && !api.Data.ContainsKey("goods_properties"))
|
||||
{
|
||||
|
||||
api.Data.Add("goods_properties", "[" + properties.Substring(1) + "]");
|
||||
}
|
||||
|
||||
r.tiny_name = r.tiny_name.Replace("【", "")
|
||||
.Replace("】", "")
|
||||
.Replace("!", "")
|
||||
.Replace(" ", "")
|
||||
.Replace("!", "");
|
||||
if (r.tiny_name.Length > 10)
|
||||
r.tiny_name = r.tiny_name.Substring(0, 10);
|
||||
api.Data.Add("goods_id", Pid.ToString());
|
||||
api.Data.Add("goods_name", title.Replace("\",\"",""));
|
||||
api.Data.Add("goods_type", r.goods_type.ToString());
|
||||
api.Data.Add("goods_desc", r.goods_desc);
|
||||
api.Data.Add("cat_id", r.cat_id.ToString());
|
||||
api.Data.Add("tiny_name", r.tiny_name);
|
||||
api.Data.Add("country_id", r.country_id.ToString());
|
||||
api.Data.Add("market_price", r.market_price.ToString());
|
||||
api.Data.Add("is_pre_sale", SetNewTitle.ToString());
|
||||
api.Data.Add("pre_sale_time", endAdvanceTime.ToString());
|
||||
api.Data.Add("shipment_limit_second", r.shipment_limit_second.ToString());
|
||||
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
|
||||
api.Data.Add("customer_num", r.customer_num.ToString());//团购人数
|
||||
if (!UploadPinduoduoMain.limitCount)
|
||||
{
|
||||
api.Data.Add("buy_limit", r.buy_limit.ToString());
|
||||
api.Data.Add("order_limit", r.order_limit.ToString());
|
||||
}
|
||||
api.Data.Add("is_refundable", r.is_refundable == 1 ? "true" : "false");
|
||||
api.Data.Add("second_hand", r.second_hand == 1 ? "true" : "false");
|
||||
api.Data.Add("is_folt", r.is_folt == 1 ? "true" : "false");
|
||||
api.Data.Add("sku_list", "[" + skuApiStringNew.Substring(1) + "]");
|
||||
api.Data.Add("out_goods_id", r.outer_goods_id);
|
||||
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
|
||||
api.Data.Add("thumb_url", r.thumb_url);
|
||||
api.Data.Add("image_url", r.image_url);
|
||||
api.Data.Add("carousel_gallery", "[" + imageString.Substring(1) + "]");
|
||||
api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
|
||||
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
||||
return;
|
||||
string html = api.Updata();
|
||||
Thread.Sleep(5*1000);
|
||||
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
html = api.Updata();
|
||||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
html = api.Updata();
|
||||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
}
|
||||
TaobaoProductBase t = new TaobaoProductBase();
|
||||
t.GoodsId = Pid;
|
||||
t.Titlte = title;
|
||||
t.Price = price / 100m;
|
||||
if (string.IsNullOrEmpty(error_msg))
|
||||
{
|
||||
t.Message = "设置成功";
|
||||
SetRelation(Pid, ref r, ref Shop);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (UploadPinduoduoMain.SaleSetFalseDown)
|
||||
{
|
||||
api = new PinduoduoApiGetProduct(Shop);
|
||||
api.SetOnline(Pid, false);
|
||||
error_msg = "设置预售失败自动下架";
|
||||
}
|
||||
if (KeepAll)
|
||||
{
|
||||
html = new PinduoduoApiGetProduct(Shop).SetOnline(r.goods_id, true);
|
||||
Thread.Sleep(5 * 1000);
|
||||
}
|
||||
t.Message = error_msg;
|
||||
|
||||
}
|
||||
LogSave.Add(Name,"ID:"+ Pid+":"+ t.Message);
|
||||
UploadPinduoduoMain.ProductReplaceTemp.Add(t);
|
||||
}
|
||||
|
||||
|
||||
public bool SetAdvanceSaleNew()
|
||||
{
|
||||
GetProductDetail ge = new GetProductDetail(Shop, Name);
|
||||
var r = ge.Get(Pid);
|
||||
if (r == null)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
r = ge.Get(Pid);
|
||||
}
|
||||
if (r == null)
|
||||
{
|
||||
LogSave.Add(Name, "获取失败,店铺:" + Shop.ShopName + " ID:" + Pid);
|
||||
return false;
|
||||
}
|
||||
long pre_sale_time = BaseRegex.GetLongJson(ref ge.Html, "pre_sale_time");
|
||||
string imageString = "", apiContentString = "";
|
||||
for (int i = 0; i < r.carousel_gallery_list.Count; i++)
|
||||
{
|
||||
imageString += ",\"" + r.carousel_gallery_list[i] + "\"";
|
||||
}
|
||||
for (int i = 0; i < r.detail_gallery_list.Count; i++)
|
||||
{
|
||||
apiContentString += ",\"" + r.detail_gallery_list[i] + "\"";
|
||||
}
|
||||
int maxPriceNew = 0, maxPriceOnline = 0;
|
||||
//生成新的价格
|
||||
for (int i = 0; i < r.sku_list.Count; i++)
|
||||
{
|
||||
if (maxPriceNew < r.sku_list[i].multi_price)
|
||||
maxPriceNew = r.sku_list[i].multi_price;
|
||||
if (maxPriceOnline < r.sku_list[i].price)
|
||||
maxPriceOnline = r.sku_list[i].price;
|
||||
}
|
||||
string skuApiStringNew = "";
|
||||
int price = int.MaxValue;
|
||||
for (int i = 0; i < r.sku_list.Count; i++)
|
||||
{
|
||||
if (price > r.sku_list[i].multi_price)
|
||||
price = r.sku_list[i].multi_price;
|
||||
string spec = "";
|
||||
for (int j = 0; j < r.sku_list[i].spec.Count; j++)
|
||||
spec += "," + r.sku_list[i].spec[j].spec_id;
|
||||
if (!string.IsNullOrEmpty(spec))
|
||||
spec = spec.Substring(1);
|
||||
skuApiStringNew += ",{\"is_onsale\":" + r.sku_list[i].is_onsale + ",\"limit_quantity\":" + r.sku_list[i].limit_quantity +
|
||||
",\"price\":\"" + r.sku_list[i].price + "\",\"weight\":1000,\"multi_price\":\"" + r.sku_list[i].multi_price
|
||||
+ "\",\"thumb_url\":\"" + r.sku_list[i].thumb_url + "\",\"out_sku_sn\":\"" + r.sku_list[i].out_sku_sn +
|
||||
"\",\"quantity\":" + r.sku_list[i].quantity + ",\"spec_id_list\":\"[" + spec + "]\"}";
|
||||
}
|
||||
r.goods_name = BaseClass.SubCharLength(r.goods_name, 60);
|
||||
foreach (string noWord in NoWords)
|
||||
{
|
||||
if (r.goods_name.Contains(noWord))
|
||||
r.goods_name = r.goods_name.Replace(noWord, "");
|
||||
if (r.goods_desc.Contains(noWord))
|
||||
r.goods_desc = r.goods_desc.Replace(noWord, "");
|
||||
}
|
||||
|
||||
r.goods_desc = BaseRegex.Clear(r.goods_desc, "");
|
||||
string title;
|
||||
if (!string.IsNullOrEmpty(Title))
|
||||
title = Title;
|
||||
else
|
||||
title = r.goods_name.Replace("\",\"", "");
|
||||
r.cat_id = PinduoduoCatList.GetNewCat3(r.cat_id);
|
||||
var api = new PinduoduoApiGetProduct(Shop);
|
||||
if (BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id") > 0)
|
||||
{
|
||||
api.Data.Add("fabric", BaseRegex.GetIntJson(ref ge.Html, "fabric_id").ToString());
|
||||
api.Data.Add("fabric_content", BaseRegex.GetIntJson(ref ge.Html, "fabric_content_id").ToString());
|
||||
}
|
||||
if (r.shelf_life > 0)
|
||||
{
|
||||
api.Data.Add("shelf_life", r.shelf_life.ToString());
|
||||
api.Data.Add("start_production_date", r.start_production_date.ToString());
|
||||
api.Data.Add("end_production_date", r.end_production_date.ToString());
|
||||
}
|
||||
if (BaseRegex.GetIntJson(ref ge.Html, "paper_width") > 0)
|
||||
{
|
||||
api.Data.Add("paper_net_weight", BaseRegex.GetIntJson(ref ge.Html, "paper_net_weight").ToString());
|
||||
api.Data.Add("paper_length", BaseRegex.GetIntJson(ref ge.Html, "paper_length").ToString());
|
||||
api.Data.Add("paper_width", BaseRegex.GetIntJson(ref ge.Html, "paper_width").ToString());
|
||||
api.Data.Add("paper_plies_num", BaseRegex.GetIntJson(ref ge.Html, "paper_plies_num").ToString());
|
||||
}
|
||||
if (r.goods_property_list.Count > 0)
|
||||
{
|
||||
string code = "";
|
||||
for (int i = 0; i < r.goods_property_list.Count; i++)
|
||||
{
|
||||
code +=
|
||||
",{\"template_pid\":" + r.goods_property_list[i].template_pid + ",\"template_module_id\":" + r.goods_property_list[i].vid
|
||||
+ ",\"pid\":" + r.goods_property_list[i].ref_pid + ",\"vid\":" + r.goods_property_list[i].vid
|
||||
+ ",\"value\":\"" + r.goods_property_list[i].vvalue + "\",\"value_unit\":\"" + r.goods_property_list[i].punit + "\"}";
|
||||
}
|
||||
api.Data.Add("goods_properties", "[" + code.Substring(1) + "]");
|
||||
}
|
||||
ProductCollectBase pb = new ProductCollectBase();
|
||||
int Cat1 = 0;
|
||||
if (PinduoduoCatList.CatIds.ContainsKey(r.cat_id))
|
||||
Cat1 = PinduoduoCatList.CatIds[r.cat_id].cat1;
|
||||
string mustCode = "";
|
||||
string properties = UploadPinduoduoProperties.GetNew(r.cat_id, Cat1, ref pb, ref Shop, out mustCode);
|
||||
|
||||
if (!string.IsNullOrEmpty(properties) && !api.Data.ContainsKey("goods_properties"))
|
||||
{
|
||||
|
||||
api.Data.Add("goods_properties", "[" + properties.Substring(1) + "]");
|
||||
}
|
||||
|
||||
r.tiny_name = r.tiny_name.Replace("【", "")
|
||||
.Replace("】", "")
|
||||
.Replace("!", "")
|
||||
.Replace(" ", "")
|
||||
.Replace("!", "");
|
||||
if (r.tiny_name.Length > 10)
|
||||
r.tiny_name = r.tiny_name.Substring(0, 10);
|
||||
api.Data.Add("goods_id", Pid.ToString());
|
||||
api.Data.Add("goods_name", title.Replace("\",\"", ""));
|
||||
api.Data.Add("goods_type", r.goods_type.ToString());
|
||||
api.Data.Add("goods_desc", r.goods_desc);
|
||||
api.Data.Add("cat_id", r.cat_id.ToString());
|
||||
api.Data.Add("tiny_name", r.tiny_name);
|
||||
api.Data.Add("country_id", r.country_id.ToString());
|
||||
api.Data.Add("market_price", r.market_price.ToString());
|
||||
api.Data.Add("is_pre_sale", SetNewTitle.ToString());
|
||||
api.Data.Add("pre_sale_time", endAdvanceTime.ToString());
|
||||
api.Data.Add("shipment_limit_second", r.shipment_limit_second.ToString());
|
||||
api.Data.Add("cost_template_id", Shop.ExpressId.ToString());
|
||||
api.Data.Add("customer_num", r.customer_num.ToString());//团购人数
|
||||
if (!UploadPinduoduoMain.limitCount)
|
||||
{
|
||||
api.Data.Add("buy_limit", r.buy_limit.ToString());
|
||||
api.Data.Add("order_limit", r.order_limit.ToString());
|
||||
}
|
||||
api.Data.Add("is_refundable", r.is_refundable == 1 ? "true" : "false");
|
||||
api.Data.Add("second_hand", r.second_hand == 1 ? "true" : "false");
|
||||
api.Data.Add("is_folt", r.is_folt == 1 ? "true" : "false");
|
||||
api.Data.Add("sku_list", "[" + skuApiStringNew.Substring(1) + "]");
|
||||
api.Data.Add("out_goods_id", r.outer_goods_id);
|
||||
api.Data.Add("hd_thumb_url", r.hd_thumb_url);
|
||||
api.Data.Add("thumb_url", r.thumb_url);
|
||||
api.Data.Add("image_url", r.image_url);
|
||||
api.Data.Add("carousel_gallery", "[" + imageString.Substring(1) + "]");
|
||||
api.Data.Add("detail_gallery", "[" + apiContentString.Substring(1) + "]");
|
||||
if (Shop.SignErrorTimes.ContainsKey(DateTime.Now.ToString("yyyy-MM-dd")) && Shop.SignErrorTimes[DateTime.Now.ToString("yyyy-MM-dd")] > 3)
|
||||
return false;
|
||||
api.FromWeiDian = true;
|
||||
string html = api.UpdataNew();
|
||||
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 false;
|
||||
}
|
||||
api.Data.Remove("cost_template_id");
|
||||
api.Data["cost_template_id"] = Shop.ExpressId.ToString();
|
||||
html = api.AddNew();
|
||||
}
|
||||
Thread.Sleep(5 * 1000);
|
||||
string error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
html = api.UpdataNew();
|
||||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
}
|
||||
if (!string.IsNullOrEmpty(error_msg) && error_msg.Contains("频繁"))
|
||||
{
|
||||
Thread.Sleep(30000);
|
||||
html = api.UpdataNew();
|
||||
error_msg = BaseRegex.GetStringJson(ref html, "error_msg") + BaseRegex.GetStringJson(ref html, "sub_msg");
|
||||
}
|
||||
TaobaoProductBase t = new TaobaoProductBase();
|
||||
t.GoodsId = Pid;
|
||||
t.Titlte = title;
|
||||
t.Price = price / 100m;
|
||||
if (string.IsNullOrEmpty(error_msg))
|
||||
{
|
||||
t.Message = "设置成功";
|
||||
//SetRelation(Pid, ref r, ref Shop);
|
||||
|
||||
var ad = AdvanceSale.dic[Shop.ShopName];
|
||||
ad.SetSuccess = ++ad.SetSuccess;
|
||||
if (SetNewTitle)
|
||||
{
|
||||
ad.PreCount = ++ad.PreCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
ad.PreCount = --ad.PreCount;
|
||||
if (ad.PreCount < 0)
|
||||
{
|
||||
ad.PreCount = 0;
|
||||
}
|
||||
}
|
||||
AdvanceSale.AdvanceList.Add(ad);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (AdvanceSale.SaleSetFalseDown && !error_msg.Contains("签名验证失败"))
|
||||
{
|
||||
api = new PinduoduoApiGetProduct(Shop);
|
||||
string htmlx = api.SetOnline(Pid, false);
|
||||
error_msg = "设置预售失败自动下架:" + error_msg;
|
||||
if (htmlx.Contains("false"))
|
||||
htmlx = api.SetOnline(Pid, false);
|
||||
var ad = AdvanceSale.dic[Shop.ShopName];
|
||||
ad.DownSuccess = ++ad.DownSuccess;
|
||||
ad.DownCount = ++ad.DownCount;
|
||||
AdvanceSale.AdvanceList.Add(ad);
|
||||
}
|
||||
else
|
||||
{
|
||||
var ad = AdvanceSale.dic[Shop.ShopName];
|
||||
ad.status = error_msg;
|
||||
AdvanceSale.AdvanceList.Add(ad);
|
||||
}
|
||||
if (KeepAll)
|
||||
{
|
||||
html = new PinduoduoApiGetProduct(Shop).SetOnline(r.goods_id, true);
|
||||
Thread.Sleep(5 * 1000);
|
||||
}
|
||||
t.Message = error_msg;
|
||||
}
|
||||
LogSave.Add(Name, "ID:" + Pid + ":" + t.Message);
|
||||
if (error_msg.Contains("签名验证失败"))
|
||||
{
|
||||
var ad = AdvanceSale.dic[Shop.ShopName];
|
||||
ad.status = "签名验证失败,请检查授权";
|
||||
AdvanceSale.AdvanceList.Add(ad);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static void SetRelation(long id,ref ProductDetailBase r,ref ShopChatBase shop)
|
||||
{
|
||||
decimal maxPriceNewx = 0, minPriceNewx = Decimal.MaxValue;
|
||||
//生成新的价格
|
||||
for (int i = 0; i < r.sku_list.Count; i++)
|
||||
{
|
||||
if (maxPriceNewx < r.sku_list[i].multi_price)
|
||||
maxPriceNewx = r.sku_list[i].multi_price;
|
||||
if (minPriceNewx > r.sku_list[i].multi_price)
|
||||
minPriceNewx = r.sku_list[i].multi_price;
|
||||
}
|
||||
var api = new PinduoduoApiGetProduct(shop);
|
||||
long upid = 0;
|
||||
string html = api.GetRelation(r.goods_id.ToString());
|
||||
// 有获取到对应的上家id
|
||||
if (html.Contains("out_goods_id") && html.Contains("out_goods_platform"))
|
||||
{
|
||||
upid = BaseRegex.GetLongJson(ref html, "out_goods_id");
|
||||
html = api.Relation(r.goods_id, upid, (int)(minPriceNewx * 0.94m), (int)(maxPriceNewx * 0.94m), 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int fromSite = 0;
|
||||
if (upid == 0)
|
||||
upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10, 99999);
|
||||
html = api.Relation(id, upid, (int)(minPriceNewx * 0.95m), (int)(maxPriceNewx * 0.95m), 0, fromSite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class CatListPinduoduo
|
||||
{
|
||||
public static Dictionary<int, KeyValuesBase> CatIds = new Dictionary<int, KeyValuesBase>();
|
||||
public ShopChatBase Shop = null;
|
||||
public void Get()
|
||||
{
|
||||
string cookies = Shop == null ? "" : Shop.Cookies;
|
||||
string url = "https://mms.pinduoduo.com/earth/api/mallInfo/catList?{}";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", cookies);
|
||||
if (!Directory.Exists("temp"))
|
||||
Directory.CreateDirectory("temp");
|
||||
string dir = "temp/cat_pinduoduo";
|
||||
if (!Directory.Exists(dir))
|
||||
Directory.CreateDirectory(dir);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""id"":([\d]+),""name"":""([^']+?)""");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
int id = int.Parse(m[i].Groups[1].Value);
|
||||
string name = m[i].Groups[2].Value;
|
||||
string file = dir + "/" + id + ".tjm";
|
||||
if (FileBase.Exists(file))
|
||||
html = FileBase.ReadAllText(file, Encoding.Default);
|
||||
else
|
||||
{
|
||||
url = "https://mms.pinduoduo.com/vodka/v2/mms/categories?parentId=" + id;
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", cookies);
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
FileBase.WriteAllText(file, html, Encoding.Default);
|
||||
}
|
||||
var mm = BaseRegex.GetMatchRegex(ref html,
|
||||
@"""cat_id_1"":([\d]+),""cat_id_2"":([\d]+),""cat_id_3"":([\d]+)");
|
||||
for (int j = 0; mm != null && j < mm.Count; j++)
|
||||
{
|
||||
int id2 = int.Parse(mm[j].Groups[2].Value);
|
||||
file = dir + "/" + id2 + ".tjm";
|
||||
if (FileBase.Exists(file))
|
||||
html = FileBase.ReadAllText(file, Encoding.Default);
|
||||
else
|
||||
{
|
||||
url = "https://mms.pinduoduo.com/vodka/v2/mms/categories?parentId=" + id2;
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, "", cookies);
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
FileBase.WriteAllText(file, html, Encoding.Default);
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
var mmm = BaseRegex.GetMatchRegex(ref html,
|
||||
@"""cat_id_1"":([\d]+),""cat_id_2"":([\d]+),""cat_id_3"":([\d]+)");
|
||||
for (int k = 0; mmm != null && k < mmm.Count; k++)
|
||||
{
|
||||
int id3 = int.Parse(mmm[k].Groups[3].Value);
|
||||
if (CatIds.ContainsKey(id3))
|
||||
continue;
|
||||
CatIds.Add(id3, new KeyValuesBase(id.ToString(), id.ToString(), id2.ToString(), id3.ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class CatTemplateBase
|
||||
{
|
||||
public OpenApiResponseBase open_api_response = new OpenApiResponseBase();
|
||||
}
|
||||
|
||||
public class OpenApiResponseBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 模板允许的最大的自定义规格数量
|
||||
/// </summary>
|
||||
public int? input_max_spec_num = 0;
|
||||
/// <summary>
|
||||
/// 为true时限定规格要么全选要么全不选
|
||||
/// </summary>
|
||||
public bool? choose_all_qualify_spec = false;
|
||||
/// <summary>
|
||||
/// 单个自定义规格值上限
|
||||
/// </summary>
|
||||
public int? single_spec_value_num = 0;
|
||||
/// <summary>
|
||||
/// 最大sku数目上限
|
||||
/// </summary>
|
||||
public int? max_sku_num = 0;
|
||||
public List<PropertiesBase> properties = new List<PropertiesBase>();
|
||||
}
|
||||
|
||||
public class PropertiesBase
|
||||
{
|
||||
public int? id = 0;
|
||||
public string name_alias = "";
|
||||
public string name = "";
|
||||
/// <summary>
|
||||
/// 属性值单位
|
||||
/// </summary>
|
||||
public string value_unit = "";
|
||||
/// <summary>
|
||||
/// 小数点允许最大精度,为0时代表不允许输入小数
|
||||
/// </summary>
|
||||
public int? value_precision = 0;
|
||||
public string max_value = "";
|
||||
public string min_value = "";
|
||||
/// <summary>
|
||||
/// 是否必填
|
||||
/// </summary>
|
||||
public bool? required = false;
|
||||
/// <summary>
|
||||
/// 0-可输入、1-可勾选、3-可输入又可勾选
|
||||
/// </summary>
|
||||
public int? control_type = 0;
|
||||
/// <summary>
|
||||
/// 0-文本、1-数值、4-绝对时间、5-相对时间
|
||||
/// </summary>
|
||||
public int? value_type = 0;
|
||||
/// <summary>
|
||||
/// 允许的最大的自定义规格数量
|
||||
/// </summary>
|
||||
public int? choose_max_num = 0;
|
||||
/// <summary>
|
||||
/// 最大可输入数目,为0时代表不可输入
|
||||
/// </summary>
|
||||
public int? input_max_num = 0;
|
||||
/// <summary>
|
||||
/// 父属性id
|
||||
/// </summary>
|
||||
public int? parent_id = 0;
|
||||
/// <summary>
|
||||
/// 是否销售属性
|
||||
/// </summary>
|
||||
public bool? is_sale = false;
|
||||
public bool? can_note = false;
|
||||
/// <summary>
|
||||
/// 销售属性规格id,非销售属性为null
|
||||
/// </summary>
|
||||
public long? spec_id = 0;
|
||||
/// <summary>
|
||||
/// 0普通,1颜色,2尺码
|
||||
/// </summary>
|
||||
public int? feature = 0;
|
||||
/// <summary>
|
||||
/// 是否父属性
|
||||
/// </summary>
|
||||
public bool? is_parent = false;
|
||||
/// <summary>
|
||||
/// 引用属性id
|
||||
/// </summary>
|
||||
public int? ref_pid = 0;
|
||||
/// <summary>
|
||||
/// 是否按条件展示
|
||||
/// </summary>
|
||||
public bool? is_condition_show = false;
|
||||
/// <summary>
|
||||
/// 只有show_vids中的值被选择时属性才可使用
|
||||
/// </summary>
|
||||
public List<int> show_vids = new List<int>();
|
||||
/// <summary>
|
||||
/// 属性值列表
|
||||
/// </summary>
|
||||
public List<PropertiesValuesBase> values = new List<PropertiesValuesBase>();
|
||||
}
|
||||
|
||||
public class PropertiesValuesBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础属性值id
|
||||
/// </summary>
|
||||
public int? vid = 0;
|
||||
/// <summary>
|
||||
/// 属性值
|
||||
/// </summary>
|
||||
public string value = "";
|
||||
/// <summary>
|
||||
/// 扩展信息,颜色的话色号在这里,ARGB,非销售属性为null
|
||||
/// </summary>
|
||||
public string extend_info = "";
|
||||
/// <summary>
|
||||
/// 规格id,非销售属性为null
|
||||
/// </summary>
|
||||
public long? spec_id = 0;
|
||||
/// <summary>
|
||||
/// 是否父属性值
|
||||
/// </summary>
|
||||
public bool? is_parent = false;
|
||||
/// <summary>
|
||||
/// 对应的父属性值id
|
||||
/// </summary>
|
||||
public List<int> parent_vids = new List<int>();
|
||||
/// <summary>
|
||||
/// 分组信息
|
||||
/// </summary>
|
||||
public PropertiesGroupBase group = new PropertiesGroupBase();
|
||||
}
|
||||
|
||||
public class PropertiesGroupBase
|
||||
{
|
||||
public int? id = 0;
|
||||
public string name = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 删除已驳回
|
||||
*
|
||||
*/
|
||||
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class DeleteRejectProduct
|
||||
{
|
||||
public ShopChatBase Shop;
|
||||
|
||||
public DeleteRejectProduct(ShopChatBase shop)
|
||||
{
|
||||
Shop = shop;
|
||||
}
|
||||
|
||||
public void Get()
|
||||
{
|
||||
int al = 1,count =1;
|
||||
while (true)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/list";
|
||||
string data = "{\"start\":0,\"length\":15,\"check_status\":3}";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.JsonPinduoduoUpload(url, refere, true, data, Shop.Cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"\{""id"":([\d]+),");
|
||||
if (m == null || m.Count == 0)
|
||||
break;
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string id = m[i].Groups[1].Value;
|
||||
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/" + id + "/delete";
|
||||
html = GetPostTaobaoHtml.JsonPinduoduoUpload(url, refere, true, "{}", Shop.Cookies);
|
||||
Thread.Sleep(300);
|
||||
}
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/list";
|
||||
string data = "{\"start\":0,\"length\":15,\"check_status\":0}";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.JsonPinduoduoUpload(url, refere, true, data, Shop.Cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"\{""id"":([\d]+),");
|
||||
if (m == null || m.Count == 0)
|
||||
return;
|
||||
for (int i = 0; i < m.Count; i++)
|
||||
{
|
||||
string id = m[i].Groups[1].Value;
|
||||
url = "https://mms.pinduoduo.com/glide/v2/mms/edit/commit/" + id + "/delete";
|
||||
html = GetPostTaobaoHtml.JsonPinduoduoUpload(url, refere, true, "{}", Shop.Cookies);
|
||||
Thread.Sleep(300);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
using System;
|
||||
using Work.CollectClass;
|
||||
using JavaScriptEngineSwitcher.Core;
|
||||
using JavaScriptEngineSwitcher.V8;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class DownUpProductExploder
|
||||
{
|
||||
public string Name;
|
||||
public bool SetOn;
|
||||
public string GoodsId;
|
||||
public string Cookies = "";
|
||||
public ShopChatBase Shop;
|
||||
public DownUpProductExploder(string name, bool setOn, string goodsId)
|
||||
{
|
||||
Name = name;
|
||||
SetOn = setOn;
|
||||
GoodsId = goodsId;
|
||||
}
|
||||
public void Get()
|
||||
{
|
||||
string data = "{\"goodsIds\":[" + GoodsId + "]}";
|
||||
string urlx = "https://mms.pinduoduo.com/vodka/v2/mms/batchOffSale";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
if (html.Contains("{\"success\":true"))
|
||||
{
|
||||
string[] l = GoodsId.Split(',');
|
||||
foreach (string s in l)
|
||||
{
|
||||
var good = Shop.OnlineProduct.Find(p => p.GoodsId == long.Parse(s));
|
||||
good.Message = "下架成功";
|
||||
UploadPinduoduoMain.ProductReplaceTemp.Add(good);
|
||||
LogSave.Add(Name, "下架产品成功:" + s);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (html.Contains("手速太快了"))
|
||||
{
|
||||
LogSave.Add(Name, "手速太快了,休眠30秒后,继续执行");
|
||||
Thread.Sleep(30*1000);
|
||||
string[] l = GoodsId.Split(',');
|
||||
urlx = "https://mms.pinduoduo.com/vodka/v2/mms/pc/offSale";
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
data = "{\"goodsId\":"+l[i]+"}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
var good = Shop.OnlineProduct.Find(p => p.GoodsId == long.Parse(l[i]));
|
||||
if (good != null)
|
||||
{
|
||||
good.Message = "下架成功";
|
||||
UploadPinduoduoMain.ProductReplaceTemp.Add(good);
|
||||
}
|
||||
Thread.Sleep(3*1000);
|
||||
LogSave.Add(Name, "下架产品成功:" + l[i]);
|
||||
if(!html.Contains("success"))
|
||||
Thread.Sleep(60*1000);
|
||||
}
|
||||
|
||||
//html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(30 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(90 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
LogSave.Add(Name, "速度太快,休眠2-5分钟");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogSave.Add(Name, html);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] l = GoodsId.Split(',');
|
||||
foreach (string s in l)
|
||||
{
|
||||
var good= Shop.OnlineProduct.Find(p => p.GoodsId == long.Parse(s));
|
||||
good.Message = "下架成功";
|
||||
UploadPinduoduoMain.ProductReplaceTemp.Add(good);
|
||||
LogSave.Add(Name, "下架产品成功:" + s);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public void Up()
|
||||
{
|
||||
string data = "{\"goodsIds\":[" + GoodsId + "]}";
|
||||
string urlx = "https://mms.pinduoduo.com/vodka/v2/mms/batchOnSale";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("{\"success\":true"))
|
||||
{
|
||||
string[] l = GoodsId.Split(',');
|
||||
foreach (string s in l)
|
||||
{
|
||||
var good = Shop.OnlineProduct.Find(p => p.GoodsId == long.Parse(s));
|
||||
good.Message = "上架成功";
|
||||
UploadPinduoduoMain.ProductReplaceTemp.Add(good);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (html.Contains("手速太快了"))
|
||||
{
|
||||
LogSave.Add(Name, "手速太快了,休眠30秒后,继续执行");
|
||||
Thread.Sleep(30 * 1000);
|
||||
string[] l = GoodsId.Split(',');
|
||||
urlx = "https://mms.pinduoduo.com/vodka/v2/mms/pc/onSale";
|
||||
for (int i = 0; i < l.Length; i++)
|
||||
{
|
||||
data = "{\"goodsId\":" + l[i] + "}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
Thread.Sleep(3 * 1000);
|
||||
LogSave.Add(Name, "下架产品成功:" + l[i]);
|
||||
if (!html.Contains("success"))
|
||||
Thread.Sleep(30 * 1000);
|
||||
}
|
||||
//Thread.Sleep(30 * 60 * 1000);
|
||||
//html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(30 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("过于频繁"))
|
||||
{
|
||||
Thread.Sleep(90 * 1000);
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("过于频繁"))
|
||||
{
|
||||
LogSave.Add(Name, "速度太快,休眠2-5分钟");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogSave.Add(Name, html);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] l = GoodsId.Split(',');
|
||||
foreach (string s in l)
|
||||
{
|
||||
|
||||
LogSave.Add(Name, "上架产品成功:" + s);
|
||||
}
|
||||
}
|
||||
}
|
||||
public string Delete()
|
||||
{
|
||||
//var api = new PinduoduoApiGetProduct(Shop);
|
||||
//string html = api.DelGoods("["+GoodsId+"]");
|
||||
string url = "https://mms.pinduoduo.com/plutus/api/plutus/bin/goods/delete/batch";
|
||||
string refere = "http://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{\"goods_ids\":[" + GoodsId + "],\"mall_id\":" + Shop.MallId + ",\"creator\":\"" + Shop.ShopName + "\",\"creator_id\":" + Shop.ReceiverId + "}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Cookies);
|
||||
Thread.Sleep(1000);
|
||||
return html;
|
||||
}
|
||||
public void OffSale()
|
||||
{
|
||||
string NoCode = "";
|
||||
string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000";
|
||||
if (string.IsNullOrEmpty(NoCode))
|
||||
{
|
||||
string htmlx = GetHtml.Gbk("http://nano.qixiaoke.com/nano.txt");
|
||||
NoCode = BaseRegex.GetMatchRegexString(ref htmlx, @"([\w\W]+?)-----");
|
||||
}
|
||||
if (string.IsNullOrEmpty(PinduoduoAuth.strContent))
|
||||
{
|
||||
PinduoduoAuth.strContent = GetVisitProductNew.strJs;//FileBase.ReadAllText(path);
|
||||
}
|
||||
string codex = "";
|
||||
//using (IJsEngine jsEngine = new V8JsEngine())
|
||||
//{
|
||||
// jsEngine.Execute(GetProductOnlineClass.JsCodeGetSms);
|
||||
// codex = jsEngine.CallFunction("aaa", "").ToString();
|
||||
//}
|
||||
codex = Work.ManageClass.CpsSetAllGoods.getAnti0aon();
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string urlx = "https://mms.pinduoduo.com/vodka/v2/mms/pc/offSale";
|
||||
string data = "{\"goodsId\":" + GoodsId + ",\"crawlerInfo\":\"" + codex + "\"}";
|
||||
//string html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
string html = Work.ManageClass.CpsSetAllGoods.Request_mms_pinduoduo_com(urlx, refere, Cookies, data, codex);
|
||||
Thread.Sleep(5*1000);
|
||||
}
|
||||
public void OffSaleApi()
|
||||
{
|
||||
var api = new PinduoduoApiGetProduct(Shop);
|
||||
try
|
||||
{
|
||||
var html = api.SetOnline(Convert.ToInt64(GoodsId), false);
|
||||
}
|
||||
catch { }
|
||||
Thread.Sleep(3 * 1000);
|
||||
}
|
||||
public string GetPidsStore()
|
||||
{
|
||||
string data = "{\"goodsIds\":[" + GoodsId + "]}";
|
||||
string urlx = "https://mms.pinduoduo.com/vodka/v2/mms/batchOffSale";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(urlx, refere, true, data, Cookies);
|
||||
Thread.Sleep(1000);
|
||||
return html;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class EncryptionCode
|
||||
{
|
||||
/// <summary>
|
||||
/// 加密
|
||||
/// </summary>
|
||||
/// <param name="pid"></param>
|
||||
/// <param name="sid"></param>
|
||||
/// <param name="mid"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCode(long pid, int sid, int mid,out string code)
|
||||
{
|
||||
code = "";
|
||||
if (sid == 1)
|
||||
code = "tb-";
|
||||
if (sid == 2)
|
||||
code = "pd-";
|
||||
if (sid == 3)
|
||||
code = "al-";
|
||||
if (sid == 4)
|
||||
code = "jx-";
|
||||
if (sid == 6)
|
||||
code = "wd-";
|
||||
code += pid;
|
||||
if (pid == 0 || sid == 0 || mid == 0)
|
||||
return "";
|
||||
string url = BaseClass.LoginApiUrl + "api/encodex.php?mall_id=" + mid + "&pid=" + pid + "&site_id=" + sid;
|
||||
string html = GetHtml.GetUrl(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Length < 50)
|
||||
return html;
|
||||
|
||||
code = "";
|
||||
if (sid == 1)
|
||||
code = "tb-";
|
||||
if (sid == 2)
|
||||
code = "pd-";
|
||||
if (sid == 3)
|
||||
code = "al-";
|
||||
if (sid == 4)
|
||||
code = "jx-";
|
||||
if (sid == 6)
|
||||
code = "wd-";
|
||||
code += pid;
|
||||
|
||||
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(100, 999);
|
||||
int rmk = (mid % 27 + randx % 27) % 27;
|
||||
int[] mainKey = new int[] { 6, 1, 5, 8, 4, 3, 6, 7, 0, 2, 9, 1, 2, 4, 7, 6, 5, 0, 1, 6, 8, 4, 6, 7, 9, 1 };
|
||||
string news = new Random(Guid.NewGuid().GetHashCode()).Next(100, 999).ToString();
|
||||
for (int i = 0; i < code.Length; i++)
|
||||
{
|
||||
int newValue = (int)code[i] - 40 + mainKey[i] * (i % 6) + rmk * (i % 5);
|
||||
news += (char)newValue;
|
||||
}
|
||||
return "PBB" + EncodeBase64(Encoding.UTF8, news) + "?" + randx;
|
||||
return code;
|
||||
|
||||
|
||||
//int ridMain = new Random(Guid.NewGuid().GetHashCode()).Next(100, 999);
|
||||
//int ridClient = (mid % ridMain) % 26;
|
||||
|
||||
//byte[] b = Encoding.Default.GetBytes(code);
|
||||
//List<int> k = new List<int>();
|
||||
//char[] ke = mid.ToString().ToCharArray();
|
||||
//for (int i = 0; i < ke.Length; i++)
|
||||
//{
|
||||
// int j = int.Parse(ke[i].ToString());
|
||||
// k.Add(j);
|
||||
//}
|
||||
//int y = 0;
|
||||
//for (int i = 0; i < b.Length; i++)
|
||||
//{
|
||||
// int z = b[i] + k[y] * ridClient;
|
||||
// b[i] = (byte)(z % 256);
|
||||
// y++;
|
||||
// if (y >= ke.Length)
|
||||
// y = 0;
|
||||
//}
|
||||
//return "PBB" + Convert.ToBase64String(b) + "|" + ridMain;
|
||||
}
|
||||
public static string EncodeBase64(Encoding encode, string source)
|
||||
{
|
||||
byte[] bytes = encode.GetBytes(source);
|
||||
try
|
||||
{
|
||||
string code = Convert.ToBase64String(bytes);
|
||||
return code;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void Test()
|
||||
{
|
||||
StringBuilder s = new StringBuilder();
|
||||
for (int i = 0; i < 200; i++)
|
||||
{
|
||||
for (int sid = 1; sid < 4; sid++)
|
||||
{
|
||||
string code = "";
|
||||
if (sid == 1)
|
||||
code = "tb-";
|
||||
if (sid == 2)
|
||||
code = "pd-";
|
||||
if (sid == 3)
|
||||
code = "al-";
|
||||
|
||||
string mid = Randomx.GetNumber(Randomx.GetId(3, 8));
|
||||
string pid = Randomx.GetNumber(Randomx.GetId(6,13));
|
||||
code +=pid;
|
||||
string url = "http://127.0.0.1:81/api/encodex.php?mall_id=" + mid + "&pid=" + pid + "&site_id=" + sid;
|
||||
string html = GetHtml.Utf8(url);
|
||||
url = "http://127.0.0.1:81/?obj=pinbaobao/decode&act=getx&mall_id=" + mid + "&encode=" + GetHtml.UrlEncodeUtf8(html);
|
||||
string htmlx = GetHtml.Utf8(url);
|
||||
s.AppendLine(code + "\t" + htmlx + "\t" + html);
|
||||
}
|
||||
}
|
||||
string xxxx = s.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,770 @@
|
||||
using System.Collections.Generic;
|
||||
using AllBase;
|
||||
using Work.CollectClass;
|
||||
using System;
|
||||
using Work.ManageClass;
|
||||
using System.Linq;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class FromTitleToCat
|
||||
{
|
||||
public string Cat1 = "", Cat2 = "", Cat3 = "", Cat4 = "", Title = "", MainCatId = "";
|
||||
public List<KeyValuesBase> Cats = new List<KeyValuesBase>();
|
||||
public List<KeyValuesBase> CatTop = new List<KeyValuesBase>();
|
||||
public static List<KeyValuesBase> MainCat = new List<KeyValuesBase>();
|
||||
public static Dictionary<long, KeyValuesBase> TempCat = new Dictionary<long, KeyValuesBase>();
|
||||
public static Dictionary<int, string> TaobaoCat = new Dictionary<int, string>();
|
||||
public bool MainServer = false, AddToStock = false, JustGetCat = false;
|
||||
public static bool UserApi = false;
|
||||
public bool AgainCat = false;
|
||||
public int TaobaoCatId = 0;
|
||||
public TaobaoProductBase TaobaoProduct;
|
||||
public FromTitleToCat()
|
||||
{
|
||||
if (MainCat.Count > 0)
|
||||
return;
|
||||
MainCat.Add(new KeyValuesBase("0", ",0,", "全类目"));//全类目
|
||||
//MainCat.Add(new KeyValuesBase("5", ",8583,8439,8538,8634,8508,8509,8669,239,,210,263,270,277,990,1366,3817,", "服饰箱包"));//服饰箱包
|
||||
//MainCat.Add(new KeyValuesBase("4", ",17412,16901,17671,16155,16676,17455,16192,16209,16989,17249,17285,17803,16794,16288,16548,15543,17134,,,483,489,282,519,479,1715,259,1166,3202,525,1889,4958,", "家居生活"));//家居生活
|
||||
//MainCat.Add(new KeyValuesBase("11", ",5921,6209,5955,2629,5834,2603,5839,6128,5906,6290,2933,8502,5752,5851,7323,6076,", "数码电器"));//数码电器
|
||||
//MainCat.Add(new KeyValuesBase("3", ",18482,18574,18601,18637,,,,1464,1432,69,", "美容个护"));//美容个护
|
||||
//MainCat.Add(new KeyValuesBase("6", ",14697,14740,14933,14966,15083,15356,,77,", "母婴玩具"));//母婴玩具
|
||||
//MainCat.Add(new KeyValuesBase("12", ",9313,9314,9315,9316,9317,9318,9319,9320,9321,9322,9323,9324,,,879,873,2479,1629,4886,1896,", "家纺家具家装"));//家纺家具
|
||||
//MainCat.Add(new KeyValuesBase("10", ",11683,11684,11685,11686,11687,11688,11689,,,,4173,281,2351,", "运动户外"));//运动户外
|
||||
//MainCat.Add(new KeyValuesBase("2", ",83,8172,", "水果生鲜"));//水果生鲜
|
||||
//MainCat.Add(new KeyValuesBase("7", ",6586,6785,6883,6758,6536,6630,6398,,2,", "食品保健"));//食品保健
|
||||
//MainCat.Add(new KeyValuesBase("9", ",80,", "虚拟商品"));//虚拟商品
|
||||
//MainCat.Add(new KeyValuesBase("13", ",6785,1715,6883,13176,13177,13178,16237,", "医药健康"));//医药健康
|
||||
//MainCat.Add(new KeyValuesBase("14", ",7629,7639,", "汽配摩托"));//汽配摩托
|
||||
MainCat.Add(new KeyValuesBase("5", ",8583,8439,8538,8634,8508,8509,8669,239,,210,263,270,277,990,1366,3817,", "服饰箱包"));//服饰箱包
|
||||
MainCat.Add(new KeyValuesBase("4", ",5217,17412,16901,17671,16155,16676,17455,16192,16209,16989,17249,17285,17803,16794,16288,16548,15543,17134,,,483,489,282,519,479,1715,259,1166,3202,525,1889,4958,", "家居生活"));//家居生活
|
||||
MainCat.Add(new KeyValuesBase("11", ",5921,6209,5955,2629,5834,2603,5839,6128,5906,6290,2933,8502,5752,5851,7323,6076,", "数码电器"));//数码电器
|
||||
MainCat.Add(new KeyValuesBase("3", ",18482,18574,18601,18637,,,,,1464,1432,69,", "美容个护"));//美容个护
|
||||
MainCat.Add(new KeyValuesBase("6", ",14697,19298,14740,14933,14966,15083,15356,,77,", "母婴玩具"));//母婴玩具
|
||||
MainCat.Add(new KeyValuesBase("12", ",9313,9314,9315,9316,9317,9318,9319,9320,9321,9322,9323,9324,,,879,873,2479,1629,4886,1896,20340,", "家纺家具家装"));//家纺家具
|
||||
MainCat.Add(new KeyValuesBase("10", ",11683,11684,11685,11686,11687,11688,11689,,,,4173,281,2351,", "运动户外"));//运动户外
|
||||
MainCat.Add(new KeyValuesBase("2", ",83,8172,", "水果生鲜"));//水果生鲜
|
||||
MainCat.Add(new KeyValuesBase("7", ",6586,6785,6883,6758,6536,6630,6398,,2,", "食品保健"));//食品保健
|
||||
MainCat.Add(new KeyValuesBase("9", ",80,20078,", "虚拟商品"));//虚拟商品
|
||||
MainCat.Add(new KeyValuesBase("13", ",1715,13176,13177,13178,16237,18814,", "医药健康"));//医药健康
|
||||
MainCat.Add(new KeyValuesBase("14", ",7629,7639,", "汽配摩托"));//汽配摩托
|
||||
MainCat.Add(new KeyValuesBase("8", ",,", "海淘进口"));//海淘进口
|
||||
}
|
||||
/// <summary>
|
||||
/// 是否在当前分类中
|
||||
/// </summary>
|
||||
/// <param name="cat1"></param>
|
||||
/// <returns></returns>
|
||||
public bool InMainCatId(int cat1)
|
||||
{
|
||||
for (int i = 0; i < MainCat.Count; i++)
|
||||
{
|
||||
if (MainCat[i].Key == BaseClass.MainCatId.ToString() && MainCat[i].Value1.Contains("," + cat1 + ","))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public string MainCatName = "";
|
||||
public int GetMainCatId(int cat1)
|
||||
{
|
||||
for (int i = 0; i < MainCat.Count; i++)
|
||||
{
|
||||
if (MainCat[i].Value1.Contains("," + cat1 + ","))
|
||||
{
|
||||
MainCatName = MainCat[i].Value2;
|
||||
return int.Parse(MainCat[i].Key);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static ShopChatBase inShop = null;
|
||||
/// <summary>
|
||||
/// 线程级查询分类
|
||||
/// </summary>
|
||||
public void Get()
|
||||
{
|
||||
if (TaobaoProduct == null || string.IsNullOrEmpty(TaobaoProduct.Titlte))
|
||||
return;
|
||||
TaobaoProductBase t = TaobaoProduct;
|
||||
if (UserApi)
|
||||
{
|
||||
ShopChatBase shop = null;
|
||||
if (BaseClass.UserVersion == 110) // 特殊版本,只使用API,默认授权成功店铺就是可用
|
||||
{
|
||||
inShop = GetShopLoginInfo.Shops.FirstOrDefault(s => s.Message == "授权成功");
|
||||
}
|
||||
if (inShop == null && BaseClass.UserVersion != 110) // 非特殊版本,逻辑
|
||||
{
|
||||
for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++)
|
||||
{
|
||||
if (!GetShopLoginInfo.Shops[i].Select)
|
||||
continue;
|
||||
if (inShop == null)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/hades/oauth/authed/list";
|
||||
string refere = "https://mms.pinduoduo.com/service-market/my-auth";
|
||||
string data = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + UploadPinduoduoMain.AntiContent + "\"}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, GetShopLoginInfo.Shops[i].Cookies, UploadPinduoduoMain.AntiContent); //GetPostTaobaoHtml.GetJsonPostAnti(url, refere, true, data, GetShopLoginInfo.Shops[i].Cookies, crawlerInfo);
|
||||
var mc = BaseRegex.GetMatchRegex(ref html, @"\{[\w\W]+?\}");
|
||||
for (int j = 0; mc != null && j < mc.Count; j++)
|
||||
{
|
||||
string list = mc[j].Groups[0].Value;
|
||||
string cxid = BaseRegex.GetStringJson(ref list, "clientId");
|
||||
long expiredAt = BaseRegex.GetLongJson(ref list, "refreshTokenExpiredAt");
|
||||
DateTime t1 = DateTime.Now;
|
||||
DateTime t2 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(expiredAt);
|
||||
System.TimeSpan t3 = t2 - t1;
|
||||
double getDay = t3.TotalDays;
|
||||
if (BaseClass.ClientIdx.Contains(cxid) && getDay > 0)
|
||||
{
|
||||
inShop = GetShopLoginInfo.Shops[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inShop==null)
|
||||
{
|
||||
string urlxs = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
||||
string referes = "https://fuwu.pinduoduo.com/service-market/my-service";
|
||||
string dataxs = "{\"redirectUrl\":\"https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2Fmy-service\"}";
|
||||
string htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, GetShopLoginInfo.Shops[i].Cookies, dataxs, CpsSetAllGoods.getAnti0aon());
|
||||
string accessToken = BaseRegex.GetStringJson(ref htmlxs, "accessToken");
|
||||
urlxs = "https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2F&accessToken=" + accessToken;
|
||||
htmlxs = PinduoduoAuth.GetJsonPostURL(urlxs, referes, true, "", GetShopLoginInfo.Shops[i].Cookies);
|
||||
accessToken = BaseRegex.GetMatchRegexString(ref htmlxs, "SUB_PASS_ID=([^;]+?);");
|
||||
string cookiesx = "SUB_PASS_ID=" + accessToken;
|
||||
string codexs = CpsSetAllGoods.getAnti0aon();
|
||||
urlxs = "https://fuwu.pinduoduo.com/columbine/oauth/authed/list";
|
||||
referes = "https://fuwu.pinduoduo.com/service-market/my-auth";
|
||||
dataxs = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + codexs + "\"}";
|
||||
htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, GetShopLoginInfo.Shops[i].Cookies + cookiesx, dataxs, codexs);
|
||||
var m = BaseRegex.GetMatchRegex(ref htmlxs, @"\{[\w\W]+?\}");
|
||||
for (int j = 0; m != null && j < m.Count; j++)
|
||||
{
|
||||
string list = m[j].Groups[0].Value;
|
||||
string cxid = BaseRegex.GetStringJson(ref list, "clientId");
|
||||
if (cxid == "9558f920cf77403bb475243fe44482ad" || cxid == "81fd2bbabbd54ec5bf312e05401a0343"
|
||||
|| cxid == "9f7d0ce6460b46e7a3833ac2e8325519" || cxid == "3069c1c325e44e85bcf5b6295694bdae"
|
||||
|| cxid == "f23bda7f6d9c4b6c8751268891779660" || cxid == "5d755c0cf97a4cbdb8aa958beea25011" || cxid == "911bd1c0c0a0403da88334e24ca288a2")
|
||||
continue;
|
||||
long auditAt = BaseRegex.GetLongJson(ref list, "auditAt");
|
||||
long refreshTokenExpiredAt = BaseRegex.GetLongJson(ref list, "refreshTokenExpiredAt");
|
||||
DateTime t1 = DateTime.Now;// DateTime.Parse(DateTime.Now.ToString("1970-01-01 00:00:00")).AddMilliseconds(auditAt);
|
||||
DateTime t2 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(refreshTokenExpiredAt);
|
||||
System.TimeSpan t3 = t2 - t1; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
|
||||
double getDay = t3.TotalDays;
|
||||
if (BaseClass.ClientIdx.Contains(cxid) && getDay > 0)
|
||||
{
|
||||
inShop = GetShopLoginInfo.Shops[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (inShop == null)
|
||||
GetShopLoginInfo.Shops[i].APIMessage = "请先购买API再上传";
|
||||
}
|
||||
}
|
||||
shop = inShop;
|
||||
if (shop == null)
|
||||
return;
|
||||
// shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken) && sp.Select);
|
||||
//if (shop == null)
|
||||
// shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken));
|
||||
if (shop != null)
|
||||
{
|
||||
var api = new PinduoduoApiGetProduct(shop);
|
||||
string taobaoCatName = "0";
|
||||
if (TaobaoCat.ContainsKey(TaobaoCatId))
|
||||
taobaoCatName = TaobaoCat[TaobaoCatId];
|
||||
if (TaobaoCatId == 0)
|
||||
TaobaoCatId = 1;
|
||||
string html = api.GetCatId(TaobaoCatId, taobaoCatName, t.Titlte);
|
||||
if (html.Contains("\"error_msg\":授权失败,请先购买API再上传"))
|
||||
{
|
||||
inShop = null;
|
||||
}
|
||||
if (html.Contains("cat_id1"))
|
||||
{
|
||||
Cat1 = BaseRegex.GetIntJson(ref html, "cat_id1").ToString();
|
||||
Cat2 = BaseRegex.GetIntJson(ref html, "cat_id2").ToString();
|
||||
Cat3 = BaseRegex.GetIntJson(ref html, "cat_id3").ToString();
|
||||
Cat4 = BaseRegex.GetIntJson(ref html, "cat_id4").ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(Cat1) || Cat1 == "0")//API未执行成功
|
||||
{
|
||||
bool ok = Get(t.Titlte, t.FromId, t.FromSiteId);
|
||||
if (!ok)
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Cat4))
|
||||
Cat4 = "0";
|
||||
t.Cat1 = int.Parse(Cat1);
|
||||
t.Cat4 = int.Parse(Cat4);
|
||||
t.Cat3 = int.Parse(Cat3);
|
||||
t.Cat2 = int.Parse(Cat2);
|
||||
int id = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
||||
int cid = PinduoduoCatList.GetNewCat3(id);
|
||||
if (!AgainCat&&cid != id && PinduoduoCatList.CatIds.ContainsKey(cid))
|
||||
{
|
||||
var ci = PinduoduoCatList.CatIds[cid];
|
||||
t.CatId = ci.id;
|
||||
t.Cat1 = ci.cat1;
|
||||
t.Cat2 = ci.cat2;
|
||||
if (ci.cat3 == 0)
|
||||
{
|
||||
foreach (KeyValuePair<int, CatBase> c3 in PinduoduoCatList.CatIds)
|
||||
{
|
||||
if (c3.Value.cat2 == ci.cat2 && c3.Value.cat3 > 0)
|
||||
{
|
||||
ci.cat3 = c3.Value.cat3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Cat3 = ci.cat3;
|
||||
if (ci.cat4 == 0 && ci.cat3 > 0)
|
||||
{
|
||||
foreach (KeyValuePair<int, CatBase> c4 in PinduoduoCatList.CatIds)
|
||||
{
|
||||
if (c4.Value.cat3 == ci.cat3 && c4.Value.cat4 > 0)
|
||||
{
|
||||
ci.cat4 = c4.Value.cat4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Cat4 = ci.cat4;
|
||||
t.MainCatId = ci.main_cat_id;
|
||||
}
|
||||
t.MainCatId = GetMainCatId(t.Cat1);
|
||||
t.MainCatName = MainCatName;
|
||||
t.CatId = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
||||
if (t.MainCatId == 0 || JustGetCat || CollectKeywordByTaobao.MainCatId > 0 && CollectKeywordByTaobao.MainCatId != t.MainCatId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (AddToStock)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(t.ShopName))
|
||||
{
|
||||
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == t.ShopName);
|
||||
if (shop == null || t.MainCatId != shop.MainCatId)
|
||||
t.ShopName = "";
|
||||
else
|
||||
{
|
||||
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == t.ShopName);
|
||||
if (s != null)
|
||||
{
|
||||
s.ProductCount++;
|
||||
UploadPinduoduoMain.ShopReplaceTemp.Add(s);
|
||||
UploadPinduoduoMain.ShopTemp.Add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
UploadPinduoduoMain.ProductStock.Add(t);
|
||||
UploadPinduoduoMain.AddToDataBase(t);
|
||||
return;
|
||||
}
|
||||
if (CollectKeywordByTaobao.AutoAdd)
|
||||
{
|
||||
UploadPinduoduoMain.ProductStock.Add(t);
|
||||
UploadPinduoduoMain.AddToDataBase(t);
|
||||
}
|
||||
CollectKeywordByTaobao.Product.Add(t);
|
||||
CollectKeywordByTaobao.ProductTemp.Add(t);
|
||||
}
|
||||
public bool Get(string title, long fromId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(title))
|
||||
return false;
|
||||
if (TempCat.ContainsKey(fromId) && fromId > 0)
|
||||
{
|
||||
Cat1 = TempCat[fromId].Value1;
|
||||
Cat2 = TempCat[fromId].Value2;
|
||||
Cat3 = TempCat[fromId].Value3;
|
||||
Cat4 = TempCat[fromId].Value4;
|
||||
MainCatId = TempCat[fromId].Key;
|
||||
return true;
|
||||
}
|
||||
Title = title;
|
||||
Title = BaseRegex.Clear(Title, @"([\d\s]+)");
|
||||
GetLen(4);
|
||||
bool ok = OutPut(fromId);
|
||||
if (ok)
|
||||
return true;
|
||||
GetLen(6);
|
||||
ok = OutPut(fromId);
|
||||
if (ok)
|
||||
return true;
|
||||
GetLen(8);
|
||||
ok = OutPut(fromId);
|
||||
if (ok)
|
||||
return true;
|
||||
if (Cats.Count > 0)
|
||||
{
|
||||
var c = CatTop[0];
|
||||
Cat1 = c.Value1;
|
||||
Cat2 = c.Value2;
|
||||
for (int i = 0; i < Cats.Count; i++)
|
||||
{
|
||||
if (Cats[i].Value2 == Cat2)
|
||||
{
|
||||
Cat3 = Cats[i].Value3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
||||
{
|
||||
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
||||
{
|
||||
MainCatId = MainCat[i].Key;
|
||||
if (!TempCat.ContainsKey(fromId))
|
||||
{
|
||||
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3);
|
||||
try
|
||||
{
|
||||
TempCat.Add(fromId, k);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
public void GetLoad()
|
||||
{
|
||||
if (TaobaoProduct == null || string.IsNullOrEmpty(TaobaoProduct.Titlte))
|
||||
return;
|
||||
TaobaoProductBase t = TaobaoProduct;
|
||||
if (UserApi)
|
||||
{
|
||||
var shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken) && sp.Select);
|
||||
if (shop == null)
|
||||
shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed && !string.IsNullOrEmpty(sp.AccessToken));
|
||||
if (shop != null)
|
||||
{
|
||||
var api = new PinduoduoApiGetProduct(shop);
|
||||
string taobaoCatName = "0";
|
||||
if (TaobaoCat.ContainsKey(TaobaoCatId))
|
||||
taobaoCatName = TaobaoCat[TaobaoCatId];
|
||||
if (TaobaoCatId == 0)
|
||||
TaobaoCatId = 1;
|
||||
string html = api.GetCatId(TaobaoCatId, taobaoCatName, t.Titlte);
|
||||
if (html.Contains("cat_id1"))
|
||||
{
|
||||
Cat1 = BaseRegex.GetIntJson(ref html, "cat_id1").ToString();
|
||||
Cat2 = BaseRegex.GetIntJson(ref html, "cat_id2").ToString();
|
||||
Cat3 = BaseRegex.GetIntJson(ref html, "cat_id3").ToString();
|
||||
Cat4 = BaseRegex.GetIntJson(ref html, "cat_id4").ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(Cat1) || Cat1 == "0")//API未执行成功
|
||||
{
|
||||
bool ok = Get(t.Titlte, t.FromId, t.FromSiteId);
|
||||
if (!ok)
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(Cat4))
|
||||
Cat4 = "0";
|
||||
t.Cat1 = int.Parse(Cat1);
|
||||
t.Cat4 = int.Parse(Cat4);
|
||||
t.Cat3 = int.Parse(Cat3);
|
||||
t.Cat2 = int.Parse(Cat2);
|
||||
int id = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
||||
int cid = PinduoduoCatList.GetNewCat3(id);
|
||||
if (cid != id && PinduoduoCatList.CatIds.ContainsKey(cid))
|
||||
{
|
||||
var ci = PinduoduoCatList.CatIds[cid];
|
||||
t.CatId = ci.id;
|
||||
t.Cat1 = ci.cat1;
|
||||
t.Cat2 = ci.cat2;
|
||||
if (ci.cat3 == 0)
|
||||
{
|
||||
foreach (KeyValuePair<int, CatBase> c3 in PinduoduoCatList.CatIds)
|
||||
{
|
||||
if (c3.Value.cat2 == ci.cat2 && c3.Value.cat3 > 0)
|
||||
{
|
||||
ci.cat3 = c3.Value.cat3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Cat3 = ci.cat3;
|
||||
if (ci.cat4 == 0 && ci.cat3 > 0)
|
||||
{
|
||||
foreach (KeyValuePair<int, CatBase> c4 in PinduoduoCatList.CatIds)
|
||||
{
|
||||
if (c4.Value.cat3 == ci.cat3 && c4.Value.cat4 > 0)
|
||||
{
|
||||
ci.cat4 = c4.Value.cat4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
t.Cat4 = ci.cat4;
|
||||
t.MainCatId = ci.main_cat_id;
|
||||
}
|
||||
t.MainCatId = GetMainCatId(t.Cat1);
|
||||
t.MainCatName = MainCatName;
|
||||
t.CatId = t.Cat4 > 0 ? t.Cat4 : t.Cat3;
|
||||
if (t.MainCatId == 0 || JustGetCat || CollectKeywordByTaobao.MainCatId > 0 && CollectKeywordByTaobao.MainCatId != t.MainCatId)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (AddToStock)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(t.ShopName))
|
||||
{
|
||||
var shop = GetShopLoginInfo.Shops.Find(s => s.ShopName == t.ShopName);
|
||||
if (shop == null || t.MainCatId != shop.MainCatId)
|
||||
t.ShopName = "";
|
||||
else
|
||||
{
|
||||
var s = GetShopLoginInfo.Shops.Find(ss => ss.ShopName == t.ShopName);
|
||||
if (s != null)
|
||||
{
|
||||
s.ProductCount++;
|
||||
UploadPinduoduoMain.ShopReplaceTemp.Add(s);
|
||||
UploadPinduoduoMain.ShopTemp.Add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
var ps = UploadPinduoduoMain.ProductStock.Find(p => p.FromId == t.FromId && p.Titlte == t.Titlte);
|
||||
ps = t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (CollectKeywordByTaobao.AutoAdd)
|
||||
{
|
||||
try
|
||||
{
|
||||
var ps = UploadPinduoduoMain.ProductStock.Find(p => p.FromId == t.FromId && p.Titlte == t.Titlte);
|
||||
ps = t;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
CollectKeywordByTaobao.Product.Add(t);
|
||||
CollectKeywordByTaobao.ProductTemp.Add(t);
|
||||
}
|
||||
|
||||
public KeyValuesBase GetServerTempCat(long fromId, int siteId)
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=product/product&act=get_cat";
|
||||
string data = UserLogin.GetSignaturex() + "&site_id=" + siteId + "&id=" + fromId;
|
||||
string html = GetHtml.PostUtf8(url, data);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("cat_id"))
|
||||
{
|
||||
Cat1 = BaseRegex.GetStringJson(ref html, "cat1");
|
||||
Cat2 = BaseRegex.GetStringJson(ref html, "cat2");
|
||||
Cat3 = BaseRegex.GetStringJson(ref html, "cat3");
|
||||
Cat4 = BaseRegex.GetStringJson(ref html, "cat4");
|
||||
if (Cat3 != "0" || Cat4 != "0")
|
||||
{
|
||||
MainCatId = BaseRegex.GetStringJson(ref html, "main_cid");
|
||||
GetMainCatId(int.Parse(Cat1));
|
||||
if (!TempCat.ContainsKey(fromId))
|
||||
{
|
||||
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3, Cat4);
|
||||
try
|
||||
{
|
||||
TempCat.Add(fromId, k);
|
||||
return k;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return TempCat[fromId];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Get(string title, long fromId, int siteId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(title))
|
||||
return false;
|
||||
if (TempCat.ContainsKey(fromId) && fromId > 0)
|
||||
{
|
||||
Cat1 = TempCat[fromId].Value1;
|
||||
Cat2 = TempCat[fromId].Value2;
|
||||
Cat3 = TempCat[fromId].Value3;
|
||||
Cat4 = TempCat[fromId].Value4;
|
||||
MainCatId = TempCat[fromId].Key;
|
||||
return true;
|
||||
}
|
||||
var shop = GetShopLoginInfo.Shops.Find(sp => sp != null && sp.Showed);
|
||||
if (shop != null)
|
||||
{
|
||||
var api = new PinduoduoApiGetProduct(shop);
|
||||
string taobaoCatName = "0";
|
||||
if (TaobaoCat.ContainsKey(TaobaoCatId))
|
||||
taobaoCatName = TaobaoCat[TaobaoCatId];
|
||||
if (TaobaoCatId == 0)
|
||||
TaobaoCatId = 1;
|
||||
string htmlx = api.GetCatId(TaobaoCatId, taobaoCatName, title);
|
||||
if (htmlx.Contains("cat_id1"))
|
||||
{
|
||||
Cat1 = BaseRegex.GetIntJson(ref htmlx, "cat_id1").ToString();
|
||||
Cat2 = BaseRegex.GetIntJson(ref htmlx, "cat_id2").ToString();
|
||||
Cat3 = BaseRegex.GetIntJson(ref htmlx, "cat_id3").ToString();
|
||||
Cat4 = BaseRegex.GetIntJson(ref htmlx, "cat_id4").ToString();
|
||||
}
|
||||
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
||||
{
|
||||
if (string.IsNullOrEmpty(Cat1)) break;//主类目为空
|
||||
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
||||
{
|
||||
MainCatId = MainCat[i].Key;
|
||||
if (!TempCat.ContainsKey(fromId))
|
||||
{
|
||||
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3);
|
||||
try
|
||||
{
|
||||
TempCat.Add(fromId, k);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if ((Cat3 != "0" || Cat4 != "0") && Cat1 != "")
|
||||
return true;
|
||||
}
|
||||
string url = BaseClass.LoginApiUrl + "?obj=product/product&act=get_cat";
|
||||
string data = UserLogin.GetSignaturex() + "&site_id=" + siteId + "&id=" + fromId;
|
||||
string html = GetHtml.PostUtf8(url, data);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("cat_id"))
|
||||
{
|
||||
Cat1 = BaseRegex.GetStringJson(ref html, "cat1");
|
||||
Cat2 = BaseRegex.GetStringJson(ref html, "cat2");
|
||||
Cat3 = BaseRegex.GetStringJson(ref html, "cat3");
|
||||
Cat4 = BaseRegex.GetStringJson(ref html, "cat4");
|
||||
if (Cat3 != "0" || Cat4 != "0")
|
||||
{
|
||||
MainCatId = BaseRegex.GetStringJson(ref html, "main_cid");
|
||||
if (!TempCat.ContainsKey(fromId))
|
||||
{
|
||||
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3, Cat4);
|
||||
try
|
||||
{
|
||||
TempCat.Add(fromId, k);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Title = title;
|
||||
Title = BaseRegex.Clear(Title, @"([\d\s]+)");
|
||||
GetLen(4);
|
||||
bool ok = OutPut(fromId);
|
||||
if (ok)
|
||||
return true;
|
||||
GetLen(6);
|
||||
ok = OutPut(fromId);
|
||||
if (ok)
|
||||
return true;
|
||||
GetLen(8);
|
||||
ok = OutPut(fromId);
|
||||
if (ok)
|
||||
return true;
|
||||
if (Cats.Count > 0)
|
||||
{
|
||||
var c = CatTop[0];
|
||||
Cat1 = c.Value1;
|
||||
Cat2 = c.Value2;
|
||||
for (int i = 0; i < Cats.Count; i++)
|
||||
{
|
||||
if (Cats[i].Value2 == Cat2)
|
||||
{
|
||||
Cat3 = Cats[i].Value3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
||||
{
|
||||
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
||||
{
|
||||
MainCatId = MainCat[i].Key;
|
||||
if (!TempCat.ContainsKey(fromId))
|
||||
{
|
||||
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3);
|
||||
try
|
||||
{
|
||||
TempCat.Add(fromId, k);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
/// <summary>
|
||||
/// 使用2级分类
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool OutPut(long fromId)
|
||||
{
|
||||
if (CatTop.Count > 3 && CatTop[0].Rank > 1 || CatTop.Count > 0 && CatTop[0].Rank > 5)
|
||||
{
|
||||
var c = CatTop[0];
|
||||
Cat1 = c.Value1;
|
||||
Cat2 = c.Value2;
|
||||
|
||||
for (int i = 0; i < Cats.Count; i++)
|
||||
{
|
||||
if (Cats[i].Value2 == Cat2)
|
||||
{
|
||||
Cat3 = Cats[i].Value3;
|
||||
Cat4 = Cats[i].Value4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < MainCat.Count; i++)//计算主营类目ID
|
||||
{
|
||||
if (MainCat[i].Value1.Contains("," + Cat1 + ","))
|
||||
{
|
||||
MainCatId = MainCat[i].Key;
|
||||
if (!TempCat.ContainsKey(fromId))
|
||||
{
|
||||
KeyValuesBase k = new KeyValuesBase(MainCatId, Cat1, Cat2, Cat3, Cat4);
|
||||
try
|
||||
{
|
||||
TempCat.Add(fromId, k);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void GetLen(int len)
|
||||
{
|
||||
int count = Title.Length / len;
|
||||
if (count < 3)
|
||||
return;
|
||||
for (int i = 0; i < Cats.Count; i++)
|
||||
{
|
||||
var c = Cats[i];
|
||||
c.Rank++;
|
||||
}
|
||||
for (int i = 0; i < len; i++)
|
||||
{
|
||||
string word = Title.Substring(i * count, count);
|
||||
string url = "http://pcat.qixiaoke.com/taobao/pinduoduo_main.php?keyword=" + GetHtml.UrlEncodeUtf8(word);
|
||||
string html = GetHtml.Utf8(url);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\n"))
|
||||
continue;
|
||||
string[] l = html.Split('\n');
|
||||
for (int j = 0; j < l.Length; j++)
|
||||
{
|
||||
bool had = false;
|
||||
string[] ll = l[j].Split(',');
|
||||
if (ll.Length < 3)
|
||||
continue;
|
||||
KeyValuesBase k;
|
||||
KeyValuesBase kt;
|
||||
if (ll.Length == 3)
|
||||
{
|
||||
k = new KeyValuesBase(ll[2], ll[0], ll[1], ll[2], "0");
|
||||
kt = new KeyValuesBase(ll[1], ll[0], ll[1], ll[2], "0");
|
||||
}
|
||||
else
|
||||
{
|
||||
k = new KeyValuesBase(ll[2], ll[0], ll[1], ll[2], ll[3]);
|
||||
kt = new KeyValuesBase(ll[1], ll[0], ll[1], ll[2], ll[3]);
|
||||
}
|
||||
|
||||
if (k.Value2 == "242" || k.Value2 == "243" || k.Value3 == "3850")
|
||||
continue;
|
||||
kt.Rank = 1;
|
||||
k.Rank = 1;
|
||||
for (int m = 0; m < Cats.Count; m++)
|
||||
{
|
||||
if (Cats[m].Key == ll[2])
|
||||
{
|
||||
k = Cats[m];
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!had)
|
||||
Cats.Add(k);
|
||||
else
|
||||
k.Rank++;
|
||||
had = false;
|
||||
for (int m = 0; m < CatTop.Count; m++)
|
||||
{
|
||||
if (CatTop[m].Key == ll[1])
|
||||
{
|
||||
k = CatTop[m];
|
||||
had = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!had)
|
||||
CatTop.Add(k);
|
||||
else
|
||||
k.Rank++;
|
||||
}
|
||||
}
|
||||
Cats.Sort(delegate (KeyValuesBase x, KeyValuesBase y)
|
||||
{
|
||||
return y.Rank.CompareTo(x.Rank);
|
||||
});
|
||||
CatTop.Sort(delegate (KeyValuesBase x, KeyValuesBase y)
|
||||
{
|
||||
return y.Rank.CompareTo(x.Rank);
|
||||
});
|
||||
}
|
||||
|
||||
public static void Ini()
|
||||
{
|
||||
string[] l = FileBase.ReadAllLines("taobao_cat.ico");
|
||||
for (int i = 0; l != null && i < l.Length; i++)
|
||||
{
|
||||
if (!l[i].Contains("\t"))
|
||||
continue;
|
||||
string[] s = l[i].Split('\t');
|
||||
TaobaoCat.Add(int.Parse(s[0]), s[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,350 @@
|
||||
using AllBase;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class FromTitleToCatTaobao
|
||||
{
|
||||
/// <summary>
|
||||
/// 用标题计算分类
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <returns></returns>
|
||||
public static int Get(string title, bool IsGetMoreCatid = false)
|
||||
{
|
||||
title = BaseRegex.Clear(title, @"([\d]+)");
|
||||
char[] k = "[]\\/ -+=.【】{};,。,.::;*()()@!!&{}".ToCharArray();
|
||||
foreach (char c in k)
|
||||
title = title.Replace(c.ToString(), "");
|
||||
string[] keys = "批发,新款,特价,热卖,定制,定做,热卖,正品,包邮,正品,出售,新品,厂家,直销,自营,跨境,爆款,批发,品牌,一件,代发,清仓,直供,外贸".Split(',');
|
||||
foreach (string c in keys)
|
||||
title = title.Replace(c, "");
|
||||
|
||||
if (string.IsNullOrEmpty(title) || title.Length < 2)
|
||||
return 0;
|
||||
Dictionary<int, int> cats = new Dictionary<int, int>();
|
||||
string apiUrl = "http://tcat.qixiaoke.com/taobao/keyword.php?keyword=";
|
||||
string html = GetHtml.Utf8(apiUrl + GetHtml.UrlEncodeUtf8(title));
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
{
|
||||
string[] l = html.Split(',');
|
||||
foreach (string ss in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ss))
|
||||
continue;
|
||||
int s = int.Parse(ss);
|
||||
if (cats.ContainsKey(s))
|
||||
cats[s]++;
|
||||
else
|
||||
cats.Add(s, 1);
|
||||
}
|
||||
int top = 0;
|
||||
int all = 0;
|
||||
int catId = 0;
|
||||
foreach (KeyValuePair<int, int> cat in cats)
|
||||
{
|
||||
if (top < cat.Value)
|
||||
{
|
||||
top = cat.Value;
|
||||
catId = cat.Key;
|
||||
}
|
||||
all += cat.Value;
|
||||
}
|
||||
return catId;
|
||||
}
|
||||
int Step = 2;
|
||||
int half = title.Length / 2;
|
||||
string key1 = title.Substring(0, half);
|
||||
string key2 = title.Substring(half);
|
||||
SetCats(key1, ref cats);
|
||||
SetCats(key2, ref cats);
|
||||
int cid = GetMaxCount(ref cats, title.Length > 8 ? 4 : 16);
|
||||
if (IsGetMoreCatid && cats.Count > 5)
|
||||
{
|
||||
return cid;
|
||||
}
|
||||
else if (cats.Count > 0 && !IsGetMoreCatid)
|
||||
{
|
||||
return cid;
|
||||
}
|
||||
Step = 4;
|
||||
AddCount(ref cats);
|
||||
int four = title.Length / 4;
|
||||
if (four < 2)//没法继续细分了
|
||||
return GetMaxCount(ref cats, 4096);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
string key = title.Substring(i * four, four);
|
||||
SetCats(key, ref cats);
|
||||
}
|
||||
cid = GetMaxCount(ref cats, title.Length > 16 ? 16 : 64);
|
||||
if (cid > 0)
|
||||
return cid;
|
||||
AddCount(ref cats);
|
||||
Step = 8;
|
||||
int eigth = title.Length / 8;
|
||||
if (eigth < 2)
|
||||
return GetMaxCount(ref cats, 4096);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
string key = title.Substring(i * eigth, eigth);
|
||||
SetCats(key, ref cats);
|
||||
}
|
||||
return GetMaxCount(ref cats, 4096);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static string GetCategory(string title)
|
||||
{
|
||||
if (string.IsNullOrEmpty(title)) return string.Empty;
|
||||
string name = title;
|
||||
title = BaseRegex.Clear(title, @"([\d]+)");
|
||||
char[] k = "[]\\/ -+=.【】{};,。,.::;*()()@!!&{}".ToCharArray();
|
||||
foreach (char c in k)
|
||||
title = title.Replace(c.ToString(), "");
|
||||
string[] keys = "批发,新款,特价,热卖,定制,定做,热卖,正品,包邮,正品,出售,新品,厂家,直销,自营,跨境,爆款,批发,品牌,一件,代发,清仓,直供,外贸".Split(',');
|
||||
foreach (string c in keys)
|
||||
title = title.Replace(c, "");
|
||||
|
||||
if (string.IsNullOrEmpty(title) || title.Length < 2)
|
||||
return string.Empty;
|
||||
Dictionary<int, int> cats = new Dictionary<int, int>();
|
||||
string apiUrl = "http://tcat.qixiaoke.com/taobao/keyword.php?keyword=";
|
||||
string html = GetHtml.Utf8(apiUrl + GetHtml.UrlEncodeUtf8(title));
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
{
|
||||
string[] l = html.Split(',');
|
||||
foreach (string ss in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ss))
|
||||
continue;
|
||||
int s = int.Parse(ss);
|
||||
if (cats.ContainsKey(s))
|
||||
cats[s]++;
|
||||
else
|
||||
cats.Add(s, 1);
|
||||
}
|
||||
int top = 0;
|
||||
int all = 0;
|
||||
int catId = 0;
|
||||
foreach (KeyValuePair<int, int> cat in cats)
|
||||
{
|
||||
if (top < cat.Value)
|
||||
{
|
||||
top = cat.Value;
|
||||
catId = cat.Key;
|
||||
}
|
||||
all += cat.Value;
|
||||
}
|
||||
return name + ":" + catId;
|
||||
}
|
||||
int Step = 2;
|
||||
int half = title.Length / 2;
|
||||
string key1 = title.Substring(0, half);
|
||||
string key2 = title.Substring(half);
|
||||
SetCats(key1, ref cats);
|
||||
SetCats(key2, ref cats);
|
||||
int cid = GetMaxCount(ref cats, title.Length > 8 ? 4 : 16);
|
||||
if (cid > 0)
|
||||
return name + ":" + cid;
|
||||
|
||||
Step = 4;
|
||||
AddCount(ref cats);
|
||||
int four = title.Length / 4;
|
||||
if (four < 2)//没法继续细分了
|
||||
return name + ":" + GetMaxCount(ref cats, 4096);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
string key = title.Substring(i * four, four);
|
||||
SetCats(key, ref cats);
|
||||
}
|
||||
cid = GetMaxCount(ref cats, title.Length > 16 ? 16 : 64);
|
||||
if (cid > 0)
|
||||
return name + ":" + cid;
|
||||
AddCount(ref cats);
|
||||
Step = 8;
|
||||
int eigth = title.Length / 8;
|
||||
if (eigth < 2)
|
||||
return name + ":" + GetMaxCount(ref cats, 4096);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
string key = title.Substring(i * eigth, eigth);
|
||||
SetCats(key, ref cats);
|
||||
}
|
||||
return name + ":" + GetMaxCount(ref cats, 4096);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 用标题计算分类(为了保证防止跟之前冲突 特意写个方法)
|
||||
/// </summary>
|
||||
/// <param name="title"></param>
|
||||
/// <returns></returns>
|
||||
public int GetCataryId(string title, out Dictionary<int, int> DicTbCatId)
|
||||
{
|
||||
Dictionary<int, int> DicTbCatIdTemp = new Dictionary<int, int>();
|
||||
title = BaseRegex.Clear(title, @"([\d]+)");
|
||||
char[] k = "[]\\/ -+=.【】{};,。,.::;*()()@!!&{}".ToCharArray();
|
||||
foreach (char c in k)
|
||||
title = title.Replace(c.ToString(), "");
|
||||
string[] keys = "批发,新款,特价,热卖,定制,定做,热卖,正品,包邮,正品,出售,新品,厂家,直销,自营,跨境,爆款,批发,品牌,一件,代发,清仓,直供,外贸".Split(',');
|
||||
foreach (string c in keys)
|
||||
title = title.Replace(c, "");
|
||||
|
||||
DicTbCatId = DicTbCatIdTemp;
|
||||
|
||||
if (string.IsNullOrEmpty(title) || title.Length < 2)
|
||||
return 0;
|
||||
Dictionary<int, int> cats = new Dictionary<int, int>();
|
||||
string apiUrl = "http://tcat.qixiaoke.com/taobao/keyword.php?keyword=";
|
||||
string html = GetHtml.Utf8(apiUrl + GetHtml.UrlEncodeUtf8(title));
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
{
|
||||
string[] l = html.Split(',');
|
||||
foreach (string ss in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ss))
|
||||
continue;
|
||||
int s = int.Parse(ss);
|
||||
if (cats.ContainsKey(s))
|
||||
cats[s]++;
|
||||
else
|
||||
cats.Add(s, 1);
|
||||
}
|
||||
int top = 0;
|
||||
int all = 0;
|
||||
int catId = 0;
|
||||
foreach (KeyValuePair<int, int> cat in cats)
|
||||
{
|
||||
if (top < cat.Value)
|
||||
{
|
||||
top = cat.Value;
|
||||
catId = cat.Key;
|
||||
}
|
||||
all += cat.Value;
|
||||
}
|
||||
return catId;
|
||||
}
|
||||
int Step = 2;
|
||||
int half = title.Length / 2;
|
||||
string key1 = title.Substring(0, half);
|
||||
string key2 = title.Substring(half);
|
||||
SetCats(key1, ref cats);
|
||||
SetCats(key2, ref cats);
|
||||
int cid = GetMaxCount(ref cats, title.Length > 8 ? 4 : 16);
|
||||
DicTbCatId = cats;
|
||||
if (cats.Count > 5)
|
||||
{
|
||||
return cid;
|
||||
}
|
||||
Step = 4;
|
||||
AddCount(ref cats);
|
||||
DicTbCatId = cats;
|
||||
int four = title.Length / 4;
|
||||
if (four < 2)//没法继续细分了
|
||||
return GetMaxCount(ref cats, 4096);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
string key = title.Substring(i * four, four);
|
||||
SetCats(key, ref cats);
|
||||
}
|
||||
cid = GetMaxCount(ref cats, title.Length > 16 ? 16 : 64);
|
||||
DicTbCatId = cats;
|
||||
if (cid > 0)
|
||||
return cid;
|
||||
AddCount(ref cats);
|
||||
Step = 8;
|
||||
int eigth = title.Length / 8;
|
||||
DicTbCatId = cats;
|
||||
if (eigth < 2)
|
||||
return GetMaxCount(ref cats, 4096);
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
string key = title.Substring(i * eigth, eigth);
|
||||
SetCats(key, ref cats);
|
||||
}
|
||||
DicTbCatId = cats;
|
||||
return GetMaxCount(ref cats, 4096);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据关键词获取相关分类
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="cats"></param>
|
||||
public static void SetCats(string key, ref Dictionary<int, int> cats)
|
||||
{
|
||||
string apiUrl = "http://tcat.qixiaoke.com/taobao/keyword.php?keyword=";
|
||||
string html = GetHtml.Utf8(apiUrl + GetHtml.UrlEncodeUtf8(key));
|
||||
if (!string.IsNullOrEmpty(html))
|
||||
{
|
||||
string[] l = html.Split(',');
|
||||
foreach (string ss in l)
|
||||
{
|
||||
if (string.IsNullOrEmpty(ss))
|
||||
continue;
|
||||
int s = int.Parse(ss);
|
||||
|
||||
if (cats.ContainsKey(s))
|
||||
cats[s]++;
|
||||
else
|
||||
cats.Add(s, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据倍数判断是否要取得准确结果
|
||||
/// </summary>
|
||||
/// <param name="cats"></param>
|
||||
/// <param name="times"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetMaxCount(ref Dictionary<int, int> cats, int times)
|
||||
{
|
||||
int top = 0;
|
||||
int all = 0;
|
||||
int catId = 0;
|
||||
foreach (KeyValuePair<int, int> cat in cats)
|
||||
{
|
||||
if (top < cat.Value)
|
||||
{
|
||||
top = cat.Value;
|
||||
catId = cat.Key;
|
||||
}
|
||||
all += cat.Value;
|
||||
}
|
||||
if (all / times < top)
|
||||
return catId;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 权值翻倍
|
||||
/// </summary>
|
||||
/// <param name="cats"></param>
|
||||
public static void AddCount(ref Dictionary<int, int> cats)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (KeyValuePair<int, int> cat in cats)
|
||||
{
|
||||
cats[cat.Key] *= 2;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class GetEditDetail
|
||||
{
|
||||
public ShopChatBase Shop;
|
||||
public string Name;
|
||||
public GetEditDetail(ShopChatBase shop,string name)
|
||||
{
|
||||
Shop = shop;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public ResultBase Get(long pin)
|
||||
{
|
||||
string html = GetHtmlBy(pin);
|
||||
if (string.IsNullOrEmpty(html) || !html.Contains("\"success\":true"))
|
||||
{
|
||||
LogSave.Add(Name, "商品不存在:" + pin);
|
||||
return null;
|
||||
}
|
||||
if (BaseRegex.GetIntJson(ref html, "is_onsale") == 0)
|
||||
{
|
||||
LogSave.Add(Name, "商品已下架:" + pin);
|
||||
return null;
|
||||
}
|
||||
GetEditDetailBase tp = JsonHelper.DeserializeJsonToObject<GetEditDetailBase>(html);
|
||||
tp.result.fabricx = BaseRegex.GetIntJson(ref html, "fabric");
|
||||
tp.result.fabric_contentx = BaseRegex.GetIntJson(ref html, "fabric_content");
|
||||
return tp.result;
|
||||
}
|
||||
|
||||
public string GetHtmlBy(long pin)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/glide/v2/mms/query/commit/detail/"+pin;
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
WebClientx wb = new WebClientx();
|
||||
wb.Timeout = 30;
|
||||
wb.AllowAutoRedirect = false;
|
||||
wb.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
|
||||
wb.Headers.Add("Accept-Encoding", "gzip,deflate");
|
||||
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
||||
wb.Headers.Add("User-Agent", BaseClass.ChromeUserAgent);
|
||||
wb.Headers.Add("Upgrade-Insecure-Requests", "1");
|
||||
wb.Headers.Add("Referer", "https://mms.pinduoduo.com/Pdd.html");
|
||||
wb.Headers.Add("Cookie", Shop.Cookies);
|
||||
try
|
||||
{
|
||||
var b = wb.DownloadData(url);
|
||||
return Encoding.UTF8.GetString(b);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.Message;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public class GetEditDetailBase
|
||||
{
|
||||
public bool success;
|
||||
public ResultBase result;
|
||||
}
|
||||
|
||||
public class ResultBase
|
||||
{
|
||||
public long id;
|
||||
public long goods_id;
|
||||
public int check_status;
|
||||
public int commit_deleted;
|
||||
public string owner;
|
||||
public int is_shop;
|
||||
public string goods_sn;
|
||||
public int is_folt;
|
||||
public string warm_tips;
|
||||
public int fabricx;
|
||||
public int fabric_contentx;
|
||||
public int cost_template_id;
|
||||
public int cat_id;
|
||||
public int mall_id;
|
||||
public string goods_name;
|
||||
public string tiny_name;
|
||||
public string goods_desc;
|
||||
public string share_desc;
|
||||
public List<string> list_desc = new List<string>();
|
||||
public int market_price;
|
||||
public string thumb_url;
|
||||
public string image_url;
|
||||
public string hd_thumb_url;
|
||||
public CommitExtensionBase commit_extension;
|
||||
public List<GalleriesBase> galleries;
|
||||
public List<SkuDetailBase> sku;
|
||||
public List<int> cat_ids;
|
||||
public List<string> cats;
|
||||
public string owner_name;
|
||||
}
|
||||
|
||||
public class CommitExtensionBase
|
||||
{
|
||||
public long goods_commit_id;
|
||||
public string out_goods_sn;
|
||||
}
|
||||
|
||||
public class GalleriesBase
|
||||
{
|
||||
public string url;
|
||||
public int width;
|
||||
public int height;
|
||||
public int type;
|
||||
}
|
||||
|
||||
public class SkuDetailBase
|
||||
{
|
||||
public long id;
|
||||
public long sku_id;
|
||||
public string sku_sn;
|
||||
public int is_onsale;
|
||||
public int limit_quantity;
|
||||
public int multi_price;
|
||||
public int price;
|
||||
public int quantity;
|
||||
public string thumb_url;
|
||||
public List<SpecDetailBase> spec;
|
||||
public string out_sku_sn;
|
||||
}
|
||||
|
||||
public class SpecDetailBase
|
||||
{
|
||||
public int parent_id;
|
||||
public string parent_name;
|
||||
public long spec_id;
|
||||
public string spec_name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AllBase;
|
||||
using Work.CollectClass;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class GetNewTaobaoUpId
|
||||
{
|
||||
public static Dictionary<long, IntKeyValues> PddToTb = new Dictionary<long, IntKeyValues>();
|
||||
public ShopChatBase Shop;
|
||||
public GetNewTaobaoUpId(ShopChatBase shop)
|
||||
{
|
||||
Shop = shop;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最接近淘宝ID
|
||||
/// </summary>
|
||||
/// <param name="img">图片</param>
|
||||
/// <param name="min">最低价:分 加价之后</param>
|
||||
/// <param name="max">最高价:分 加价之后</param>
|
||||
/// <returns></returns>
|
||||
public long Get(long pid,long fromId, byte[] img, int min, int max,string berfoeTitle)
|
||||
{
|
||||
int minPrice;
|
||||
int maxPrice;
|
||||
if (PddToTb.ContainsKey(fromId) && PddToTb[fromId].Value1 > min)
|
||||
{
|
||||
var i = PddToTb[fromId];
|
||||
minPrice = i.Value1;
|
||||
maxPrice = i.Value2;
|
||||
Set(pid, i.Key, minPrice, maxPrice, i.Value3, 0);
|
||||
return i.Key;
|
||||
}
|
||||
string url = BaseClass.BuildObjString("taobao_id&act=get");
|
||||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/taobao_id&act=get";
|
||||
string data = UserLogin.GetSignaturex();
|
||||
data += "&pdd_id=" + fromId;
|
||||
string html = GetHtml.PostUtf8(url, data);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("taobao_id"))
|
||||
{
|
||||
long tid = BaseRegex.GetLongJson(ref html, "taobao_id");
|
||||
minPrice = BaseRegex.GetIntJson(ref html, "min_price");
|
||||
maxPrice = BaseRegex.GetIntJson(ref html, "max_price");
|
||||
int express_price = BaseRegex.GetIntJson(ref html, "express_price");
|
||||
try
|
||||
{
|
||||
PddToTb.Add(fromId, new IntKeyValues(tid, minPrice, maxPrice, express_price));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
if (min < minPrice)
|
||||
{
|
||||
Set(pid, tid, minPrice, maxPrice, express_price, 0);
|
||||
return tid;
|
||||
}
|
||||
}
|
||||
if (img == null)
|
||||
goto EndError;
|
||||
|
||||
url = "https://s.taobao.com/image";
|
||||
string refere = "https://www.taobao.com";
|
||||
var ks = new NameValueCollection();
|
||||
ks.Add("cross", "taobao");
|
||||
ks.Add("type", "iframe");
|
||||
html = GetPostTaobaoHtml.PostFileTaobao(url, refere, true, ks,img);
|
||||
string name = BaseRegex.GetStringJson(ref html, "name");
|
||||
string maxId = "";
|
||||
int minPricex = 0;
|
||||
if (!string.IsNullOrEmpty(name))
|
||||
{
|
||||
url =
|
||||
"https://s.taobao.com/search?q=&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.2&ie=utf8&tfsid=" +
|
||||
name + "&app=imgsearch";
|
||||
html = GetPostTaobaoHtml.GetUrl(url, refere, true, "");
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"\{""nid"":""([\d]+)"",[\w\W]+?,""view_price"":""([\d\.]+)""");
|
||||
for (int i = 0; m != null && i < m.Count && i < 8; i++)
|
||||
{
|
||||
string id = m[i].Groups[1].Value;
|
||||
int price = (int) (decimal.Parse(m[i].Groups[2].Value)*100);
|
||||
if (price > minPricex)
|
||||
{
|
||||
minPricex = price;
|
||||
maxId = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(maxId))
|
||||
{
|
||||
int p1 = max/100, p2 = max/100*3 + 500;
|
||||
url = "https://s.taobao.com/search?q=" + GetHtml.UrlEncodeUtf8(berfoeTitle) +
|
||||
"&imgfile=&js=1&style=grid&stats_click=search_radio_all%3A1&ie=utf8&filter=reserve_price%5B" + p1 +
|
||||
"%2C" + p2 + "%5D";
|
||||
html = GetPostTaobaoHtml.GetUrl(url, refere, true, "");
|
||||
var m = BaseRegex.GetMatchRegex(ref html,
|
||||
@"""nid"":""([\d]+)""[\w\W]*?""raw_title"":""([^""]+)""[\w\W]+?,""view_price"":""([\d\.]+)""");
|
||||
maxId = "";
|
||||
minPricex = 0;
|
||||
for (int i = 0; m != null && i < m.Count && i < 8; i++)
|
||||
{
|
||||
string id = m[i].Groups[1].Value;
|
||||
string title = m[i].Groups[2].Value;
|
||||
int price = (int) (decimal.Parse(m[i].Groups[3].Value)*100);
|
||||
if (price > minPricex && title.ToLower()==berfoeTitle.ToLower())
|
||||
{
|
||||
minPricex = price;
|
||||
maxId = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (minPricex > min && !string.IsNullOrEmpty(maxId))
|
||||
{
|
||||
long tid = long.Parse(maxId);
|
||||
ProductCollectBase p = new ProductCollectBase();
|
||||
p.from_id = tid;
|
||||
TaobaoMobileCollect t =new TaobaoMobileCollect(p);
|
||||
t.NoContent = true;
|
||||
t.NoUpToServer = true;
|
||||
t.Get();
|
||||
minPrice = (int) (t.MinPrice*100);
|
||||
maxPrice = (int)(t.MaxPrice * 100);
|
||||
int express_price = (int) (p.express_price*100);
|
||||
url = BaseClass.BuildObjString("taobao_id&act=add");
|
||||
data = UserLogin.GetSignaturex();
|
||||
data += "&pdd_id=" + fromId;
|
||||
data += "&taobao_id=" + tid;
|
||||
data += "&min_price=" + minPrice;
|
||||
data += "&max_price=" + maxPrice;
|
||||
data += "&express_price=" + express_price;
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
try
|
||||
{
|
||||
PddToTb.Add(fromId, new IntKeyValues(tid,minPrice,maxPrice, express_price));
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
Set(pid, tid, minPrice, maxPrice, express_price, 0);
|
||||
return tid;
|
||||
}
|
||||
|
||||
EndError:
|
||||
long upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10000, 99999);
|
||||
|
||||
minPrice =(int)( min*0.93m);
|
||||
maxPrice = (int)(max * 0.93m);
|
||||
Set(pid,upid,minPrice,maxPrice,0,5);
|
||||
return upid;
|
||||
}
|
||||
|
||||
|
||||
public void Set(long pid,long tid, int beforePriceMin,int beforePriceMax,int express_price,int from_site_id)
|
||||
{
|
||||
var api = new PinduoduoApiGetProduct(Shop);
|
||||
string html = api.Relationx(pid, tid, beforePriceMin, beforePriceMax, express_price, from_site_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class IntKeyValues
|
||||
{
|
||||
public IntKeyValues(long k, int v1, int v2, int v3)
|
||||
{
|
||||
Key = k;
|
||||
Value1 = v1;
|
||||
Value2 = v2;
|
||||
Value3 = v3;
|
||||
}
|
||||
|
||||
public long Key = 0;
|
||||
public int Value1 = 0;
|
||||
public int Value2 = 0;
|
||||
public int Value3 = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class GetProductDetail
|
||||
{
|
||||
public ShopChatBase Shop;
|
||||
public string Html = "";
|
||||
public string Name;
|
||||
public GetProductDetail(ShopChatBase shop, string name)
|
||||
{
|
||||
Shop = shop;
|
||||
}
|
||||
|
||||
public ProductDetailBase Get(long pid)
|
||||
{
|
||||
try
|
||||
{
|
||||
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
|
||||
Html = api.GetProduct(pid);
|
||||
if (string.IsNullOrEmpty(Html) || !Html.Contains("\"goods_id\""))
|
||||
{
|
||||
System.Threading.Thread.Sleep(1000 + Randomx.GetId(1000));
|
||||
Html = api.GetProduct(pid);
|
||||
}
|
||||
if (string.IsNullOrEmpty(Html) || !Html.Contains("\"goods_id\""))
|
||||
{
|
||||
LogSave.Add(Name, "商品不存在:" + pid);
|
||||
return null;
|
||||
}
|
||||
Html = Html.Replace("\"shelf_life\":null", "\"shelf_life\":0");
|
||||
Html = Html.Replace("\"start_production_date\":null", "\"start_production_date\":0");
|
||||
Html = Html.Replace("\"end_production_date\":null", "\"end_production_date\":0");
|
||||
ProductDetailBasex tp = JsonHelper.DeserializeJsonToObject<ProductDetailBasex>(Html);
|
||||
return tp.goods_detail_get_response;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogSave.Add(Name, "构建数据错误:" + e.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ProductDetailBasex
|
||||
{
|
||||
public ProductDetailBase goods_detail_get_response;
|
||||
}
|
||||
|
||||
public class ProductDetailBase
|
||||
{
|
||||
public long goods_id;
|
||||
public int buy_limit;
|
||||
//public string mai_jia_zi_ti;
|
||||
public List<string> carousel_gallery_list = new List<string>();
|
||||
public int cat_id;
|
||||
public long cost_template_id;
|
||||
public int shelf_life;
|
||||
public int start_production_date;
|
||||
public int end_production_date;
|
||||
//public int paper_net_weight;
|
||||
//public int paper_length;
|
||||
//public int paper_width;
|
||||
//public int paper_plies_num;
|
||||
public int country_id;
|
||||
public int customer_num;
|
||||
public int goods_type;
|
||||
public string goods_name;
|
||||
public string tiny_name;
|
||||
public string goods_desc;
|
||||
public string warehouse;
|
||||
public int is_customs;
|
||||
public string customs;
|
||||
public int market_price;
|
||||
public int is_pre_sale;
|
||||
public int pre_sale_time;
|
||||
public int shipment_limit_second;
|
||||
public int order_limit;
|
||||
public int is_refundable;
|
||||
public int? second_hand;
|
||||
public int is_folt;
|
||||
public string warm_tips;
|
||||
public string outer_goods_id;
|
||||
public int fabricx;
|
||||
public int fabric_contentx;
|
||||
//public int fabric_id;
|
||||
//public int fabric_content_id;
|
||||
public int mall_id;
|
||||
public List<string> list_desc = new List<string>();
|
||||
public List<GoodsPropertyListBase> goods_property_list = new List<GoodsPropertyListBase>();
|
||||
public string thumb_url;
|
||||
public string image_url;
|
||||
public string hd_thumb_url;
|
||||
public List<string> galleries;
|
||||
public List<SkuDetailBase> sku_list;
|
||||
public List<string> detail_gallery_list;
|
||||
}
|
||||
|
||||
public class GoodsPropertyListBase
|
||||
{
|
||||
public long ref_pid;
|
||||
public long template_pid;
|
||||
public string vvalue;
|
||||
public string vid;
|
||||
public string punit;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
using Work.ManageClass;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class GetShopLoginInfo
|
||||
{
|
||||
public string Name;
|
||||
public GetShopLoginInfo(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public static List<string> ShopCat = new List<string>();
|
||||
public static List<string> ShopCatTemp = new List<string>();
|
||||
public static List<ShopChatBase> Shops = new List<ShopChatBase>();
|
||||
public static List<ShopChatBase> ShopBak = new List<ShopChatBase>();
|
||||
public static List<ShopChatBase> ShopTemp = new List<ShopChatBase>();
|
||||
|
||||
private Dictionary<string, string> GetCookies(ShopInfo SpIn)
|
||||
{
|
||||
int AgainCount = 0;
|
||||
Dictionary<string, string> dicCookie = new Dictionary<string, string>();
|
||||
string NewUrl = BaseClass.BuildObjString("pdd_shop_tempx&act=get_shop_cookies_list");
|
||||
Again:
|
||||
string Newhtml = GetHtml.PostUtf8(NewUrl, UserLogin.GetSignaturex("", "") + "&shops=" + GetHtml.UrlEncodeUtf8(Newtonsoft.Json.JsonConvert.SerializeObject(SpIn)));
|
||||
if (string.IsNullOrEmpty(Newhtml) || Newhtml.Contains("Error No File"))
|
||||
{
|
||||
if (AgainCount < 2)
|
||||
{
|
||||
AgainCount++;
|
||||
Thread.Sleep(50);
|
||||
goto Again;
|
||||
}
|
||||
}
|
||||
var m = BaseRegex.GetMatchRegex(ref Newhtml, @"<shop name=""([^""]+?)"">([\w\W]+?)</shop>");
|
||||
for (int j = 0; m != null && j < m.Count; j++)
|
||||
{
|
||||
string shopName = m[j].Groups[1].Value;
|
||||
string json = m[j].Groups[2].Value;
|
||||
|
||||
if (!string.IsNullOrEmpty(json) && !json.Contains("{}") && !json.Contains("none") && !json.Contains("noney"))
|
||||
{
|
||||
if (!dicCookie.ContainsKey(shopName))
|
||||
{
|
||||
dicCookie.Add(shopName, json);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
return dicCookie;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using AllBase;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class GetVisitProduct
|
||||
{
|
||||
public Dictionary<long, int> ProductVisit = new Dictionary<long, int>();
|
||||
public GetVisitProduct(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public ShopChatBase Shop = null;
|
||||
public static List<ProductVisitBase> Product = new List<ProductVisitBase>();
|
||||
public static List<ProductVisitBase> ProductTemp = new List<ProductVisitBase>();
|
||||
public static int MaxCount = 0, ThisCount = 0, MinVisitCount = 0, MinSoldCount = 0, Days = 0, MinPrice = 0;
|
||||
public static bool Running = false;
|
||||
public string Name;
|
||||
public void Get()
|
||||
{
|
||||
Running = true;
|
||||
string cookies = "";
|
||||
if (Shop != null)
|
||||
cookies = Shop.Cookies;
|
||||
string url = "https://mms.pinduoduo.com/earth/api/goodsDataShow/detailList";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{\"orderBy\":\"pay_ord_cnt\",\"orderStrategy\":\"DESC\",\"pageNumber\":1,\"pageSize\":10,\"spanDays\":" + Days + ",\"readyDate\":\"" + BaseClass.GetServerTimeString().ToString("yyyy-MM-DD") + "\"}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
int allCount = BaseRegex.GetIntJson(ref html, "total");
|
||||
int page = allCount / 10 + (allCount % 10 > 0 ? 1 : 0);
|
||||
MaxCount = page;
|
||||
for (int i = 1; i <= page; i++)
|
||||
{
|
||||
if (Shop == null && !Running)
|
||||
break;
|
||||
ThisCount = i;
|
||||
if (i != 1)
|
||||
{
|
||||
data = "{\"orderBy\":\"pay_ord_cnt\",\"orderStrategy\":\"DESC\",\"pageNumber\":" + i + ",\"pageSize\":10,\"spanDays\":" + Days + ",\"readyDate\":\"" + BaseClass.GetServerTimeString().ToString("yyyy-MM-DD") + "\"}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"\{([^\}]+?)\}");
|
||||
for (int j = 0; m != null && j < m.Count; j++)
|
||||
{
|
||||
string list = m[j].Groups[0].Value;
|
||||
ProductVisitBase p = new ProductVisitBase();
|
||||
p.Id = BaseRegex.GetLongJson(ref list, "goodsId");
|
||||
p.GoodsSn = BaseRegex.GetLongJson(ref list, "goodsSn");
|
||||
p.OrderCount = BaseRegex.GetIntJson(ref list, "payOrderCount");
|
||||
p.Title = BaseRegex.GetStringJson(ref list, "goodsName");
|
||||
p.Uv = BaseRegex.GetIntJson(ref list, "goodsUv");
|
||||
p.Pv = BaseRegex.GetIntJson(ref list, "goodsPv");
|
||||
p.UvAvgPay = BaseRegex.GetDecimalJson(ref list, "avgGoodsVcr");
|
||||
p.SoldCount = BaseRegex.GetIntJson(ref list, "payOrderCount");
|
||||
if (Shop == null)
|
||||
ProductTemp.Add(p);
|
||||
else
|
||||
{
|
||||
if (!ProductVisit.ContainsKey(p.Id))
|
||||
ProductVisit.Add(p.Id, p.Pv);
|
||||
else
|
||||
ProductVisit[p.Id] = p.Pv;
|
||||
}
|
||||
if (!Product.Exists(pr => pr.Id == p.Id))
|
||||
Product.Add(p);
|
||||
}
|
||||
LogSave.Add(Name, "获取 " + (Shop == null ? "" : Shop.ShopName) + " 流量:" + i);
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
ThisCount = MaxCount;
|
||||
Running = false;
|
||||
}
|
||||
|
||||
public DataGridView dataGridViewX5;
|
||||
|
||||
}
|
||||
|
||||
public class ProductVisitBase
|
||||
{
|
||||
public string Message = "";
|
||||
public string Title = "";
|
||||
public long Id;
|
||||
public long GoodsSn;
|
||||
public int OrderCount = 0;
|
||||
public bool Checked = false;
|
||||
/// <summary>
|
||||
/// 支付金额
|
||||
/// </summary>
|
||||
public decimal PayMoney = 0;
|
||||
public int Uv = 0;
|
||||
public decimal Price = 0;
|
||||
/// <summary>
|
||||
/// 购物车
|
||||
/// </summary>
|
||||
public int CartCount = 0;
|
||||
/// <summary>
|
||||
/// 收藏
|
||||
/// </summary>
|
||||
public int FavCount = 0;
|
||||
/// <summary>
|
||||
/// 销量
|
||||
/// </summary>
|
||||
public int SoldCount = 0;
|
||||
|
||||
public DateTime UpdateTime = DateTime.Now.AddDays(-365);
|
||||
public int Pv = 0;
|
||||
/// <summary>
|
||||
/// 平均用户付款数
|
||||
/// </summary>
|
||||
public decimal UvAvgPay = 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using AllBase;
|
||||
using Work.CollectClass;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class MobileDetail
|
||||
{
|
||||
public string Name;
|
||||
public long Pid;
|
||||
public long FromId = 0;
|
||||
public string FromShopName = "";
|
||||
public int FromSiteId = 0;
|
||||
public string message_alert = string.Empty;
|
||||
public MobileDetail(string name, long pid)
|
||||
{
|
||||
Name = name;
|
||||
Pid = pid;
|
||||
}
|
||||
|
||||
public ProductCollectBase Get()
|
||||
{
|
||||
if (TaobaoMobileCollect.ProductTemp.ContainsKey(Pid))
|
||||
return TaobaoMobileCollect.ProductTemp[Pid];
|
||||
var p = new ProductCollectBase();
|
||||
string url = "http://apiv4.yangkeduo.com/v5/goods/" + Pid + "?timeout=1500&pdduid=0";
|
||||
string html = GetPostTaobaoHtml.GetUrl(url, "http://apiv4.yangkeduo.com", true, "");
|
||||
Thread.Sleep(3000);
|
||||
if (CollectKeywordByTaobao.SaveCollect && !string.IsNullOrEmpty(html) && html.Contains("远程服务器返回错误"))
|
||||
{
|
||||
Thread.Sleep(6000);
|
||||
html = GetHtml.ByUsa(true, url);
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("远程服务器返回错误"))
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
TaobaoProductBase t = new TaobaoProductBase();
|
||||
t.FromType = "拼多多";
|
||||
t.FromId = Pid;
|
||||
PinduoduoProductCollect pp = new PinduoduoProductCollect(Name, t);
|
||||
pp.NoAdd = true;
|
||||
pp.Get();
|
||||
p = pp.pb;
|
||||
return p;
|
||||
}
|
||||
if (string.IsNullOrEmpty(html) || html.Contains("\"success\":false"))
|
||||
{
|
||||
LogSave.Add(Name, "商品不存在:" + Pid);
|
||||
return p;
|
||||
}
|
||||
if (html.Contains("远程服务器返回错误"))
|
||||
{
|
||||
LogSave.Add(Name, "IP临时被封请切换电脑IP:" + Pid);
|
||||
return p;
|
||||
}
|
||||
if (BaseRegex.GetIntJson(ref html, "is_onsale") == 0)
|
||||
{
|
||||
LogSave.Add(Name, "商品已下架:" + Pid);
|
||||
return p;
|
||||
}
|
||||
|
||||
MobileDetailBase tp = JsonHelper.DeserializeJsonToObject<MobileDetailBase>(html);
|
||||
p.name = tp.goods_name;
|
||||
for (int i = 0; i < tp.gallery.Count; i++)
|
||||
{
|
||||
if (tp.gallery[i].type == 1)
|
||||
p.Images.Add(tp.gallery[i].url);
|
||||
else
|
||||
p.content += "<img src=\"" + tp.gallery[i].url + "\" height=\"" + tp.gallery[i].height + "\" width=\"" + tp.gallery[i].width + "\" />";
|
||||
}
|
||||
if (tp.sku.Count > 0 && tp.sku[0].specs.Count == 1)
|
||||
{
|
||||
var spe = tp.sku[0].specs[0];
|
||||
PropBase prop = new PropBase();
|
||||
prop.name = spe.spec_key;
|
||||
for (int i = 0; i < tp.sku.Count; i++)
|
||||
{
|
||||
PropValueBase pvb = new PropValueBase();
|
||||
pvb.name = tp.sku[i].specs[0].spec_value;
|
||||
pvb.id = tp.sku[i].spec;
|
||||
pvb.name_pinduoduo = pvb.name;
|
||||
pvb.image = tp.sku[i].thumb_url;
|
||||
pvb.image_from_url = pvb.image;
|
||||
prop.Values.Add(pvb);
|
||||
|
||||
SkuMapBase sku = new SkuMapBase();
|
||||
sku.name = tp.sku[i].specs[0].spec_key + ":" + tp.sku[i].specs[0].spec_value;
|
||||
sku.before_price = tp.sku[i].normal_price / 100m;
|
||||
sku.price = tp.sku[i].group_price / 100m;
|
||||
sku.number = tp.sku[i].is_onsale == 0 ? 0 : tp.sku[i].quantity;
|
||||
sku.sale_count = tp.sku[i].sold_quantity;
|
||||
sku.id = tp.sku[i].sku_id;
|
||||
sku.pinduoduo_image = tp.sku[i].thumb_url;
|
||||
sku.prop_image = tp.sku[i].thumb_url;
|
||||
p.SkuMaps.Add(sku);
|
||||
}
|
||||
p.Props.Add(prop);
|
||||
}
|
||||
if (tp.sku.Count > 0 && tp.sku[0].specs.Count == 2)
|
||||
{
|
||||
for (int i = 0; i < tp.sku[0].specs.Count; i++)
|
||||
{
|
||||
PropBase prop = new PropBase();
|
||||
prop.name = tp.sku[0].specs[i].spec_key;
|
||||
p.Props.Add(prop);
|
||||
for (int j = 0; j < tp.sku.Count; j++)
|
||||
{
|
||||
if (prop.Values.Exists(po => po.name == tp.sku[j].specs[i].spec_value))
|
||||
continue;
|
||||
PropValueBase pv = new PropValueBase();
|
||||
pv.name = tp.sku[j].specs[i].spec_value;
|
||||
pv.image = tp.sku[j].thumb_url;
|
||||
pv.name_pinduoduo = pv.name;
|
||||
pv.id = tp.sku[j].spec.Split(',')[i];
|
||||
prop.Values.Add(pv);
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < tp.sku.Count; i++)
|
||||
{
|
||||
SkuMapBase sku = new SkuMapBase();
|
||||
sku.name = tp.sku[i].specs[0].spec_key + ":" + tp.sku[i].specs[0].spec_value + ";" + tp.sku[i].specs[1].spec_key + ":" + tp.sku[i].specs[1].spec_value;
|
||||
sku.before_price = tp.sku[i].normal_price / 100m;
|
||||
sku.price = tp.sku[i].group_price / 100m;
|
||||
sku.number = tp.sku[i].is_onsale == 0 ? 0 : tp.sku[i].quantity;
|
||||
sku.sale_count = tp.sku[i].sold_quantity;
|
||||
sku.id = tp.sku[i].sku_id;
|
||||
sku.pinduoduo_image = tp.sku[i].thumb_url;
|
||||
sku.prop_image = tp.sku[i].thumb_url;
|
||||
sku.spec_pinduoduo = tp.sku[i].spec;
|
||||
p.SkuMaps.Add(sku);
|
||||
}
|
||||
}
|
||||
p.id = Pid;
|
||||
p.cat1 = tp.cat_id_1;
|
||||
p.cat2 = tp.cat_id_2;
|
||||
p.cat3 = tp.cat_id_3;
|
||||
p.cat4 = tp.cat_id == tp.cat_id_3 ? 0 : tp.cat_id;
|
||||
p.cat_id = tp.cat_id;
|
||||
p.from = "拼多多";
|
||||
p.from_site_id = 2;
|
||||
p.mall_id = tp.mall_id;
|
||||
var f = new FromTitleToCat();
|
||||
p.main_cid = f.GetMainCatId(p.cat1);
|
||||
p.main_cat_name = f.MainCatName;
|
||||
p.name_share = tp.share_desc;
|
||||
p.content_pinduoduo = tp.goods_desc;
|
||||
p.hd_thumb_url_pinduoduo = tp.hd_thumb_url;
|
||||
p.thumb_url_pinduoduo = tp.thumb_url;
|
||||
p.image = tp.image_url;
|
||||
p.cost_template_id_pinduoduo = tp.cost_template_id;
|
||||
p.saleCount = tp.sales;
|
||||
p.from_id = FromId;
|
||||
p.from_shop_name = FromShopName;
|
||||
if (p.saleCount > 0 )
|
||||
{
|
||||
//url = BaseClass.BigDataApiUrl + "?obj=product/product";
|
||||
//string json = JsonHelper.SerializeObject(p);
|
||||
//string data = "&act=update&site_id=2&shop_name=" + GetHtml.UrlEncodeUtf8(p.from_shop_name) + "&json=" + GetHtml.UrlEncodeUtf8(json);
|
||||
//html = GetHtml.PostUtf8(url, UserLogin.GetSignaturex() + data);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (TaobaoMobileCollect.ProductTemp.Count > 1000)
|
||||
{
|
||||
TaobaoMobileCollect.ProductTemp.Clear();
|
||||
}
|
||||
|
||||
TaobaoMobileCollect.ProductTemp.Add(Pid,p);
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
public TaobaoProductBase ProductToTaobao(ProductCollectBase p)
|
||||
{
|
||||
TaobaoProductBase t = new TaobaoProductBase();
|
||||
t.GoodsId = p.id;
|
||||
t.Cat1 = p.cat1;
|
||||
t.Cat2 = p.cat2;
|
||||
t.Cat3 = p.cat3;
|
||||
t.Cat4 = p.cat4;
|
||||
t.CatId = p.cat_id;
|
||||
t.FromId = p.from_id;
|
||||
t.FromType = p.from;
|
||||
t.MailId = p.mall_id;
|
||||
t.MainCatId = p.main_cid;
|
||||
t.MainCatName = p.main_cat_name;
|
||||
t.Price = p.price;
|
||||
t.SaleCount = p.saleCount;
|
||||
t.Titlte = p.name;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
public class MobileDetailBase
|
||||
{
|
||||
public string goods_sn = "";
|
||||
public string goods_name = "";
|
||||
public string goods_desc = "";
|
||||
public string thumb_url = "";
|
||||
public string hd_thumb_url = "";
|
||||
public string country = "";
|
||||
public string warehouse = "";
|
||||
public string image_url = "";
|
||||
public string share_desc = "";
|
||||
public string skip_goods = "";
|
||||
public long goods_id = 0;
|
||||
public int cat_id = 0;
|
||||
public int mall_id = 0;
|
||||
public int market_price = 0;
|
||||
public int goods_type = 0;
|
||||
public int is_refundable = 0;
|
||||
public int quick_refund = 0;
|
||||
public int is_pre_sale = 0;
|
||||
public int pre_sale_time = 0;
|
||||
public int rv_image = 0;
|
||||
public int rv = 0;
|
||||
public int gpv = 0;
|
||||
public int shipment_limit_second = 0;
|
||||
public int sales = 0;
|
||||
public int is_mall_rec = 0;
|
||||
public int min_on_sale_group_price = 0;
|
||||
public int max_on_sale_group_price = 0;
|
||||
public int min_on_sale_normal_price = 0;
|
||||
public int max_on_sale_normal_price = 0;
|
||||
public int min_group_price = 0;
|
||||
public int max_group_price = 0;
|
||||
public int max_normal_price = 0;
|
||||
public int min_normal_price = 0;
|
||||
public int old_min_on_sale_group_price = 0;
|
||||
public int old_max_on_sale_group_price = 0;
|
||||
public int old_min_group_price = 0;
|
||||
public int old_max_group_price = 0;
|
||||
public int tag = 0;
|
||||
public int cost_template_id = 0;
|
||||
public int show_rec = 0;
|
||||
public int app_new = 0;
|
||||
public int is_home_delivery = 0;
|
||||
public int second_hand = 0;
|
||||
public int is_mall_dsr = 0;
|
||||
public int created_at = 0;
|
||||
public int quantity = 0;
|
||||
public int cat_id_1 = 0;
|
||||
public int cat_id_2 = 0;
|
||||
public int cat_id_3 = 0;
|
||||
public List<MobileDetailgalleryBase> gallery = new List<MobileDetailgalleryBase>();
|
||||
public List<MobileDetailskuBase> sku = new List<MobileDetailskuBase>();
|
||||
}
|
||||
|
||||
public class MobileDetailgalleryBase
|
||||
{
|
||||
public long id = 0;
|
||||
public long goods_id = 0;
|
||||
public int width = 0;
|
||||
public int height = 0;
|
||||
public int priority = 0;
|
||||
public int type = 0;
|
||||
public string url = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sku
|
||||
/// </summary>
|
||||
public class MobileDetailskuBase
|
||||
{
|
||||
public long sku_id = 0;
|
||||
public long goods_id = 0;
|
||||
public string thumb_url = "";
|
||||
public int quantity = 0;
|
||||
public int limit_quantity = 0;
|
||||
public int sold_quantity = 0;
|
||||
public int init_quantity = 0;
|
||||
public int is_onsale = 0;
|
||||
public string spec = "";
|
||||
public string outer_id = "";
|
||||
public int normal_price = 0;
|
||||
public int group_price = 0;
|
||||
public int old_group_price = 0;
|
||||
/// <summary>
|
||||
/// 未使用
|
||||
/// </summary>
|
||||
public int price = 0;
|
||||
/// <summary>
|
||||
/// 未使用
|
||||
/// </summary>
|
||||
public int market_price = 0;
|
||||
public List<MobileDetailspecsBase> specs = new List<MobileDetailspecsBase>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 属性
|
||||
/// </summary>
|
||||
public class MobileDetailspecsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 属性名
|
||||
/// </summary>
|
||||
public string spec_key = "";
|
||||
/// <summary>
|
||||
/// 属性值
|
||||
/// </summary>
|
||||
public string spec_value = "";
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class PinduoduoApiPropId
|
||||
{
|
||||
public ShopChatBase Shop;
|
||||
public PinduoduoApiPropId(ShopChatBase shop)
|
||||
{
|
||||
Shop = shop;
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化大类
|
||||
/// </summary>
|
||||
/// <param name="mainCatId"></param>
|
||||
/// <returns></returns>
|
||||
public string Get(int mainCatId)
|
||||
{
|
||||
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
|
||||
api.Type = "pdd.goods.spec.get";
|
||||
var cid = FromTitleToCat.MainCat.Find(c => c!=null && c.Key == mainCatId.ToString());
|
||||
if (cid == null)
|
||||
return "";
|
||||
string id = cid.Value1.Substring(1);
|
||||
id = id.Substring(0, id.IndexOf(","));
|
||||
api.Data.Add("cat_id", id);
|
||||
return api.GetData();
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取
|
||||
/// </summary>
|
||||
/// <param name="parentId"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public string GetPropId(string parentId, string name)
|
||||
{
|
||||
PinduoduoApiGetProduct api = new PinduoduoApiGetProduct(Shop);
|
||||
api.Type = "pdd.goods.spec.id.get";
|
||||
api.Data.Add("parent_spec_id", parentId);
|
||||
api.Data.Add("spec_name", name);
|
||||
return api.GetData();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,717 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AllBase;
|
||||
using Work.ManageClass;
|
||||
using System.Net;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class PinduoduoAuth
|
||||
{
|
||||
public bool NoCache = false;
|
||||
public bool MustAuth = false,MustAuthCps = false;
|
||||
public bool IsCps = false, SignDuoProtocol = false;
|
||||
public static List<string> Shops = new List<string>();
|
||||
/// <summary>
|
||||
/// 拼多多api网关
|
||||
/// </summary>
|
||||
public static string Gate = "https://gw-api.pinduoduo.com/api/router";
|
||||
public static string strContent = "";
|
||||
|
||||
|
||||
public static string ExecuteScript(string sExpression, string sCode)
|
||||
{
|
||||
MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
|
||||
scriptControl.UseSafeSubset = true;
|
||||
scriptControl.Language = "JScript";
|
||||
scriptControl.AddCode(sCode);
|
||||
try
|
||||
{
|
||||
string str = scriptControl.Eval(sExpression).ToString();
|
||||
return str;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string str = ex.Message;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void UpdateMallId(ref ShopChatBase shop)
|
||||
{
|
||||
string url = BaseClass.BuildObjString("shop&act=update_mall_id");
|
||||
string data = UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
|
||||
data += "&mall_id=" + shop.MallId;
|
||||
data += "&access_token=" + shop.AccessToken;
|
||||
data += "&refresh_token=" + shop.RefreshToken;
|
||||
data += "&from_tool=" + GetHtml.UrlEncodeUtf8(BaseClass.AgentName);
|
||||
string html = GetHtml.PostUtf8(url, data);
|
||||
url = BaseClass.LoginApiUrl + "?obj=product/image_pinbaobao&act=update_cookies";
|
||||
data = UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
|
||||
data += "&cookies=" + GetHtml.UrlEncodeUtf8(shop.Cookies);
|
||||
html = GetHtml.PostUtf8(url, data);
|
||||
}
|
||||
public bool ReFresh(string refresh)
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_refreshx&act=refresh&refresh_token=" + refresh
|
||||
+ "&client_id=" + BaseClass.ClientId + "&client_secret=" + BaseClass.ApiKey.Replace("2", "z").Replace("1", "I").Replace("c", "C").Replace("9", "O");
|
||||
string html = GetHtml.Utf8(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Auth(ShopChatBase shop)
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_shop_tempx&act=get_token&shop_name=" + shop.ShopName + "&" + UserLogin.GetSignaturex();
|
||||
string html = GetHtml.Utf8(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
UpdateMallId(ref shop);
|
||||
if (ReFresh(shop.RefreshToken))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(strContent))
|
||||
{
|
||||
string path = AppDomain.CurrentDomain.BaseDirectory + "crawlerInfoInterface.js";
|
||||
strContent = FileBase.ReadAllText(path);
|
||||
}
|
||||
string toolCode = "";
|
||||
if (BaseClass.MainPath == "findgoldcat")
|
||||
toolCode = "eb-";
|
||||
if (BaseClass.MainPath == "findgoldcat_main")
|
||||
toolCode = "oms-";
|
||||
if (BaseClass.MainPath == "pinbaobao")
|
||||
toolCode = "pbb-";
|
||||
string refresh = "";
|
||||
try
|
||||
{
|
||||
string cookies = "";
|
||||
string sid = BaseClass.ShopId;
|
||||
cookies = shop.Cookies;
|
||||
sid = shop.ShopId;
|
||||
|
||||
if (MustAuth)
|
||||
goto AuthGo;
|
||||
|
||||
url = BaseClass.LoginApiUrl + "pddx.php?act=get&cid=" + BaseClass.CompanyId + "&sid=" + sid
|
||||
+ "&client_id=" + BaseClass.ClientId + "&client_secret=" + BaseClass.ApiKey.Replace("2", "z").Replace("1", "I").Replace("c", "C").Replace("9", "O")
|
||||
+ "&state=" + toolCode + sid + "-" + BaseClass.CompanyId;
|
||||
html = GetHtml.Utf8(url);
|
||||
string token = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
refresh = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (!string.IsNullOrEmpty(refresh))
|
||||
{
|
||||
bool ok = ReFresh(refresh);
|
||||
if (ok)
|
||||
{
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
AuthGo:
|
||||
string strTime = BaseClass.GetTime(DateTime.Now).ToString() + "000";
|
||||
string str = "";
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
str += new Random(Guid.NewGuid().GetHashCode()).Next(9);
|
||||
}
|
||||
string strToken = str + "-" + strTime;
|
||||
string strNumber = "";
|
||||
string fun2 = string.Format(@"getEncode('{0}','{1}','{2}')", strTime, strToken, strNumber);
|
||||
string codex = ExecuteScript(fun2, strContent);
|
||||
|
||||
string refere = "http://mms.pinduoduo.com/open.html?response_type=code&client_id=" + BaseClass.ClientId +
|
||||
"&redirect_uri=http://www." + Randomx.GetWord(5) + ".com/pdd.php&state=";
|
||||
refere += toolCode;
|
||||
refere += sid + "-" + BaseClass.CompanyId;
|
||||
|
||||
url = "https://mms.pinduoduo.com/mars/application/authorize";
|
||||
string data =
|
||||
"{\"clientId\":\"" + BaseClass.ClientId + "\",\"responseType\":\"code\",\"scope\":[],\"crawlerInfo\":\"" + codex + "\"}";
|
||||
html = GetPostTaobaoHtml.GetJsonPost(url, refere, true, data, cookies);
|
||||
string code = BaseRegex.GetStringJson(ref html, "code");
|
||||
if (string.IsNullOrEmpty(code))
|
||||
return false;
|
||||
url = BaseClass.LoginApiUrl + "pddx.php?code=" + code + "&state=" + toolCode + sid + "-" + BaseClass.CompanyId
|
||||
+ "&client_id=" + BaseClass.ClientId + "&client_secret=" + BaseClass.ApiKey.Replace("2", "z").Replace("1", "I").Replace("c", "C").Replace("9", "O");
|
||||
html = GetHtml.Utf8(url);
|
||||
token = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
refresh = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
url = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_shop_tempx&act=add_token" +
|
||||
"&shop_name=" + shop.ShopName + "&access_token=" + token + "&refresh_token=" + refresh + "&" + UserLogin.GetSignaturex();
|
||||
html = GetHtml.Utf8(url);
|
||||
End:
|
||||
shop.AccessToken = token;
|
||||
if (!string.IsNullOrEmpty(refresh))
|
||||
shop.RefreshToken = refresh;
|
||||
UpdateMallId(ref shop);
|
||||
return !string.IsNullOrEmpty(token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public bool Auth(ShopChatBase shop,ref string client_id)
|
||||
{
|
||||
string prevAccessToken = shop.AccessToken;
|
||||
string prevRefreshToken = shop.RefreshToken;
|
||||
try
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_shop_tempx&act=get_token&shop_name=" + shop.ShopName + "&" + UserLogin.GetSignaturex();
|
||||
string html = GetHtml.Utf8(url);
|
||||
if (!IsCps && !string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (!InvalidClientId(shop,client_id)&&ReFresh(shop.RefreshToken, client_id))
|
||||
return true;
|
||||
}
|
||||
string TokenResult = GetToken(shop.ShopName);
|
||||
if (!IsCps && !TokenResult.Contains("error"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref TokenResult, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref TokenResult, "refresh_token");
|
||||
string client_idTemp = BaseRegex.GetStringJson(ref TokenResult, "client_id");
|
||||
if (ReFresh(shop.RefreshToken, client_idTemp))//通过缓存的三个值 来判断是否匹配 否则重新取
|
||||
{
|
||||
if (!(InvalidClientId(shop, client_id) && shop.AccessToken == prevAccessToken && shop.RefreshToken == prevRefreshToken))
|
||||
{
|
||||
client_id = client_idTemp;
|
||||
shop.ClientId = client_idTemp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
TokenResult = GetToken(shop.ShopName);
|
||||
if (!TokenResult.Contains("error"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref TokenResult, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref TokenResult, "refresh_token");
|
||||
string client_idTemp = BaseRegex.GetStringJson(ref TokenResult, "client_id");
|
||||
if (!InvalidClientId(shop, client_id)&&ReFresh(shop.RefreshToken, client_idTemp))//通过缓存的三个值 来判断是否匹配 否则重新取
|
||||
{
|
||||
client_id = client_idTemp;
|
||||
shop.ClientId = client_idTemp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#region 之前循环七次请求 现改为一次批量请求
|
||||
string ClientIdxReSult = "";
|
||||
int retryCount = 0;
|
||||
for (int i = 0; i < BaseClass.ClientIdx.Count; i++)
|
||||
{
|
||||
ClientIdxReSult += BaseClass.ClientIdx[i] + ",";
|
||||
}
|
||||
Again:
|
||||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/reflesh_token&act=getx&client_id=" + ClientIdxReSult +
|
||||
"&shop_name=" + shop.ShopName + "&" + UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
|
||||
html = GetHtml.Utf8(url);
|
||||
if (string.IsNullOrEmpty(html))
|
||||
{
|
||||
if (retryCount < 2)//服务器返回超时 则重试两次
|
||||
{
|
||||
retryCount++;
|
||||
goto Again;
|
||||
}
|
||||
retryCount = 0;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
string clientidTemp = BaseRegex.GetStringJson(ref html, "client_id");
|
||||
if (ReFresh(shop.RefreshToken, clientidTemp))
|
||||
{
|
||||
client_id = clientidTemp;
|
||||
shop.ClientId = clientidTemp;
|
||||
SaveToken(shop);//保存
|
||||
return true;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
if (BaseClass.UserVersion < 4 && BaseClass.ClientIdSave.Count > 0)
|
||||
{
|
||||
int i = Randomx.GetId(BaseClass.ClientIdSave.Count);
|
||||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/reflesh_token&act=get&client_id=" + BaseClass.ClientIdSave[i] +
|
||||
"&shop_name=" + shop.ShopName + "&" + UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
|
||||
html = GetHtml.Utf8(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (!InvalidClientId(shop, client_id) && ReFresh(shop.RefreshToken, BaseClass.ClientIdSave[i]))
|
||||
{
|
||||
client_id = BaseClass.ClientIdSave[i];
|
||||
shop.ClientId = BaseClass.ClientIdSave[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; !IsCps && i < BaseClass.ClientIdx.Count; i++)
|
||||
{
|
||||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/reflesh_token&act=get&client_id=" + BaseClass.ClientIdx[i] +
|
||||
"&shop_name=" + shop.ShopName + "&" + UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
|
||||
html = GetHtml.Utf8(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
{
|
||||
shop.AccessToken = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
shop.RefreshToken = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (!InvalidClientId(shop, client_id) && ReFresh(shop.RefreshToken, BaseClass.ClientIdx[i]))
|
||||
{
|
||||
client_id = BaseClass.ClientIdx[i];
|
||||
shop.ClientId = BaseClass.ClientIdx[i];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (IsCps && !MustAuthCps)
|
||||
{
|
||||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/reflesh_token&act=get&client_id=" + client_id +
|
||||
"&shop_name=" + shop.ShopName + "&" + UserLogin.GetSignaturex(shop.ShopId, shop.ShopName);
|
||||
html = GetHtml.Utf8(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
{
|
||||
shop.CpsShop.AccessToken = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
shop.CpsShop.RefreshToken = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (!InvalidClientId(shop, client_id)&&ReFresh(shop.CpsShop.RefreshToken, client_id))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string cookies = "";
|
||||
string sid = BaseClass.ShopId;
|
||||
if (shop != null)
|
||||
{
|
||||
cookies = shop.Cookies;
|
||||
sid = shop.ShopId;
|
||||
}
|
||||
string cookiesx = "";
|
||||
string urlxs = "https://mms.pinduoduo.com/hades/oauth/authed/list";
|
||||
string referes = "https://mms.pinduoduo.com/service-market/my-auth";
|
||||
string dataxs = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + CpsSetAllGoods.getAnti0aon() + "\"}";
|
||||
string htmlxs = GetPostTaobaoHtml.UploadTaobaoPost(urlxs, referes, true, dataxs, cookies, CpsSetAllGoods.getAnti0aon()); //GetPostTaobaoHtml.GetJsonPostAnti(url, refere, true, data, GetShopLoginInfo.Shops[i].Cookies, crawlerInfo);
|
||||
if (string.IsNullOrEmpty(htmlxs)||htmlxs.Contains("无效"))
|
||||
{
|
||||
urlxs = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
||||
referes = "https://fuwu.pinduoduo.com/service-market/my-service";
|
||||
dataxs = "{\"redirectUrl\":\"https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2Fmy-service\"}";
|
||||
htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, cookies, dataxs, CpsSetAllGoods.getAnti0aon());
|
||||
string accessToken = BaseRegex.GetStringJson(ref htmlxs, "accessToken");
|
||||
urlxs = "https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2F&accessToken=" + accessToken;
|
||||
htmlxs = GetJsonPostURL(urlxs, referes, true, "", cookies);
|
||||
accessToken = BaseRegex.GetMatchRegexString(ref htmlxs, "SUB_PASS_ID=([^;]+?);");
|
||||
cookiesx = "SUB_PASS_ID=" + accessToken;
|
||||
string codexs = CpsSetAllGoods.getAnti0aon();
|
||||
urlxs = "https://fuwu.pinduoduo.com/columbine/oauth/authed/list";
|
||||
referes = "https://fuwu.pinduoduo.com/service-market/my-auth";
|
||||
dataxs = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + codexs + "\"}";
|
||||
htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, cookies + cookiesx, dataxs, codexs);
|
||||
}
|
||||
var m = BaseRegex.GetMatchRegex(ref htmlxs, @"\{[\w\W]+?\}");
|
||||
for (int j = 0; m != null && j < m.Count; j++)
|
||||
{
|
||||
string list = m[j].Groups[0].Value;
|
||||
string id = BaseRegex.GetStringJson(ref list, "clientId");
|
||||
if (id == "9558f920cf77403bb475243fe44482ad"||id== "81fd2bbabbd54ec5bf312e05401a0343"
|
||||
|| id == "9f7d0ce6460b46e7a3833ac2e8325519"||id== "3069c1c325e44e85bcf5b6295694bdae"
|
||||
||id== "f23bda7f6d9c4b6c8751268891779660"||id== "5d755c0cf97a4cbdb8aa958beea25011" || id == "911bd1c0c0a0403da88334e24ca288a2")
|
||||
continue;
|
||||
long auditAt = BaseRegex.GetLongJson(ref list, "auditAt");
|
||||
long refreshTokenExpiredAt = BaseRegex.GetLongJson(ref list, "refreshTokenExpiredAt");
|
||||
DateTime t1 = DateTime.Now;// DateTime.Parse(DateTime.Now.ToString("1970-01-01 00:00:00")).AddMilliseconds(auditAt);
|
||||
DateTime t2 = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddMilliseconds(refreshTokenExpiredAt);
|
||||
System.TimeSpan t3 = t2 - t1; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
|
||||
double getDay = t3.TotalDays;
|
||||
if (BaseClass.ClientIdx.Contains(id) && getDay > 0)
|
||||
{
|
||||
client_id = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (client_id == "9558f920cf77403bb475243fe44482ad" || client_id == "81fd2bbabbd54ec5bf312e05401a0343"
|
||||
|| client_id == "9f7d0ce6460b46e7a3833ac2e8325519" || client_id == "3069c1c325e44e85bcf5b6295694bdae"
|
||||
|| client_id == "f23bda7f6d9c4b6c8751268891779660" || client_id == "5d755c0cf97a4cbdb8aa958beea25011" || client_id == "911bd1c0c0a0403da88334e24ca288a2")
|
||||
return false;
|
||||
//string urlxs = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
||||
//string referes = "https://fuwu.pinduoduo.com/service-market/my-service";
|
||||
//string dataxs = "{\"redirectUrl\":\"https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2Fmy-service\"}";
|
||||
//string htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes,cookies, dataxs, CpsSetAllGoods.getAnti0aon());
|
||||
//string accessToken = BaseRegex.GetStringJson(ref htmlxs, "accessToken");
|
||||
////urlxs = "https://fuwu.pinduoduo.com/columbine/public/user/login";
|
||||
////dataxs = "{\"accessToken\":\"" + accessToken + "\"}";
|
||||
////htmlxs = GetJsonPostURL(urlxs, referes, true, dataxs, cookies);
|
||||
//urlxs = "https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2F&accessToken=" + accessToken;
|
||||
//htmlxs = GetJsonPostURL(urlxs, referes, true, "", cookies);
|
||||
//accessToken = BaseRegex.GetMatchRegexString(ref htmlxs, "SUB_PASS_ID=([^;]+?);");
|
||||
//string cookiesx = "SUB_PASS_ID=" + accessToken;
|
||||
//string serverUrl = "https://fuwu.pinduoduo.com/columbine/pop/service/time/length/list";
|
||||
//string serverRefere = "https://fuwu.pinduoduo.com/service-market/my-service";
|
||||
//string serverdata = "{\"page\":1,\"pageSize\":10,\"isExpired\":false}";
|
||||
//string serverhtml = CpsSetAllGoods.Request_mms_pinduoduo_com(serverUrl, serverRefere, cookies + cookiesx, serverdata, CpsSetAllGoods.getAnti0aon());//GetPostTaobaoHtml.GetJsonPost(serverUrl, serverRefere, true, serverdata, cookies+ cookiesx);
|
||||
//var m = BaseRegex.GetMatchRegex(ref serverhtml, @"\{[\w\W]+?\}");
|
||||
//for (int j = 0; m != null && j < m.Count; j++)
|
||||
//{
|
||||
// string list = m[j].Groups[0].Value;
|
||||
// string clientName = BaseRegex.GetStringJson(ref list, "serviceName");
|
||||
// string id=GetClientId(clientName);
|
||||
// if (BaseClass.ClientIdx.Contains(id))
|
||||
// {
|
||||
// client_id = id;
|
||||
// break;
|
||||
// }
|
||||
//}
|
||||
if (MustAuth)
|
||||
goto AuthGo;
|
||||
url = BaseClass.LoginApiUrl + "pddx.php?act=get&cid=" + BaseClass.CompanyId + "&sid=" + sid + "&state=" + "pbb-" + sid + "-" + BaseClass.CompanyId
|
||||
+ "&client_id=" + client_id;
|
||||
html = GetHtml.Utf8(url);
|
||||
string time = BaseRegex.GetStringJson(ref html, "token_time");
|
||||
DateTime token_time = BaseClass.GetServerTimeString().AddHours(-1);
|
||||
if (!string.IsNullOrEmpty(time))
|
||||
token_time = DateTime.Parse(time);
|
||||
string token = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
string refresh = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (token_time.AddMinutes(3) > BaseClass.GetServerTimeString() || !NoCache && !string.IsNullOrEmpty(token))
|
||||
goto End;
|
||||
if (!string.IsNullOrEmpty(refresh))
|
||||
{
|
||||
bool ok = ReFresh(refresh, client_id);
|
||||
if (ok)
|
||||
{
|
||||
goto End;
|
||||
}
|
||||
}
|
||||
AuthGo:
|
||||
string refere = "https://mms.pinduoduo.com/open.html?response_type=code&client_id=" +
|
||||
client_id + "&redirect_uri=http://www.qimake.cn/pdd.php&state=";
|
||||
refere += "pbb-";
|
||||
refere += sid + "-" + BaseClass.CompanyId;
|
||||
if (IsCps && SignDuoProtocol && BaseClass.Balance >= 20)
|
||||
{
|
||||
url = "https://mms.pinduoduo.com/cps/api/mall/signDuoProtocol";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, "{}", cookies);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("\"success\":true"))
|
||||
{
|
||||
//url = BaseClass.BuildObjString("shop&act=time_addx");
|
||||
//string datax = UserLogin.GetSignaturex("", shop.ShopName) + "&tool_name=" + GetHtml.UrlEncodeUtf8(BaseClass.AgentName);
|
||||
//html = GetHtml.PostUtf8(url, datax);
|
||||
//if (html.Contains("ok,"))
|
||||
// BaseClass.Balance = int.Parse(html.Replace("ok,", "").Trim());
|
||||
shop.CpsShop.Status = 1;
|
||||
CpsShopNew.ShopTemp.Add(shop);
|
||||
}
|
||||
}
|
||||
url = "https://mms.pinduoduo.com/mars/application/authorize";
|
||||
cookies = shop.Cookies;
|
||||
string data = "{\"clientId\":\"" + client_id + "\",\"responseType\":\"code\",\"scope\":[]}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
if (html.Contains("接口已下线")|| html.Contains("403"))
|
||||
{
|
||||
string codex = UploadPinduoduoMain.AntiContent;
|
||||
url = "https://mms.pinduoduo.com/hades/oauth/authorize";
|
||||
data = "{\"clientId\":\""+ client_id + "\",\"responseType\":\"code\",\"scope\":[],\"isTrial\":0,\"crawlerInfo\":\"" + codex + "\"}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
if (html.Contains("接口已下线") || html.Contains("403"))
|
||||
{
|
||||
if (string.IsNullOrEmpty(cookiesx))
|
||||
{
|
||||
urlxs = "https://mms.pinduoduo.com/janus/api/subSystem/generateAccessToken";
|
||||
referes = "https://fuwu.pinduoduo.com/service-market/my-service";
|
||||
dataxs = "{\"redirectUrl\":\"https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2Fmy-service\"}";
|
||||
htmlxs = CpsSetAllGoods.Request_mms_pinduoduo_com(urlxs, referes, cookies, dataxs, CpsSetAllGoods.getAnti0aon());
|
||||
string accessToken = BaseRegex.GetStringJson(ref htmlxs, "accessToken");
|
||||
urlxs = "https://fuwu.pinduoduo.com/clint/api/login?redirect=https%3A%2F%2Ffuwu.pinduoduo.com%2Fservice-market%2F&accessToken=" + accessToken;
|
||||
htmlxs = GetJsonPostURL(urlxs, referes, true, "", cookies);
|
||||
accessToken = BaseRegex.GetMatchRegexString(ref htmlxs, "SUB_PASS_ID=([^;]+?);");
|
||||
cookiesx = "SUB_PASS_ID=" + accessToken;
|
||||
}
|
||||
string codex = UploadPinduoduoMain.AntiContent;
|
||||
url = "https://fuwu.pinduoduo.com/columbine/oauth/authorize";
|
||||
data = "{\"clientId\":\"" + client_id + "\",\"responseType\":\"code\",\"scope\":[],\"isTrial\":0,\"crawlerInfo\":\"" + codex + "\"}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, referes, true, data, cookiesx);
|
||||
}
|
||||
if (html.Contains("403"))
|
||||
{
|
||||
for (int j = 0; j < GetProxyHtml.ipCount; j++)
|
||||
{
|
||||
var proxyObject = GetProxyHtml.GetIPSProxyQueue();
|
||||
if (proxyObject == null)
|
||||
continue;
|
||||
html = GetProxyHtml.UploadNewProxyTaobaoPost(url, refere, true, data, cookies, proxyObject);
|
||||
GetProxyHtml.IpIndex++;
|
||||
if (html.Contains("\"success\":true"))
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int i = 0; (html.Contains("应用处罚中")|| html.Contains("购买")) && i < BaseClass.ClientIdx.Count; i++)
|
||||
{
|
||||
shop.ClientId = BaseClass.ClientIdx[i];
|
||||
client_id = shop.ClientId;
|
||||
data = "{\"clientId\":\"" + client_id + "\",\"responseType\":\"code\",\"scope\":[]}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
string code = BaseRegex.GetStringJson(ref html, "code");
|
||||
if (string.IsNullOrEmpty(code) && !html.Contains("应用处罚中"))
|
||||
{
|
||||
html = GetPostTaobaoHtml.GetJsonPostByProxy(url, refere, true, data, cookies);
|
||||
code = BaseRegex.GetStringJson(ref html, "code");
|
||||
}
|
||||
if (string.IsNullOrEmpty(code) && !html.Contains("应用处罚中") && !html.Contains("403"))
|
||||
{
|
||||
string crawlerInfo = "";
|
||||
string serverUrl = "https://mms.pinduoduo.com/hades/oauth/authed/list";
|
||||
string serverRefere = "https://mms.pinduoduo.com/service-market/my-auth";
|
||||
string serverdata = "{\"page\":1,\"pageSize\":50,\"crawlerInfo\":\"" + crawlerInfo + "\"}";
|
||||
string serverhtml = GetPostTaobaoHtml.GetJsonPost(serverUrl, serverRefere, true, serverdata, cookies, crawlerInfo);
|
||||
m = BaseRegex.GetMatchRegex(ref serverhtml, @"\{[\w\W]+?\}");
|
||||
for (int j = 0; m != null && j < m.Count; j++)
|
||||
{
|
||||
string list = m[j].Groups[0].Value;
|
||||
string id = BaseRegex.GetStringJson(ref list, "clientId");
|
||||
if (BaseClass.ClientIdx.Contains(id))
|
||||
{
|
||||
url = "https://mms.pinduoduo.com/mars/application/authorize";
|
||||
cookies = shop.Cookies;
|
||||
data = "{\"clientId\":\"" + id + "\",\"responseType\":\"code\",\"scope\":[]}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
if (html.Contains("接口已下线") || html.Contains("403"))
|
||||
{
|
||||
string codex = UploadPinduoduoMain.AntiContent;
|
||||
url = "https://mms.pinduoduo.com/hades/oauth/authorize";
|
||||
data = "{\"clientId\":\"" + client_id + "\",\"responseType\":\"code\",\"scope\":[],\"isTrial\":0,\"crawlerInfo\":\"" + codex + "\"}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
}
|
||||
if (html.Contains("403"))
|
||||
{
|
||||
for (int i = 0; i < GetProxyHtml.ipCount; i++)
|
||||
{
|
||||
var proxyObject = GetProxyHtml.GetIPSProxyQueue();
|
||||
if (proxyObject == null)
|
||||
continue;
|
||||
html = GetProxyHtml.UploadNewProxyTaobaoPost(url, refere, true, data, cookies, proxyObject);
|
||||
GetProxyHtml.IpIndex++;
|
||||
if (html.Contains("\"success\":true"))
|
||||
break;
|
||||
}
|
||||
}
|
||||
code = BaseRegex.GetStringJson(ref html, "code");
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
client_id = id;
|
||||
shop.ClientId = id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(code) && !html.Contains("应用处罚中"))
|
||||
{
|
||||
for (int i = 0; !IsCps && i < BaseClass.ClientIdx.Count; i++)
|
||||
{
|
||||
url = "https://mms.pinduoduo.com/mars/application/authorize";
|
||||
cookies = shop.Cookies;
|
||||
data = "{\"clientId\":\"" + BaseClass.ClientIdx[i] + "\",\"responseType\":\"code\",\"scope\":[]}";
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
code = BaseRegex.GetStringJson(ref html, "code");
|
||||
if (!string.IsNullOrEmpty(code))
|
||||
{
|
||||
client_id = BaseClass.ClientIdx[i];
|
||||
shop.ClientId = BaseClass.ClientIdx[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (string.IsNullOrEmpty(code))
|
||||
return false;
|
||||
}
|
||||
Shops.Add(shop.Name);
|
||||
url = BaseClass.LoginApiUrl + "pddx.php?code=" + code + "&state=" + "pbb-";
|
||||
url += sid + "-" + BaseClass.CompanyId
|
||||
+ "&client_id=" + client_id;
|
||||
html = GetHtml.Utf8(url);
|
||||
token = BaseRegex.GetStringJson(ref html, "access_token");
|
||||
refresh = BaseRegex.GetStringJson(ref html, "refresh_token");
|
||||
if (string.IsNullOrEmpty(token) || string.IsNullOrEmpty(refresh))
|
||||
return false;
|
||||
//if (string.IsNullOrEmpty(shop.ClientId))
|
||||
shop.ClientId = client_id;
|
||||
if (!IsCps)
|
||||
{
|
||||
url = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_shop_tempx&act=add_token" +
|
||||
"&shop_name=" + shop.ShopName + "&access_token=" + token + "&refresh_token=" + refresh + "&" + UserLogin.GetSignaturex();
|
||||
html = GetHtml.Utf8(url);
|
||||
}
|
||||
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/reflesh_token&act=add&client_id="+client_id +
|
||||
"&shop_name=" + shop.ShopName + "&access_token=" + token + "&refresh_token=" + refresh + "&" + UserLogin.GetSignaturex(shop.ShopId,shop.ShopName);
|
||||
html = GetHtml.Utf8(url);
|
||||
End:
|
||||
if (!IsCps)
|
||||
{
|
||||
shop.AccessToken = token;
|
||||
shop.RefreshToken = refresh;
|
||||
}
|
||||
else
|
||||
{
|
||||
shop.CpsShop.AccessToken = token;
|
||||
shop.CpsShop.RefreshToken = refresh;
|
||||
}
|
||||
return !string.IsNullOrEmpty(token);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断失效id
|
||||
/// </summary>
|
||||
/// <param name="shop"></param>
|
||||
/// <param name="client_id"></param>
|
||||
/// <returns></returns>
|
||||
public bool InvalidClientId(ShopChatBase shop, string client_id)
|
||||
{
|
||||
bool invalfalg = false;
|
||||
if (PinduoduoApiGetProduct.ShopInvalidClientID.ContainsKey(shop.ShopId))
|
||||
{
|
||||
var lst = PinduoduoApiGetProduct.ShopInvalidClientID[shop.ShopId];
|
||||
for (int i = 0; i < lst.Count; i++)
|
||||
{
|
||||
if (lst[i] == client_id)
|
||||
{
|
||||
invalfalg = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return invalfalg;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存ClientId
|
||||
/// </summary>
|
||||
/// <param name="Shop"></param>
|
||||
private void SaveToken(ShopChatBase Shop)
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=pinbaobao/cache_authorize&act=save&shop_name=" + Shop.ShopName + "&access_token=" + Shop.AccessToken + "&client_id=" + Shop.ClientId + "&refresh_token=" + Shop.RefreshToken + "&" + UserLogin.GetSignaturex();
|
||||
string html = GetHtml.Utf8(url);
|
||||
}
|
||||
private string GetToken(string ShopName)
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=pinbaobao/cache_authorize&act=get&shop_name=" + ShopName + "&" + UserLogin.GetSignaturex();
|
||||
string html = GetHtml.Utf8(url);
|
||||
return html;
|
||||
}
|
||||
public bool ReFresh(string refresh, string client_id)
|
||||
{
|
||||
string url = BaseClass.LoginApiUrl + "?obj=upshopid/pdd_refreshx&act=refresh&refresh_token=" + refresh
|
||||
+ "&client_id=" + client_id;
|
||||
string html = GetHtml.Utf8(url);
|
||||
if (!string.IsNullOrEmpty(html) && html.Contains("access_token"))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
public static string GetJsonPostURL(string url, string refere, bool isUtf8, string data, string cookies)
|
||||
{
|
||||
string userAgent = string.IsNullOrEmpty(BaseClass.ChromeUserAgent) ? BaseClass.UserAgent : BaseClass.ChromeUserAgent;
|
||||
WebClientx wb = new WebClientx();
|
||||
wb.Timeout = 10;
|
||||
wb.AllowAutoRedirect = false;
|
||||
wb.Headers.Add("Upgrade-Insecure-Requests", @"1");
|
||||
wb.Headers.Add("Accept-Encoding", "gzip,deflate,br");
|
||||
wb.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
|
||||
wb.Headers.Add("User-Agent", userAgent);
|
||||
wb.Headers.Add("Sec-Fetch-Site", @"same-site");
|
||||
wb.Headers.Add("Sec-Fetch-Mode", @"navigate");
|
||||
wb.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
|
||||
wb.Headers.Add("Referer", "https://mms.pinduoduo.com/login/sso?platform=fuwu&redirectUrl=https%3A%2F%2Ffuwu.pinduoduo.com%2Fclint%2Fapi%2Flogin%3Fredirect%3Dhttps%253A%252F%252Ffuwu.pinduoduo.com%252Fservice-market%252Fmy-service");
|
||||
if (!string.IsNullOrEmpty(cookies))
|
||||
wb.Headers.Add("Cookie", cookies);
|
||||
string rehead = wb.Headers.ToString();
|
||||
var encode = isUtf8 ? Encoding.UTF8 : Encoding.GetEncoding("gbk");
|
||||
byte[] b, postData = encode.GetBytes(data);
|
||||
string html, head;
|
||||
try
|
||||
{
|
||||
//wb.Headers.Add("Accept", "application/json");
|
||||
//wb.Headers.Add("Content-Type", "application/json; charset=UTF-8");
|
||||
if (string.IsNullOrEmpty(data))
|
||||
{
|
||||
b = wb.DownloadData(url);
|
||||
}
|
||||
else
|
||||
{
|
||||
wb.Headers.Add("ContentLength", postData.Length.ToString());
|
||||
rehead = wb.Headers.ToString();
|
||||
b = wb.UploadData(url, "POST", postData);
|
||||
}
|
||||
html = encode.GetString(b);
|
||||
head = wb.ResponseHeaders.ToString();
|
||||
html = wb.ResponseHeaders["Set-Cookie"];
|
||||
}
|
||||
catch (Exception ee)
|
||||
{
|
||||
html = "提交错误:" + ee.Message;
|
||||
head = "";
|
||||
}
|
||||
return html;
|
||||
}
|
||||
|
||||
public string GetClientId(string clientName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(clientName))
|
||||
return "";
|
||||
string result = "";
|
||||
switch (clientName.ToUpper())
|
||||
{
|
||||
case "螃蟹工具":
|
||||
result = "7feaefdf527d45129219ca398c922bb0";
|
||||
break;
|
||||
case "奶爸助理":
|
||||
result = "f4a3e3bb0253448d8272537726299621";
|
||||
break;
|
||||
case "途途上货助手":
|
||||
result = "b1981defcd704a7d88c8a734358fb065";
|
||||
break;
|
||||
case "微木ERP":
|
||||
result = "81fd2bbabbd54ec5bf312e05401a0343";
|
||||
break;
|
||||
case "蛮牛工具":
|
||||
result = "911bd1c0c0a0403da88334e24ca288a2";
|
||||
break;
|
||||
case "微木订单":
|
||||
result = "5d755c0cf97a4cbdb8aa958beea25011";
|
||||
break;
|
||||
case "点金工具箱":
|
||||
result = "3069c1c325e44e85bcf5b6295694bdae";
|
||||
break;
|
||||
case "拼商宝":
|
||||
result = "9558f920cf77403bb475243fe44482ad";
|
||||
break;
|
||||
case "凯达工具":
|
||||
result = "88d6ef134c3b4a07b7a22d8bbef9b1b4";
|
||||
break;
|
||||
case "飓风管家":
|
||||
result = "f23bda7f6d9c4b6c8751268891779660";
|
||||
break;
|
||||
case "飓风发货":
|
||||
result = "9f7d0ce6460b46e7a3833ac2e8325519";
|
||||
break;
|
||||
case "运筹ERP":
|
||||
result = "716a6bcc69d7441d856905eb79b892fd";
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,205 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using CefSharp.WinForms;
|
||||
using Work.CollectClass;
|
||||
using AllBase;
|
||||
using WebSocketSharp;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class ShopChatBase
|
||||
{
|
||||
public string ShopId = "";
|
||||
public DateTime EndDate = DateTime.Now.AddDays(-1);
|
||||
public DateTime EndDateExplode = DateTime.Now.AddDays(-1);
|
||||
public string ShopName = "";
|
||||
public string Name = "";
|
||||
public string UserName = "";
|
||||
public string UserInfo = "";
|
||||
public string PassId = "";
|
||||
public string ClientId = "";
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public ChromiumWebBrowser Chat = null;
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public ChromiumWebBrowser Main = null;
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public WebSocket client = null;
|
||||
public string clientMessage = "";
|
||||
public bool clientflag = false;
|
||||
public int ChatCount = 0;
|
||||
public string Cookies = "";
|
||||
public string CookiesUid = "";
|
||||
public string CookiesPid = "";
|
||||
public string Password = "";
|
||||
public string Message = "";
|
||||
public string APIMessage = "";
|
||||
public string bondedWarehouseKey = "";
|
||||
public string bondedWarehouseName = "";
|
||||
public string pjtToken = "";
|
||||
/// <summary>
|
||||
/// 是否续费和有cookies
|
||||
/// </summary>
|
||||
public bool Showed = false;
|
||||
/// <summary>
|
||||
/// 是否高级突破
|
||||
/// </summary>
|
||||
public bool Explode = false;
|
||||
/// <summary>
|
||||
/// 店铺是否可上传
|
||||
/// </summary>
|
||||
public bool CanUpload = false;
|
||||
/// <summary>
|
||||
/// 选择
|
||||
/// </summary>
|
||||
public bool Select = false;
|
||||
/// <summary>
|
||||
/// 极品飞车推广专用
|
||||
/// </summary>
|
||||
public bool SelectForFlightCar = false;
|
||||
/// <summary>
|
||||
/// 极品飞车优化专用
|
||||
/// </summary>
|
||||
public bool SelectForFlightCar2 = false;
|
||||
/// <summary>
|
||||
/// 极品飞车推广答题考试专用
|
||||
/// </summary>
|
||||
public bool SelectForFlightCar3 = false;
|
||||
|
||||
/// <summary>
|
||||
/// 极品飞车定时检测专用
|
||||
/// </summary>
|
||||
public bool SelectForFlightCar4 = false;
|
||||
/// <summary>
|
||||
/// 极品飞车明细专用
|
||||
/// </summary>
|
||||
public bool SelectForFlightCar5 = false;
|
||||
|
||||
/// <summary>
|
||||
/// 选择
|
||||
/// </summary>
|
||||
public bool SelectReplace = false;
|
||||
public bool SelectClearDown = false;
|
||||
public bool SelectPayOrder = false;
|
||||
public bool SelectStore = false;
|
||||
public bool SelectFood = false;
|
||||
public bool SelectMedicinal = false;
|
||||
public bool SelectResure = false;
|
||||
public bool SelectPlan = false;
|
||||
public bool SelectCps = false;
|
||||
public bool SelectVio = false;
|
||||
public bool SelectAdv = false;
|
||||
public bool SelectQue = false;
|
||||
public bool SelectWhite = false;
|
||||
public bool SelectCoS = false;
|
||||
public bool SelectResurVio = false;
|
||||
public bool SelectWithMoney = false;
|
||||
public bool SelectProductCheck = false;
|
||||
public int X = 0;
|
||||
public int Y = 0;
|
||||
public int MallId = 0;
|
||||
/// <summary>
|
||||
/// 店铺主营类目
|
||||
/// </summary>
|
||||
public int MainCatId = 0;
|
||||
public int ReceiverId = 0;
|
||||
public string MainCatName = "";
|
||||
public string UserCatName = "";
|
||||
public int UpCount = 0;
|
||||
public int ProductCount = 0;
|
||||
public long ExpressId = 0;
|
||||
public int WaitTimes = 0;
|
||||
public string AccessToken = "";
|
||||
public string RefreshToken = "";
|
||||
public int GoodsCount = 0;
|
||||
public int MappCount = 0;
|
||||
public List<TaobaoProductBase> ReplaceTitleProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> OnlineProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> OnOrOffProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> OnOrOffArrProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> ResurVioProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> ResurVioSalesProduct = new List<TaobaoProductBase>();
|
||||
public List<long> OnIds = new List<long>();
|
||||
public List<long> OffIds = new List<long>();
|
||||
public List<TaobaoProductBase> SellOutProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> jinBaoProduct = new List<TaobaoProductBase>();
|
||||
public List<TaobaoProductBase> VioProduct = new List<TaobaoProductBase>();
|
||||
public List<ProductVisitBase> Visit = new List<ProductVisitBase>();
|
||||
public DateTime Expiration = DateTime.Now.AddDays(-1);
|
||||
public string commission = "";
|
||||
public WithDraw withDraw = new WithDraw();
|
||||
public Dictionary<string, int> SignErrorTimes = new Dictionary<string, int>();
|
||||
/// <summary>
|
||||
/// 已上传过的商品
|
||||
/// </summary>
|
||||
public Dictionary<long, int> UpFromIds = new Dictionary<long, int>();
|
||||
public ShopChatBase Clone()
|
||||
{
|
||||
string html = JsonHelper.SerializeObject(this);
|
||||
ShopChatBase tp = JsonHelper.DeserializeJsonToObject<ShopChatBase>(html);
|
||||
return tp;
|
||||
}
|
||||
|
||||
public CpsShopBase CpsShop = new CpsShopBase();
|
||||
public class CpsShopBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 全店进宝佣金比例
|
||||
/// </summary>
|
||||
public string Percent = "";
|
||||
/// <summary>
|
||||
/// 店铺商品总数
|
||||
/// </summary>
|
||||
public int GoodsCount = 0;
|
||||
/// <summary>
|
||||
/// 已有进宝数
|
||||
/// </summary>
|
||||
public int HadCpsCount = 0;
|
||||
/// <summary>
|
||||
/// 新增进宝数
|
||||
/// </summary>
|
||||
public int NewCpsCount = 0;
|
||||
/// <summary>
|
||||
/// 未达标进宝数
|
||||
/// </summary>
|
||||
public int InvalidCpsCount = 0;
|
||||
/// <summary>
|
||||
/// 店铺开通状态,0:待查询 1:已开通特权 2:未开通 3:非特权开通
|
||||
/// </summary>
|
||||
public int Status = 0;
|
||||
|
||||
public string StatusString
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Status == 0)
|
||||
return "待查询";
|
||||
if (Status == 1)
|
||||
return "已开通";
|
||||
if (Status == 2)
|
||||
return "待同意协议";
|
||||
if (Status == 3)
|
||||
return "可设置";
|
||||
return "待查询";
|
||||
}
|
||||
}
|
||||
public string Message = "";
|
||||
public string AccessToken = "";
|
||||
public string RefreshToken = "";
|
||||
public Dictionary<long, decimal> GoodsIds = new Dictionary<long, decimal>();
|
||||
}
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public DelGroupStatus ArrangeShop = new DelGroupStatus();
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public DelGroupStatus AutoShop = new DelGroupStatus();
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public DelGroupStatus DelGroupShop = new DelGroupStatus();
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
public DelGroupStatus ClearNoVisitShop = new DelGroupStatus();
|
||||
}
|
||||
public class UpProId
|
||||
{
|
||||
public string upProIdOne = "";
|
||||
public string upProIdTwo = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using AllBase;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Work.CollectClass;
|
||||
using Work.ManageClass;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class TaoJiJiProductGet
|
||||
{
|
||||
public ProductCollectBase Product;
|
||||
public bool IsPinduoduo = false;
|
||||
public bool OnSale = true;
|
||||
public TaoJiJiProductGet(ProductCollectBase p)
|
||||
{
|
||||
Product = p;
|
||||
}
|
||||
|
||||
public void Get()
|
||||
{
|
||||
if (TaobaoMobileCollect.ProductTemp.ContainsKey(Product.from_id))
|
||||
{
|
||||
Product = TaobaoMobileCollect.ProductTemp[Product.from_id].Clone();
|
||||
return;
|
||||
}
|
||||
string url = Product.from_url;
|
||||
string refere = string.Empty;
|
||||
string html = GetPostTaobaoHtml.GetUrl(url, refere, true, string.Empty);
|
||||
JObject json = JObject.Parse(html);
|
||||
if (json["result"].ToString() == "1")
|
||||
{
|
||||
var data = json["data"];
|
||||
Product.from_cat_id = BaseRegex.GetIntJson(ref html, @"catid");
|
||||
Product.item_size = "";
|
||||
Product.item_weight = 1;
|
||||
Product.price = data["price"].ParseToDecimal();
|
||||
Product.discount = 0;
|
||||
Product.discountPrice = 0;
|
||||
if (Product.discount == 0)
|
||||
{
|
||||
Product.discount = 1;
|
||||
Product.discountPrice = Product.price;
|
||||
}
|
||||
Product.name = data["name"].ParseToString();
|
||||
foreach (string s in AlibabaShop.NoTitleWords)
|
||||
{
|
||||
Product.name = Product.name.Replace(s, "");
|
||||
}
|
||||
Product.sell_pt = "";
|
||||
var album = data["album"];
|
||||
foreach (var image in album)
|
||||
{
|
||||
Product.Images.Add(image["img640url"].ParseToString());
|
||||
}
|
||||
Product.image = Product.Images[0];
|
||||
Product.image_from_url = Product.image;
|
||||
Product.image_path = "";
|
||||
|
||||
var contentImage = data["image"];
|
||||
foreach (var image in contentImage)
|
||||
{
|
||||
Product.content += "<img src='" + image["img640url"].ParseToString().Replace("_480_480", "_750_750").Replace("_640_640", "_750_750") + "' />";
|
||||
}
|
||||
SetSkuMap(data);
|
||||
}
|
||||
Product.main_cid = 0;
|
||||
Product.from_title = Product.name;
|
||||
Product.from_site_id = 3;
|
||||
Product.main_cid = new FromTitleToCat().GetMainCatId(Product.cat1);
|
||||
if (Product.main_cid == 0)
|
||||
return;
|
||||
if (TaobaoMobileCollect.ProductTemp.Count > 1000)
|
||||
{
|
||||
TaobaoMobileCollect.ProductTemp.Clear();
|
||||
}
|
||||
|
||||
if (!TaobaoMobileCollect.ProductTemp.ContainsKey(Product.from_id))
|
||||
{
|
||||
TaobaoMobileCollect.ProductTemp.Add(Product.from_id, Product);
|
||||
}
|
||||
LogSave.Add("获取成功:" + Product.name);
|
||||
}
|
||||
|
||||
public void SetSkuMap(JToken json)
|
||||
{
|
||||
var skuList = json["show"];
|
||||
foreach (var sku in skuList.Values())
|
||||
{
|
||||
PropBase p = new PropBase();
|
||||
p.name = sku["label"].ParseToString();
|
||||
p.sort++;
|
||||
|
||||
var skuValueList = sku["list"];
|
||||
foreach (var skuValue in skuValueList)
|
||||
{
|
||||
PropValueBase pr = new PropValueBase();
|
||||
pr.name = skuValue.ParseToString();
|
||||
pr.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
|
||||
p.Values.Add(pr);
|
||||
}
|
||||
Product.Props.Add(p);
|
||||
}
|
||||
var specList = json["spec"];
|
||||
foreach (var spec in specList)
|
||||
{
|
||||
SkuMapBase sm = new SkuMapBase();
|
||||
foreach (JProperty attr in spec["attr"].Children().OfType<JProperty>())
|
||||
{
|
||||
string titleName = skuList[attr.Name]["label"].ParseToString();
|
||||
sm.name += titleName + ":" + attr.Value.ToString() + ";";
|
||||
}
|
||||
sm.name = sm.name.Trim(';');
|
||||
sm.prop_image = spec["smallImgUrl"].ParseToString();
|
||||
sm.price = spec["groupPrice"].ParseToDecimal();
|
||||
sm.prop_image = spec["smallImgUrl"].ParseToString();
|
||||
int nu = 0;
|
||||
int.TryParse(spec["stocknum"].ParseToString(), out nu);
|
||||
sm.number = nu;
|
||||
Product.SkuMaps.Add(sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using AllBase;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using JavaScriptEngineSwitcher.Core;
|
||||
using JavaScriptEngineSwitcher.V8;
|
||||
using Work.CollectClass;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
|
||||
namespace Work.Api
|
||||
{
|
||||
public class UpdatePinduoduoExpressSet
|
||||
{
|
||||
public static List<KeyValueBase> Express = new List<KeyValueBase>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取最后一个运费模板
|
||||
/// </summary>
|
||||
/// <param name="cookies"></param>
|
||||
/// <param name="mallid"></param>
|
||||
/// <param name="Shop"></param>
|
||||
/// <returns></returns>
|
||||
public long GetFirst(string cookies, int mallid, ShopChatBase Shop)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""costTemplateId"":[\s]*([\d]+)");
|
||||
long id = 0;
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
long j = long.Parse(m[0].Groups[1].Value);
|
||||
if (j > id)
|
||||
id = j;
|
||||
}
|
||||
if (id > 0)
|
||||
return id;
|
||||
html = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate();
|
||||
m = BaseRegex.GetMatchRegex(ref html, @"""template_id"":[\s]*([\d]+)");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
long j = long.Parse(m[0].Groups[1].Value);
|
||||
if (j > id)
|
||||
id = j;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定第几新的运费模板,如果超过模板总数,返回最旧的一个
|
||||
/// </summary>
|
||||
/// <param name="cookies"></param>
|
||||
/// <param name="mallid"></param>
|
||||
/// <param name="Shop"></param>
|
||||
/// <param name="Rank">排名第几新的运费模板</param>
|
||||
/// <returns></returns>
|
||||
public long GetOneRank(string cookies, int mallid, ShopChatBase Shop, ref int rank)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""costTemplateId"":[\s]*([\d]+)");
|
||||
List<long> tempIds = new List<long>();
|
||||
long id = 0;
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
long j = long.Parse(m[0].Groups[1].Value);
|
||||
if (j > 0)
|
||||
tempIds.Add(j);
|
||||
}
|
||||
if (tempIds.Count > 0)
|
||||
{
|
||||
tempIds = tempIds.OrderByDescending(t => t).ToList();
|
||||
if (rank < tempIds.Count - 1)
|
||||
return tempIds[rank];
|
||||
else
|
||||
{
|
||||
rank = 1000;
|
||||
return tempIds.Last();
|
||||
}
|
||||
}
|
||||
|
||||
// 使用api获取
|
||||
html = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate();
|
||||
m = BaseRegex.GetMatchRegex(ref html, @"""template_id"":[\s]*([\d]+)");
|
||||
for (int i = 0; m != null && i < m.Count; i++)
|
||||
{
|
||||
long j = long.Parse(m[0].Groups[1].Value);
|
||||
if (j > 0)
|
||||
tempIds.Add(j);
|
||||
}
|
||||
if (tempIds.Count > 0)
|
||||
{
|
||||
tempIds = tempIds.OrderByDescending(t => t).ToList();
|
||||
if (rank < tempIds.Count - 1)
|
||||
return tempIds[rank];
|
||||
else
|
||||
{
|
||||
rank = 1000;
|
||||
return tempIds.Last();
|
||||
}
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public long GetRandx(string cookies, int mallid, ShopChatBase Shop)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/express_inf/cost_template/get_list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
var m = BaseRegex.GetMatchRegex(ref html, @"""costTemplateId"":[\s]*([\d]+)");
|
||||
long id = 0;
|
||||
if (m == null)
|
||||
goto UseApi;
|
||||
if (m.Count == 1)
|
||||
{
|
||||
long tid = BaseRegex.GetLongJson(ref html, "costTemplateId");
|
||||
string urlxt = "https://mms.pinduoduo.com/express_inf/cost_template/copy";
|
||||
string referext = "https://mms.pinduoduo.com/orders/order/carriage/list";
|
||||
string dataxt = "{\"costTemplateId\":" + tid + ",\"sourceKey\":\"MMS\"}";
|
||||
string htmlxt = Request_mms_pinduoduo_com(urlxt, referext, Shop.Cookies, dataxt, getAnti0aon());
|
||||
if (htmlxt.Contains("ok"))
|
||||
{
|
||||
html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
tid = BaseRegex.GetLongJson(ref html, "costTemplateId");
|
||||
return tid;
|
||||
}
|
||||
}
|
||||
int randx = new Random(Guid.NewGuid().GetHashCode()).Next(1, m.Count);
|
||||
return long.Parse(m[randx].Groups[1].Value);
|
||||
UseApi:
|
||||
html = new PinduoduoApiGetProduct(Shop).GetLogisticsTemplate();
|
||||
m = BaseRegex.GetMatchRegex(ref html, @"""template_id"":[\s]*([\d]+)");
|
||||
if (m == null || m.Count <= 1)
|
||||
return id;
|
||||
int randxt = new Random(Guid.NewGuid().GetHashCode()).Next(1, m.Count);
|
||||
return long.Parse(m[randxt].Groups[1].Value);
|
||||
}
|
||||
|
||||
public int GetFirst(string cookies, int mallid)
|
||||
{
|
||||
string url = "https://mms.pinduoduo.com/express_base/cost_template/get_list";
|
||||
string refere = "https://mms.pinduoduo.com/Pdd.html";
|
||||
string data = "{\"mallId\":" + mallid + ",\"pageNo\":1,\"pageSize\":1000}";
|
||||
string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies);
|
||||
int id = BaseRegex.GetIntJson(ref html, "costTemplateId");
|
||||
return id;
|
||||
}
|
||||
public static string Request_mms_pinduoduo_com(string url, string referer, string cookie, string data, string antiContent, IWebProxy proxy = null)
|
||||
{
|
||||
string responseText = "";
|
||||
HttpWebResponse response = null;
|
||||
|
||||
try
|
||||
{
|
||||
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://mms.pinduoduo.com/cps/api/coupon/createCommonCoupon");
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Accept = "application/json";
|
||||
//request.Headers.Add("Anti-Content", @"0aoAfxnUgOQoU9dVEHIuLKYezEfQ51QpOcKVg_S0aww9S8dseM_tTxYptgFssmH7wfRCpRvfISyXp-bZ8hcq7ux0Z1kvhFUkfIMk7EsEefUAZS7Jv1vYHm1Cplb4GZ43dSFtKu19dO7snIyL-VRj0JFy0ETKDkf1EdaPbWEu22sZ4s1duGD6WO9lgeS-oTsEwwa9ohcX2E_DG2PggPHqIuxcN_tIthAewaqklSPvPmFwzYxrlo256wd2i74SMvTzGTB--UkZ3gPl5t6K-6IVCz1MDD7WDS9HeoGm4RBmyd0LIpXG400lOfKBvPh-z09PL3_hjiL1KiBCENrs1ANosN35LJ8zhlCRi0YrDxphd8LGJFWDG0LrARGRuMW7d3d4IlWlEKFFMiucGGNlIZqDyExDIMny-8T-KY8fJ8BnNuzWyr");
|
||||
request.Headers.Add("Anti-Content", antiContent);
|
||||
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36";
|
||||
request.UserAgent = BaseClass.ChromeUserAgent;
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
request.Headers.Add("Origin", @"https://mms.pinduoduo.com");
|
||||
request.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
||||
request.Headers.Add("Sec-Fetch-Mode", @"cors");
|
||||
request.Headers.Add("Sec-Fetch-Dest", @"empty");
|
||||
request.Referer = referer;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, cookie);
|
||||
if (proxy != null)
|
||||
request.Proxy = proxy;
|
||||
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
|
||||
string body = data;
|
||||
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
|
||||
request.ContentLength = postBytes.Length;
|
||||
Stream stream = request.GetRequestStream();
|
||||
stream.Write(postBytes, 0, postBytes.Length);
|
||||
stream.Close();
|
||||
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||||
else responseText = "error," + e.Message;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
responseText = "error," + ex.Message;
|
||||
}
|
||||
if (response != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(responseText))
|
||||
responseText = ReadResponse(response);
|
||||
response.Close();
|
||||
}
|
||||
|
||||
Thread.Sleep(50 + Randomx.GetId(100));
|
||||
|
||||
return responseText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取返回值
|
||||
/// </summary>
|
||||
/// <param name="response"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadResponse(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 static string getAnti0aon()
|
||||
{
|
||||
string anti = "";
|
||||
using (IJsEngine jsEngine = new V8JsEngine())
|
||||
{
|
||||
jsEngine.Execute(GetProductOnlineClass.PinDuoDUo_0ao);
|
||||
anti = jsEngine.CallFunction("get_anti", "").ToString();
|
||||
try
|
||||
{ anti = "0ao" + anti.Substring(3); }
|
||||
catch { }
|
||||
}
|
||||
return anti;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user