Files
KJD_WebService/Work/CollectClass/TaobaoMobileCollect.cs
T
2025-06-29 19:38:31 +08:00

2843 lines
140 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AllBase;
using Work.CollectClass;
using System.IO;
using System.Text.RegularExpressions;
using Work.Api;
using System.IO.Compression;
using Newtonsoft.Json.Linq;
using System.Security.Cryptography;
using System.Windows.Forms;
using Work.BLL.Upload;
using AllBase.Extension;
using NaiBa.Util.Extension;
namespace Work.CollectClass
{
public class TaobaoMobileCollect
{
public string Name, Content;
public bool IsPreSale = false; // 是否预售
public bool IsUrlCollect = false, Pinduoduo = false;
public bool IsUpdateSku = false, ThisShopId = false;
public bool GetSuccess = false, NoTemp = false, Delete = false, NoContent = false, IsDown = false, NoUpToServer = false;
public static bool LastError = false;
public static bool IsProxyOverdue = false;
public decimal BeforePrice = 0, MinPrice = 0, MaxPrice = 0;
public static Dictionary<long, ProductCollectBase> ProductTemp = new Dictionary<long, ProductCollectBase>();
public bool hasCookies = false;
public ProductCollectBase Product;
public string taoBaoCookies;
/// <summary>
/// 是否是净化数据模块
/// </summary>
public bool IsPurifyData = false;
public static Dictionary<string, string> CookiesDic = new Dictionary<string, string>();
public static Dictionary<string, bool> CurrentCookiesDic = new Dictionary<string, bool>();
/// <summary>
/// 淘宝采集控制锁,防止高并发导致淘宝采集cookie被限制
/// </summary>
private static readonly object _lockerCollectTaobaoDetail = new object();
public string pbMessage = "";
public TaobaoMobileCollect(ProductCollectBase product)
{
Product = product;
}
private string GetTaobaoProductMainInfoAndDesc(long productId, bool isVerify, string f = "", string sMainOrDesc = "Main")
{
HttpWebResponse response;
string html = MakeRequestThroughTradeAscM(productId, isVerify, out response, sMainOrDesc, f);
if (isVerify && html.Contains("被挤爆啦"))
{
while (Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) != null)
{
Thread.Sleep(2000);
}
}
return html;
}
private string GetTaobaoProductMainInfoAndDescProxyNew(long productId, string uri, string f = "", string sMainOrDesc = "Main")
{
//HttpWebResponse response;
//return MakeRequestThroughTradeAscMNew(productId, out response, sMainOrDesc, f);
//return GetProxyHtml.Request_TaoBao_com(GetProxyHtml.txtUrl, productId, GetProxyHtml.UserAgentList.ToArray(), out IsProxyOverdue, sMainOrDesc, f);
return GetProxyHtml.RequestUrl_TaoBao_com(productId, uri, GetProxyHtml.UserAgentList.ToArray(), out IsProxyOverdue);
}
private string GetTaobaoProductMainInfo(long productId, string sMainOrDesc = "Main")
{
HttpWebResponse response;
return MakeRequestProductMainInfo(productId, out response, sMainOrDesc);
}
private string GetTaobaoProductMainInfoAndDescNew(long productId, bool isVerify, string f = "", string sMainOrDesc = "Main")
{
HttpWebResponse response;
string html = MakeRequestThroughTradeAscMNew(productId, isVerify, out response, sMainOrDesc, f);
if (isVerify && html.Contains("被挤爆啦"))
{
while (Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) != null)
{
Thread.Sleep(2000);
}
}
return html;
}
/// <summary>
/// 通过MtopAlibaba Api获取淘宝Detail
/// </summary>
/// <param name="productId"></param>
/// <returns></returns>
private string GetTaobaoProductDetailByMtopAlibabaApi(long productId, bool isVerify)
{
HttpWebResponse response;
bool isRetry = false;
retry:
string html = MakeRequestThroughMtopAlibaba(productId, isVerify, out response);
if (isVerify && html.Contains("登陆"))
{
if (string.IsNullOrEmpty(BaseClass.IeUrlShow) && Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) == null)
BaseClass.IeUrlShow = "https://login.taobao.com/member/login.jhtml?style=mini&newMini2=true&redirectURL=https://s.taobao.com/search?q=se&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.1&ie=utf8&initiative_id=tbindexz_20170306";
Thread.Sleep(5000);
while (Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) != null)
{
Thread.Sleep(1000);
}
if (isRetry == false)
{
isRetry = true;
goto retry;
}
}
if (isVerify && html.Contains("被挤爆啦"))
{
string sPunishUrl = BaseRegex.GetStringJson(ref html, "url");
BaseClass.IeUrlShow = sPunishUrl;
Thread.Sleep(5000);
while (Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) != null)
{
Thread.Sleep(1000);
}
if (isRetry == false)
{
isRetry = true;
goto retry;
}
}
return html;
}
/// <summary>
/// 模拟请求通过MtopAlibaba Api获取淘宝Detail
/// </summary>
/// <param name="productId"></param>
/// <param name="response"></param>
/// <returns></returns>
private string MakeRequestThroughMtopAlibaba(long productId, bool isVerify, out HttpWebResponse response)
{
response = null;
try
{
var utdid = "XUEI6Cqy4UgDAHCsEH0z5one";
var uid = "";
var appKey = "25443018";
var t = BaseClass.GetTime(BaseClass.GetServerTimeString()).ToString();
var sid = "";
var deviceId = @"AqjuNSqg5WtUMlGAgV2ZsudCBHdVINyeYYmyjrge4w2P";
var features = "27";
var x_pv = "5.1";
var data = "{\"exParams\":\"{\\\"id\\\":\\\"" + productId + "\\\",\\\"version\\\":\\\"3.0.0\\\",\\\"enterNewLink\\\":true,\\\"miniChannel\\\":true,\\\"itemId\\\":\\\"" + productId + "\\\",\\\"flutter\\\":true,\\\"originalUrl\\\":\\\"\\\",\\\"utparam\\\":\\\"\\\",\\\"itemBanner\\\":\\\"\\\"}\",\"itemId\":\"" + productId + "\",\"ttid\":\"11320@taobao_android_5.0.0\"}";
var olData = data;
string url_getSign = url_getSign = BaseClass.BuildObjString("get_taobao_sign&act=get_tb_sign");
string url_data = UserLogin.GetSignaturex("", "");
string sign = string.Empty;
int iTryTimes = 0;
LbGetTaobaoSign:
sign = GetHtml.PostUtf8(url_getSign, url_data + "&t=" + t + "&api=mtop.alibaba.jnpiter.detail.getdetail&v=1.0&data=" + data);
if (string.IsNullOrEmpty(sign) && iTryTimes < 3)
{
iTryTimes++;
goto LbGetTaobaoSign;
}
var url = "http://trade-acs.m.taobao.com/gw/mtop.alibaba.jnpiter.detail.getdetail/1.0/?data=" + GetHtml.UrlEncodeUtf8(data);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
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);
request.Headers.Set(HttpRequestHeader.Cookie, taoBaoCookies);
//string s = Randomx.GetWord(Randomx.GetId(5, 10));
//string sCookie = $"x5sec=Õâ¸ö½Ó¿ÚÌ«ÄÑÁËww{s};cookie17={s};unb={s};dnk={s};";
//request.Headers.Set(HttpRequestHeader.Cookie, sCookie);
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-mini-wua", @"HHnB_7IQ%2FC9%2BKRTErVPjrtzNx4iE6tVh2dyw0qkwtnCJmdk7wZ2y0NPDSmcBAC3Gx0pWM%2FVBDBLrDfE2diEE2Q%2BYXQd%2FMd5vQPLCzV2Mmq5SfLifuh3sHasrpVbdRys4tobC8");
request.Headers.Add("x-nettype", @"WIFI");
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "deflate");
request.Timeout = 10000;
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
else return "";
}
catch (Exception)
{
if (response != null) response.Close();
return "";
}
if (response != null)
{
string responseText = ReadResponse(response);
if (isVerify && !string.IsNullOrEmpty(responseText) && responseText.Contains("被挤爆啦"))
{
BaseClass.IeUrlShow = response.Headers["Location"];
Thread.Sleep(10 * 1000);
}
return responseText;
}
return "";
}
private string MakeRequestProductMainInfo(long sProductId, out HttpWebResponse response, string sMainOrDesc = "Main", string f = "")
{
response = null;
int count = 0;
Again:
try
{
count++;
System.DateTime starttime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
DateTime datetime = BaseClass.GetServerTimeString();
long t = (long)(datetime - starttime).TotalMilliseconds; // 相差毫秒数
var client = new Random(Guid.NewGuid().GetHashCode()).Next(1000, 100000);
string sign = BaseClass.GetMd5("client=" + client + "&time=" + t + "shiyixuan").ToLower();
string url = "http://81.68.239.162:8080/check?group=tbtv&action=registerGetData&client=" + client + "&time=" + t + "&sign=" + sign + "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
request.UserAgent = "taobao";
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Accept = "*/*";
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.ServicePoint.Expect100Continue = false;
string body = @"data=%7B%22detail_v%22%3A+%223.1.0%22%2C+%22itemNumId%22%3A+%22" + sProductId + "%22%7D&api=mtop.taobao.detail.getdetail&ttid=142857%40taobao_iphone_7.10.3&v=6.0&hasExtParams=1";
if (sMainOrDesc == "Desc")
body = "data=%7B%22detail_v%22%3A+%223.3.2%22%2C+%22f%22%3A+%22TB1XRE2VND1gK0jSZFs8qvldVXa%22%2C+%22id%22%3A+%22" + sProductId + "%22%2C+%22isShowWeex%22%3A+%220%22%2C+%22shopId%22%3A+%22210079136%22%7D&api=mtop.taobao.detail.getdesc&ttid=142857%40taobao_iphone_7.10.3&v=6.0&hasExtParams=1";
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 (count < 3)
{
Thread.Sleep(300);
goto Again;
}
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
else return "";
}
catch (Exception)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
if (response != null) response.Close();
return "";
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
}
if (response != null)
{
string responseText = ReadResponse(response);
if (!string.IsNullOrEmpty(responseText) && responseText.Contains("https://login.m.taobao") && count < 2)
{
Thread.Sleep(1000);
goto Again;
}
return responseText;
}
return "";
}
private string MakeRequestThroughTradeAscM(long sProductId, bool isVerify, out HttpWebResponse response, string sMainOrDesc = "Main", string f = "")
{
response = null;
int count = 0;
Again:
try
{
count++;
bool bIsGetDesc = !sMainOrDesc.Equals("Main");
var utdid = "XUEI6Cqy4UgDAHCsEH0z5one";
var uid = "";
var appKey = "25443018";
var t = BaseClass.GetTime(BaseClass.GetServerTimeString()).ToString();
var sid = "";
var deviceId = @"AqjuNSqg5WtUMlGAgV2ZsudCBHdVINyeYYmyjrge4w2P";
var features = "27";
var x_pv = "5.1";
var data = bIsGetDesc ? "{\"id\":\"" + sProductId + "\",\"type\":\"0\",\"f\":\"" + f + "\"}"
: "{\"detail_v\":\"3.3.2\",\"exParams\":\"{\\\"action\\\":\\\"ipv\\\",\\\"ad_type\\\":\\\"1.0\\\",\\\"appReqFrom\\\":\\\"detail\\\",\\\"container_type\\\":\\\"xdetail\\\",\\\"countryCode\\\":\\\"CN\\\",\\\"device\\\":\\\"56\\\",\\\"dinamic_v3\\\":\\\"true\\\",\\\"from\\\":\\\"search\\\",\\\"id\\\":\\\"" + sProductId + "\\\",\\\"item_id\\\":\\\"" + sProductId + "\\\",\\\"latitude\\\":\\\"0\\\",\\\"list_type\\\":\\\"search\\\",\\\"longitude\\\":\\\"0\\\",\\\"osVersion\\\":\\\"23\\\",\\\"phoneType\\\":\\\"MuMu\\\",\\\"search_action\\\":\\\"initiative\\\",\\\"soVersion\\\":\\\"2.0\\\",\\\"ultron2\\\":\\\"true\\\",\\\"utdid\\\":\\\"XUEI6Cqy4UgDAHCsEH0z5one\\\"}\",\"itemNumId\":\"" + sProductId + "\"}";
var olData = data;
string url_getSign = BaseClass.BuildObjString("get_taobao_sign&act=get_tb_sign");
string url_data = UserLogin.GetSignaturex("", "");
if (!string.IsNullOrEmpty(f)) url_data += "&f=" + f;
if (!bIsGetDesc) url_data += "&bIsGetDesc=main";
string sign = GetHtml.PostUtf8(url_getSign, url_data + "&t=" + t + "&sProductId=" + sProductId);
var url = bIsGetDesc ? "http://trade-acs.m.taobao.com/gw/mtop.taobao.detail.getdesc/6.0/?type=1&data=" + GetHtml.UrlEncodeUtf8(olData)
: "http://trade-acs.m.taobao.com/gw/mtop.taobao.detail.getdetail/6.0/?data=%7B%22detail_v%22%3A%223.3.2%22%2C%22exParams%22%3A%22%7B%5C%22action%5C%22%3A%5C%22ipv%5C%22%2C%5C%22ad_type%5C%22%3A%5C%221.0%5C%22%2C%5C%22appReqFrom%5C%22%3A%5C%22detail%5C%22%2C%5C%22container_type%5C%22%3A%5C%22xdetail%5C%22%2C%5C%22countryCode%5C%22%3A%5C%22CN%5C%22%2C%5C%22device%5C%22%3A%5C%2256%5C%22%2C%5C%22dinamic_v3%5C%22%3A%5C%22true%5C%22%2C%5C%22from%5C%22%3A%5C%22search%5C%22%2C%5C%22id%5C%22%3A%5C%22" + sProductId + "%5C%22%2C%5C%22item_id%5C%22%3A%5C%22" + sProductId + "%5C%22%2C%5C%22latitude%5C%22%3A%5C%220%5C%22%2C%5C%22list_type%5C%22%3A%5C%22search%5C%22%2C%5C%22longitude%5C%22%3A%5C%220%5C%22%2C%5C%22osVersion%5C%22%3A%5C%2223%5C%22%2C%5C%22phoneType%5C%22%3A%5C%22MuMu%5C%22%2C%5C%22search_action%5C%22%3A%5C%22initiative%5C%22%2C%5C%22soVersion%5C%22%3A%5C%222.0%5C%22%2C%5C%22ultron2%5C%22%3A%5C%22true%5C%22%2C%5C%22utdid%5C%22%3A%5C%22XUEI6Cqy4UgDAHCsEH0z5one%5C%22%7D%22%2C%22itemNumId%22%3A%22" + sProductId + "%22%7D";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("x-features", features);
request.UserAgent = "MTOPSDK%2F3.1.1.7+%28Android%3B5.1%3BOPPO%3BOPPO+R9m%29";
//request.Headers.Add("x-mini-wua", @"HHnB_mzRal5X4IXAcTxtEgwmHrZdDXNc0XlRLOemtkzSNtCwcDyGQ3tfXxI5oy9xIVme1wWJk9EELd0TS8hhy6KG3KepCdy7FNi1OVyEaDB3ph2utD4QBb4PEAuD5HiJGrP%2FF");
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);
//request.Headers.Set(HttpRequestHeader.Cookie, @"");
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");
request.Headers.Set(HttpRequestHeader.Cookie, taoBaoCookies);
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (count < 3)
{
Thread.Sleep(300);
goto Again;
}
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
else return "";
}
catch (Exception)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
if (response != null) response.Close();
return "";
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
}
if (response != null)
{
string responseText = ReadResponse(response);
if (!string.IsNullOrEmpty(responseText) && responseText.Contains("https://login.m.taobao") && count < 3)
{
Thread.Sleep(1000);
goto Again;
}
if (isVerify && !string.IsNullOrEmpty(responseText) && responseText.Contains("被挤爆啦"))
{
BaseClass.IeUrlShow = response.Headers["Location"];
Thread.Sleep(10 * 1000);
//goto Again;
}
return responseText;
}
return "";
}
private string MakeRequestThroughTradeAscMNew(long sProductId, bool isVerify, out HttpWebResponse response, string sMainOrDesc = "Main", string f = "")
{
response = null;
int count = 0;
Again:
try
{
count++;
bool bIsGetDesc = !sMainOrDesc.Equals("Main");
var t = BaseClass.GetTime(BaseClass.GetServerTimeString()).ToString();
var data = bIsGetDesc ? "{\"id\":\"" + sProductId + "\",\"type\":\"0\",\"f\":\"" + f + "\"}"
: "{\"detail_v\":\"3.3.2\",\"exParams\":\"{\\\"action\\\":\\\"ipv\\\",\\\"ad_type\\\":\\\"1.0\\\",\\\"appReqFrom\\\":\\\"detail\\\",\\\"container_type\\\":\\\"xdetail\\\",\\\"countryCode\\\":\\\"CN\\\",\\\"device\\\":\\\"56\\\",\\\"dinamic_v3\\\":\\\"true\\\",\\\"from\\\":\\\"search\\\",\\\"id\\\":\\\"" + sProductId + "\\\",\\\"item_id\\\":\\\"" + sProductId + "\\\",\\\"latitude\\\":\\\"0\\\",\\\"list_type\\\":\\\"search\\\",\\\"longitude\\\":\\\"0\\\",\\\"osVersion\\\":\\\"23\\\",\\\"phoneType\\\":\\\"MuMu\\\",\\\"search_action\\\":\\\"initiative\\\",\\\"soVersion\\\":\\\"2.0\\\",\\\"ultron2\\\":\\\"true\\\",\\\"utdid\\\":\\\"XUEI6Cqy4UgDAHCsEH0z5one\\\"}\",\"itemNumId\":\"" + sProductId + "\"}";
var olData = data;
string url_getSign = BaseClass.BuildObjString("get_taobao_sign&act=get_tb_sign");
string url_data = UserLogin.GetSignaturex("", "");
if (!string.IsNullOrEmpty(f)) url_data += "&f=" + f;
if (!bIsGetDesc) url_data += "&bIsGetDesc=main";
string sign = GetHtml.PostUtf8(url_getSign, url_data + "&t=" + t + "&sProductId=" + sProductId);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?jsv=2.6.1&appKey=12574478&t=" + t + "&sign=" + sign + "&api=mtop.taobao.detail.getdetail&v=6.0&isSec=0&ecode=0&AntiFlood=true&AntiCreep=true&H5Request=true&ttid=2018%40taobao_h5_9.9.9&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22id%22%3A%22" + sProductId + "%22%2C%22hybrid%22%3A%22true%22%2C%22ttid%22%3A%2210001401%40taobao_android_9.15.0%22%2C%22itemNumId%22%3A%22" + sProductId + "%22%2C%22itemId%22%3A%22" + sProductId + "%22%2C%22exParams%22%3A%22%7B%5C%22id%5C%22%3A%5C%22" + sProductId + "%5C%22%2C%5C%22hybrid%5C%22%3A%5C%22true%5C%22%2C%5C%22ttid%5C%22%3A%5C%2210001401%40taobao_android_9.15.0%5C%22%7D%22%2C%22detail_v%22%3A%228.0.0%22%2C%22utdid%22%3A%221%22%7D");
request.KeepAlive = true;
request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
request.UserAgent = "Mozilla/5.0 (Linux; Android 5.1.1; NX627J Build/LYZ28N; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.100 Safari/537.36 AliApp(TB/9.15.0) TTID/10001401@taobao_android_9.15.0 WindVane/8.5.0 900X1600 UT4Aplus/0.2.16";
request.Accept = "*/*";
request.Referer = "https://h5.m.taobao.com/awp/core/detail.htm?id=" + sProductId + "&hybrid=true&ttid=10001401%40taobao_android_9.15.0";
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,en-US;q=0.8");
//request.Headers.Set(HttpRequestHeader.Cookie,@"");
request.Headers.Set(HttpRequestHeader.Cookie, taoBaoCookies);
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (count < 3)
{
Thread.Sleep(300);
goto Again;
}
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
else return "";
}
catch (Exception)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
if (response != null) response.Close();
return "";
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
}
if (response != null)
{
string responseText = ReadResponse(response);
if (!string.IsNullOrEmpty(responseText) && responseText.Contains("https://login.m.taobao") && count < 5)
{
Thread.Sleep(1000);
goto Again;
}
if (isVerify && !string.IsNullOrEmpty(responseText) && responseText.Contains("被挤爆啦"))
{
BaseClass.IeUrlShow = BaseRegex.GetStringJson(ref responseText, "url");
Thread.Sleep(10 * 1000);
//goto Again;
}
//if (!string.IsNullOrEmpty(responseText) && responseText.Contains("被挤爆啦") && count < 5)
//{
// Thread.Sleep(3000);
// goto Again;
//}
//if (!string.IsNullOrEmpty(responseText) && responseText.Contains("被挤爆啦"))
//{
// //BaseClass.IeUrlShow = BaseRegex.GetStringJson(ref responseText, "url");
// //Thread.Sleep(20 * 1000);
// //goto Again;
//}
return responseText;
}
return "";
}
/// <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 void GetTaobaoCookies()
{
foreach (KeyValuePair<string, string> kvp in CookiesDic)
{
if (!CurrentCookiesDic.ContainsKey(kvp.Value))
CurrentCookiesDic.Add(kvp.Value, false);
}
int count = 0;
while (true)
{
if (CookiesDic.Count == 1)
{
taoBaoCookies = CookiesDic.FirstOrDefault().Value;
CurrentCookiesDic[taoBaoCookies] = true;
break;
}
if (!string.IsNullOrEmpty(taoBaoCookies))
break;
foreach (KeyValuePair<string, bool> kvp in CurrentCookiesDic)
{
if (kvp.Value == false)
{
taoBaoCookies = kvp.Key;
CurrentCookiesDic[kvp.Key] = true;
break;
}
}
if (count == 3)
{
if (CurrentCookiesDic.Count == 0)
break;
int index = new Random().Next(0, CurrentCookiesDic.Keys.Count - 1);
taoBaoCookies = CurrentCookiesDic.Keys.ElementAt(index);
CurrentCookiesDic[taoBaoCookies] = true;
break;
}
count++;
Thread.Sleep(500);
}
}
public static byte[] key = new byte[32] { 145, 232, 156, 201, 201, 0, 42, 184, 222, 111, 109, 49, 226, 169, 9, 44, 151, 148, 143, 120, 62, 84, 30, 170, 127, 242, 20, 141, 231, 33, 230, 6 };
public static byte[] iv = new byte[16] { 113, 6, 75, 177, 160, 112, 73, 39, 178, 147, 82, 107, 186, 58, 144, 187 };
public static string sAgentOrderId = "";
/// <summary>
/// 从后台提取一个可用代理订单
/// </summary>
public static void GetAProxyOrderId()
{
string sUrlGetAgent = BaseClass.BuildObjString("common&act=get_agent_ip");
string sData = UserLogin.GetSignaturex();
string sRes = GetHtml.PostUtf8(sUrlGetAgent, sData);
if (!string.IsNullOrEmpty(sRes) && sRes.Contains("the_key_temp"))
{
sAgentOrderId = BaseRegex.GetStringJson(ref sRes, "the_key_temp");
sAgentOrderId = DecryptString(sAgentOrderId);
}
}
public static string DecryptString(string cipherText)
{
cipherText = cipherText.Replace("-", "+").Replace("_", "/");
var x1 = cipherText.Length % 4;
if (x1 > 0)
{
cipherText = cipherText + "====".Substring(x1);
}
// Instantiate a new Aes object to perform string symmetric encryption
Aes encryptor = Aes.Create();
encryptor.Mode = CipherMode.CBC;
// Set key and IV
byte[] aesKey = new byte[32];
Array.Copy(key, 0, aesKey, 0, 32);
encryptor.Key = aesKey;
encryptor.IV = iv;
// Instantiate a new MemoryStream object to contain the encrypted bytes
MemoryStream memoryStream = new MemoryStream();
// Instantiate a new encryptor from our Aes object
ICryptoTransform aesDecryptor = encryptor.CreateDecryptor();
// Instantiate a new CryptoStream object to process the data and write it to the
// memory stream
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesDecryptor, CryptoStreamMode.Write);
// Will contain decrypted plaintext
string plainText = String.Empty;
try
{
// Convert the ciphertext string into a byte array
byte[] cipherBytes = Convert.FromBase64String(cipherText);
// Decrypt the input ciphertext string
cryptoStream.Write(cipherBytes, 0, cipherBytes.Length);
// Complete the decryption process
cryptoStream.FlushFinalBlock();
// Convert the decrypted data from a MemoryStream to a byte array
byte[] plainBytes = memoryStream.ToArray();
// Convert the decrypted byte array to string
plainText = Encoding.UTF8.GetString(plainBytes, 0, plainBytes.Length);
}
catch (Exception)
{
//throw;
}
finally
{
// Close both the MemoryStream and the CryptoStream
memoryStream.Close();
cryptoStream.Close();
}
// Return the decrypted data as a string
return plainText;
}
public static int ConvertDateTimeInt(DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (int)(time - startTime).TotalSeconds;
}
public string GetSign()
{
string url = BaseClass.LoginApiUrl + "/?obj=littlecow/sign&act=get_strawberry_sign";
int time = ConvertDateTimeInt(BaseClass.GetServerTimeString());
string time1 = UserLogin.Encryption(time);
string data = "&time=" + time + "&code=" + time1 + "&NbCodeVersion=1";
string html = GetHtml.PostUtf8(url, data);
if (html.Contains("error"))
{
Thread.Sleep(2000);
html = GetHtml.PostUtf8(url, data);
}
return html;
}
public string GetTaoBaoNewOther(long productId)
{
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://129.204.71.240/ycj/api/v1/taobao/goodsDetail/653498299812?cacheCycle=1");
//request.Headers.Add("G-Sign-V1", @"ew0KICAiaXYiOiAiWmJhNXFyZHBWRWVzUm9SY21vR2hFQT09IiwNCiAgInZhbHVlIjogImVmQ1VFSW5hYjAzWU02MXY4OGtyL1Q3Sk5WY2gzTENJU2o1OGNhNFBseUNqY1p3SGZKWnZrT05oK0svUndXUDhlRml2VXBpTHBjM29kaEllMXQrZlA3c2o2UWRuOHlrbm1kYU9PTENLVktGeERSYmdKdmpCOVZ6VG1haDhJUGVsdXh0WHVrak1XcTVJZE1yM1VuQkFWclViZ25reVRwMmY2RDVkcFVJN01UclZTMFZkK1RFbzJlR2pTQ1dwZkNyWSIsDQogICJtYWMiOiAiODVlYmEyMDk2YWUyNTE1N2UxMzBlZTVhOWVjZjRlZmM1MmFkZjNmYTcyZTdkYmVlYmQ2NTUwNzcxNTA1NjA4MCINCn0=");
//request.Accept = "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml";
//request.UserAgent = "RestSharp/106.3.1.0";
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
int count = 0;
Again:
HttpWebResponse response = null;
try
{
count++;
string sign = GetSign();
string url = "http://129.204.71.240/ycj/api/v1/taobao/goodsDetail/" + productId + "?cacheCycle=1";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
request.UserAgent = BaseClass.ChromeUserAgent;
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Add("G-Sign-V1", sign);
request.Accept = "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml";
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception)
{
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
}
if (response != null)
{
string responseText = ReadResponse(response);
return responseText;
}
return "";
}
public string GetTaoBaoNewOtherDesc(long productId)
{
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://129.204.71.240/ycj/api/v1/taobao/goodsDetail/653498299812?cacheCycle=1");
//request.Headers.Add("G-Sign-V1", @"ew0KICAiaXYiOiAiWmJhNXFyZHBWRWVzUm9SY21vR2hFQT09IiwNCiAgInZhbHVlIjogImVmQ1VFSW5hYjAzWU02MXY4OGtyL1Q3Sk5WY2gzTENJU2o1OGNhNFBseUNqY1p3SGZKWnZrT05oK0svUndXUDhlRml2VXBpTHBjM29kaEllMXQrZlA3c2o2UWRuOHlrbm1kYU9PTENLVktGeERSYmdKdmpCOVZ6VG1haDhJUGVsdXh0WHVrak1XcTVJZE1yM1VuQkFWclViZ25reVRwMmY2RDVkcFVJN01UclZTMFZkK1RFbzJlR2pTQ1dwZkNyWSIsDQogICJtYWMiOiAiODVlYmEyMDk2YWUyNTE1N2UxMzBlZTVhOWVjZjRlZmM1MmFkZjNmYTcyZTdkYmVlYmQ2NTUwNzcxNTA1NjA4MCINCn0=");
//request.Accept = "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml";
//request.UserAgent = "RestSharp/106.3.1.0";
//request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
int count = 0;
Again:
HttpWebResponse response = null;
try
{
count++;
string sign = GetSign();
string url = "http://129.204.71.240/ycj/api/v1/taobao/goodsDesc/" + productId + "?cacheCycle=1";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.KeepAlive = true;
request.UserAgent = BaseClass.ChromeUserAgent;
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.Headers.Add("G-Sign-V1", sign);
request.Accept = "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml";
response = (HttpWebResponse)request.GetResponse();
}
catch (Exception)
{
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
}
if (response != null)
{
string responseText = ReadResponse(response);
return responseText;
}
return "";
}
private string GetTaobaoProductAlibabaMainInfoAndDesc(long productId, bool isVerify, string f = "", string sMainOrDesc = "Main")
{
HttpWebResponse response;
string html = MakeRequestThroughProxyTradeAscM(productId, isVerify, out response, sMainOrDesc, f);
return html;
}
private string MakeRequestThroughProxyTradeAscM(long sProductId, bool isVerify, out HttpWebResponse response, string sMainOrDesc = "Main", string f = "")
{
response = null;
int count = 0;
Again:
try
{
count++;
bool bIsGetDesc = !sMainOrDesc.Equals("Main");
var utdid = "XUEI6Cqy4UgDAHCsEH0z5one";
var uid = "";
var appKey = "25443018";
var t = BaseClass.GetTime(BaseClass.GetServerTimeString()).ToString();
var sid = "";
var deviceId = @"AqjuNSqg5WtUMlGAgV2ZsudCBHdVINyeYYmyjrge4w2P";
var features = "27";
var x_pv = "5.1";
var data = "{\"parameters\":\"{\\\"miniapp_astore\\\":\\\"true\\\",\\\"detail_v\\\":\\\"9.9.9\\\",\\\"ttid\\\":\\\"2018@taobao_iphone_9.9.9\\\",\\\"itemId\\\":\\\"" + sProductId + "\\\",\\\"bizCode\\\":\\\"ali.china.tmall.good\\\",\\\"scenario\\\":\\\"goods_miniapp\\\"}\"}";
//var olData = data;
string url_getSign = BaseClass.BuildObjString("get_taobao_sign&act=get_tb_sign");
string url_data = UserLogin.GetSignaturex("", "");
//if (!string.IsNullOrEmpty(f)) url_data += "&f=" + f;
//if (!bIsGetDesc) url_data += "&bIsGetDesc=main";
//string sign = GetHtml.PostUtf8(url_getSign, url_data + "&t=" + t + "&sProductId=" + sProductId);
string api = "mtop.alibaba.detail.dynamic.service.getdetail";
string sign = GetHtml.PostUtf8(url_getSign, url_data + "&t=" + t + "&api=" + api + "&v=" + "1.0" + "&data=" + data);
var url = "https://guide-acs.m.taobao.com/gw/mtop.alibaba.detail.dynamic.service.getdetail/1.0?type=originaljson&rnd=155A23C4D8AD7737C1D1F2404ACD8AB5&data={\"parameters\":\"{\\\"miniapp_astore\\\":\\\"true\\\",\\\"detail_v\\\":\\\"9.9.9\\\",\\\"ttid\\\":\\\"2018@taobao_iphone_9.9.9\\\",\\\"itemId\\\":\\\"" + sProductId + "\\\",\\\"bizCode\\\":\\\"ali.china.tmall.good\\\",\\\"scenario\\\":\\\"goods_miniapp\\\"}\"}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("x-features", features);
request.UserAgent = "MTOPSDK%2F3.1.1.7+%28Android%3B5.1%3BOPPO%3BOPPO+R9m%29";
//request.Headers.Add("x-mini-wua", @"HHnB_mzRal5X4IXAcTxtEgwmHrZdDXNc0XlRLOemtkzSNtCwcDyGQ3tfXxI5oy9xIVme1wWJk9EELd0TS8hhy6KG3KepCdy7FNi1OVyEaDB3ph2utD4QBb4PEAuD5HiJGrP%2FF");
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);
//request.Headers.Set(HttpRequestHeader.Cookie, @"");
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");
//request.Headers.Set(HttpRequestHeader.Cookie, taoBaoCookies);
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException e)
{
if (count < 3)
{
Thread.Sleep(300);
goto Again;
}
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
else return "";
}
catch (Exception)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
if (response != null) response.Close();
return "";
}
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
if (count < 3)
{
Thread.Sleep(500);
goto Again;
}
}
if (response != null)
{
string responseText = ReadResponse(response);
if (!string.IsNullOrEmpty(responseText) && responseText.Contains("https://login.m.taobao") && count < 3)
{
Thread.Sleep(1000);
goto Again;
}
if (isVerify && !string.IsNullOrEmpty(responseText) && responseText.Contains("被挤爆啦"))
{
BaseClass.IeUrlShow = response.Headers["Location"];
Thread.Sleep(10 * 1000);
//goto Again;
}
return responseText;
}
return "";
}
public static string FromUnicodeString(string str)
{
//最直接的方法Regex.Unescape(str);
StringBuilder strResult = new StringBuilder();
if (!string.IsNullOrEmpty(str))
{
string[] strlist = str.Replace("\\", "").Split('u');
try
{
for (int i = 1; i < strlist.Length; i++)
{
int charCode = Convert.ToInt32(strlist[i], 16);
strResult.Append((char)charCode);
}
}
catch (FormatException ex)
{
return Regex.Unescape(str);
}
}
return strResult.ToString();
}
public void Get()
{
if (ProductTemp.ContainsKey(Product.from_id))
{
GetSuccess = true;
Product = ProductTemp[Product.from_id].Clone();
return;
}
GetSuccess = false;
Delete = false;
bool useTemp = false;
string urlProduct = "http://acs.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?api=mtop.taobao.detail.getdetail&v=6.0&ttid=2016%40taobao_h5_2.0.0&isSec=0&ecode=0&AntiFlood=true&AntiCreep=true&H5Request=true&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22exParams%22%3A%22%7B%5C%22id%5C%22%3A%5C%22549564635405%5C%22%7D%22%2C%22itemNumId%22%3A%22" + (ThisShopId ? Product.id : Product.from_id) + "%22%7D";
bool nokey = false, hadFile = false;
string content = "", newContent = "";
string refere = "https://h5.m.taobao.com/awp/core/detail.htm?id=" + (ThisShopId ? Product.id : Product.from_id);
//string html =NoTemp?"": TempFileReadWrite.Read(Product.id, "content", out hadFile);
//if(string.IsNullOrEmpty(html))
// html = GetPostTaobaoHtml.UploadTaobao(urlProduct, refere, true);
string html = "";
bool canUse = false;
if (UploadPinduoduoMain.isUseTaoBaoCache)
{
html = ServerTemp.Get(2, "main-" + Product.from_id.ToString(), out canUse);
html = html.Replace("\": \"", "\":\"").Replace("\": \"", "\":\"");
}
if (!canUse || !(html.Contains("调用成功") || html.Contains("\"dataType\":\"v2\"")) || html.Contains("expired.html?isInvalid=true"))
{
int it = UploadPinduoduoMain.ShopThreadCount * UploadPinduoduoMain.SingleThreadCount;
if ((string.IsNullOrEmpty(html) || !canUse || !html.Contains("调用成功")))
{
//GetTaobaoCookies();
if (string.IsNullOrEmpty(taoBaoCookies))
taoBaoCookies = BaseClass.IeFormCookies;
//if ((string.IsNullOrEmpty(html) || !html.Contains("调用成功")))
//{
// Thread.Sleep(1000);
// html = GetTaoBaoNewOther(Product.from_id);
//}
if (!string.IsNullOrEmpty(GetProxyHtml.orderId) && !IsProxyOverdue)
{
html = GetTaobaoProductMainInfoAndDescProxyNew(Product.from_id, "real-taobao-api");
html = html.Replace("\\/", "/");
html = html.Replace("\": \"", "\":\"").Replace("\": \"", "\":\"");
}
else // 共享代理IP
{
string purl = BaseClass.LoginApiUrl + "index.php?obj=api/shared_pool&act=get_agent_ip";
string phtml = GetHtml.PostUtf8(purl, UserLogin.GetSignaturex());
string sAgentIpKey = BaseRegex.GetStringJson(ref phtml, "the_key");
GetProxyHtml.orderId = GetProxyHtml.DESDecode(sAgentIpKey, AllBase.Helper.GlobalConfig.cAgentIpCode);
html = GetTaobaoProductMainInfoAndDescProxyNew(Product.from_id, "real-taobao-api");
html = html.Replace("\\/", "/");
html = html.Replace("\": \"", "\":\"").Replace("\": \"", "\":\"");
}
if ((string.IsNullOrEmpty(html) || !(html.Contains("调用成功") || html.Contains("\"dataType\":\"v2\""))))
{
if (string.IsNullOrEmpty(taoBaoCookies))
taoBaoCookies = BaseClass.IeFormCookies;
html = GetTaobaoProductDetailByMtopAlibabaApi(Product.from_id, true);
if ((string.IsNullOrEmpty(html) || !html.Contains("调用成功")))
{
if (!string.IsNullOrEmpty(BaseClass.x5Sec))
{
string oldCookies = taoBaoCookies;
if (BaseClass.IeFormCookies.Contains("x5sec"))
{
string sec = BaseRegex.GetMatchRegexString(ref BaseClass.IeFormCookies, @"x5sec=([\w\W]+?);");
BaseClass.IeFormCookies = BaseClass.IeFormCookies.Replace(sec, BaseClass.x5Sec);
}
else
BaseClass.IeFormCookies += "x5sec=" + BaseClass.x5Sec + ";";
taoBaoCookies = BaseClass.IeFormCookies;
BaseClass.x5Sec = "";
string ck = BaseRegex.GetMatchRegexString(ref taoBaoCookies, @"tracknick=([\w\W]+?);");
if (ck.Contains("%"))
ck = GetHtml.UrlDecode(ck);
CookiesDic[ck] = taoBaoCookies;
CurrentCookiesDic.Remove(oldCookies);
SaveCookies();
html = GetTaobaoProductDetailByMtopAlibabaApi(Product.from_id, true);
//if ((string.IsNullOrEmpty(html) || !html.Contains("调用成功")))
// LogSave.AddCrash("barleyinterface取完参数,重新执行失败");
}
else
{
taoBaoCookies = BaseClass.IeFormCookies;
html = GetTaobaoProductDetailByMtopAlibabaApi(Product.from_id, false);
}
}
}
//////阿里巴巴
//if ((string.IsNullOrEmpty(html) || !html.Contains("调用成功")))
//{
// Thread.Sleep(2000);
// html = GetTaobaoProductDetailByMtopAlibabaApi(Product.from_id);
//}
if ((string.IsNullOrEmpty(html) || !(html.Contains("调用成功") || html.Contains("\"dataType\":\"v2\"")) || html.Contains("商品不存在")))
{
Thread.Sleep(5000);
//心选
html = GetTaobaoProductAlibabaMainInfoAndDesc(Product.from_id, true);
}
//Thread.Sleep(it * 200);
//html = GetTaoBaoNewOther(Product.from_id);
//if ((string.IsNullOrEmpty(html) || !html.Contains("调用成功")))
//{
// Thread.Sleep(it * 500);
// html = GetTaobaoProductAlibabaMainInfoAndDesc(Product.from_id, false);
//}
if (CookiesDic.Count == 0 && (string.IsNullOrEmpty(html) || !(html.Contains("调用成功") || html.Contains("\"dataType\":\"v2\""))))
{
html = GetPostTaobaoHtml.UploadTaobaoH5(urlProduct, refere, true, BaseClass.IeFormCookies);
Thread.Sleep(it * 500);
if (html.Contains("login.m.taobao.") && Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) == null)
{
//BaseClass.IeFormCookies = "";
string sPunishUrl = BaseRegex.GetStringJson(ref html, "url");
BaseClass.IeUrlShow = sPunishUrl;
Thread.Sleep(5000);
while (Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) != null)
{
Thread.Sleep(3000);
}
if (!string.IsNullOrEmpty(BaseClass.x5Sec))
{
if (BaseClass.IeFormCookies.Contains("x5sec"))
{
string sec = BaseRegex.GetMatchRegexString(ref BaseClass.IeFormCookies, @"x5sec=([\w\W]+?);");
BaseClass.IeFormCookies = BaseClass.IeFormCookies.Replace(sec, BaseClass.x5Sec);
}
else
BaseClass.IeFormCookies += "x5sec=" + BaseClass.x5Sec + ";";
}
html = GetPostTaobaoHtml.UploadTaobaoH5(urlProduct, refere, true, BaseClass.IeFormCookies);
}
if (html.Contains("FAIL_SYS_USER_VALIDATE") && html.Contains("_____tmd_____/punish") && Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) == null)
{
string sPunishUrl = BaseRegex.GetStringJson(ref html, "url");
BaseClass.IeUrlShow = sPunishUrl;
Thread.Sleep(5000);
while (Application.OpenForms.Cast<Form>().ToList().Find(frm => frm.Text.Contains("淘宝验证窗口")) != null)
{
Thread.Sleep(3000);
}
if (!string.IsNullOrEmpty(BaseClass.x5Sec))
{
if (BaseClass.IeFormCookies.Contains("x5sec"))
{
string sec = BaseRegex.GetMatchRegexString(ref BaseClass.IeFormCookies, @"x5sec=([\w\W]+?);");
BaseClass.IeFormCookies = BaseClass.IeFormCookies.Replace(sec, BaseClass.x5Sec);
}
else
BaseClass.IeFormCookies += "x5sec=" + BaseClass.x5Sec + ";";
}
html = GetPostTaobaoHtml.UploadTaobaoH5(urlProduct, refere, true, BaseClass.IeFormCookies);
}
}
if (html.Contains("请检查是否使用了代理软件或VPN"))// || html.Contains("登陆成功后请点击重试获得查询结果")
{
////清除cookie,让其出滑块
CookiesDic.Clear();
taoBaoCookies = "";
BaseClass.IeFormCookies = "";
}
if (!string.IsNullOrEmpty(html) && html.Contains("被挤爆啦"))
{
LogSave.Add(Name, "被挤爆啦,请设置代理IP,解决采集限制问题:");
}
if (html.Contains("https://login.m.taobao.com"))
{
LogSave.Add(Name, "读取页面失败:" + urlProduct);
}
if (!string.IsNullOrEmpty(html) && (html.Contains("调用成功") || html.Contains("\"dataType\":\"v2\"")) && !(html.Contains("expired.html?isInvalid=true") || html.Contains("\"已下架")))
{
if (!html.Contains("mtopjsonp1(") && html.Contains("cache_time"))
{
JObject ja = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
html = ja["data"].ToString();
}
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = "main-" + Product.from_id.ToString(), SaveHtml = html });
}
}
//}
}
if (!string.IsNullOrEmpty(html) &&
(html.Contains("expired.html?isInvalid=true") || html.Contains("\\\"已下架\\\"") || html.Contains("商品已经下架啦") || html.Contains("expired?wh_weex=true")))
IsDown = true;
if (!string.IsNullOrEmpty(html) && html.Contains("预售"))
Product.IsPreSale = IsPreSale = true;
if (string.IsNullOrEmpty(html) || !(html.Contains("调用成功") || html.Contains("\"dataType\":\"v2\"")))
{
LogSave.Add(Name, "宝贝已经下架:" + urlProduct);
LogSave.AddFile(html);
BigDataBuild.Delete(Product.from_id, 1);
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
return;
}
//if (!hadFile)
// TempFileReadWrite.Write(Product.id, "content",html);
GetSuccess = true;
if (!string.IsNullOrEmpty(html) && canUse)
{
int index = html.IndexOf(",") + 1;
html = html.Substring(index);
var matches = BaseRegex.GetMatchRegex(ref html, "\\d{4}-\\d{2}-\\d{2} ,");
foreach (Match match in matches)
{
html = html.Replace(match.ToString(), "").Trim();
}
while ((int)html[0] == 65279)
html = html.Substring(1).Trim();
}
string desc = "";
html = html.Replace("\": \"", "\":\"").Replace("\": \"", "\":\"");
#region 66新格式 20220725
if (html.Contains("\"dataType\":\"v2\""))
{
Product = Parser(html);
goto detalPic;
}
#endregion
Product.name = BaseRegex.GetMatchRegexString(ref html, @"""item"":\{[^\}]*?""title"":""([^""]+)""");
if (string.IsNullOrEmpty(Product.name))
Product.name = BaseRegex.GetMatchRegexString(ref html, @"""itemId"":[^\}]*?""title"":""([^""]+)""");
if (html.Contains("mtop.alibaba.detail.dynamic.service.getdetail"))
{
var vRes = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
html = vRes["data"]["result"].ToString();
//普通商品属性
#region 商品属性
//html = html.Replace("\\\"", "\"");
//新格式名称
if (string.IsNullOrEmpty(Product.name))
Product.name = BaseRegex.GetStringJson(ref html, "itemTitle");
string pricext = BaseRegex.GetMatchRegexString(ref html,
@"""price"":\{""priceMoney"":[\d]+,""priceText"":""([\d\.]+)""");
string originPrice = BaseRegex.GetStringJson(ref html, "originPriceText");
if (string.IsNullOrEmpty(originPrice))
{
originPrice = pricext;
}
if (originPrice == "0" || string.IsNullOrEmpty(originPrice))
{
LogSave.Add("价格为空,退出:" + Product.from_url);
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
return;
}
Product.saleCount = BaseRegex.GetIntJson(ref html, "sellCount");
string epricex = BaseRegex.GetMatchRegexString(ref html, @"""postage"":""快递[::][\s]*([\d\.]+)");
Product.express_price = string.IsNullOrEmpty(epricex) ? 0 : decimal.Parse(epricex);
Product.price = decimal.Parse(pricext);
MinPrice = Product.price;
MaxPrice = Product.price;
Product.num = BaseRegex.GetIntJson(ref html, "num");
Product.from_shop_name = BaseRegex.GetStringJson(ref html, "sellerNick");
if (Product.num == 0)
{
string num = BaseRegex.GetMatchRegexString(ref html, @"""quantity"":([\d]+)");
if (!string.IsNullOrEmpty(num))
Product.num = int.Parse(num);
}
Product.discountPrice = decimal.Parse(pricext);
//Product.before_price = decimal.Parse(originPrice);
Product.discount = Product.discountPrice / Product.before_price;//折扣比例
Product.onlinePrice = Product.discountPrice * Product.shopAddPercent / 100 + new Random(Guid.NewGuid().GetHashCode()).Next((int)(Product.shopAddPriceMin * 100),
(int)(Product.shopAddPriceMax * 100)) / 100;
if (IsUrlCollect)
{
Product.onlinePrice = GetOnlinePrice(Product.price);
}
//if (IsUpdateSku)//如果是更新SKU则直接跳转到SKU部分
//{
// goto GetSku;
//}
//string catId = BaseRegex.GetStringJson(ref html, @"categoryId");
//catId = string.IsNullOrEmpty(catId) ? BaseRegex.GetMatchRegexString(ref html, @"categoryId:([\d]+)") : catId;
//if (catId.Contains(","))
// catId = catId.Substring(catId.LastIndexOf(",") + 1);
//Product.cat_id = int.Parse(catId);
Product.main_cid = BaseRegex.GetIntJson(ref html, @"rootCategoryId");
Product.from_cat_id = Product.cat_id;
Product.from_site_id = 1;
//if (Product.main_cid == 0)
//{
// LogSave.Add(Name, "没有找到主分类:" + Product.from_url);
// //删除掉正在使用的cookies
// if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
// CurrentCookiesDic.Remove(taoBaoCookies);
// return;
//}
#endregion
//主图
#region 主图
string imgHtml = BaseRegex.GetMatchRegexString(ref html, @"[\s]*""images"":[\s]*\[([^\]]+?)\]");
if (string.IsNullOrEmpty(imgHtml))
{
LogSave.Add(Name, "图片错误:" + Product.from_url);
return;
}
if (!(imgHtml.Contains("jpg") || imgHtml.Contains("jpeg") || imgHtml.Contains("png")))
{
var mg = BaseRegex.GetMatchRegex(ref html, @",[\s]*""images"":[\s]*\[([^\]]+?)\]");
for (int i = 0; mg != null && i < mg.Count; i++)
{
if (i == 0)
continue;
imgHtml = mg[i].Groups[1].Value;
}
}
var mc = BaseRegex.GetMatchRegex(ref imgHtml, @"""([^""]+)""");
if (mc.Count == 0)
{
LogSave.Add(Name, "图片错误:" + Product.from_url);
return;
}
for (int i = 0; i < mc.Count; i++)
{
Product.Images.Add(mc[i].Groups[1].Value);
}
Product.image = Product.Images[0];
Product.image_from_url = Product.Images[0];
#endregion
//商品属性
#region 商品属性
string pro = BaseRegex.GetMatchRegexString(ref html, @"[\s]*\{""param"":\[([^\]]+?)\]");
if (!string.IsNullOrEmpty(pro))
{
mc = BaseRegex.GetMatchRegex(ref pro, @"\{""([^""]+)"":[\s]*""([^""]+)"",""([^""]+)"":[\s]*""([^""]+)""\}");
if (mc.Count == 0)
{
LogSave.Add("参数错误:" + Product.from_url);
return;
}
for (int i = 0; i < mc.Count; i++)
{
string name = mc[i].Groups[4].Value;
string value = mc[i].Groups[2].Value;
if (name.Length > 50 || value.Length > 50)
continue;
Product.Prop.Add(new KeyValueBase(name, value));
}
}
#endregion
//规格
#region 规格
string footer_55098 = BaseRegex.GetMatchRegexString(ref html, "\"footer_[\\d]+\":([\\w\\W]+?\"type\":[\\s]*\"footer\"[\\s]*\\})");
var vFooter = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(footer_55098);
if (vFooter["fields"]["skuInfo"]["skuBase"]?["props"] != null)
{
var vSkuProps = JArray.Parse(vFooter["fields"]["skuInfo"]["skuBase"]?["props"]?.ToString())?.ToObject<List<Object>>();
foreach (var skuProp in vSkuProps)
{
var jSkuProp = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(skuProp.ToString());
PropBase p = new PropBase
{
id = long.Parse(jSkuProp["pid"].ToString()),
name = jSkuProp["name"].ToString()
};
var jSkuValue = JArray.Parse(jSkuProp["values"].ToString()).ToObject<List<Object>>();
foreach (var skuPropValue in jSkuValue)
{
var jSkuPropValue = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(skuPropValue.ToString());
PropValueBase pv = new PropValueBase()
{
value = jSkuPropValue["vid"].ToString(),
name = jSkuPropValue["name"].ToString(),
image = jSkuPropValue?["image"]?.ToString(),
image_from_url = jSkuPropValue?["image"]?.ToString(),
number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000)
};
p.Values.Add(pv);
p.sort = vSkuProps.IndexOf(skuProp) + 1;
}
Product.Props.Add(p);
}
}
#endregion
#region sku
decimal before_price = BaseRegex.GetDecimalJson(ref html, "originPriceText");
//sku属性
if (vFooter["fields"]["skuInfo"]["skuBase"]?["skus"] != null)
{
var vSkus = JArray.Parse(vFooter["fields"]["skuInfo"]["skuBase"]?["skus"]?.ToString()).ToObject<List<Object>>();
foreach (var sku in vSkus)
{
var vSku = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(sku.ToString());
string skuId = vSku["skuId"].ToString();
string propPath = vSku["propPath"].ToString();
var vSkuInfo = vFooter["fields"]["skuInfo"]["skuCore"]["sku2info"][skuId];
int iSkuNum = (int)vSkuInfo["quantity"];
if (iSkuNum > 100)
iSkuNum = 100;
decimal price = (decimal)vSkuInfo["price"]["priceText"];
string skuName = BuildName(propPath);
SkuMapBase skuBase = new SkuMapBase()
{
id = long.Parse(skuId),
name = skuName,
price = price,
number = iSkuNum,
before_price = before_price,
//values = values,
sale_count = 0
};
Product.SkuMaps.Add(skuBase);
}
}
#endregion
goto detalPic;
}
if (html.Contains("mtop.alibaba.jnpiter.detail.getdetail"))
{
#region 解析
var vRes = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
if (vRes == null) return;
Product.from_site_id = 1;
if (vRes["data"] != null && vRes["data"].ToString() != "{}")
{
Product.from_title = Product.name = vRes?["data"]?["item"]?["title"]?.ToString();
if (vRes?["data"]?["detailFeeds"]?[1]?["price"] == null)
Product.price = 0;
else
Product.price = decimal.Parse(vRes?["data"]?["detailFeeds"]?[1]?["price"]?.ToString());
//Product.price = decimal.Parse(((int)vRes["data"]["price"]["price"]["priceMoney"] / 100.0).ToString());
//if (AgentProductBuild.IsGuidancePrice)
//{
//var orginalPrice = decimal.Parse(((int)vRes["data"]["skuCore"]["sku2info"]["0"]["originalPrice"]["priceMoney"] / 100.0).ToString());
//var pricet = decimal.Parse(((int)vRes["data"]["skuCore"]["sku2info"]["0"]["price"]["priceMoney"] / 100.0).ToString());
//if (orginalPrice <= pricet)
//{
// //Product.isPromotion = false;
// Product.price = pricet;
//}
//else
//{
// Product.price = orginalPrice;
//}
//}
//else
//{
// Product.price = decimal.Parse(vRes["data"]["detailFeeds"][1]["price"].ToString());
//}
if (vRes["data"]?["item"]?["sellCount"] == null)
Product.saleCount = 0;
else
Product.saleCount = (int)vRes["data"]?["item"]?["sellCount"];
//TODO 根据返回内容分析邮费
string epricex = BaseRegex.GetMatchRegexString(ref html, @"""postage"":""快递[::][\s]*([\d\.]+)");
Product.express_price = string.IsNullOrEmpty(epricex) ? 0 : decimal.Parse(epricex);
//Product.express_price = 0;
Product.num = (int)vRes["data"]?["skuCore"]?["sku2info"]?["0"]?["quantity"];
Product.cat_id = Product.from_cat_id = (int)vRes["data"]?["item"]?["categoryId"];
Product.main_cid = (int)vRes["data"]?["item"]?["rootCategoryId"];
////TODO 主图视频ID
//if (vRes["data"]["video"]?["videos"] != null)
//{
// Product.VideoId = vRes["data"]["video"]?["videos"]?[0]?["videoId"].ToString();
//}
Product.item_size = "";
Product.item_weight = 1;
//TODO 发货城市
Product.state = "浙江";
Product.city = "杭州";
//string sDelivery = vRes["data"]["delivery"]["from"].ToString();
//ResolveProductDelivery(sDelivery);
var imgStr = vRes["data"]?["item"]?["images"]?.ToString();
Product.Images = JArray.Parse(imgStr).ToObject<List<string>>();
Product.image = Product.image_from_url = Product.Images[0];
string sDetailFeeds = vRes["data"]?["detailFeeds"]?.ToString();
string sProps = BaseRegex.GetMatchMaxRegexString(ref sDetailFeeds, "\"props\":[\\s]*(\\[[\\w\\W]+?\\])");
if (sProps != null)
{
var v = JArray.Parse(sProps).ToObject<List<Object>>();
foreach (var prop in v)
{
string s = prop.ToString();
var key = BaseRegex.GetStringJson(ref s, "word");
var value = BaseRegex.GetStringJson(ref s, "content");
{
Product.Prop.Add(new KeyValueBase(key, value));
}
}
}
}
if (vRes["data"]["skuBase"]?["props"] != null && !string.IsNullOrEmpty(vRes["data"]["skuBase"]?["props"].ToString()))
{
var vSkuProps = JArray.Parse(vRes["data"]["skuBase"]?["props"]?.ToString())?.ToObject<List<Object>>();
foreach (var skuProp in vSkuProps)
{
var jSkuProp = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(skuProp.ToString());
PropBase p = new PropBase
{
id = long.Parse(jSkuProp["pid"].ToString()),
name = jSkuProp["name"].ToString()
};
var jSkuValue = JArray.Parse(jSkuProp["values"].ToString()).ToObject<List<Object>>();
foreach (var skuPropValue in jSkuValue)
{
var jSkuPropValue = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(skuPropValue.ToString());
PropValueBase pv = new PropValueBase() // 此处序列化可能会出问题报错
{
value = jSkuPropValue["vid"].ToString(),
name = jSkuPropValue["name"].ToString(),
image = jSkuPropValue?["image"]?.ToString(),
image_from_url = jSkuPropValue?["image"]?.ToString(),
number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000)
};
p.Values.Add(pv);
p.sort = vSkuProps.IndexOf(skuProp) + 1;
}
Product.Props.Add(p);
}
}
if (vRes["data"]["skuBase"]?["skus"] != null && !string.IsNullOrEmpty(vRes["data"]["skuBase"]?["skus"].ToString()))
{
var vSkus = JArray.Parse(vRes["data"]["skuBase"]?["skus"]?.ToString()).ToObject<List<Object>>();
foreach (var sku in vSkus)
{
var vSku = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(sku.ToString());
string skuId = vSku["skuId"].ToString();
string propPath = vSku["propPath"].ToString();
var vSkuInfo = vRes["data"]["skuCore"]["sku2info"][skuId];
int iSkuNum = (int)vSkuInfo["quantity"];
decimal price = (decimal)vSkuInfo["price"]["priceText"];//AgentProductBuild.IsGuidancePrice && Product.isPromotion ? (decimal)vSkuInfo["originalPrice"]["priceText"] : (decimal)vSkuInfo["price"]["priceText"];
//string values;
string skuName = BuildName(propPath); //BuildName(propPath, out values);
SkuMapBase skuBase = new SkuMapBase()
{
id = long.Parse(skuId),
name = skuName,
price = price,
number = iSkuNum,
//values = values,
sale_count = 0
};
Product.SkuMaps.Add(skuBase);
}
}
#endregion
goto detalPic;
}
#region 商品属性
if (string.IsNullOrEmpty(Product.name) && !IsDown)
{
try
{
if (html.Contains("mtopjsonp1("))
html = BaseRegex.GetMatchRegexString(ref html, @"mtopjsonp1\(({[\w\W]+?})\)");
JObject ja = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(html);
if (html.Contains("{\"desc\":{\"itemProperties\"") || html.Contains("{\"desc\": {\"itemProperties\""))
{
Product.name = ja["item"]["data"]["item"]["title"].ToString();
desc = ja["desc"].ToString();
}
else if (html.Contains("{\"clientId\"") || html.Contains("cache_time"))
Product.name = ja["data"]["data"]["item"]["title"].ToString();
else
Product.name = ja["data"]["item"]["title"].ToString();
}
catch (Exception ex)
{
var mm = BaseRegex.GetMatchRegex(ref html, @"""item"":\{[^\}]*?""title"":""([^""]+)""");
string tempx = "";
for (int i = 0; mm != null && i < mm.Count; i++)
{
if (mm[i].Groups[1].Value.Length > tempx.Length)
{
tempx = mm[i].Groups[1].Value;
}
}
Product.name = tempx;
}
}
if (string.IsNullOrEmpty(Product.name))
{
if (IsUpdateSku)
{
Delete = true;
LogSave.Add(Name, "上家已经删除:" + (ThisShopId ? Product.id : Product.from_id));
}
else
{
LogSave.Add(Name, "标题获取错误:" + Product.from_url);
}
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
return;
}
if (string.IsNullOrEmpty(desc) && (html.Contains("{\"desc\":{\"itemProperties\"") || html.Contains("{\"desc\": {\"itemProperties\"")))
{
desc = BaseRegex.GetMatchRegexString(ref html, @"{(""desc"":\{[\w\W]*?),""item""");
}
html = GetHtml.Decode(html).Replace("\\\"", "\"").Replace("\\\\", "\\");
html = Regex.Replace(html, "\"endpoint\"[\\w\\W]+?\"global\"", "\"global\"");
string pricex = BaseRegex.GetMatchRegexString(ref html,
@"""transmitPrice"":\{""priceText"":""([\d\.]+)");
if (string.IsNullOrEmpty(pricex))
{
pricex = BaseRegex.GetStringJson(ref html, "price1");
}
if (string.IsNullOrEmpty(pricex))
{
pricex = BaseRegex.GetMatchRegexString(ref html,
@"""price"":\{""price"":\{""priceMoney"":""[\d]+"",""priceText"":""([\d\.]+)""");
}
if (string.IsNullOrEmpty(pricex))
{
pricex = BaseRegex.GetMatchRegexString(ref html,
@"""price"":\{""priceMoney"":""[\d]+"",""priceText"":""([\d\.]+)""");
}
if (string.IsNullOrEmpty(pricex))
pricex = BaseRegex.GetMatchRegexString(ref html,
@"""price"":\{""price"":\{""priceText"":""([\d\.]+)");
string price_beforex = BaseRegex.GetMatchRegexString(ref html,
@"""extraPrices"":\[\{""priceMoney"":""[\d]+"",""priceText"":""([\d\.]+)""");
if (string.IsNullOrEmpty(price_beforex))
{
price_beforex = BaseRegex.GetMatchRegexString(ref html,
@"""extraPrices"":\[\{[\w\W]+?""priceMoney"":""[\d]+"",""priceText"":""([\d\.]+)""");
}
if (string.IsNullOrEmpty(price_beforex))
{
price_beforex = BaseRegex.GetMatchRegexString(ref html,
@"""extraPrices"":\[\{[\w\W]+?""priceMoney"":""[\d]+"",""priceText"":""([\d\.]+)""");
}
if (string.IsNullOrEmpty(price_beforex))
{
price_beforex = pricex;
}
if (price_beforex == "0" || string.IsNullOrEmpty(price_beforex))
{
LogSave.Add("价格为空,退出:" + Product.from_url);
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
return;
}
Product.saleCount = BaseRegex.GetIntJson(ref html, "sellCount");
string eprice = BaseRegex.GetMatchRegexString(ref html, @"""postage"":""快递[::][\s]*([\d\.]+)");
Product.express_price = string.IsNullOrEmpty(eprice) ? 0 : decimal.Parse(eprice);
Product.price = decimal.Parse(pricex);
MinPrice = Product.price;
MaxPrice = Product.price;
Product.num = BaseRegex.GetIntJson(ref html, "num");
Product.from_shop_name = BaseRegex.GetStringJson(ref html, "sellerNick");
if (Product.num == 0)
{
string num = BaseRegex.GetMatchRegexString(ref html, @"""skuCore"":[\w\W]+?""quantity"":""([\d]+)""");
if (!string.IsNullOrEmpty(num))
Product.num = int.Parse(num);
}
Product.discountPrice = decimal.Parse(pricex);
Product.before_price = decimal.Parse(price_beforex);
Product.discount = Product.discountPrice / Product.before_price;//折扣比例
Product.onlinePrice = Product.discountPrice * Product.shopAddPercent / 100 + new Random(Guid.NewGuid().GetHashCode()).Next((int)(Product.shopAddPriceMin * 100),
(int)(Product.shopAddPriceMax * 100)) / 100;
if (IsUrlCollect)
{
Product.onlinePrice = GetOnlinePrice(Product.price);
}
if (IsUpdateSku)//如果是更新SKU则直接跳转到SKU部分
{
goto GetSku;
}
string catId = BaseRegex.GetStringJson(ref html, @"categoryId");
catId = string.IsNullOrEmpty(catId) ? BaseRegex.GetMatchRegexString(ref html, @"categoryId:([\d]+)") : catId;
if (catId.Contains(","))
catId = catId.Substring(catId.LastIndexOf(",") + 1);
Product.cat_id = int.Parse(catId);
Product.main_cid = BaseRegex.GetIntJson(ref html, @"rootCategoryId");
Product.from_cat_id = Product.cat_id;
Product.from_site_id = 1;
if (Product.main_cid == 0)
{
LogSave.Add(Name, "没有找到主分类:" + Product.from_url);
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
return;
}
//===================标题过滤======================
string title = Product.name.ToLower();
long md5 = BaseClass.GetLong(Product.name);
foreach (string s in BaseClass.CantTitleKeywords)
{
if (title.Contains(s))
{
nokey = true;
LogSave.Add(Name, s + " : " + title);
break;
}
}
foreach (string s in BaseClass.CantTitle)
{
if (title.Contains(s))
{
nokey = true;
LogSave.Add(Name, s + " : " + title);
break;
}
}
foreach (string s in BaseClass.CantCatId)
{
if (Product.cat_id.ToString() == s || Product.main_cid.ToString() == s)
{
nokey = true;
LogSave.Add(Name, s + " : " + title);
break;
}
}
string temp = BaseRegex.GetMatchRegexString(ref html, @",[\s]*""images"":[\s]*\[([^\]]+?)\]");
if (string.IsNullOrEmpty(temp))
{
LogSave.Add(Name, "图片错误:" + Product.from_url);
return;
}
if (!(temp.Contains("jpg") || temp.Contains("jpeg") || temp.Contains("png")))
{
var mg = BaseRegex.GetMatchRegex(ref html, @",[\s]*""images"":[\s]*\[([^\]]+?)\]");
for (int i = 0; mg != null && i < mg.Count; i++)
{
if (i == 0)
continue;
temp = mg[i].Groups[1].Value;
}
}
var m = BaseRegex.GetMatchRegex(ref temp, @"""([^""]+)""");
if (m.Count == 0)
{
LogSave.Add(Name, "图片错误:" + Product.from_url);
return;
}
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.Images[0];
var tempVideo = BaseRegex.GetMatchRegexString(ref html, @"""videos"":[\s]*\[\{""url"":[\s]*""([\w\W]+?)""");
//Product.vid = tempVideo;
temp = BaseRegex.GetMatchRegexString(ref html, @"""props"":[\s]*\{""groupProps"":[\s]*([\w\W]+?)\]\},");
if (!string.IsNullOrEmpty(temp))
{
m = BaseRegex.GetMatchRegex(ref temp, @"\{""([^""]+)"":[\s]*""([^""]+)""\}");
if (m.Count == 0)
{
LogSave.Add("参数错误:" + Product.from_url);
return;
}
for (int i = 0; i < m.Count; i++)
{
string name = m[i].Groups[1].Value;
string value = m[i].Groups[2].Value;
if (name.Length > 50 || value.Length > 50)
continue;
Product.Prop.Add(new KeyValueBase(name, value));
}
}
GetSku:
bool hadPrice = false;
m = BaseRegex.GetMatchRegex(ref html,
@"\{""pid"":[\s]*""([-\d]+)"",[\s]*""name"":[\s]*""([^""]+)"",(\s*|.+?)""values"":[\s]*\[([\w\W]+?)\]\}");
if (m != null && m.Count == 0)
{
m = BaseRegex.GetMatchRegex(ref html,
@"""name"":[\s]*""([^""]+)"",""nameDesc"":[\s]*""[^""]*?"",""pid"":[\s]*""([-\d]+)"",(\s*|.+?)""values"":[\s]*\[([\w\W]+?)\]\}");
}
if (m != null && m.Count == 0)
{
m = BaseRegex.GetMatchRegex(ref html,
@"\{[\s]*""values"":[\s]*\[([\w\W]+?)\],""name"":[\s]*""([^""]+)"",[\s]*""pid"":[\s]*""([-\d]+)""\}");
}
bool has = false;
if (m != null && m.Count == 0)
{
has = true;
m = BaseRegex.GetMatchRegex(ref html,
@"\{""name"":[\s]*""([^""]+)"",[\s]*""pid"":[\s]*""([-\d]+)"",[\s]*""values"":[\s]*\[([\w\W]+?)\]\}");
}
for (int i = 0; i < m.Count; i++)
{
string item = m[i].Groups[0].Value;
PropBase p = new PropBase();
p.id = BaseRegex.GetLongJson(ref item, "pid");// long.Parse(m[i].Groups[1].Value);
p.name = BaseRegex.GetStringJson(ref item, "name");//m[i].Groups[2].Value;
if (string.IsNullOrEmpty(p.name) || has)
{
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[4].Value;
var mm = BaseRegex.GetMatchRegex(ref temp, @"""vid"":[\s]*""([-\d]+?)"",[\s]*""name"":[\s]*""([^""]+?)""[^\}]*\}");
if (mm != null && mm.Count == 0)
{
mm = BaseRegex.GetMatchRegex(ref temp, @"[\s]*""image"":[\s]*""([^""]+?)"",[\s]*""name"":[\s]*""([^""]+?)"",""sortOrder\"":[\s]*""[-\d]+?"",""vid"":[\s]*""([-\d]+?)""[^\}]*\}");
}
if (mm != null && mm.Count == 0)
{
temp = m[i].Groups[1].Value;
mm = BaseRegex.GetMatchRegex(ref temp, @"[\s]*""name"":[\s]*""([^""]+?)""[^\}]*,""vid"":[\s]*""([-\d]+?)""\}");
}
if (mm != null && mm.Count == 0)
{
mm = BaseRegex.GetMatchRegex(ref temp, @"\{[^\}]+?\}");
}
for (int j = 0; j < mm.Count; j++)
{
string specItem = mm[j].Groups[0].Value;
string v = BaseRegex.GetStringJson(ref specItem, "vid");//mm[j].Groups[1].Value;
//string vi = mm[j].Groups[0].Value;
string image = BaseRegex.GetStringJson(ref specItem, "image");
PropValueBase pr = new PropValueBase();
pr.value = v;
pr.name = BaseRegex.GetStringJson(ref specItem, "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);
}
}
//if (Product.Props.Count>2)
//{
// Product.Props = Product.Props.OrderBy(u => u.Values.Count).ToList();
// int count = Product.Props.Count - 2;
// Product.Props.RemoveRange(0,count);
// Product.Props = Product.Props.OrderByDescending(u => u.sort).ToList();
//}
m = BaseRegex.GetMatchRegex(ref html, @"""skuId"":[\s]*""([\d]+)"",[\s]*""propPath"":[\s]*""([-\d:;]+)""");
if (m != null && m.Count == 0)
{
m = BaseRegex.GetMatchRegex(ref html, @"""propPath"":[\s]*""([-\d:;]+)"",[\s]*""skuId"":[\s]*""([\d]+)""");
}
for (int i = 0; i < m.Count; i++)
{
string skuItem = m[i].Groups[0].Value;
string skuid = BaseRegex.GetStringJson(ref skuItem, "skuId");// m[i].Groups[1].Value;
string skuValues = BaseRegex.GetStringJson(ref skuItem, "propPath");//m[i].Groups[2].Value;
//var mm = BaseRegex.GetMatchRegex(ref html,
// @"""" + skuid + @""":[^\}]+?""priceText"":""([\d.]+)""[^\}]*?},""quantity"":([\d]+)\}");
//if (mm.Count == 0)
//{
html = html.Replace(" ", "");
var mm = BaseRegex.GetMatchRegex(ref html,
@"""" + skuid + @""":\{""price"":\{""priceMoney"":""[\d]+"",""priceText"":""([\d.]+)""[^\}]*?},""quantity"":([\w\W]+?)\}");
//}
if (mm.Count == 0)
{
mm = BaseRegex.GetMatchRegex(ref html,
@"""" + skuid + @""":\{""price"":\{""priceMoney"":""[\d]+"",""priceText"":""([\d.]+)""[^\}]*?}");
}
if (mm.Count == 0)
{
//"moreQuantity":"false",
mm = BaseRegex.GetMatchRegex(ref html,
@"""" + skuid + @""":\{""moreQuantity"":""false"",""price"":\{""priceMoney"":""[\d]+"",""priceText"":""([\d.]+)""[^\}]*?}");
}
if (mm.Count == 0)
{
LogSave.Add("SKU识别错误:" + Product.from_url);
continue;
}
string priceText = mm[0].Groups[1].Value;
decimal before_price = decimal.Parse(priceText);
decimal price = before_price;
string numberString = BaseRegex.GetMatchRegexString(ref html,
@"""" + skuid + @""":[\w\W]+?""quantity"":""([\d]+)""");
if (string.IsNullOrEmpty(numberString))
numberString = BaseRegex.GetMatchRegexString(ref html,
@"""" + skuid + @""":[\w\W]+?""quantity"":([\d]+)");
int number = 0;
if (!string.IsNullOrEmpty(numberString))
number = int.Parse(numberString);
if (number > 100)
number = 100;
string name = BuildName(skuValues);
if (string.IsNullOrEmpty(name))
continue;
bool had = false;
for (int j = 0; j < Product.SkuMaps.Count; j++)
{
if (Product.SkuMaps[j].name == name)
{
had = true;
break;
}
}
if (had)
{
continue;
}
mm = BaseRegex.GetMatchRegex(ref html,
@"""" + skuid + @""":[^\}]+?""priceText"":""([\d.]+)"",""(type|showTitle|sugProm|priceMoney)""");
if (mm.Count != 0)
{
price = decimal.Parse(mm[0].Groups[1].Value);//这是折扣后的价格
decimal dic = before_price > 0 ? price / before_price : 1;
if (dic < Product.discount)
Product.discount = dic;
}
SkuMapBase sm = new SkuMapBase();
sm.id = long.Parse(skuid);
sm.name = name;
sm.price = price;
if (MaxPrice < price)
MaxPrice = price;
if (MinPrice > price)
MinPrice = price;
sm.online_price = (int)(sm.price * Product.shopAddPercent / 100 +
new Random(Guid.NewGuid().GetHashCode()).Next((int)(Product.shopAddPriceMin * 100),
(int)(Product.shopAddPriceMax * 100)) / 100);
if (!Pinduoduo && (price < BaseClass.MinPrice || price > BaseClass.MaxPrice))
number = 0;
else
hadPrice = true;
if (IsUrlCollect)
{
sm.online_price = (int)GetOnlinePrice(sm.price);
}
sm.number = number;
sm.before_price = before_price;
sm.sale_count = 0;
Product.SkuMaps.Add(sm);
}
for (int i = 0; Product.discount < 1 && i < Product.SkuMaps.Count; i++)
{
if (Product.SkuMaps[i].number == 0)
Product.SkuMaps[i].price = Decimal.Round(Product.discount * Product.SkuMaps[i].before_price, 2);
}
#endregion
detalPic:
#region 详情图信息
string url = "https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdesc/6.0/?jsv=2.4.11&appKey=12574478&t=1539706329587&sign=7467352c72e2cc0c53bbf733f4323b16&api=mtop.taobao.detail.getdesc&v=6.0&type=jsonp&dataType=jsonp&timeout=20000&callback=mtopjsonp1&data=%7B%22id%22%3A%22" + Product.from_id + "%22%2C%22type%22%3A%220%22%2C%22f%22%3A%22%22%7D";
if (NoContent)
{
content = "不需要描述";
}
else
{
content = "";
if (!string.IsNullOrEmpty(desc))
content = desc;
if (string.IsNullOrEmpty(content))
{
string contentHtml = "";
//if (UploadPinduoduoMain.isUseTaoBaoCache)
contentHtml = ServerTemp.Get(2, "content-" + Product.from_id.ToString(), out canUse);
if (canUse && contentHtml.Contains(",") && !contentHtml.Contains("punish/wait_h5")
&& (contentHtml.Contains("<img ") || contentHtml.Contains("\"url\":\"https://img") || contentHtml.Contains("\"url\":\"http://img")))
{
content = contentHtml.Substring(contentHtml.IndexOf(",") + 1);
useTemp = true;
}
}
if (string.IsNullOrEmpty(content))
{
string taobaoDescUrl = BaseRegex.GetStringJson(ref html, "taobaoDescUrl");//m[i].Groups[2].Value;
if (string.IsNullOrEmpty(taobaoDescUrl))
taobaoDescUrl = BaseRegex.GetStringJson(ref html, "descUrl");
string fa = BaseRegex.GetMatchRegexString(ref taobaoDescUrl, @"f=desc/([\w\W]+?)&");
if (string.IsNullOrEmpty(fa))
fa = BaseRegex.GetMatchRegexString(ref taobaoDescUrl, @"f=([\w\W]+?)&");
if (!fa.Contains("icoss") && !string.IsNullOrEmpty(taobaoDescUrl))
{
taobaoDescUrl = BaseRegex.GetStringJson(ref html, "taobaoPcDescUrl");
fa = BaseRegex.GetMatchRegexString(ref taobaoDescUrl, @"f=desc/([\w\W]+?)&");
if (string.IsNullOrEmpty(fa))
fa = BaseRegex.GetMatchRegexString(ref taobaoDescUrl, @"f=([\w\W]+?)&");
}
string descUrl = "https://itemcdn.tmall.com/desc/" + fa + "?var=desc";
string descHtml = GetPostTaobaoHtml.UploadTaobaoDetailPic(descUrl, refere, true, "");
var mm = BaseRegex.GetMatchRegex(ref descHtml, @"""picUrl"":""([\w\W]+?)""");
string tempx = "";
for (int i = 0; mm != null && i < mm.Count; i++)
{
tempx += "<img src=\"" + mm[i].Groups[1].Value + "\" />";
}
if (mm.Count == 0 && !string.IsNullOrEmpty(descHtml))
tempx = descHtml;
content = tempx.Replace("\\\"", "\"").Replace("\\\\", "\\");
if (content.Contains("<img "))
{
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = "content-" + Product.from_id.ToString(), SaveHtml = content });
}
if (content.Contains("提交错误"))
{
content = "";
}
}
if (string.IsNullOrEmpty(content))
{
if (string.IsNullOrEmpty(taoBaoCookies))
GetTaobaoCookies();
if (string.IsNullOrEmpty(content))
{
int count = 0;
Again:
count++;
string descUrl = "https://mdetail.tmall.com/templates/pages/desc?id=" + Product.from_id;
string descHtml = GetPostTaobaoHtml.UploadTaobao(descUrl, "", true);
descUrl = BaseRegex.GetStringJson(ref descHtml, "descUrl");
if (!string.IsNullOrEmpty(descUrl))
{
if (!descUrl.Contains("https://"))
descUrl = "https:" + descUrl;
descHtml = GetPostTaobaoHtml.UploadTaobao(descUrl, "", true);
//var vMatches = Regex.Matches(descHtml, "<img align=\"absmiddle\" src=\"([\\w\\W]+?)\"");
var vMatches = Regex.Matches(descHtml, "desc='([\\w\\W]+?)'");
if (vMatches.Count == 0)
content = "";
content = vMatches[0].Groups[1].Value;
}
if (content.Contains("<img "))
{
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = "content-" + Product.from_id.ToString(), SaveHtml = content });
}
if (string.IsNullOrEmpty(content))
{
LogSave.Add("md获取到的详情图为空" + Product.from_id + "\r\n");
}
}
}
if (string.IsNullOrEmpty(content))
{
content = GetPostTaobaoHtml.UploadTaobaoPic(url, refere, true, taoBaoCookies);
if (Product.Prop.Count == 0)
{
string pro = BaseRegex.GetMatchRegexString(ref content, @"""itemProperties"":\[([^\]]+?)\]");
if (!string.IsNullOrEmpty(pro))
{
var mc = BaseRegex.GetMatchRegex(ref pro, @"\{""([^""]+)"":[\s]*""([^""]+)"",""([^""]+)"":[\s]*""([^""]+)""\}");
if (mc.Count == 0)
{
LogSave.Add("参数错误:" + Product.from_url);
return;
}
for (int i = 0; i < mc.Count; i++)
{
string name = mc[i].Groups[4].Value;
string value = mc[i].Groups[2].Value;
if (name.Length > 50 || value.Length > 50)
continue;
Product.Prop.Add(new KeyValueBase(name, value));
}
}
}
if (string.IsNullOrEmpty(content))
{
LogSave.Add("H获取到的详情图为空" + Product.from_id + "\r\n");
}
if (content != null && content.Contains("被挤爆啦"))
{
content = "";
}
}
if (string.IsNullOrEmpty(content))
{
string f = BaseRegex.GetStringJson(ref html, "f");
f = BaseRegex.GetMatchRegexString(ref html, "f=([\\w\\W]+?)&");
//取详情图
if ((string.IsNullOrEmpty(content) || !content.Contains("<img ")) && !UploadPinduoduoSet.IsUseProxyCollectUp)
content = GetTaobaoProductMainInfoAndDesc(Product.from_id, false, f, "Desc");
if (!string.IsNullOrEmpty(content) && content.Contains("被挤爆啦") && !UploadPinduoduoSet.IsUseProxyCollectUp)
{
content = GetTaobaoProductMainInfoAndDesc(Product.from_id, true, f, "Desc");
}
if (content.Contains("<img "))
{
IdFessionTaobao.ConcurrentQueueHtmlSaveServer.Enqueue(new SaveServerParm() { SaveType = 2, ProuctId = "content-" + Product.from_id.ToString(), SaveHtml = content });
//Task.Run(() =>
//{
// ServerTemp.Set(2, "content-" + Product.from_id.ToString(), content);
//});
}
string tempx = BaseRegex.GetMatchRegexString(ref content, @"""pcDescContent"":""([\w\W]+?)"",""anchors");
if (string.IsNullOrEmpty(tempx))
tempx = BaseRegex.GetMatchRegexString(ref content, @"""pcDescContent"":""([\w\W]+?)"",""");
if (string.IsNullOrEmpty(tempx))
{
tempx = BaseRegex.GetMatchRegexString(ref content, @"""pages"":([\w\W]+?)\]");
var mm = BaseRegex.GetMatchRegex(ref tempx, "<img[^>]*?>([^>]+?)</img>");
tempx = "";
for (int i = 0; mm != null && i < mm.Count; i++)
{
tempx += "<img src=\"" + mm[i].Groups[1].Value + "\" />";
}
}
if (string.IsNullOrEmpty(tempx))
{
tempx = BaseRegex.GetMatchRegexString(ref content, @"""pages"":[\w\W]+?(<img[^>]*?>[\w\W]+?)\]");
var mm = BaseRegex.GetMatchRegex(ref tempx, "<img[^>]*?>([^>]+?)</img>");
tempx = "";
for (int i = 0; mm != null && i < mm.Count; i++)
{
tempx += "<img src=\"" + mm[i].Groups[1].Value + "\" />";
}
}
if (string.IsNullOrEmpty(tempx))
{
string img = BaseRegex.GetStringJson(ref content, "taobaoDescUrl");
tempx = "<img src=\"" + img + "\" />";
}
if (string.IsNullOrEmpty(tempx))
{
LogSave.Add(Name, "描述正文正则失败,跳过 " + url);
pbMessage = "无详情信息";
Product.message = pbMessage;
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
return;
}
content = tempx.Replace("\\\"", "\"").Replace("\\\\", "\\");
content = Regex.Replace(content, "<p><img class=\"desc_anchor[\\w\\W]+?</p >", "");
}
if (string.IsNullOrEmpty(content) || !content.Contains("img"))
{
string tempx = "";
for (int i = 0; i < Product.Images.Count; i++)
{
tempx += "<img src=\"" + Product.Images[i] + "\" />";
}
content = tempx;
}
}
//删除掉正在使用的cookies
if (!string.IsNullOrEmpty(taoBaoCookies) && CurrentCookiesDic.ContainsKey(taoBaoCookies))
CurrentCookiesDic.Remove(taoBaoCookies);
//识别上家ID
if (content.Contains("<img"))
Product.upShopId = GetUpId(ref content);
newContent = ClearContent(content);
if (string.IsNullOrEmpty(content) || string.IsNullOrEmpty(newContent))
{
LogSave.Add(Name, "描述正文为空,跳过 " + url);
return;
}
//if (!(html.Contains("\"title\":\"七天无理由") || html.Contains("\"name\":\"七天无理由") || html.Contains("\"title\":\"7天无理由")))
// Product.isSevNoReason = false;
Content = newContent.Replace("\\\"", "\"").Replace("\\\\", "\\");
Product.content = Content;
Product.item_size = "";
Product.item_weight = 1;
Product.state = "浙江";
Product.city = "杭州";
string address = BaseRegex.GetMatchRegexString(ref html, @"""delivery"":\{""from"":""([^""]+?)""");
if (string.IsNullOrEmpty(address))
address = BaseRegex.GetStringJson(ref html, @"location");
string[] provice =
"上海,北京,天津,重庆,黑龙江,辽宁,内蒙古,吉林,河北,河南,山西,山东,陕西,青海,宁夏,甘肃,新疆,西藏,四川,云南,贵州,广西,湖南,湖北,安徽,江苏,浙江,广东,福建,海南,台湾,香港,澳门".Split(',');
string[] city =
"上海,北京,天津,重庆,哈尔滨,沈阳,呼和浩特,长春,石家庄,郑州,太远,济南,西安,西宁,银川,兰州,乌鲁木齐,拉萨,程度,昆明,贵阳,南宁,长沙,武汉,合肥,南京,杭州,广州,福州,海口,台北,香港,澳门".Split(',');
if (!string.IsNullOrEmpty(address))
{
for (int i = 0; i < provice.Length; i++)
{
if (address.Contains(provice[i]))
{
Product.state = provice[i];
Product.city = city[i];
break;
}
}
}
#endregion
try
{
if (ProductTemp.Count > 3000)
{
ProductTemp.Clear();
}
if (!ProductTemp.ContainsKey(Product.from_id) && !NoContent)
ProductTemp.Add(Product.from_id, Product);
}
catch
{
}
//if (!hadPrice && (Product.price < (IsUpdateSku ? BaseClass.MinPrice * 0.8m : BaseClass.MinPrice) || Product.price > BaseClass.MaxPrice))
//{
// //LogSave.Add(Name, "价格太低:" + Product.from_url);
// //if (IsUpdateSku)
// //{
// // SetSku( 0, 0, 5);
// //}
// //else
// //{
// // return;
// //}
//}
Product.logisticsTime = BaseRegex.GetMatchRegexString(ref html, @"""logisticsTime"":""([\w\W]+?)""}");
if (string.IsNullOrEmpty(Product.logisticsTime))
{
Product.logisticsTime = "";
var mx = BaseRegex.GetMatchRegex(ref html, @"{""title"":""([\w\W]+?)""}");
for (int i = 0; i < mx.Count; i++)
{
string item = mx[i].Groups[0].Value;
string logtitle = BaseRegex.GetStringJson(ref item, "title");
if (logtitle.Contains("发货"))
{
Product.logisticsTime = logtitle;
break;
}
}
}
if (string.IsNullOrEmpty(Product.logisticsTime))
{
string item = BaseRegex.GetMatchRegexString(ref html, @"""ReceiveTime"":([\w\W]+?"")}");
if (!string.IsNullOrEmpty(item))
{
string logtitle = BaseRegex.GetStringJson(ref item, "text");
string month = BaseRegex.GetMatchRegexString(ref logtitle, @"([\d]+)月");
string day = BaseRegex.GetMatchRegexString(ref logtitle, @"([\d]+)日");
if (!string.IsNullOrEmpty(month) && string.IsNullOrEmpty(day))
{
string curiqi = DateTime.Now.Year + "-" + month + "-" + day + " 00:00:00";
string cuTime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
DateTime t1 = Convert.ToDateTime(curiqi);
DateTime t2 = Convert.ToDateTime(cuTime);
System.TimeSpan t3 = t1 - t2; //两个时间相减 。默认得到的是 两个时间之间的天数 得到:365.00:00:00
Product.logisticsTime = Math.Abs(t3.TotalDays).ToString();
}
}
}
if (NoUpToServer)
return;
if (IsUpdateSku || Pinduoduo) //如果是更新上家价格,则执行此代码
{
if (Product.cat1 == 0)
{
FromTitleToCat.UserApi = true;
FromTitleToCat ft = new FromTitleToCat();
ft.TaobaoProduct = new TaobaoProductBase();
ft.Title = Product.name;
ft.TaobaoProduct.Titlte = Product.name;
ft.TaobaoProduct.FromId = Product.from_id;
ft.TaobaoCatId = Product.from_cat_id;
ft.JustGetCat = true;
ft.Get();
if (!string.IsNullOrEmpty(ft.Cat1) && ft.Cat1 != "0")
{
Product.cat1 = int.Parse(ft.Cat1);
Product.cat2 = int.Parse(ft.Cat2);
Product.cat3 = int.Parse(ft.Cat3);
Product.cat4 = int.Parse(ft.Cat4);
}
}
var ftc = new FromTitleToCat();
Product.main_cid = ftc.GetMainCatId(Product.cat1);
Product.main_cat_name = ftc.MainCatName;
if (html.Contains("探索全球美好生活") || html.Contains("globalBuyer") || html.Contains("globalHeadUpdate"))
{
Product.main_cid = 8;
Product.main_cat_name = "海淘进口";
string country = "";
for (int i = 0; i < Product.Prop.Count; i++)
{
if (Product.Prop[i].Key == "产地")
{
country = Product.Prop[i].Value;
break;
}
}
if (string.IsNullOrEmpty(country))
{
country = BaseRegex.GetMatchRegexString(ref html, @"""delivery"":{""from"":""([\w\W]+?)""");
}
Product.country = country;
}
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;
}
}
}
return;
}
//if (Product.FromType == "搜款网净化")
//{
// string jhtml = ServerTemp.GetJinHuaCache(Product.FromId.ToString());
// AslasyHtml(jhtml);
//}
//淘宝大数据收集
//string json = JsonHelper.SerializeObject(Product);
//string data = "id=" + Product.id + "&site_id=" + Product.from_site_id + "&" + UserLogin.GetSignaturex() +
// "&json=" + GetHtml.UrlEncodeUtf8(json);
//string upUrl = BaseClass.BuildObjString("upload_data");
//html = GetHtml.PostUtf8(upUrl, data);
if (nokey)//过滤数据
return;
if (html == "Ok" || html == "Had")
{
LogSave.Add(Name, "采集成功:" + Product.id);
}
if (html.Contains("探索全球美好生活") || html.Contains("globalBuyer") || html.Contains("globalHeadUpdate"))
{
Product.main_cid = 8;
Product.main_cat_name = "海淘进口";
string country = "";
for (int i = 0; i < Product.Prop.Count; i++)
{
if (Product.Prop[i].Key == "产地")
{
country = Product.Prop[i].Value;
break;
}
}
if (string.IsNullOrEmpty(country))
{
country = BaseRegex.GetMatchRegexString(ref html, @"""delivery"":{""from"":""([\w\W]+?)""");
}
Product.country = country;
}
Product.from_title = 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
{
}
}
/// <summary>
/// 生成名称
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private string BuildName(string name)
{
string temp = "";
string[] props = name.Split(';');
if (name.Contains("-"))
{
name = "";
for (int i = 0; i < props.Length; i++)
{
name += props[i].Split(':')[1] + ",";
}
}
for (int i = 0; i < Product.Props.Count; i++)
{
for (int j = 0; j < Product.Props[i].Values.Count; j++)
{
if (name.Contains(Product.Props[i].Values[j].value))
{
temp += Product.Props[i].name + ":" + Product.Props[i].Values[j].name + ";";
break;
}
}
}
if (string.IsNullOrEmpty(temp))
return "";
return temp.Substring(0, temp.Length - 1);
}
/// <summary>
/// 网址采集计算价格
/// </summary>
/// <param name="price"></param>
/// <returns></returns>
public decimal GetOnlinePrice(decimal price)
{
if (price < 40)
{
price = price * 100 + new Random(Guid.NewGuid().GetHashCode()).Next(1500, 2000);
}
else if (price < 100)
{
price = price * 100 + new Random(Guid.NewGuid().GetHashCode()).Next(2500, 3000);
}
else if (price < 200)
{
price = price * 100 + new Random(Guid.NewGuid().GetHashCode()).Next(3000, 5000);
}
else
{
price = price * 100 + new Random(Guid.NewGuid().GetHashCode()).Next(4000, 6000);
}
return price / 100;
}
public static void SaveCookies()
{
string temp = "";
foreach (var item in TaobaoMobileCollect.CookiesDic)
{
temp += item.Key + "-----" + item.Value + "\r\n";
}
FileBase.WriteAllText("temp/taobaocookies.txt", temp);
}
/// <summary>
/// 获取上家ID
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static long GetUpId(ref string content)
{
string upShopId = BaseRegex.GetMatchRegexString(ref content, @"//item\.taobao\.com/item\.htm\?id=([345][\d]{11})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = BaseRegex.GetMatchRegexString(ref content, @"<[^>]*#fff[^>]*>[^<]*([345][\d]{11})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = BaseRegex.GetMatchRegexString(ref content, @"<[^>]*white[^>]*>[^<]*([345][\d]{11})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = BaseRegex.GetMatchRegexString(ref content, @"<[^>]*#ffffff[^>]*>[^<]*([345][\d]{11})[\D]");
if (string.IsNullOrEmpty(upShopId) && content.Length > 100)
upShopId = BaseRegex.GetMatchRegexString(content.Substring(0, 100), @"[\D]([345][\d]{11})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = BaseRegex.GetMatchRegexString(ref content, @"//item\.taobao\.com/item\.htm\?id=[\D]([\d]{11,12})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = BaseRegex.GetMatchRegexString(ref content, @"[\D]([\d]{11,12})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = BaseRegex.GetMatchRegexString(ref content, @"[\D]([\d]{6,12})[\D]");
if (string.IsNullOrEmpty(upShopId))
upShopId = "0";
long up;
long.TryParse(upShopId, out up);
return up;
}
/// <summary>
/// 清理正文
/// </summary>
/// <param name="content"></param>
/// <returns></returns>
public static string ClearContent(string content)
{
string newContent = BaseRegex.Relpace(content, @"(<img[^>]*assets\.alicdn\.com[^>]*>)", "");
if (newContent.Contains("<img src="))
{
ClearTable(ref newContent);
BaseRegex.Relpace(ref newContent, @"(<[aA] [\w\W]+?</[aA]>)", "");
BaseRegex.Relpace(ref newContent, @"(<p[^>]*>[^<]*[\d]{10,15}[^<]*</p>)", "");
BaseRegex.Relpace(ref newContent, @"(<[^>]*#ffffff[^>]*>[^<]*[\d]{10,15}[^<]*<[^>]*>)", "");
BaseRegex.Relpace(ref newContent, @"((<[pdiv]+[^>]*width:[\s]*0;[\s]*height:[\s]*0;[^>]*>[\w\W]*?</[pdiv]+>))", "");
BaseRegex.Relpace(ref newContent, @"((<[pdiv]+[^>]*width:[\s]*0px;[\s]*height:[\s]*0px;[^>]*>[\w\W]*?</[pdiv]+>))", "");
BaseRegex.Relpace(ref newContent, @"(http[\s]{0,1}://item\.taobao\.com/item\.htm\?id=[\d]+)", "");
newContent = newContent.Replace("<p>&nbsp;</p>", "");
newContent = newContent.Replace("\\\n", "").Replace("var desc=", "").Replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", "");
newContent = newContent.Replace("<wapDesc>", "").Replace("</wapDesc>", "");
newContent = newContent.Trim(' ', ';', '\'');
}
else
{
var matchImg = BaseRegex.GetMatchRegex(ref newContent, "(https:|http:)?//[^\"\'<>]+(.jpg|.jpeg|.png)");
List<string> imageAll = new List<string>();
foreach (Match match in matchImg)
{
imageAll.Add("<img src=\"" + match.Value + "\"></img>");
}
newContent = string.Join("", imageAll);
}
if (!newContent.Contains("<img "))
return content;
return newContent;
}
/// <summary>
/// 清除表格广告代码
/// </summary>
/// <param name="html"></param>
/// <returns></returns>
public static void ClearTable(ref string html)
{
if (string.IsNullOrEmpty(html))
return;
int i = html.IndexOf("<table");
Again:
int first = i;
if (i < 0)
return;
int end = html.IndexOf("</table", i);
if (i < 0 || end < 0 || end < i)
return;
int top = 1;
while (top > 0 && i >= 0)
{
end = html.IndexOf("</table", i);
string temp = html.Substring(i + 6, end - i + 2);
int add = (temp.Length - temp.Replace("<table", "").Length) / 6;
top = top - 1 + add;
int t1 = html.IndexOf("<table", end + 7);
int t2 = html.IndexOf("</table", end + 7);
if (t1 >= 0 && (t1 < t2 || t2 < 0))
i = t1;
if (t2 >= 0 && (t2 < t1 || t1 < 0))
i = t2;
}
string re = html.Substring(first, end - first + 8);
if (re.Contains("<a "))
{
html = html.Replace(re, "");
i = html.IndexOf("<table");
}
else
{
i = html.IndexOf("<table", end);
}
goto Again;
}
protected ProductCollectBase Parser(string html)
{
ProductCollectBase product = new ProductCollectBase();
try
{
if (html == "err data")
{
throw new Exception("采集失败");
}
JToken rootToken = JToken.Parse(html);
int code = rootToken["code"].ToValue(0);
if (code != 200)
{
string msg = rootToken["msg"]?.ToString() ?? "";
product.message = msg;
return product;
}
JToken productToken = rootToken.SelectToken("$.data.item");
if (productToken == null)
{
product.message = "获取失败.";
}
product.from_id = productToken["itemId"].ToValue(0L);
product.from_url = "https://item.taobao.com/item.htm?id=" + product.from_id;
product.from_shop_name = rootToken.SelectToken("$.data.seller.shopName")?.ToString() ?? "";
product.name = productToken["title"]?.ToString() ?? "";
product.cat_id = productToken["categoryId"].ToValue(0);
product.main_cid = productToken["rootCategoryId"].ToValue(0);
product.from_cat_id = product.cat_id;
product.from_site_id = 1;
//var videoToken = productToken.SelectToken("$.videos[0]");
//if (videoToken != null)
//{
// product.VideoId = videoToken["videoId"]?.ToString() ?? "";
//}
product.Images = productToken["images"].HasValues ? productToken["images"].ToObject<List<string>>() : new List<string>();
if (product.Images.Count > 0)
{
product.image = product.Images[0];
product.image_from_url = product.Images[0];
}
string sellCount = productToken["sellCount"].ToString();
if (string.IsNullOrEmpty(sellCount))
{
sellCount = productToken["vagueSellCount"].ToString();
}
if (!string.IsNullOrEmpty(sellCount))
{
var sellCntMatch = Regex.Match(sellCount, @"((^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$)|(^[1-9]\d*|0$))(万)?");
if (sellCntMatch.Length > 0)
{
product.saleCount = int.Parse(sellCntMatch.Value.Contains("万") ? (double.Parse(sellCntMatch.Groups[1].Value) * 10000).ToString() : sellCntMatch.Value);
}
}
//product.IsPreSale 是否预售
// product.isPromotion 是否促销
//
//
// product.discountPrice
// product.discount
// product.onlinePrice
// product.item_size = "";
product.item_weight = 1;
var expressToken = productToken["delivery"];
if (expressToken != null)
{
string fromAddress = expressToken["from"]?.ToString() ?? "";
var dicaddress = ResolveProductDelivery(fromAddress);
product.state = dicaddress.Key;
product.city = dicaddress.Value;
string _expPrice = expressToken["postage"]?.ToString() ?? "";
Regex regPrice = new Regex(@"快递[::][\s]*([\d\.]+)");
if (regPrice.IsMatch(_expPrice))
{
_expPrice = BaseRegex.GetMatchRegexString(ref _expPrice, @"快递[::][\s]*([\d\.]+)");
product.express_price = _expPrice.ParseToDecimal();
}
}
ParserProp(productToken, product);
ParserSkuProp(productToken, product);
ParserSkuMap(productToken, product);
if (product.SkuMaps.Count > 0)
{
product.num = product.SkuMaps.Sum(a => a.number);
product.price = product.SkuMaps.Min(a => a.price);
product.before_price = product.SkuMaps.Min(a => a.before_price);
}
else
{
var onlyOneSkuMap = productToken.SelectToken("$.sku[?(@.skuId=='0')]");
if (onlyOneSkuMap != null)
{
product.num = onlyOneSkuMap["quantity"].ToValue(0);
product.price = onlyOneSkuMap["price"].ToValue(0M);
product.before_price = onlyOneSkuMap["oldPrice"].ToValue(0M);
}
}
//if (product.price == product.before_price)
//{
// product.isPromotion = false;
//}
string descUrl = productToken["descUrl"]?.ToString() ?? "";
//if (!string.IsNullOrEmpty(descUrl))
//{
// product.content = base.GetContent(product.from_id, descUrl);
//}
}
catch (Exception ex)
{
product.message = ex.Message;
LogSave.Add(ex.Message);
}
return product;
}
/// <summary>
/// 解析商品属性
/// </summary>
/// <param name="productToken"></param>
/// <param name="productinfo"></param>
protected virtual void ParserProp(JToken productToken, ProductCollectBase productinfo)
{
JToken propToken = productToken.SelectToken("$.groupProps");
if (propToken == null)
{
return;
}
var basePropListToken = propToken.SelectToken("$..基本信息");
if (basePropListToken == null)
{
return;
}
var basePropsToekn = basePropListToken.SelectTokens("$.[*]");
foreach (var item in basePropsToekn)
{
if (item.First is JProperty baseItem)
{
string name = baseItem.Name;
string value = baseItem.Value.ToString();
if (name.Length > 50 || value.Length > 50)
continue;
productinfo.Prop.Add(new KeyValueBase(name, value));
}
}
}
/// <summary>
/// 格式化地区
/// </summary>
/// <param name="sDelivery"></param>
/// <returns></returns>
protected KeyValuePair<string, string> ResolveProductDelivery(string sDelivery)
{
KeyValuePair<string, string> dic = new KeyValuePair<string, string>("浙江", "杭州");
string[] provice =
"上海,北京,天津,重庆,黑龙江,辽宁,内蒙古,吉林,河北,河南,山西,山东,陕西,青海,宁夏,甘肃,新疆,西藏,四川,云南,贵州,广西,湖南,湖北,安徽,江苏,浙江,广东,福建,海南,台湾,香港,澳门".Split(',');
string[] city =
"上海,北京,天津,重庆,哈尔滨,沈阳,呼和浩特,长春,石家庄,郑州,太原,济南,西安,西宁,银川,兰州,乌鲁木齐,拉萨,成都,昆明,贵阳,南宁,长沙,武汉,合肥,南京,杭州,广州,福州,海口,台北,香港,澳门".Split(',');
if (!string.IsNullOrEmpty(sDelivery))
{
for (int i = 0; i < provice.Length; i++)
{
if (sDelivery.Contains(provice[i]))
{
string _state = provice[i];
string _city = "";
//Product.city = city[i];
if (sDelivery.Length < 4) //直辖市 获取到的长度小于4 直辖市的省和市都是一样的
{
_city = city[i];
}
else
{
//现改成实际地址 发送运费模板
_city = sDelivery.Replace(provice[i], "");
}
dic = new KeyValuePair<string, string>(_state, _city);
break;
}
}
}
return dic;
}
/// <summary>
/// 解析商品Sku属性
/// </summary>
/// <param name="productToken"></param>
/// <param name="productinfo"></param>
protected virtual void ParserSkuProp(JToken productToken, ProductCollectBase productinfo)
{
JToken rootToken = productToken.SelectToken("$.props");
if (rootToken == null)
{
return;
}
var skupropsToekn = rootToken.SelectTokens("$.[*]");
foreach (var item in skupropsToekn)
{
string name = item["name"].ToString();
long pid = item["pid"].ToValue(0L);
PropBase p = new PropBase();
p.id = pid;
p.name = name;
var valuesToekn = item.SelectTokens("$.values[*]");
if (valuesToekn != null && valuesToekn.Count() > 0)
{
foreach (var valueToken in valuesToekn)
{
PropValueBase pv = new PropValueBase();
pv.value = valueToken["vid"]?.ToString() ?? "";
pv.name = valueToken["name"]?.ToString() ?? "";
pv.number = new Random(Guid.NewGuid().GetHashCode()).Next(100, 1000);
pv.image = valueToken["image"]?.ToString() ?? "";
pv.image_from_url = pv.image;
p.Values.Add(pv);
}
}
productinfo.Props.Add(p);
}
}
/// <summary>
/// 解析 Skumpa
/// </summary>
/// <param name="productToken"></param>
/// <param name="productinfo"></param>
protected virtual void ParserSkuMap(JToken productToken, ProductCollectBase productinfo)
{
JToken rootToken = productToken.SelectToken("$.sku");
if (rootToken == null)
{
return;
}
var skumapTokens = rootToken.SelectTokens("$.[*]");
int i = 0;
foreach (var maptoken in skumapTokens)
{
long skuId = maptoken["skuId"].ToValue(0L);
string name = maptoken["skuName"].ToString();
if (skuId == 0 && string.IsNullOrEmpty(name))
{
continue;
}
name = name.Replace("--", ":");
int quantity = maptoken["quantity"].ToValue(0);
decimal price = maptoken["price"].ToValue(0M);
decimal oldPrice = maptoken["oldPrice"].ToValue(0M);
string propPath = maptoken["propPath"].ToString();
string value = "";
Regex regValue = new Regex(":(?<value>.+?)(;|$)");
MatchCollection matchs = regValue.Matches(name);
foreach (Match item in matchs)
{
value += "," + item.Groups["value"].Value;
}
value = value.Remove(0, 1);
SkuMapBase sku = new SkuMapBase();
sku.id = skuId;
sku.name = name;
sku.number = quantity;
sku.price = price;
sku.before_price = oldPrice;
//sku.values = value;
productinfo.SkuMaps.Add(sku);
//i++;
}
}
}
}