186 lines
7.1 KiB
C#
186 lines
7.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AllBase;
|
|
using Work.CollectClass;
|
|
|
|
namespace Work.Api
|
|
{
|
|
public class GetNewTaobaoUpId
|
|
{
|
|
public static Dictionary<long, IntKeyValues> PddToTb = new Dictionary<long, IntKeyValues>();
|
|
public ShopChatBase Shop;
|
|
public GetNewTaobaoUpId(ShopChatBase shop)
|
|
{
|
|
Shop = shop;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取最接近淘宝ID
|
|
/// </summary>
|
|
/// <param name="img">图片</param>
|
|
/// <param name="min">最低价:分 加价之后</param>
|
|
/// <param name="max">最高价:分 加价之后</param>
|
|
/// <returns></returns>
|
|
public long Get(long pid,long fromId, byte[] img, int min, int max,string berfoeTitle)
|
|
{
|
|
int minPrice;
|
|
int maxPrice;
|
|
if (PddToTb.ContainsKey(fromId) && PddToTb[fromId].Value1 > min)
|
|
{
|
|
var i = PddToTb[fromId];
|
|
minPrice = i.Value1;
|
|
maxPrice = i.Value2;
|
|
Set(pid, i.Key, minPrice, maxPrice, i.Value3, 0);
|
|
return i.Key;
|
|
}
|
|
string url = BaseClass.BuildObjString("taobao_id&act=get");
|
|
url = BaseClass.LoginApiUrl + "?obj=pinbaobao/taobao_id&act=get";
|
|
string data = UserLogin.GetSignaturex();
|
|
data += "&pdd_id=" + fromId;
|
|
string html = GetHtml.PostUtf8(url, data);
|
|
if (!string.IsNullOrEmpty(html) && html.Contains("taobao_id"))
|
|
{
|
|
long tid = BaseRegex.GetLongJson(ref html, "taobao_id");
|
|
minPrice = BaseRegex.GetIntJson(ref html, "min_price");
|
|
maxPrice = BaseRegex.GetIntJson(ref html, "max_price");
|
|
int express_price = BaseRegex.GetIntJson(ref html, "express_price");
|
|
try
|
|
{
|
|
PddToTb.Add(fromId, new IntKeyValues(tid, minPrice, maxPrice, express_price));
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
if (min < minPrice)
|
|
{
|
|
Set(pid, tid, minPrice, maxPrice, express_price, 0);
|
|
return tid;
|
|
}
|
|
}
|
|
if (img == null)
|
|
goto EndError;
|
|
|
|
url = "https://s.taobao.com/image";
|
|
string refere = "https://www.taobao.com";
|
|
var ks = new NameValueCollection();
|
|
ks.Add("cross", "taobao");
|
|
ks.Add("type", "iframe");
|
|
html = GetPostTaobaoHtml.PostFileTaobao(url, refere, true, ks,img);
|
|
string name = BaseRegex.GetStringJson(ref html, "name");
|
|
string maxId = "";
|
|
int minPricex = 0;
|
|
if (!string.IsNullOrEmpty(name))
|
|
{
|
|
url =
|
|
"https://s.taobao.com/search?q=&imgfile=&commend=all&ssid=s5-e&search_type=item&sourceId=tb.index&spm=a21bo.2017.201856-taobao-item.2&ie=utf8&tfsid=" +
|
|
name + "&app=imgsearch";
|
|
html = GetPostTaobaoHtml.GetUrl(url, refere, true, "");
|
|
var m = BaseRegex.GetMatchRegex(ref html, @"\{""nid"":""([\d]+)"",[\w\W]+?,""view_price"":""([\d\.]+)""");
|
|
for (int i = 0; m != null && i < m.Count && i < 8; i++)
|
|
{
|
|
string id = m[i].Groups[1].Value;
|
|
int price = (int) (decimal.Parse(m[i].Groups[2].Value)*100);
|
|
if (price > minPricex)
|
|
{
|
|
minPricex = price;
|
|
maxId = id;
|
|
}
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(maxId))
|
|
{
|
|
int p1 = max/100, p2 = max/100*3 + 500;
|
|
url = "https://s.taobao.com/search?q=" + GetHtml.UrlEncodeUtf8(berfoeTitle) +
|
|
"&imgfile=&js=1&style=grid&stats_click=search_radio_all%3A1&ie=utf8&filter=reserve_price%5B" + p1 +
|
|
"%2C" + p2 + "%5D";
|
|
html = GetPostTaobaoHtml.GetUrl(url, refere, true, "");
|
|
var m = BaseRegex.GetMatchRegex(ref html,
|
|
@"""nid"":""([\d]+)""[\w\W]*?""raw_title"":""([^""]+)""[\w\W]+?,""view_price"":""([\d\.]+)""");
|
|
maxId = "";
|
|
minPricex = 0;
|
|
for (int i = 0; m != null && i < m.Count && i < 8; i++)
|
|
{
|
|
string id = m[i].Groups[1].Value;
|
|
string title = m[i].Groups[2].Value;
|
|
int price = (int) (decimal.Parse(m[i].Groups[3].Value)*100);
|
|
if (price > minPricex && title.ToLower()==berfoeTitle.ToLower())
|
|
{
|
|
minPricex = price;
|
|
maxId = id;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (minPricex > min && !string.IsNullOrEmpty(maxId))
|
|
{
|
|
long tid = long.Parse(maxId);
|
|
ProductCollectBase p = new ProductCollectBase();
|
|
p.from_id = tid;
|
|
TaobaoMobileCollect t =new TaobaoMobileCollect(p);
|
|
t.NoContent = true;
|
|
t.NoUpToServer = true;
|
|
t.Get();
|
|
minPrice = (int) (t.MinPrice*100);
|
|
maxPrice = (int)(t.MaxPrice * 100);
|
|
int express_price = (int) (p.express_price*100);
|
|
url = BaseClass.BuildObjString("taobao_id&act=add");
|
|
data = UserLogin.GetSignaturex();
|
|
data += "&pdd_id=" + fromId;
|
|
data += "&taobao_id=" + tid;
|
|
data += "&min_price=" + minPrice;
|
|
data += "&max_price=" + maxPrice;
|
|
data += "&express_price=" + express_price;
|
|
html = GetHtml.PostUtf8(url, data);
|
|
try
|
|
{
|
|
PddToTb.Add(fromId, new IntKeyValues(tid,minPrice,maxPrice, express_price));
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
Set(pid, tid, minPrice, maxPrice, express_price, 0);
|
|
return tid;
|
|
}
|
|
|
|
EndError:
|
|
long upid = Randomx.GetId(100000, 9999999) * (long)Randomx.GetId(10000, 99999);
|
|
|
|
minPrice =(int)( min*0.93m);
|
|
maxPrice = (int)(max * 0.93m);
|
|
Set(pid,upid,minPrice,maxPrice,0,5);
|
|
return upid;
|
|
}
|
|
|
|
|
|
public void Set(long pid,long tid, int beforePriceMin,int beforePriceMax,int express_price,int from_site_id)
|
|
{
|
|
var api = new PinduoduoApiGetProduct(Shop);
|
|
string html = api.Relationx(pid, tid, beforePriceMin, beforePriceMax, express_price, from_site_id);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class IntKeyValues
|
|
{
|
|
public IntKeyValues(long k, int v1, int v2, int v3)
|
|
{
|
|
Key = k;
|
|
Value1 = v1;
|
|
Value2 = v2;
|
|
Value3 = v3;
|
|
}
|
|
|
|
public long Key = 0;
|
|
public int Value1 = 0;
|
|
public int Value2 = 0;
|
|
public int Value3 = 0;
|
|
}
|
|
}
|