This commit is contained in:
老道 2022-10-03 11:31:32 +08:00
parent 3970d268ca
commit 8ac1f62a23
2 changed files with 59 additions and 27 deletions

View File

@ -205,10 +205,10 @@ namespace Api.Framework
Mode = SuperSocket.SocketBase.SocketMode.Tcp, Mode = SuperSocket.SocketBase.SocketMode.Tcp,
TextEncoding = "UTF-8", TextEncoding = "UTF-8",
Port = port, Port = port,
MaxConnectionNumber = 100 * 5, MaxConnectionNumber = 100 * 5 + 50,
ReceiveBufferSize = bufSize, ReceiveBufferSize = bufSize,
MaxRequestLength = Int32.MaxValue, MaxRequestLength = Int32.MaxValue,
SendingQueueSize = 300, SendingQueueSize = 400,
}; };

View File

@ -1138,14 +1138,62 @@ namespace Api.Framework.Tools
private string getMTbCn(string url, AlimamaApi api) private string getMTbCn(string url, AlimamaApi api)
{ {
try if (!url.ToLower().Contains("m.tb.cn") && !url.ToLower().Contains("s.tb.cn"))
{
if (!url.ToLower().Contains("m.tb.cn"))
{ {
return string.Empty; return string.Empty;
} }
for (int i = 0; i < 3; i++) var urlTmp = url;
for (int i = 0; i < 4; i++)
{
try
{
if (urlTmp.Contains("m.tb"))
{
urlTmp = urlTmp.Replace("m.tb", "s.tb");
}
else if (urlTmp.Contains("s.tb"))
{
urlTmp = urlTmp.Replace("s.tb", "m.tb");
}
var html = getTb(urlTmp, api);
if (html.Contains("操作超时"))
{
Thread.Sleep(500);
continue;
}
var item_id = string.Empty;
var reg = Regex.Match(html, @"var url = '(?<url>.*?)';");
if (reg.Success)
{
var oriUrl = reg.Groups["url"].Value;
if (string.IsNullOrWhiteSpace(oriUrl))
{
return "00000";
}
item_id = CouponByItemId(oriUrl, api);
}
if (string.IsNullOrWhiteSpace(item_id))
item_id = FindTbItemIdByStr(html);
if (!string.IsNullOrWhiteSpace(item_id))
return item_id;
}
catch (Exception ex)
{
LogHelper.GetSingleObj().Error("淘宝解析请求异常2", $"{urlTmp} -> {ex.Message}");
}
}
return string.Empty;
}
private string getTb(string url, AlimamaApi api)
{
try
{ {
HttpHelper http = new HttpHelper(); HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem() HttpItem item = new HttpItem()
@ -1168,29 +1216,13 @@ namespace Api.Framework.Tools
LogHelper.GetSingleObj().Error("淘宝解析请求", $"{url} =>> {html}"); LogHelper.GetSingleObj().Error("淘宝解析请求", $"{url} =>> {html}");
var item_id = string.Empty; return html;
var reg = Regex.Match(html, @"var url = '(?<url>.*?)';");
if (reg.Success)
{
var oriUrl = reg.Groups["url"].Value;
if (string.IsNullOrWhiteSpace(oriUrl))
{
return "00000";
}
item_id = CouponByItemId(oriUrl, api);
}
if (string.IsNullOrWhiteSpace(item_id))
item_id = FindTbItemIdByStr(html);
if (!string.IsNullOrWhiteSpace(item_id))
return item_id;
Thread.Sleep(500);
}
} }
catch (Exception ex) catch (Exception ex)
{ {
LogHelper.GetSingleObj().Error("淘宝解析请求异常", $"{url} -> {ex.Message}"); LogHelper.GetSingleObj().Error("淘宝解析请求异常", $"{url} -> {ex.Message}");
} }
return string.Empty; return string.Empty;
} }