temu客户端程序
This commit is contained in:
commit
4aaf264e89
694 files changed
+263780
No files matched your search
@@ -0,0 +1,167 @@
|
||||
using AllBase.Model.Result;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Work.BLL.Collect
|
||||
{
|
||||
/// <summary>
|
||||
/// 抖音好物采集
|
||||
/// </summary>
|
||||
public class HaoWuCollectBLL
|
||||
{
|
||||
private static bool CheckValidationResult(object sender, object certificate, object chain, SslPolicyErrors errors) => true; // 总是接受
|
||||
|
||||
public static string getHtml_fxg_20201220(string url, string cookies, string ip = "")
|
||||
{
|
||||
string str = "";
|
||||
try
|
||||
{
|
||||
int num = 0;
|
||||
while (num < 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = null;
|
||||
if (!url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
request.ProtocolVersion = HttpVersion.Version10;
|
||||
}
|
||||
request.Timeout = 25000;
|
||||
request.ReadWriteTimeout = 25000;
|
||||
request.Method = "Get";
|
||||
request.ContentType = "application/json; charset=utf-8";
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36";
|
||||
if ((DateTime.Now.Second % 5) == 0)
|
||||
{
|
||||
request.UserAgent = "com.ss.android.ugc.aweme/140001 (Linux; U; QuicVersion:47946d2a 2020-10-14)";
|
||||
}
|
||||
else if ((DateTime.Now.Second % 5) == 1)
|
||||
{
|
||||
request.UserAgent = "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3";
|
||||
}
|
||||
else if ((DateTime.Now.Second % 5) == 2)
|
||||
{
|
||||
request.UserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3";
|
||||
}
|
||||
else if ((DateTime.Now.Second % 5) == 3)
|
||||
{
|
||||
request.UserAgent = "Mozilla/5.0 (Linux; Android 10; TAS-AL00 Build/HUAWEITAS-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045120 Mobile Safari/537.36 V1_AND_SQ_8.2.7_1334_YYB_D QQ/8.2.7.4410 NetType/WIFI WebP/0.3.0 Pixel/1080 StatusBarHeight/81 SimpleUISwitch/0";
|
||||
}
|
||||
else if ((DateTime.Now.Second % 5) == 4)
|
||||
{
|
||||
request.UserAgent = "Mozilla/5.0 (Linux; Android 6.0.1; Redmi Note 3 Build/MMB29M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/76.0.3809.89 Mobile Safari/537.36 T7/11.19 SP-engine/2.15.0 baiduboxapp/11.19.5.10 (Baidu; P1 6.0.1)";
|
||||
}
|
||||
request.Host = new Uri(url).Host;
|
||||
if (cookies.Trim() != "")
|
||||
{
|
||||
request.Headers.Add("Cookie", cookies);
|
||||
}
|
||||
request.Headers.Add("x-agw-info", "w6S2IHH6-wDuuvNtk2hidFD2MalfJTaURnf6XobYTqjSXcFmCxT79rJjYPudFSWQKnvYl1_OuIsDwtMtheGHihJf4OgPYQqcLNzPkIgpYAEbkfMAvBCAm1gY6uOq0Q_7DbfFOJAMQRGwDEkbVSLUxQSX5cc0hIkwhm36AUf0CflSXVno");
|
||||
request.Headers.Add("x-tt-logid", "2020122015563901002902921706016162");
|
||||
request.Headers.Add("x-tt-trace-host", "010c04b40779d7ea1251fcddf2faf54650937df4831d71a387846d4b65371bb93d891684d9895d083828b415698988c161a98e8e3579dfbba439a0f3317851b468507df11e82922352c8b013941f82ea53");
|
||||
request.Headers.Add("x-trans-level", "0");
|
||||
request.Headers.Add("x-tt-trace-tag", "id=3;cdn-cache=miss");
|
||||
char[] separator = new char[] { ':' };
|
||||
string[] strArray = ip.Split(separator);
|
||||
char[] chArray2 = new char[] { '.' };
|
||||
string[] strArray2 = ip.Split(chArray2);
|
||||
if (((ip.Trim() != "") && ((strArray.Length == 2) && (ip.IndexOf(".") > 0))) && (strArray2.Length == 4))
|
||||
{
|
||||
request.Proxy = new WebProxy(strArray[0], Convert.ToInt32(strArray[1].Trim()));
|
||||
}
|
||||
Encoding encoding = Encoding.Default;
|
||||
encoding = Encoding.UTF8;
|
||||
str = new StreamReader(((HttpWebResponse)request.GetResponse()).GetResponseStream(), encoding).ReadToEnd();
|
||||
num = 10;
|
||||
}
|
||||
catch
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public static string getHtml(string url, string cookies, string encod = "")
|
||||
{
|
||||
string str = "";
|
||||
try
|
||||
{
|
||||
int num = 0;
|
||||
while (num < 3)
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = null;
|
||||
if (!url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
|
||||
request = WebRequest.Create(url) as HttpWebRequest;
|
||||
request.ProtocolVersion = HttpVersion.Version10;
|
||||
}
|
||||
request.Method = "Get";
|
||||
request.Referer = url;
|
||||
request.ContentType = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;";
|
||||
request.ContentType = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.75 Safari/537.36";
|
||||
request.Host = new Uri(url).Host;
|
||||
if (cookies.Trim() != "")
|
||||
{
|
||||
request.Headers.Add("Cookie", cookies);
|
||||
}
|
||||
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
||||
Encoding encoding = Encoding.Default;
|
||||
if (encod == "utf8")
|
||||
{
|
||||
encoding = Encoding.UTF8;
|
||||
}
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream(), encoding);
|
||||
str = reader.ReadToEnd();
|
||||
try
|
||||
{
|
||||
reader.Close();
|
||||
response.Close();
|
||||
reader.Dispose();
|
||||
response = null;
|
||||
request = null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
num = 10;
|
||||
}
|
||||
catch
|
||||
{
|
||||
num++;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return str;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,788 @@
|
||||
using NaiBa.Util;
|
||||
using NaiBa.Util.Extension;
|
||||
using NaiBa.Util.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BLL.Collect
|
||||
{
|
||||
public class PddSameScreeningBLL
|
||||
{
|
||||
#region http请求
|
||||
|
||||
//Returns the text contained in the response. For example, the page HTML. Only handles the most common HTTP encodings.
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求当前店铺销量
|
||||
/// </summary>
|
||||
/// <param name="response">After the function has finished, will possibly contain the response to the request.</param>
|
||||
/// <returns>True if the request was successful; false otherwise.</returns>
|
||||
public static string RequestShopSold(string url, string Token)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
//Create request to URL.
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
//Set request headers.
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
|
||||
request.Headers.Add("Upgrade-Insecure-Requests", @"1");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36";
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
request.Headers.Set(HttpRequestHeader.Cookie, Token);
|
||||
|
||||
//Get response to request.
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
//ProtocolError indicates a valid HTTP response, but with a non-200 status code (e.g. 304 Not Modified, 404 Not Found)
|
||||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||||
else return "";
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (response != null) response.Close();
|
||||
return "";
|
||||
}
|
||||
|
||||
return ReadResponse(response);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取宝贝数量
|
||||
/// </summary>
|
||||
/// <param name="response">After the function has finished, will possibly contain the response to the request.</param>
|
||||
/// <returns>True if the request was successful; false otherwise.</returns>
|
||||
public static string RequestShopCount(string url, string Token)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
|
||||
try
|
||||
{
|
||||
//Create request to URL.
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://yangkeduo.com/proxy/api/api/turing/mall/query_mall_category_list?pdduid=2423695749878&mall_id=" + url);
|
||||
|
||||
//Set request headers.
|
||||
request.KeepAlive = true;
|
||||
request.Accept = "application/json, text/plain, */*";
|
||||
request.Headers.Add("AccessToken", Token);
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36";
|
||||
request.Headers.Add("VerifyAuthToken", @"kUo_K6VOliEhlNZNorECKQ");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
//Get response to request.
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
//ProtocolError indicates a valid HTTP response, but with a non-200 status code (e.g. 304 Not Modified, 404 Not Found)
|
||||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||||
else return "";
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (response != null) response.Close();
|
||||
return "";
|
||||
}
|
||||
|
||||
return ReadResponse(response);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to request the URL: http://api.yangkeduo.com/mall/412236912/info
|
||||
/// </summary>
|
||||
/// <param name="response">After the function has finished, will possibly contain the response to the request.</param>
|
||||
/// <returns>True if the request was successful; false otherwise.</returns>
|
||||
public static string Request_api_yangkeduo_com(string url, string Token)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
//Create request to URL.
|
||||
string requestUrl = "http://api.yangkeduo.com/mall/" + url + "/info";
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUrl);
|
||||
//Set request headers.
|
||||
request.Referer = "Android";
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
request.Headers.Add("AccessToken", Token);
|
||||
request.UserAgent = "android Mozilla/5.0 (Linux; Android 5.1.1; m1 metal Build/LMY49I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.100 Safari/537.36 phh_android_version/4.17.1 phh_android_build/1a7ec8b149 phh_android_channel/gw";
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip");
|
||||
|
||||
//Get response to request.
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
//ProtocolError indicates a valid HTTP response, but with a non-200 status code (e.g. 304 Not Modified, 404 Not Found)
|
||||
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||||
else return "";
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (response != null) response.Close();
|
||||
return "";
|
||||
}
|
||||
|
||||
return ReadResponse(response);
|
||||
}
|
||||
|
||||
public static string Request_api_yangkeduo_Ip(string url, string[] UserAgentList)
|
||||
{
|
||||
string result = "";
|
||||
try
|
||||
{
|
||||
string requestUrl = url;
|
||||
HttpParam httpParam = new HttpParam();
|
||||
httpParam.Url = requestUrl;
|
||||
httpParam.Referer = url;
|
||||
string UserAgentTemp = UserAgentList[new Random().Next(UserAgentList.Count())];
|
||||
if (!string.IsNullOrEmpty(UserAgentTemp) && !UserAgentTemp.Contains("MicroMessenger"))
|
||||
{
|
||||
UserAgentTemp = UserAgentTemp.Insert(new Random().Next(UserAgentTemp.Length), "MicroMessenger" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, new Random().Next(5)));
|
||||
}
|
||||
httpParam.UserAgent = UserAgentTemp;
|
||||
httpParam.TryTimes = 60;
|
||||
httpParam.ProxySleep = 500;
|
||||
if (url.Contains("mall_page.html"))
|
||||
{
|
||||
result = GlobalProxyHelper.Request(httpParam, (response) => !string.IsNullOrEmpty(response) && !response.Contains("<title>店铺主页</title>"));
|
||||
if (result.Contains(("<title>店铺主页</title>")))
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
httpParam.TryTimes = 60;
|
||||
httpParam.Timeout = 10000;
|
||||
result = GlobalProxyHelper.Request(httpParam, (response) => !string.IsNullOrEmpty(response) && !response.Contains("<title>店铺主页</title>"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = GlobalProxyHelper.Request(httpParam, (response) => !string.IsNullOrEmpty(response) && !response.Contains("error_code"));
|
||||
if (result.Contains(("error_code")))
|
||||
{
|
||||
Thread.Sleep(10000);
|
||||
httpParam.TryTimes = 60;
|
||||
result = GlobalProxyHelper.Request(httpParam, (response) => !string.IsNullOrEmpty(response) && !response.Contains("error_code"));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static List<string> listIp = new List<string>();
|
||||
|
||||
private static readonly object obj = new object();
|
||||
private static int UseCount = 0;
|
||||
public static string Request_yangkeduo_com(string sIpAndPort, long lProdId, string[] UserAgentList, out bool IsOverdue, bool IsBreak = false)
|
||||
{
|
||||
IsOverdue = false;
|
||||
try
|
||||
{
|
||||
if (IsBreak)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
if (UseCount >= 150 && listIp.Count > 0)//代理ip 使用超过150次 才去请求一次ip
|
||||
{
|
||||
listIp.Clear();
|
||||
}
|
||||
lock (obj)
|
||||
{
|
||||
//Thread.Sleep(3000);
|
||||
if (listIp.Count() <= 0)
|
||||
{
|
||||
//Thread.Sleep(1000);
|
||||
listIp = InitIp(sIpAndPort, out IsOverdue);
|
||||
UseCount = 0;
|
||||
}
|
||||
}
|
||||
if (IsOverdue)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
string ProxyIP = listIp[new Random().Next(0, listIp.Count)];
|
||||
UseCount++;
|
||||
//listIp.Remove(listIp[0]);
|
||||
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
string UserAgentTemp = UserAgentList[new Random().Next(UserAgentList.Count())];
|
||||
if (!string.IsNullOrEmpty(UserAgentTemp) && !UserAgentTemp.Contains("MicroMessenger"))
|
||||
{
|
||||
UserAgentTemp = UserAgentTemp.Insert(new Random().Next(UserAgentTemp.Length), "MicroMessenger" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, new Random().Next(5)));
|
||||
}
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://mobile.yangkeduo.com/goods.html?goods_id=" + lProdId);
|
||||
request.Timeout = 5000;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en;q=0.8");
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
||||
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
request.UserAgent = UserAgentTemp;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "deflate");
|
||||
System.Net.WebProxy proxy = GetWebProxy(ProxyIP);
|
||||
request.Proxy = proxy;
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
Thread.Sleep(3000);
|
||||
LogHelper.Write(e.Message);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if (response != null)
|
||||
{
|
||||
|
||||
string result = ReadResponse(response);
|
||||
if (result.Contains("mallID"))
|
||||
{
|
||||
//GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
|
||||
return HtmlHelper.UnicodeDecode(result);
|
||||
}
|
||||
|
||||
}
|
||||
return "";
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static string RequestUrl_yangkeduo_com(long lProdId, string[] UserAgentList, string orderId, out bool IsOverdue)
|
||||
{
|
||||
IsOverdue = false;
|
||||
int count = 0;
|
||||
try
|
||||
{
|
||||
Again:
|
||||
count++;
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
string UserAgentTemp = UserAgentList[new Random().Next(UserAgentList.Count())];
|
||||
if (!string.IsNullOrEmpty(UserAgentTemp) && !UserAgentTemp.Contains("MicroMessenger"))
|
||||
{
|
||||
UserAgentTemp = UserAgentTemp.Insert(new Random().Next(UserAgentTemp.Length), "MicroMessenger" + Guid.NewGuid().ToString().Replace("-", "").Substring(0, new Random().Next(5)));
|
||||
}
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://goods.66daili.cn/api/goods/get/?orderid=" + orderId + "&token=5AF433ED506FA475&goodID=" + lProdId);
|
||||
request.Timeout = 5000;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9,en;q=0.8");
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
|
||||
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
|
||||
request.UserAgent = UserAgentTemp;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "deflate");
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
LogHelper.Write(ex.Message);
|
||||
}
|
||||
if (response != null)
|
||||
{
|
||||
string result = ReadResponse(response);
|
||||
if (result.Contains("order expire or not exist"))
|
||||
{
|
||||
IsOverdue = true;
|
||||
return "";
|
||||
}
|
||||
if (result.Contains("mall_id") || result.Contains("mallId") || result.Contains("mallID"))
|
||||
{
|
||||
return HtmlHelper.UnicodeDecode(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count < 10)
|
||||
{
|
||||
Thread.Sleep(new Random().Next(50, 200));
|
||||
goto Again;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (count < 10)
|
||||
{
|
||||
Thread.Sleep(new Random().Next(50, 200));
|
||||
goto Again;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static string MakeRequestForGetPddProdDetailByWeixin(string sIpAndPort, long lProdId)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
bool IsOverdue = false;
|
||||
List<string> listIp = InitIp(sIpAndPort, out IsOverdue);
|
||||
//if(listIp!=null&&listIp.Count>0)
|
||||
for (int i = 0; i < listIp.Count; i++)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wxapp.yangkeduo.com/compose/vtx/goods/detail/first/v3?pdduid=4014246301&xcx=20161201&xcx_version=v5.7.6.1&xcx_hash=" + GetTimeStampMilliSec() + GetRandomString(16));
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "no-cache");
|
||||
request.Headers.Add("GZToken", Guid.NewGuid().ToString().Replace("-", "").Substring(0, 32));
|
||||
//request.Headers.Add("GZToken", @"8dc2715af33d80577efe1cccd945fd38");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat";
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
request.Referer = "https://servicewechat.com/wx32540bd863b27570/1116/page-frame.html";
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||||
System.Net.WebProxy proxy = GetWebProxy(listIp[i]);
|
||||
request.Proxy = proxy;
|
||||
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
|
||||
string body = @"{""goods_id"":""" + lProdId + @""",""from"":""24"",""has_rec"":true,""address_list"":[{""address_id"":""19159230174"",""province_id"":""3"",""city_id"":""3401"",""district_id"":""4124"",""is_default"":""1"",""is_top"":0}],""page_version"":7,""show_type"":1,""xcx_trace_id"":""" + GetRandrom(16) + @""",""client_time"":" + GetTimeStampMilliSec() + @",""anti_content"":""3aje" + GetRandomString(122) + @""",""xcx_version"":""v5.7.6.1""}";
|
||||
//string body = @"{""goods_id"":""" + lProdId + @""",""from"":""24"",""has_rec"":true,""address_list"":[{""address_id"":""19159230174"",""province_id"":""3"",""city_id"":""3401"",""district_id"":""4124"",""is_default"":""1"",""is_top"":0}],""page_version"":7,""show_type"":1,""xcx_trace_id"":""4277241276553842"",""client_time"":" + GetTimeStampMilliSec() + @",""anti_content"":""3ajeJxjZGRgYAhjYGJMBOIkIE4G4hQgTmVQZEyTMzEwMDAzsDCxMLYwNDY2MdU1NLU0MDW1NDUyNjM2ZeBiTGdnYCwK2WOnxMDKmMEENIyZMZMByM5iYmAEADpcDLo"",""xcx_version"":""v5.7.6.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)
|
||||
{
|
||||
//return "";
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
//return "";
|
||||
}
|
||||
if (response == null) continue;
|
||||
string result = ReadResponse(response);
|
||||
if (result.Contains("\"success\":true"))
|
||||
{
|
||||
//GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
|
||||
return result;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
GlobalProxyHelper.CloseIp(listIp);//没找到也关闭
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 整店采集
|
||||
/// </summary>
|
||||
/// <param name="sIpAndPort"></param>
|
||||
/// <param name="lProdId"></param>
|
||||
/// <param name="UserAgent"></param>
|
||||
/// <returns></returns>
|
||||
public static string RequestAllShopList(string sIpAndPort, string url, Func<string, string> antiContentFunc, string UserAgent)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
bool IsOverdue = false;
|
||||
List<string> listIp = InitIp(sIpAndPort, out IsOverdue);
|
||||
string NewUrl = "";
|
||||
for (int i = 0; i < listIp.Count; i++)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
NewUrl = url + "&anticontent=" + antiContentFunc(UserAgent);
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(NewUrl);
|
||||
request.KeepAlive = true;
|
||||
request.Accept = "application/json, text/plain, */*";
|
||||
request.UserAgent = UserAgent;
|
||||
//request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36 QBCore/4.0.1301.400 QQBrowser/9.0.2524.400 Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2875.116 Safari/537.36 NetType/WIFI MicroMessenger/7.0.5 WindowsWechat";
|
||||
request.Referer = "https://mobile.yangkeduo.com/";
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.5;q=0.4");
|
||||
System.Net.WebProxy proxy = GetWebProxy(listIp[i]);
|
||||
request.Proxy = proxy;
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
if (response == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string result = ReadResponse(response);
|
||||
if (result.Contains("goods_list"))
|
||||
{
|
||||
//GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
|
||||
return HtmlHelper.UnicodeDecode(result);
|
||||
}
|
||||
Thread.Sleep(new Random().Next(500, 1500));
|
||||
}
|
||||
GlobalProxyHelper.CloseIp(listIp);//没找到也关闭
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static long GetRandrom(int len)
|
||||
{
|
||||
Random rand = new Random();
|
||||
string strNum = "";
|
||||
int i = 0;
|
||||
while (i < len)
|
||||
{
|
||||
i++;
|
||||
int randomNum = rand.Next(0, 10);
|
||||
strNum += randomNum.ToString();
|
||||
}
|
||||
|
||||
return strNum.ParseToLong();
|
||||
}
|
||||
|
||||
|
||||
public static string Request_weixinKweWords(string sIpAndPort, string keyword, int page)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
bool IsOverdue = false;
|
||||
List<string> listIp = InitIp(sIpAndPort, out IsOverdue);
|
||||
//if(listIp!=null&&listIp.Count>0)
|
||||
for (int i = 0; i < listIp.Count; i++)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://wxapp.yangkeduo.com/compose/vtx/search?pdduid=4014246301&xcx=20161201&xcx_version=v5.7.9&xcx_hash=1590732694274NkDSTBGS61cRPBiD");
|
||||
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "no-cache");
|
||||
request.Headers.Add("GZToken", @"7933a2eca48857c7640ce14ff17d4bbb");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat";
|
||||
request.ContentType = "application/json;charset=UTF-8";
|
||||
request.Referer = "https://servicewechat.com/wx32540bd863b27570/1125/page-frame.html";
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
||||
System.Net.WebProxy proxy = GetWebProxy(listIp[i]);
|
||||
request.Proxy = proxy;
|
||||
|
||||
request.Method = "POST";
|
||||
request.ServicePoint.Expect100Continue = false;
|
||||
|
||||
//string body = "{\"\"is_form_wallet\"\":false,\"\"query\"\":\"\"" + keyword + "\"\",\"\"new_search\"\":true,\"\"search\"\":{\"\"page\"\":" + page + ",\"\"size\"\":20,\"\"requery\"\":0,\"\"list_id\"\":\"\"xcx_search_ZN6Xie\"\",\"\"source\"\":\"\"index\"\",\"\"sort\"\":\"\"default\"\"},\"\"anti_content\"\":\"\"3ajeJxjZGRgYAhjYGJMBOIkIE4G4hQgTmVQZEyTMzYzMzU0trAwNzU1NbI0NdU1NLU0MDc2MrM0NTA0Z-BiTGdnYCyK51vMwMDKmMEENIyZMRPEzgKyATcqDHE\"\",\"\"xcx_version\"\":\"\"v5.7.9\"\"}";
|
||||
string body = @"{""is_form_wallet"":false,""query"":""连衣裙"",""new_search"":true,""search"":{""page"":1,""size"":20,""requery"":0,""list_id"":""xcx_search_ZN6Xie"",""source"":""index"",""sort"":""default""},""anti_content"":""3ajeJxjZGRgYAhjYGJMBOIkIE4G4hQgTmVQZEyTMzYzMzU0trAwNzU1NbI0NdU1NLU0MDc2MrM0NTA0Z-BiTGdnYCyK51vMwMDKmMEENIyZMRPEzgKyATcqDHE"",""xcx_version"":""v5.7.9""}";
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
string result = ReadResponse(response);
|
||||
//if (result.Contains("mallID"))
|
||||
{
|
||||
GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
|
||||
return result;
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
GlobalProxyHelper.CloseIp(listIp);//没找到也关闭
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
private static char[] constant =
|
||||
{
|
||||
'0','1','2','3','4','5','6','7','8','9',
|
||||
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
|
||||
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
|
||||
};
|
||||
private static string GetRandomString(int iLength)
|
||||
{
|
||||
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(62);
|
||||
Random rd = new Random();
|
||||
for (int i = 0; i < iLength; i++)
|
||||
{
|
||||
newRandom.Append(constant[rd.Next(62)]);
|
||||
}
|
||||
return newRandom.ToString();
|
||||
|
||||
}
|
||||
public static string GetTimeStampMilliSec()
|
||||
{
|
||||
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
|
||||
return Convert.ToInt64(ts.TotalMilliseconds).ToString();
|
||||
}
|
||||
|
||||
public static List<string> InitIp(string ProxyUrl, out bool IsOverdue)
|
||||
{
|
||||
IsOverdue = false;
|
||||
if (listIp.Count > 0)
|
||||
{
|
||||
return listIp;
|
||||
}
|
||||
HttpParam httpParm = new HttpParam { Url = ProxyUrl };
|
||||
GlobalProxyHelper.SetAuthorization(httpParm);
|
||||
string proxyIpHtml = string.Empty;
|
||||
List<string> proxyIpList = new List<string>();
|
||||
int tryTimes = 0;
|
||||
int maxTryTimes = 10;
|
||||
while (true && tryTimes <= maxTryTimes)
|
||||
{
|
||||
proxyIpHtml = HttpHelper.Get(httpParm);
|
||||
if (proxyIpHtml.Contains("过期") || proxyIpHtml.Contains("套餐不存在"))
|
||||
{
|
||||
IsOverdue = true;
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(proxyIpHtml) && !proxyIpHtml.Contains("后获取") && !proxyIpHtml.Contains("过期") && !proxyIpHtml.Contains("套餐不存在"))
|
||||
{
|
||||
proxyIpList = proxyIpHtml.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Trim()).ToList();
|
||||
break;
|
||||
}
|
||||
tryTimes++;
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
return proxyIpList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static string RequestTest(string sIpAndPort, string url)
|
||||
{
|
||||
|
||||
while (true)
|
||||
{
|
||||
bool IsOverdue = false;
|
||||
List<string> listIp = InitIp(sIpAndPort, out IsOverdue);
|
||||
//if(listIp!=null&&listIp.Count>0)
|
||||
for (int i = 0; i < listIp.Count; i++)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.KeepAlive = true;
|
||||
request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
|
||||
request.Headers.Add("Upgrade-Insecure-Requests", @"1");
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/82.0.2444.133 Safari/537.36";
|
||||
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
|
||||
request.Referer = url;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
System.Net.WebProxy proxy = GetWebProxy(listIp[i]);
|
||||
request.Proxy = proxy;
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
string result = ReadResponse(response);
|
||||
if (!result.Contains("<title>店铺主页</title>"))
|
||||
{
|
||||
GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
|
||||
return result;
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
GlobalProxyHelper.CloseIp(listIp);//没找到也关闭
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
//HttpWebResponse response = null;
|
||||
|
||||
//try
|
||||
//{
|
||||
// HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
|
||||
// request.KeepAlive = true;
|
||||
// request.Headers.Set(HttpRequestHeader.CacheControl, "max-age=0");
|
||||
// request.Headers.Add("Upgrade-Insecure-Requests", @"1");
|
||||
// request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36";
|
||||
// request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
|
||||
// request.Referer = url;
|
||||
// request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
// request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
// System.Net.WebProxy proxy = GetWebProxy("120.79.214.87 11318 test200420-1 gu05VREpn349KSiT");
|
||||
// request.Proxy = proxy;
|
||||
|
||||
// response = (HttpWebResponse)request.GetResponse();
|
||||
//}
|
||||
//catch (WebException e)
|
||||
//{
|
||||
// //ProtocolError indicates a valid HTTP response, but with a non-200 status code (e.g. 304 Not Modified, 404 Not Found)
|
||||
// if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
||||
// else return "";
|
||||
//}
|
||||
//catch (Exception)
|
||||
//{
|
||||
// if (response != null) response.Close();
|
||||
// return "";
|
||||
//}
|
||||
|
||||
//return ReadResponse(response);
|
||||
}
|
||||
public static string RequestTestA(string sIpAndPort, string url)
|
||||
{
|
||||
|
||||
while (true)
|
||||
{
|
||||
bool IsOverdue = false;
|
||||
List<string> listIp = InitIp(sIpAndPort, out IsOverdue);
|
||||
//if(listIp!=null&&listIp.Count>0)
|
||||
for (int i = 0; i < listIp.Count; i++)
|
||||
{
|
||||
HttpWebResponse response = null;
|
||||
try
|
||||
{
|
||||
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
||||
request.KeepAlive = true;
|
||||
request.Accept = "application/json, text/plain, */*";
|
||||
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36";
|
||||
//request.Headers.Add("VerifyAuthToken", @"ymXDWelTcWGRcf9dQBsVgw");
|
||||
request.Referer = url;
|
||||
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
|
||||
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
System.Net.WebProxy proxy = GetWebProxy(listIp[i]);
|
||||
request.Proxy = proxy;
|
||||
response = (HttpWebResponse)request.GetResponse();
|
||||
}
|
||||
catch (WebException e)
|
||||
{
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
string result = ReadResponse(response);
|
||||
if (!result.Contains("error_code"))
|
||||
{
|
||||
GlobalProxyHelper.CloseIp(listIp);//找到了 把当前获取到的ip关闭
|
||||
return result;
|
||||
}
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
GlobalProxyHelper.CloseIp(listIp);//没找到也关闭
|
||||
Thread.Sleep(3000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static WebProxy GetWebProxy(string ip = "")
|
||||
{
|
||||
WebProxy webProxy = null;
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(ip))
|
||||
{
|
||||
string[] ipArr = ip.Split(new string[] { " ", ":" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
switch (ipArr.Length)
|
||||
{
|
||||
case 2:
|
||||
webProxy = new WebProxy(ipArr[0], ipArr[1].ParseToInt());
|
||||
break;
|
||||
|
||||
case 4:
|
||||
webProxy = new WebProxy(ipArr[0], ipArr[1].ParseToInt());
|
||||
webProxy.Credentials = new NetworkCredential(ipArr[2], ipArr[3]);
|
||||
break;
|
||||
}
|
||||
return webProxy;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteWithTime(ex);
|
||||
}
|
||||
return webProxy;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using AllBase.Model.Result;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Work.DouyinApiClass;
|
||||
|
||||
namespace Work.BLL.Product
|
||||
{
|
||||
public class ShopProductBLL
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取店铺商品列表
|
||||
/// </summary>
|
||||
/// <param name="shop">店铺</param>
|
||||
/// <param name="productStatus">商品是否在售 0在售 1仓库</param>
|
||||
/// <param name="page">页数 从1开始</param>
|
||||
/// <param name="pageSize">每页商品数量</param>
|
||||
/// <param name="update_end_time">最后更新时间</param>
|
||||
/// <returns></returns>
|
||||
public string GetShopProductListData(DouShopLoginInfo shop, int productStatus = 0, int page = 1, int pageSize = 50, long update_end_time = 0)
|
||||
{
|
||||
// 读取在售商品数量
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
dictionary.Add("page", page.ToString());
|
||||
dictionary.Add("size", pageSize.ToString());
|
||||
if (update_end_time > 0)
|
||||
dictionary.Add("update_end_time", update_end_time.ToString());
|
||||
// check_status 指定审核状态返回商品列表:1未提审 2审核中 3审核通过 4审核驳回 5封禁 7审核通过,待上架状态
|
||||
if (productStatus == 0)
|
||||
dictionary["check_status"] = "3";
|
||||
//else
|
||||
// dictionary["check_status"] = "1";
|
||||
dictionary["status"] = productStatus.ToString();
|
||||
DouyinApi douApi = new DouyinApi(shop);
|
||||
douApi.JsonData = dictionary;
|
||||
var resultOnline = douApi.GetProductList();
|
||||
return resultOnline;
|
||||
}
|
||||
|
||||
public string OnSaleProduct(DouShopLoginInfo shop, string productIds)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
dictionary.Add("product_id", productIds);
|
||||
dictionary.Add("start_sale_type", "0");
|
||||
dictionary.Add("commit", "true");
|
||||
DouyinApi douApi = new DouyinApi(shop);
|
||||
douApi.JsonData = dictionary;
|
||||
var resultOnline = douApi.GetProductEdit();
|
||||
return resultOnline;
|
||||
}
|
||||
|
||||
public string OffSaleProduct(DouShopLoginInfo shop, string productIds)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
dictionary.Add("product_id", productIds);
|
||||
DouyinApi douApi = new DouyinApi(shop);
|
||||
douApi.JsonData = dictionary;
|
||||
var resultOnline = douApi.SetProductOffline();
|
||||
return resultOnline;
|
||||
}
|
||||
|
||||
public string DeleteProduct(DouShopLoginInfo shop, string productIds)
|
||||
{
|
||||
Dictionary<string, string> dictionary = new Dictionary<string, string>();
|
||||
dictionary.Add("product_id", productIds);
|
||||
DouyinApi douApi = new DouyinApi(shop);
|
||||
douApi.JsonData = dictionary;
|
||||
var resultOnline = douApi.DeleteProduct();
|
||||
return resultOnline;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using AllBase;
|
||||
using NaiBa.Util.Extension;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BLL.Product
|
||||
{
|
||||
public class ViolateBLL
|
||||
{
|
||||
public static string GetViolate(string upId, long upIdNumber)
|
||||
{
|
||||
string address = BaseClass.BuildObjString("violate&act=get");
|
||||
string param = UserLogin.GetSignaturex()
|
||||
+ "&pid=" + upId
|
||||
+ "&suffix=" + upIdNumber % 1024;
|
||||
string html = GetHtml.PostUtf8(address, param);
|
||||
if (html == null)
|
||||
html = "";
|
||||
var data = BaseRegex.GetStringJson(ref html, "data");
|
||||
if (data == null)
|
||||
{
|
||||
if (html.Contains("\"msg\":\"success\""))
|
||||
data = "none";
|
||||
else
|
||||
data = "";
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
public static string GetViolateList(List<string> upIds)
|
||||
{
|
||||
if (upIds == null)
|
||||
upIds = new List<string>();
|
||||
|
||||
string address = BaseClass.BuildObjString("violate&act=get_list");
|
||||
string param = UserLogin.GetSignaturex() + "&pids=";
|
||||
foreach (var id in upIds)
|
||||
{
|
||||
var idStr = id;
|
||||
idStr = BaseRegex.GetMatchRegexString(ref idStr, "(\\d{5,30})");
|
||||
if (idStr == null)
|
||||
continue;
|
||||
|
||||
param += id + "," + (idStr.ParseToLong() % 1024) + ";";
|
||||
}
|
||||
string html = GetHtml.PostUtf8(address, param.TrimEnd(';'));
|
||||
return html;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,298 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BLL.Tools
|
||||
{
|
||||
public class Base64ChangeImgUrl
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 将Base64字符串转换为图片
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
public Bitmap ToImage(string imgBase64)
|
||||
{
|
||||
imgBase64 = imgBase64.Substring("data:image/jpeg;base64,".Length);
|
||||
byte[] bytes = Convert.FromBase64String(imgBase64);
|
||||
MemoryStream ms = new MemoryStream(bytes);
|
||||
Image mImage = Image.FromStream(ms);
|
||||
Bitmap bmpt = new Bitmap(ms);
|
||||
return bmpt;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片转Base64
|
||||
/// </summary>
|
||||
/// <param name="ImageFileName">图片的完整路径</param>
|
||||
/// <returns></returns>
|
||||
public static string ImgToBase64(Bitmap bmp)
|
||||
{
|
||||
try
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
|
||||
byte[] arr = new byte[ms.Length];
|
||||
ms.Position = 0;
|
||||
ms.Read(arr, 0, (int)ms.Length);
|
||||
ms.Close();
|
||||
return Convert.ToBase64String(arr);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public string CutZoom(string Base64pic)
|
||||
{
|
||||
|
||||
byte[] arr2 = Convert.FromBase64String(Base64pic);
|
||||
Bitmap bmp3 = null;
|
||||
using (MemoryStream ms2 = new MemoryStream(arr2))
|
||||
{
|
||||
Bitmap bmp2 = new System.Drawing.Bitmap(ms2);
|
||||
bmp3 = GetThumbnail(bmp2, 130, 270);
|
||||
}
|
||||
|
||||
return ImgToBase64(bmp3);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片转为二进制
|
||||
/// </summary>
|
||||
/// <param name="Bitmap"></param>
|
||||
/// <returns></returns>
|
||||
public byte[] GetPictureData(Bitmap Bitmap)
|
||||
{
|
||||
MemoryStream ms = null;
|
||||
try
|
||||
{
|
||||
ms = new MemoryStream();
|
||||
Bitmap.Save(ms, Bitmap.RawFormat);
|
||||
byte[] byteImage = new Byte[ms.Length];
|
||||
byteImage = ms.ToArray();
|
||||
return byteImage;
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ms.Close();
|
||||
}
|
||||
}
|
||||
|
||||
public byte[] Base64ChangeBuffer(String imgBase64)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(imgBase64))
|
||||
{
|
||||
return GetPictureData(ToImage(imgBase64));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Bitmap GetThumbnail(Bitmap b, int destHeight, int destWidth)
|
||||
{
|
||||
System.Drawing.Image imgSource = b;
|
||||
System.Drawing.Imaging.ImageFormat thisFormat = imgSource.RawFormat;
|
||||
int sW = 0, sH = 0;
|
||||
// 按比例缩放
|
||||
int sWidth = imgSource.Width;
|
||||
int sHeight = imgSource.Height;
|
||||
if (sHeight > destHeight || sWidth > destWidth)
|
||||
{
|
||||
if ((sWidth * destHeight) > (sHeight * destWidth))
|
||||
{
|
||||
sW = destWidth;
|
||||
sH = (destWidth * sHeight) / sWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
sH = destHeight;
|
||||
sW = (sWidth * destHeight) / sHeight;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sW = sWidth;
|
||||
sH = sHeight;
|
||||
}
|
||||
Bitmap outBmp = new Bitmap(destWidth, destHeight);
|
||||
Graphics g = Graphics.FromImage(outBmp);
|
||||
g.Clear(Color.Transparent);
|
||||
// 设置画布的描绘质量
|
||||
g.CompositingQuality = CompositingQuality.HighQuality;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.DrawImage(imgSource, new Rectangle((destWidth - sW) / 2, (destHeight - sH) / 2, sW, sH), 0, 0, imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
|
||||
g.Dispose();
|
||||
// 以下代码为保存图片时,设置压缩质量
|
||||
EncoderParameters encoderParams = new EncoderParameters();
|
||||
long[] quality = new long[1];
|
||||
quality[0] = 100;
|
||||
EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
|
||||
encoderParams.Param[0] = encoderParam;
|
||||
imgSource.Dispose();
|
||||
return outBmp;
|
||||
}
|
||||
|
||||
public int CalculateNick(Bitmap bitmap, int v)
|
||||
{
|
||||
int iNickX = 0;
|
||||
int iDis = 5; //差异值
|
||||
List<int> lstiNickX = new List<int>();
|
||||
for (int y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < bitmap.Width - v; x++)
|
||||
{
|
||||
Color color1 = bitmap.GetPixel(x, y);
|
||||
Color color2 = bitmap.GetPixel(x + 1, y);
|
||||
int icolor1 = GetRGBFromColor(color1);
|
||||
int icolor2 = GetRGBFromColor(color2);
|
||||
double dDistance = GetDistance(color2, color1);
|
||||
if (dDistance > iDis && icolor2 < icolor1)
|
||||
{
|
||||
for (int i = 0; i < v + v / 2; i++)
|
||||
{
|
||||
iNickX = x + i;
|
||||
if (iNickX >= bitmap.Width - 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Color colorNickPre = bitmap.GetPixel(iNickX, y);
|
||||
Color colorNickAft = bitmap.GetPixel(iNickX + 1, y);
|
||||
|
||||
int icolorNickPre = GetRGBFromColor(colorNickPre);
|
||||
int icolorNickAft = GetRGBFromColor(colorNickAft);
|
||||
double dNickDistance = GetDistance(colorNickAft, colorNickPre);
|
||||
if (dNickDistance > dDistance && icolorNickAft > icolorNickPre)
|
||||
{
|
||||
int iGap = Math.Abs(iNickX - x - v);
|
||||
if (iGap <= 2)
|
||||
{
|
||||
lstiNickX.Add(x);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lstiNickX.Count > 0)
|
||||
{
|
||||
iNickX = GetRight(lstiNickX);
|
||||
//label1.Text = iNickX.ToString();
|
||||
}
|
||||
return iNickX;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 滑块的宽度
|
||||
/// </summary>
|
||||
/// <param name="bitmap"></param>
|
||||
/// <param name="v"></param>
|
||||
/// <returns></returns>
|
||||
public int CalculateNickNew(Bitmap bitmap, int v = 39)
|
||||
{
|
||||
int iNickX = 0;
|
||||
decimal idif = 0.50m; // 差异比例
|
||||
List<int> lstiNickX = new List<int>();
|
||||
for (int y = 0; y < bitmap.Height; y++)
|
||||
{
|
||||
for (int x = 0; x < bitmap.Width - v - 1; x++)
|
||||
{
|
||||
Color color1 = bitmap.GetPixel(x, y);
|
||||
Color color2 = bitmap.GetPixel(x + 1, y);
|
||||
int icolor1 = color1.R + color1.G + color1.B;
|
||||
int icolor2 = color2.R + color2.G + color2.B;
|
||||
if (color2.R < color1.R * (1 - idif) && color2.G < color1.G * (1 - idif) && color2.G < color1.G * (1 - idif))
|
||||
{
|
||||
for (int i = 1; i < v + v / 2; i++)
|
||||
{
|
||||
iNickX = x + i;
|
||||
if (iNickX >= bitmap.Width - 1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Color color3 = bitmap.GetPixel(iNickX, y);
|
||||
Color color4 = bitmap.GetPixel(iNickX + 1, y);
|
||||
|
||||
int icolor3 = GetRGBFromColor(color3);
|
||||
int icolor4 = GetRGBFromColor(color4);
|
||||
if (color3.R < color4.R * (1 - idif) && color3.G < color4.G * (1 - idif) && color3.G < color4.G * (1 - idif))
|
||||
{
|
||||
int iGap = Math.Abs(iNickX - x - v);
|
||||
if (iGap <= 2)
|
||||
{
|
||||
lstiNickX.Add(x);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lstiNickX.Count > 0)
|
||||
{
|
||||
iNickX = GetRight(lstiNickX);
|
||||
//label1.Text = iNickX.ToString();
|
||||
}
|
||||
return iNickX + 1;
|
||||
}
|
||||
|
||||
public int GetRGBFromColor(Color color)
|
||||
{
|
||||
return (int)(((int)color.B << 16) | (ushort)(((ushort)color.G << 8) | color.R));
|
||||
byte r = color.R;
|
||||
byte g = color.G;
|
||||
byte b = color.B;
|
||||
//转化为32bit RGB值:
|
||||
int rgb = r + g * 256 + b * 256 * 256;
|
||||
return rgb;
|
||||
}
|
||||
|
||||
private double GetDistance(Color color1, Color color2)
|
||||
{
|
||||
double y1, u1, v1, y2, u2, v2;
|
||||
y1 = 0.299 * color1.R + 0.587 * color1.G + 0.114 * color1.B;
|
||||
u1 = -0.14713 * color1.R - 0.28886 * color1.G + 0.436 * color1.B;
|
||||
v1 = 0.615 * color1.R - 0.51498 * color1.G - 0.10001 * color1.B;
|
||||
y2 = 0.299 * color2.R + 0.587 * color2.G + 0.114 * color2.B;
|
||||
u2 = -0.14713 * color2.R - 0.28886 * color2.G + 0.436 * color2.B;
|
||||
v2 = 0.615 * color2.R - 0.51498 * color2.G - 0.10001 * color2.B;
|
||||
return Math.Sqrt((y1 - y2) * (y1 - y2) + (u1 - u2) * (u1 - u2) + (v1 - v2) * (v1 - v2));
|
||||
}
|
||||
|
||||
private int GetRight(List<int> lstiNickX)
|
||||
{
|
||||
var res = from n in lstiNickX
|
||||
group n by n into g
|
||||
orderby g.Count() descending
|
||||
select g;
|
||||
var gr = res.First();
|
||||
return gr.Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
using AllBase;
|
||||
using AllBase.Model.Param.FissionManage;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BLL.Upload
|
||||
{
|
||||
public class FissionDataBaseBLL
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取分组
|
||||
/// </summary>
|
||||
public List<string> GetCategoryGroup()
|
||||
{
|
||||
List<string> cateList = new List<string>();
|
||||
|
||||
string getRequestData = UserLogin.GetSignaturex() + "&act=get";
|
||||
string getUrl = BaseClass.BuildFissionObjString("category_api");
|
||||
string categoryResult = GetHtml.PostUtf8(getUrl, getRequestData);
|
||||
try
|
||||
{
|
||||
JObject jCategoryObj = (JObject)JsonConvert.DeserializeObject(categoryResult);
|
||||
if (jCategoryObj == null)
|
||||
{
|
||||
return cateList;
|
||||
}
|
||||
string categoryList = jCategoryObj["list"].ToString();
|
||||
JArray jCategoryList = (JArray)JsonConvert.DeserializeObject(categoryList);
|
||||
cateList.Clear();
|
||||
cateList.Add("不限");
|
||||
foreach (var category in jCategoryList)
|
||||
{
|
||||
string cateStr = category["cate_name"].ToString();
|
||||
var isHas = cateList.Find(x => x != null && x.Equals(cateStr));
|
||||
if (isHas != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
cateList.Add(cateStr);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
return cateList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主分类
|
||||
/// </summary>
|
||||
public List<string> GetMainCate()
|
||||
{
|
||||
List<string> mainCateList = new List<string>();
|
||||
string getRequestData = UserLogin.GetSignaturex() + "&act=get_cate";
|
||||
string getUrl = BaseClass.BuildFissionObjString("fession_api");
|
||||
string categoryResult = GetHtml.PostUtf8(getUrl, getRequestData);
|
||||
try
|
||||
{
|
||||
var MainCateObj = JsonConvert.DeserializeObject<MainCate>(categoryResult);
|
||||
mainCateList.Clear();
|
||||
mainCateList.Add("不限");
|
||||
if (MainCateObj != null && MainCateObj.list.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < MainCateObj.list.Count; i++)
|
||||
{
|
||||
var isHas = mainCateList.Find(x => x != null && x.Contains(MainCateObj.list[i].main_cate));
|
||||
if (isHas != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
mainCateList.Add(MainCateObj.list[i].main_cate);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
return mainCateList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除产品数据库裂变商品
|
||||
/// </summary>
|
||||
/// <param name="FessIds"></param>
|
||||
public string DelFessionData(string FessIds, bool isMultiDelete = false)
|
||||
{
|
||||
string getRequestData = UserLogin.GetSignaturex() + "&act=delete&id=" + FessIds;
|
||||
string getUrl = BaseClass.BuildFissionObjString("fession_api");
|
||||
string Result = GetHtml.PostUtf8(getUrl, getRequestData);
|
||||
return Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 恢复被删除的产品数据库裂变商品
|
||||
/// </summary>
|
||||
/// <param name="strTemp"></param>
|
||||
public void RestoreFessionData(string strTemp)
|
||||
{
|
||||
string getRequestData = UserLogin.GetSignaturex() + "&act=update&ids=" + strTemp;
|
||||
string getUrl = BaseClass.BuildFissionObjString("fession_recover");
|
||||
string Result = GetHtml.PostUtf8(getUrl, getRequestData);
|
||||
}
|
||||
|
||||
public FissionData GetFessionDetailById(int FessId)
|
||||
{
|
||||
string url = BaseClass.BuildFissionObjString("fession_api");
|
||||
string requestData = UserLogin.GetSignaturex() + "&act=get_detail";
|
||||
string paraStr = "&id=" + FessId;
|
||||
requestData = requestData + paraStr;
|
||||
string htmlData = GetHtml.PostUtf8(url, requestData);
|
||||
var FessionObj = JsonConvert.DeserializeObject<FissionData>(htmlData);
|
||||
if (FessionObj == null || string.IsNullOrEmpty(FessionObj.main_pic))
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
FessionObj = JsonConvert.DeserializeObject<FissionData>(htmlData);
|
||||
}
|
||||
return FessionObj;
|
||||
}
|
||||
}
|
||||
|
||||
public class MainCateList
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string main_cate { get; set; }
|
||||
}
|
||||
public class MainCate
|
||||
{
|
||||
/// <summary>
|
||||
/// List
|
||||
/// </summary>
|
||||
public List<MainCateList> list { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string page { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string next_url { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Work.BLL.Upload
|
||||
{
|
||||
public class UploadMaterialBLL
|
||||
{
|
||||
public bool DelOldestApiMaterialFolder(AllBase.Model.Result.DouShopLoginInfo shop)
|
||||
{
|
||||
///^(\d{4})-(\d{2})-(\d{2})/
|
||||
var folder = GetApiMaterialFolder(shop);
|
||||
if (folder != null && folder.Contains("\"code\":10000"))
|
||||
{
|
||||
var JObj = AllBase.JsonHelper.JObjectParse(folder);
|
||||
if (JObj?["data"]?["folder_info_list"] != null)
|
||||
{
|
||||
foreach (Newtonsoft.Json.Linq.JObject j in JObj?["data"]?["folder_info_list"])
|
||||
{
|
||||
var s = j?["name"]?.ToString();
|
||||
if (s != null && AllBase.BaseRegex.GetMatchRegex(ref s, "^(\\d{4})-(\\d{2})-(\\d{2})").Count > 0)
|
||||
{
|
||||
var folderId = j["folder_id"]?.ToString();
|
||||
|
||||
DouyinApiClass.DouyinApi api = new DouyinApiClass.DouyinApi(shop);
|
||||
api.JsonData = new Dictionary<string, string>();
|
||||
//api.JsonData.Add("name", DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
api.JsonData.Add("folder_ids", "[" + folderId + "]");
|
||||
string html = api.MaterialDeleteFolder();
|
||||
if (html != null && html.Contains("\"code\":10000") && html.Contains("\"success_ids\":[\"" + folderId + "\"]"))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="shop"></param>
|
||||
/// <param name="parent_folder_id"></param>
|
||||
/// <param name="page_size">每页返回的数量。最大为100,默认为50</param>
|
||||
/// <param name="page_num">分页的页数,从1开始</param>
|
||||
/// <param name="order_by">排序方式 0-创建时间倒序 1-创建时间正序 2-修改时间倒序 3-修改时间正序 4-文件夹名倒序 5-文件夹名正序</param>
|
||||
/// <returns></returns>
|
||||
public string GetApiMaterialFolder(AllBase.Model.Result.DouShopLoginInfo shop, string parent_folder_id = "0", int page_size = 10, int page_num = 1, int order_by = 1,
|
||||
string create_time_start = "", string create_time_end = "")
|
||||
{
|
||||
//var api = new DouyinApiClass.DouyinApi(shop);
|
||||
//var folderResult = api.MaterialSearchFolder(1, 10);
|
||||
//return folderResult;
|
||||
|
||||
DouyinApiClass.DouyinApi api = new DouyinApiClass.DouyinApi(shop);
|
||||
api.JsonData = new Dictionary<string, string>();
|
||||
//api.JsonData.Add("name", DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
api.JsonData.Add("parent_folder_id", parent_folder_id);
|
||||
api.JsonData.Add("order_by", order_by.ToString());
|
||||
api.JsonData.Add("page_num", page_num.ToString());
|
||||
api.JsonData.Add("page_size", page_size.ToString());
|
||||
if (!string.IsNullOrEmpty(create_time_start))
|
||||
api.JsonData.Add("create_time_start", create_time_start.ToString());
|
||||
if (!string.IsNullOrEmpty(create_time_end))
|
||||
api.JsonData.Add("create_time_end", create_time_end.ToString());
|
||||
string html = api.GetSearchFolder();
|
||||
if (html == null)
|
||||
return "";
|
||||
return html;
|
||||
}
|
||||
|
||||
public string GetApiMaterial(AllBase.Model.Result.DouShopLoginInfo shop, string parent_folder_id = "0", int page_size = 10, int page_num = 1, int order_by = 1,
|
||||
string create_time_start = "", string create_time_end = "")
|
||||
{
|
||||
DouyinApiClass.DouyinApi api = new DouyinApiClass.DouyinApi(shop);
|
||||
api.JsonData = new Dictionary<string, string>();
|
||||
//api.JsonData.Add("name", DateTime.Now.ToString("yyyy-MM-dd"));
|
||||
api.JsonData.Add("folder_id", parent_folder_id);
|
||||
api.JsonData.Add("order_by", order_by.ToString());
|
||||
api.JsonData.Add("page_num", page_num.ToString());
|
||||
api.JsonData.Add("page_size", page_size.ToString());
|
||||
if (!string.IsNullOrEmpty(create_time_start))
|
||||
api.JsonData.Add("create_time_start", create_time_start.ToString());
|
||||
if (!string.IsNullOrEmpty(create_time_end))
|
||||
api.JsonData.Add("create_time_end", create_time_end.ToString());
|
||||
string html = api.GetSearchMaterial();
|
||||
return html == null ? "" : html;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,849 @@
|
||||
using AllBase;
|
||||
using AllBase.Model.Result;
|
||||
using NaiBa.Util.Extension;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Work.DouyinApiClass;
|
||||
|
||||
namespace Work.BLL.Upload
|
||||
{
|
||||
public class UploadPropertyBLL
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否模糊匹配属性选项
|
||||
/// </summary>
|
||||
public static bool IsFuzzyMatching = false;
|
||||
|
||||
public static string getCatePropertyInterface(string c3, DouShopLoginInfo shop, ProductCollectBase pc)
|
||||
{
|
||||
//string url = "https://fxg.jinritemai.com/product/tproduct/formatTpl?category_leaf_id=" + c3;
|
||||
//string htmlx = GetPostTaobaoHtml.UploadTaobao(url, "", true, shop.Cookies);
|
||||
DouyinApi api = new DouyinApi(shop);
|
||||
api.JsonData = new Dictionary<string, string>();
|
||||
api.JsonData.Add("category_leaf_id", c3);
|
||||
string result = api.GetCateProperty();
|
||||
return result;
|
||||
}
|
||||
|
||||
public CatePropertyResponseInfo getCatePropertyInterfaceV2(string c3, DouShopLoginInfo shop)
|
||||
{
|
||||
DouyinApi api = new DouyinApi(shop);
|
||||
api.JsonData = new Dictionary<string, string>();
|
||||
api.JsonData.Add("category_leaf_id", c3);
|
||||
string html = api.GetCatePropertyV2();
|
||||
if (html.Contains("access_token已过期"))
|
||||
{
|
||||
shop.ApiAuthStatus = "未授权";
|
||||
}
|
||||
|
||||
if (!html.Contains("\"required\""))
|
||||
{
|
||||
//return "";
|
||||
}
|
||||
|
||||
CatePropertyResponseInfo cateProperyInfo;
|
||||
try
|
||||
{
|
||||
cateProperyInfo = JsonConvert.DeserializeObject<CatePropertyResponseInfo>(html);
|
||||
return cateProperyInfo;
|
||||
}
|
||||
catch
|
||||
{
|
||||
cateProperyInfo = new CatePropertyResponseInfo();
|
||||
}
|
||||
return cateProperyInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据服务端返回的类目属性要求分析获取属性字段
|
||||
/// </summary>
|
||||
/// <param name="cateProperyInfo"></param>
|
||||
/// <param name="shop"></param>
|
||||
/// <param name="pcb"></param>
|
||||
/// <returns></returns>
|
||||
public string GetCatePropertyAnalysis(CatePropertyResponseInfo cateProperyInfo, DouShopLoginInfo shop, ProductCollectBase pcb)
|
||||
{
|
||||
if (cateProperyInfo?.data?.data == null)
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
|
||||
//if (property == null || !property.Contains("货号"))
|
||||
// property = "货号|" + from_name + p.from_id.ToString() + "^" + property;
|
||||
|
||||
// 拆分拼多多属性中含 "/" 的集合属性,如 "key":"衣长/袖长","value":"常规款/短袖"
|
||||
var props = pcb.Prop.Where(p => p.Key.Contains("/")).ToList();
|
||||
foreach (var pr in props)
|
||||
{
|
||||
var prKeys = pr.Key.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var prValues = pr.Value.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (prKeys.Length == prValues.Length)
|
||||
{
|
||||
for (int j = 0; j < prKeys.Length; j++)
|
||||
{
|
||||
pcb.Prop.Add(new KeyValueBase() { Key = prKeys[j], Value = prValues[j] });
|
||||
}
|
||||
pcb.Prop.Remove(pr);
|
||||
}
|
||||
}
|
||||
|
||||
Dictionary<string, List<product_format_new_item>> dicProp = new Dictionary<string, List<product_format_new_item>>();
|
||||
string html = "";
|
||||
|
||||
for (int i = 0; i < cateProperyInfo.data.data.Count; i++)
|
||||
{
|
||||
string pName = "";
|
||||
string pId = "0";
|
||||
var douyinProp = cateProperyInfo.data.data[i];
|
||||
|
||||
var upProp = pcb.Prop.Find(pr => pr.Key == douyinProp.property_name);
|
||||
if (upProp == null)
|
||||
{
|
||||
var upProps = pcb.Prop.Where(pr => UpProperty2DouyinPropertyNameConverter(pr.Key, douyinProp.property_name) == douyinProp.property_name).ToList();
|
||||
upProp = upProps?.Find(pr => UpProperty2DouyinPropertyValueConverter(pr.Value, douyinProp.options).Count > 0);
|
||||
if (upProp == null)
|
||||
upProp = upProps?.FirstOrDefault();
|
||||
}
|
||||
|
||||
var options = "";
|
||||
if (douyinProp.options?.FirstOrDefault() != null)
|
||||
options = string.Join(",", douyinProp.options?.Select(o => o.name));
|
||||
var x = html;
|
||||
|
||||
#region 优先单独处理特殊属性
|
||||
if (douyinProp.property_name == "品牌")
|
||||
{
|
||||
if (pcb.Prop.Any(pr => pr.Key == "品牌") && pcb.Prop.Any(pr => pr.Key == "品牌编号"))
|
||||
pName = pcb.Prop.FirstOrDefault(pr => pr.Key == "品牌").Value;
|
||||
else if (douyinProp.required)
|
||||
pName = "无品牌";
|
||||
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
html += "^品牌|" + pName;
|
||||
}
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name == "型号")
|
||||
{
|
||||
if (!douyinProp.required && (upProp == null || upProp.Value?.Length < 4))
|
||||
continue;
|
||||
|
||||
upProp = pcb.Prop.FirstOrDefault(pr => pr.Key == "型号" && pr.Value != "缺省");
|
||||
if (upProp != null)
|
||||
{
|
||||
pName = upProp.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
pName = Randomx.GetWord(2) + "-" + Randomx.GetNumber(Randomx.GetId(3, 6));
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
var op = douyinProp.options.Find(o => o.name == pName);
|
||||
if (op != null)
|
||||
{
|
||||
pId = op.value;
|
||||
}
|
||||
else if (douyinProp.diy_type == 1)
|
||||
{
|
||||
pName = "$diy$" + pName;
|
||||
}
|
||||
|
||||
html += "^型号|" + pName;
|
||||
}
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name == "适用型号" && douyinProp.required)
|
||||
{
|
||||
upProp = pcb.Prop.FirstOrDefault(pr => pr.Key.Contains("适用型号") && pr.Value != "缺省");
|
||||
if (upProp != null)
|
||||
pName = upProp.Value;
|
||||
else
|
||||
pName = Randomx.GetWord(Randomx.GetId(2, 5)) + "-" + Randomx.GetNumber(Randomx.GetId(3, 8));
|
||||
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
html += "^适用型号|" + pName;
|
||||
}
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name == "产地" && (upProp == null || douyinProp.options?.FirstOrDefault(o => o.name == upProp.Value) == null))
|
||||
{
|
||||
if (!douyinProp.required)
|
||||
continue;
|
||||
|
||||
if (douyinProp.options.Count > 0)
|
||||
{
|
||||
var op = douyinProp.options.Find(o => o.name == "中国大陆");
|
||||
if (op == null)
|
||||
{
|
||||
upProp = pcb.Prop.FirstOrDefault(p => p.Key.Contains("产地") && p.Key != "产地");
|
||||
if (upProp != null)
|
||||
op = douyinProp.options?.FirstOrDefault(o => o.name == upProp.Value);
|
||||
}
|
||||
if (op != null)
|
||||
{
|
||||
pId = op.value;
|
||||
pName = op.name;
|
||||
html += "^产地|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "单果重量")
|
||||
{
|
||||
// 水果生鲜直接上传特例
|
||||
if (douyinProp.required && (pcb.main_cat_name.Contains("水果") || pcb.main_cat_name.Contains("生鲜")))
|
||||
{
|
||||
pName = Randomx.GetId(1, 6) + "00";
|
||||
html += "^单果重量|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "单果重量(g)")
|
||||
{
|
||||
// 水果生鲜直接上传特例
|
||||
if (douyinProp.required && (pcb.main_cat_name.Contains("水果") || pcb.main_cat_name.Contains("生鲜")))
|
||||
{
|
||||
if (html.Contains("单果重量|"))
|
||||
pName = BaseRegex.GetMatchRegex(ref html, "单果重量|(\\d{1,10})")[1].Groups[0].ToString();
|
||||
else
|
||||
pName = Randomx.GetId(1, 6) + "00";
|
||||
html += "^单果重量(g)|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "包装方式")
|
||||
{
|
||||
// 水果生鲜直接上传特例
|
||||
if (douyinProp.required && (pcb.main_cat_name.Contains("水果") || pcb.main_cat_name.Contains("生鲜")) && douyinProp.options.Any(o => o.name == "食用农产品"))
|
||||
{
|
||||
var op = douyinProp.options.Find(o => o.name == "食用农产品");
|
||||
pId = op.value;
|
||||
pName = "食用农产品";
|
||||
html += "^包装方式|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "品质认证")
|
||||
{
|
||||
// 水果生鲜、茶叶、食品保健直接上传特例(选无认证不用填认证证书)
|
||||
if (douyinProp.required && (pcb.main_cat_name.Contains("水果") || pcb.main_cat_name.Contains("生鲜")
|
||||
|| pcb.main_cat_name.Contains("茶") || pcb.main_cat_name.Contains("食品保健"))
|
||||
&& douyinProp.options.Any(o => o.name == "无认证" || o.name == "无认证认证"))
|
||||
{
|
||||
var op = douyinProp.options.Find(o => o.name == "无认证" || o.name == "无认证认证");
|
||||
pId = op.value;
|
||||
pName = op.name;
|
||||
html += "^品质认证|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "贮存条件")
|
||||
{
|
||||
if (upProp == null)
|
||||
upProp = pcb.Prop.Find(pr => pr.Key == "储藏方法");
|
||||
PropertiesValuesBase op = null;
|
||||
if (upProp != null)
|
||||
op = douyinProp.options.FirstOrDefault(o => upProp.Value.Contains(o.name));
|
||||
else
|
||||
op = douyinProp.options.FirstOrDefault(o => o.name == "常温");
|
||||
if (op == null)
|
||||
op = douyinProp.options.FirstOrDefault();
|
||||
if (op != null)
|
||||
{
|
||||
pId = op.value;
|
||||
pName = op.name;
|
||||
}
|
||||
if (pName != null)
|
||||
html += "^贮存条件|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name == "食品生产许可证编号")
|
||||
{
|
||||
var qualify = pcb.qualifications?.FirstOrDefault(q => douyinProp.property_name.Contains(q.quality_name));
|
||||
if (qualify != null)
|
||||
{
|
||||
pName = qualify.quality_number;
|
||||
html += "^食品生产许可证编号|" + pName;
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(upProp?.Value))
|
||||
{
|
||||
pName = upProp.Value;
|
||||
html += "^食品生产许可证编号|" + pName;
|
||||
}
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name.Contains("是否为有机食品"))
|
||||
{
|
||||
var op = douyinProp.options.FirstOrDefault(o => o.name == "否");
|
||||
if (op == null)
|
||||
op = douyinProp.options.LastOrDefault();
|
||||
|
||||
pId = op.value;
|
||||
pName = op.name.Trim();
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name == "是否有导购视频")
|
||||
{
|
||||
var op = douyinProp.options.FirstOrDefault(o => o.name == "否");
|
||||
if (op == null)
|
||||
continue;
|
||||
|
||||
pId = op.value;
|
||||
pName = op.name.Trim();
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
if (douyinProp.property_name == "单件净含量")
|
||||
{
|
||||
if (upProp == null && douyinProp.type == "text")
|
||||
{
|
||||
upProp = pcb.Prop.FirstOrDefault(p => p.Key == "净含量");
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "茶种类")
|
||||
{
|
||||
if (upProp == null)
|
||||
{
|
||||
var op = douyinProp.options.FirstOrDefault(o => pcb.name.Contains(o.name));
|
||||
if (op == null)
|
||||
continue;
|
||||
|
||||
pId = op.value;
|
||||
pName = op.name.Trim();
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
if (douyinProp.property_name == "生产企业名称")
|
||||
{
|
||||
}
|
||||
if (douyinProp.property_name == "糕点种类" && !douyinProp.required)
|
||||
{
|
||||
}
|
||||
if (douyinProp.property_name == "特产品类" && !douyinProp.required)
|
||||
{
|
||||
}
|
||||
if (douyinProp.property_name == "款式")
|
||||
{
|
||||
}
|
||||
if (douyinProp.property_name == "包装方式")
|
||||
{
|
||||
if (douyinProp.required == true)
|
||||
{
|
||||
if (upProp == null && pcb.main_cat_name == "家纺家具家装")
|
||||
{
|
||||
if (douyinProp.options.Count > 0)
|
||||
{
|
||||
var op = douyinProp.options.LastOrDefault();
|
||||
pId = op.value;
|
||||
pName = op.name.Replace("/", "%2F");
|
||||
html += "^包装方式|" + op.value; // 此处只能用value不能用name
|
||||
}
|
||||
goto GetNextProperty;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 通用属性操作
|
||||
if (upProp != null && upProp.Key == "消毒品卫生许可证编号" && !upProp.Value.Contains("消证字"))
|
||||
{
|
||||
string[] arr = { "粤卫消证字[2012]第1140号", "粤卫消证字[2020]-50-第0144号", "鄂卫消证字(2010)第(0020)号", "(苏)卫消证字(2014)第3210-0036号", "(津)卫消证字(2012)第0408号" };
|
||||
upProp.Value = arr[Randomx.GetId(arr.Length)];
|
||||
}
|
||||
|
||||
// 该属性不是必填时,上家总店商品详情没有此属性就跳过
|
||||
if (upProp == null && !douyinProp.required)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
#region 处理面料、材质、含量属性
|
||||
if (douyinProp.property_name.Contains("面料") ||
|
||||
douyinProp.property_name.Contains("材质") ||
|
||||
douyinProp.property_name.Contains("含量"))
|
||||
{
|
||||
// 如果上家没有对应属性,在避免违规的情况下,按照以下规则处理属性填写逻辑
|
||||
if (upProp == null)
|
||||
{
|
||||
// 含量如果有多少多少以下,选多少多少以下
|
||||
if (string.IsNullOrEmpty(pName) && douyinProp.property_name.Contains("含量") && douyinProp.options?.FirstOrDefault(o => o.name.Contains("以下")) != null)
|
||||
{
|
||||
var op = douyinProp.options?.FirstOrDefault(o => o.name.Contains("以下"));
|
||||
pId = op.value;
|
||||
pName = op.name;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 特殊处理成分含量
|
||||
if (douyinProp.property_name.Contains("含量") && douyinProp.options?.FirstOrDefault() != null)
|
||||
{
|
||||
string upPropValue = BaseRegex.GetMatchRegexString(upProp.Value, @"([1-9]\d*\.?\d*)|(0\.\d*[1-9])%");
|
||||
if (string.IsNullOrEmpty(upPropValue))
|
||||
upPropValue = "0";
|
||||
|
||||
// 抖音成分含量里居然有不是数值单位的选项,如:棉、聚酯纤维等,将这些选项过滤出去
|
||||
var opts = douyinProp.options.Where(o => BaseRegex.GetMatchRegexString(o.name, @"([\w\W]+?)%")?.ParseToDecimal() >= 0).ToList();
|
||||
opts = opts.OrderBy(o => BaseRegex.GetMatchRegexString(o.name, @"([\w\W]+?)%")?.ParseToDecimal()).ToList();
|
||||
foreach (var op in opts)
|
||||
{
|
||||
string propValue = BaseRegex.GetMatchRegexString(op.name, @"([\w\W]+?)%");
|
||||
if (propValue?.ParseToDecimal() >= upPropValue.ParseToDecimal())
|
||||
{
|
||||
pId = op.value;
|
||||
pName = op.name.Trim();
|
||||
break;
|
||||
}
|
||||
else if (opts.Last(o => o.name != "100%") == op && op.name.Contains("以上") && upPropValue.ParseToDecimal() > propValue?.ParseToDecimal())
|
||||
{
|
||||
pId = op.value;
|
||||
pName = op.name.Trim();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (pName == "")
|
||||
{
|
||||
var op = douyinProp.options.FirstOrDefault(o => o.name.Contains("以下"));
|
||||
if (op == null)
|
||||
op = douyinProp.options.FirstOrDefault(o => o.name.Contains("其他"));
|
||||
if (op != null)
|
||||
{
|
||||
pId = op.value;
|
||||
pName = op.name.Trim();
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 如果上家对应面料、材质、含量属性不存在且没有使用模糊匹配,则直接跳过该属性,不论是否必填
|
||||
if ((upProp == null
|
||||
|| UpProperty2DouyinPropertyValueConverter(upProp.Value, douyinProp.options).Count == 0)
|
||||
&& !IsFuzzyMatching)
|
||||
{
|
||||
// 属性为字符型且上家不为空的直接填写上家值
|
||||
if (string.IsNullOrEmpty(pName) && douyinProp.type == "text")
|
||||
{
|
||||
if (upProp != null)
|
||||
pName = upProp.Value;
|
||||
else if (douyinProp.property_name.Contains("材质"))
|
||||
pName = "普通材质";
|
||||
else if (douyinProp.property_name.Contains("净含量"))
|
||||
pName = "<100";
|
||||
else if (douyinProp.property_name.Contains("有效成分含量"))
|
||||
pName = "<29%";
|
||||
else
|
||||
pName = "其他/Other";
|
||||
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
|
||||
// 支持自定义,填写其他
|
||||
if (douyinProp.diy_type == 1)
|
||||
{
|
||||
if (upProp == null || upProp.Value == "其他")
|
||||
pName = "$diy$其他/Other";
|
||||
else
|
||||
pName = "$diy$" + upProp.Value;
|
||||
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
#region 模糊查找上家商品面料、材质、含量属性
|
||||
if (douyinProp.property_name.Contains("面料") || douyinProp.property_name.Contains("材质"))
|
||||
{
|
||||
if (upProp == null)
|
||||
upProp = pcb.Prop.Find(pr => pr.Key.Contains("面料") || pr.Key.Contains("材质"));
|
||||
if (upProp == null)
|
||||
{
|
||||
var op = douyinProp.options?.Find(o => pcb.name.Contains(o.name));
|
||||
if (op != null)
|
||||
{
|
||||
pId = op.value;
|
||||
pName = op.name;
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
if (upProp == null && douyinProp.required && douyinProp.options?.FirstOrDefault() == null)
|
||||
{
|
||||
if (douyinProp.property_name == "备案/批准文号")
|
||||
{
|
||||
pName = "";
|
||||
}
|
||||
if (douyinProp.property_name == "CCC证书编号")
|
||||
{
|
||||
pName = "";
|
||||
}
|
||||
if (douyinProp.property_name == "吊牌价")
|
||||
{
|
||||
pName = (pcb.market_price == 0 ? pcb.price * 2 : pcb.market_price).ToString();
|
||||
}
|
||||
if (douyinProp.property_name == "保质期")
|
||||
{
|
||||
pName = "30";
|
||||
}
|
||||
if (douyinProp.property_name == "生产企业名称")
|
||||
{
|
||||
//pName = "工厂店"; //pvalue = "清风";
|
||||
pName = shop.ShopAccount;
|
||||
}
|
||||
if (douyinProp.property_name == "上市年份季节")
|
||||
{
|
||||
pName = DateTime.Now.AddMonths(-3).Year.ToString();
|
||||
}
|
||||
if (douyinProp.property_name == "毛重") // todo: 这种没有如何处理
|
||||
{
|
||||
pName = "暂无数据";
|
||||
}
|
||||
if (douyinProp.property_name == "包装体积")
|
||||
{
|
||||
pName = "暂无数据";
|
||||
}
|
||||
//if (string.IsNullOrEmpty(pName))
|
||||
// pName = "" + Randomx.GetId(1000, 9999);
|
||||
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
|
||||
// 上家属性不为空
|
||||
if (upProp != null)
|
||||
{
|
||||
// 抖音类目属性为文本类型时
|
||||
if (douyinProp.type == "text")
|
||||
{
|
||||
pName = upProp.Value;
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
// 抖音类目属性非文本类型且选项为空时
|
||||
else if (douyinProp.options?.FirstOrDefault() == null)
|
||||
{
|
||||
pName = upProp.Value.ToString().Trim();
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
// 抖音类目属性列表数量大于0且与上家匹配时
|
||||
else if (UpProperty2DouyinPropertyValueConverter(upProp.Value, douyinProp.options).Count > 0)
|
||||
{
|
||||
var ops = UpProperty2DouyinPropertyValueConverter(upProp.Value, douyinProp.options);
|
||||
foreach (var op in ops)
|
||||
{
|
||||
pName += op.name + ",";
|
||||
pId += op.value + ",";
|
||||
}
|
||||
pName = pName.Trim(',');
|
||||
pId = pId.Trim(',');
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
// 模糊匹配时去找类似的选项
|
||||
else if (douyinProp.required && IsFuzzyMatching &&
|
||||
douyinProp.options?.FirstOrDefault(o => upProp.Value.Contains(o.name) && o.name.Length > upProp.Value.Length / 2M) != null)
|
||||
{
|
||||
var optionsTemp = douyinProp.options?.Where(o => upProp.Value.Contains(o.name) && o.name.Length > upProp.Value.Length / 2M).ToList();
|
||||
if (optionsTemp.Count > 1)
|
||||
optionsTemp = optionsTemp.Take(1).ToList();
|
||||
foreach (var op in optionsTemp)
|
||||
{
|
||||
pId = op.value;
|
||||
pName += op.name + ",";
|
||||
if (douyinProp.type != "multi_select")
|
||||
break;
|
||||
}
|
||||
pName = pName.Trim(',');
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
|
||||
if (upProp == null && douyinProp.required)
|
||||
{
|
||||
if (douyinProp.options?.FirstOrDefault() != null)
|
||||
{
|
||||
var op = douyinProp.options.FirstOrDefault(o => o.name.Contains("其他") ||
|
||||
o.name.Contains("不限") ||
|
||||
o.name.Contains("默认") ||
|
||||
o.name.Contains("通用") ||
|
||||
o.name.Contains("中性") ||
|
||||
o.name.Contains("缺省"));
|
||||
if (op != null)
|
||||
{
|
||||
pName = op.name.ToString().Trim();
|
||||
pId = op.value;
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 前面都未能成功匹配
|
||||
if (pName == "" && douyinProp.required)
|
||||
{
|
||||
if (douyinProp.property_name == "测量功能")
|
||||
{
|
||||
var op = douyinProp.options?.Find(o => pcb.name.Contains(o.name));
|
||||
}
|
||||
if (douyinProp.property_name == "图案")
|
||||
{
|
||||
var op = douyinProp.options?.Find(o => pcb.name.Contains(o.name.Replace("图案", "")));
|
||||
if (op != null)
|
||||
{
|
||||
pName = op.name.ToString().Trim();
|
||||
pId = op.value;
|
||||
goto GetNextProperty;
|
||||
}
|
||||
}
|
||||
// 是否可以随意填写值
|
||||
if (douyinProp.diy_type == 1)
|
||||
{
|
||||
if (upProp != null && upProp.Value != "其他" && upProp.Value != "其他/other")
|
||||
pName = "$diy$" + upProp.Value;
|
||||
else if (douyinProp.property_name == "适用年龄")
|
||||
pName = "$diy$通用";
|
||||
else if (douyinProp.property_name == "植物品种")
|
||||
{
|
||||
int subIndex = Randomx.GetId(15, 20);
|
||||
var subText = pcb.name.Length > subIndex ? pcb.name.Substring(0, subIndex) : pcb.name;
|
||||
pName = "$diy$" + subText;
|
||||
}
|
||||
else
|
||||
pName = "$diy$其他/Other";
|
||||
}
|
||||
else
|
||||
if (douyinProp.type == "text")
|
||||
{
|
||||
if (douyinProp.property_name == "产品名称")
|
||||
pName = pcb.name;
|
||||
if (douyinProp.property_name == "连接方式" || douyinProp.property_name == "兼容平台")
|
||||
pName = "其他/Other";
|
||||
else
|
||||
pName = "通用";
|
||||
}
|
||||
else
|
||||
if (douyinProp.options?.FirstOrDefault() != null)
|
||||
{
|
||||
if (upProp != null)
|
||||
{
|
||||
var ops = douyinProp.options.Where(o => ("," + upProp.Value + ",").Contains("," + o.name + ",")).ToList();
|
||||
if (ops.Count > 0)
|
||||
{
|
||||
pName = pId = "";
|
||||
foreach (var op in ops)
|
||||
{
|
||||
pName += op.name + ",";
|
||||
pId += op.value + ",";
|
||||
}
|
||||
pName = pName.Trim(',');
|
||||
pId = pId.Trim(',');
|
||||
}
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(pName))
|
||||
{
|
||||
var op = douyinProp.options.Find(o => o.name == "正常规格");
|
||||
if (op == null && douyinProp.property_name == "适用年龄")
|
||||
{
|
||||
op = douyinProp.options.Last(o => o.name.Contains("周岁"));
|
||||
}
|
||||
if (op == null)
|
||||
op = douyinProp.options[Randomx.GetId(douyinProp.options.Count - 1)];
|
||||
pName = op.name.ToString().Trim();
|
||||
pId = op.value;
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
html += "^" + douyinProp.property_name + "|" + pName;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
GetNextProperty:;
|
||||
|
||||
if (!string.IsNullOrEmpty(pName))
|
||||
{
|
||||
var pNames = pName.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var pIds = pId.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
dicProp[douyinProp.property_id.ToString()] = new List<product_format_new_item>();
|
||||
for (int j = 0; j < pIds.Length; j++)
|
||||
{
|
||||
var formatItem = new product_format_new_item
|
||||
{
|
||||
diy_type = pNames[j].StartsWith("$diy$") ? 1 : 0,
|
||||
name = pNames[j].Replace("$diy$", ""),
|
||||
value = pIds[j].ParseToLong()
|
||||
};
|
||||
dicProp[douyinProp.property_id.ToString()].Add(formatItem);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
var result = html.Replace("^^", "^").Trim('^').Replace("/", "\\/").Replace("$diy$", "");
|
||||
//return result;
|
||||
var resultNew = JsonHelper.SerializeObject(dicProp).Replace("\"", "\\\"");
|
||||
return resultNew;
|
||||
}
|
||||
|
||||
public string UpProperty2DouyinPropertyNameConverter(string upPropName, string douyinPropName)
|
||||
{
|
||||
if (dicPropNameConverter.Keys.Contains(upPropName))
|
||||
{
|
||||
if (("," + dicPropNameConverter[upPropName] + ",").Contains("," + douyinPropName + ","))
|
||||
return douyinPropName;
|
||||
}
|
||||
return upPropName;
|
||||
}
|
||||
|
||||
Dictionary<string, string> dicPropNameConverter { get; } = new Dictionary<string, string>() {
|
||||
{ "主材质", "材质" },
|
||||
{ "拍杆材质", "材质" },
|
||||
{ "外壳材质", "材质" },
|
||||
{ "材质种类", "材质" },
|
||||
{ "面料分类", "材质" },
|
||||
{ "材质成分", "面料材质,面料材质成分含量,材质"},
|
||||
{ "面料", "面料材质" },
|
||||
{ "面料俗称", "面料材质,材质" },
|
||||
{ "材质", "面料材质,主材质" },
|
||||
{ "被里材质", "被里材质" },
|
||||
{ "被里面料俗称", "被里材质" },
|
||||
{ "被里材质含量", "被里成分含量" },
|
||||
{ "被面材质", "被面材质" },
|
||||
{ "被面材质含量", "被面成分含量" },
|
||||
{ "成分含量", "面料成分含量" },
|
||||
{ "衣柜面料", "饰面材质" },
|
||||
{ "饰面面料", "面料材质" },
|
||||
{ "鞋面材质", "帮面材质,材质" },
|
||||
{ "刷毛材质", "材质" },
|
||||
{ "储藏方法", "贮存条件" },
|
||||
{ "适用人群", "适用对象" },
|
||||
{ "是否支持定制", "是否可定制" },
|
||||
{ "清扫模式", "清洁类型" },
|
||||
{ "3C认证证书编号", "CCC证书编号" },
|
||||
{ "上市时节", "上市年份季节" },
|
||||
{ "适用年龄段", "适用年龄" },
|
||||
{ "产品类型", "鞋垫种类" },
|
||||
{ "杯身材质", "材质" }, // 水杯 水杯女可爱大容量塑料杯可爱学生便携夏季大肚带吸管杯子男高颜值
|
||||
{ "净含量", "有效成分含量" },
|
||||
{ "续航时间", "电池使用时间"},
|
||||
{ "防水级别", "防水等级" },
|
||||
{ "绳材质", "材质" },
|
||||
{ "内里材质", "填充物种类" },
|
||||
};
|
||||
|
||||
public List<PropertiesValuesBase> UpProperty2DouyinPropertyValueConverter(string upPropName, List<PropertiesValuesBase> options)
|
||||
{
|
||||
if (options?.Find(o => o.name.ToLower() == upPropName.ToLower()) != null)
|
||||
return options.Where(o => o.name.ToLower() == upPropName.ToLower()).ToList();
|
||||
if (options?.Find(o => o.name.ToLower() == upPropName.ToLower() + "镶嵌") != null)
|
||||
return options.Where(o => o.name.ToLower() == upPropName.ToLower() + "镶嵌").ToList();
|
||||
if (dicPropValueConverter.Keys.Contains(upPropName.ToLower()))
|
||||
{
|
||||
var ops = options.Where(o => ("," + dicPropValueConverter[upPropName.ToLower()] + ",").Contains("," + o.name + ",")).ToList();
|
||||
if (ops.Count > 0)
|
||||
return ops;
|
||||
}
|
||||
if (upPropName.Contains("%"))
|
||||
{
|
||||
string[] strArr = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." };
|
||||
foreach (var item in strArr)
|
||||
{
|
||||
upPropName = upPropName.Replace(item, "");
|
||||
}
|
||||
var upPropNames = upPropName.Split(new string[] { "%" }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var upPropNameConverted = "";
|
||||
foreach (var item in upPropNames)
|
||||
{
|
||||
if (dicPropValueConverter.Keys.Contains(item.ToLower().Trim()))
|
||||
upPropNameConverted += dicPropValueConverter[item.ToLower().Trim()] + ",";
|
||||
else
|
||||
upPropNameConverted += item.ToLower().Trim() + ",";
|
||||
}
|
||||
var ops = options.Where(o => ("," + upPropNameConverted.ToLower() + ",").Contains("," + o.name + ",")).ToList();
|
||||
|
||||
if (ops.Count > 0)
|
||||
return ops;
|
||||
}
|
||||
return new List<PropertiesValuesBase>();
|
||||
}
|
||||
|
||||
Dictionary<string, string> dicPropValueConverter { get; } = new Dictionary<string, string>() {
|
||||
{ "人造革", "聚酯纤维" },
|
||||
{ "涤纶", "聚酯纤维" },
|
||||
{ "丝绵", "聚酯纤维" },
|
||||
{ "仿丝棉", "聚酯纤维" },
|
||||
{ "涤纶(聚酯纤维)", "聚酯纤维,涤纶" },
|
||||
{ "粘胶纤维(粘纤)", "粘胶纤维,粘纤" },
|
||||
{ "聚酰胺纤维(锦纶)", "聚酰胺纤维,锦纶" },
|
||||
{ "聚氨酯弹性纤维(氨纶),", "聚氨酯弹性纤维,氨纶" },
|
||||
{ "记忆棉(聚氨酯)", "记忆棉,聚氨酯" },
|
||||
{ "二层牛皮", "牛剖层皮革" },
|
||||
{ "二层牛皮(除牛反绒)", "牛剖层皮革"},
|
||||
{ "超纤皮", "牛剖层皮革" },
|
||||
{ "pu", "聚氨酯,人造革" },
|
||||
{ "吸口滚刷互换式", "滚刷吸口互换" },
|
||||
{ "科技布", "涤纶" },
|
||||
{ "毛毡" , "聚酯纤维" },
|
||||
{ "人造纤维", "仿生纤维毛" },
|
||||
{ "925银", "925银镶嵌" },
|
||||
{ "绸缎", "丝绸" },
|
||||
{ "棉布", "棉" },
|
||||
{ "pvc", "PVC(聚氯乙烯)"},
|
||||
{ "包芯丝", "尼龙,氨纶"},
|
||||
{ "全碳素", "碳纤维" },
|
||||
{ "棉麻", "棉,亚麻" },
|
||||
{ "帆布", "纺织" },
|
||||
{ "天丝(莱赛尔纤维)", "天丝,莱赛尔纤维" },
|
||||
{ "天丝", "莱赛尔纤维" },
|
||||
{ "eva", "EVA发泡胶" },
|
||||
{ "蚕丝", "桑蚕丝" },
|
||||
{ "弹力布", "纺织" },
|
||||
{ "发泡橡胶", "橡胶发泡" },
|
||||
{ "复合底", "橡胶+EVA" },
|
||||
{ "冰丝", "粘胶纤维" },
|
||||
{ "橡胶", "橡胶底" },
|
||||
{ "丁腈", "NBR,nbr"},
|
||||
{ "丁腈橡胶", "NBR,nbr"},
|
||||
{ "棉", "纺织" },
|
||||
};
|
||||
}
|
||||
|
||||
public class product_format_new_item
|
||||
{
|
||||
public string name { get; set; }
|
||||
public long value { get; set; }
|
||||
public long diy_type { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user