119 lines
4.1 KiB
C#
119 lines
4.1 KiB
C#
using AllBase;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Work.BaseForms;
|
|
using Work.Tips;
|
|
|
|
namespace Work.Pinduoduo
|
|
{
|
|
public class PddProductDetail
|
|
{
|
|
#region 通过代理ip获取商品详情
|
|
public static string key = "";
|
|
public static DateTime endTime = BaseClass.GetServerTimeString();
|
|
|
|
public static List<SkuDetail> GetProDetails(string id)
|
|
{
|
|
string url = "";
|
|
string html = "";
|
|
if (string.IsNullOrEmpty(key) || endTime <= BaseClass.GetServerTimeString())
|
|
{
|
|
string data = UserLogin.GetSignaturex();
|
|
url = BaseClass.BuildObjString("check_vcode&act=get_agent_ip");
|
|
html = GetHtml.PostUtf8(url, data);
|
|
if (!html.Contains("\"code\":200"))
|
|
{
|
|
BaseMsgForm.ShowError("请求失败,请过几秒后再试!", "提示", FormLevel.SMALL);
|
|
return null;
|
|
}
|
|
key = BaseRegex.GetStringJson(ref html, "the_key_temp");
|
|
var endTimeStr = BaseRegex.GetStringJson(ref html, "end_time");
|
|
endTime = Convert.ToDateTime(endTimeStr);
|
|
}
|
|
|
|
url = "http://goods.66daili.cn/api/goods/get/?orderid=" + DataOpenSSL.DecryptString(key) + "&token=5AF433ED506FA475&goodID=" + id;
|
|
html = GetHtml.PostUtf8(url, "");
|
|
if (html.Contains("req too many"))
|
|
{
|
|
Thread.Sleep(3000);
|
|
html = GetHtml.PostUtf8(url, "");
|
|
}
|
|
if (html.Contains("\"code\":408"))
|
|
{
|
|
BaseMsgForm.ShowError("请求频繁,请过几秒后再试!", "提示", FormLevel.SMALL);
|
|
return null;
|
|
}
|
|
html = GetHtml.UrlDecode(html);
|
|
return GetSkuArr(html);
|
|
}
|
|
#endregion
|
|
|
|
public static List<SkuDetail> GetSkuArr(string html)
|
|
{
|
|
var skuArr = BaseRegex.GetMatchRegex(ref html, "\"sku_id\":[\\s\\S]+?attribute\":[\\S\\s]+?\"");
|
|
|
|
List<SkuDetail> skuDetailList = new List<SkuDetail>();
|
|
for (int i = 0; i < skuArr.Count; i++)
|
|
{
|
|
SkuDetail skuDetail = new SkuDetail();
|
|
var skuItem = skuArr[i].Value;
|
|
string sku_id = BaseRegex.GetStringJson(ref skuItem, "sku_id");
|
|
string thumb_url = BaseRegex.GetStringJson(ref skuItem, "thumb_url");
|
|
decimal normal_price = BaseRegex.GetDecimalJson(ref skuItem, "normal_price");
|
|
decimal group_price = BaseRegex.GetDecimalJson(ref skuItem, "group_price");
|
|
var skuSpecArr = BaseRegex.GetMatchRegex(ref skuItem, "(\\{\"spec_key\":[\\s\\S]+?\"spec_value_id\":[\\s\\S]+?\\})");
|
|
|
|
skuDetail.sku_id = sku_id;
|
|
skuDetail.thumb_url = thumb_url;
|
|
skuDetail.normal_price = normal_price;
|
|
skuDetail.group_price = group_price;
|
|
|
|
skuDetail.skuSpecs = new List<SkuSpecs>();
|
|
for (int j = 0; j < skuSpecArr.Count; j++)
|
|
{
|
|
SkuSpecs skuSpec = new SkuSpecs();
|
|
var specItem = skuSpecArr[j].Value;
|
|
string spec_value = BaseRegex.GetStringJson(ref specItem, "spec_value");
|
|
skuSpec.spec_value = spec_value;
|
|
skuSpec.spec_value = spec_value;
|
|
skuDetail.skuSpecs.Add(skuSpec);
|
|
}
|
|
|
|
|
|
skuDetailList.Add(skuDetail);
|
|
}
|
|
|
|
|
|
return skuDetailList;
|
|
}
|
|
}
|
|
|
|
//public class ProductDetail
|
|
//{
|
|
// public List<SkuDetail> skuDetail { get; set; }
|
|
//}
|
|
|
|
|
|
public class SkuDetail
|
|
{
|
|
public string sku_id { get; set; }
|
|
|
|
public string thumb_url { get; set; }
|
|
|
|
public List<SkuSpecs> skuSpecs { get; set; }
|
|
|
|
public decimal normal_price { get; set; }
|
|
|
|
public decimal group_price { get; set; }
|
|
}
|
|
|
|
public class SkuSpecs
|
|
{
|
|
public string spec_value { get; set; }
|
|
}
|
|
}
|