|
|
@@ -118,6 +118,7 @@ namespace molilian.core
|
|
|
return (true, resultUrl);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return (false, url);
|
|
|
}
|
|
|
|
|
|
@@ -177,7 +178,7 @@ namespace molilian.core
|
|
|
/// </summary>
|
|
|
/// <param name="url"></param>
|
|
|
/// <returns></returns>
|
|
|
- async Task<(bool, string)> GetDesiredUrlAsync(string url, CancellationToken cancellationToken = default)
|
|
|
+ public async Task<(bool, string)> GetDesiredUrlAsync(string url, CancellationToken cancellationToken = default)
|
|
|
{
|
|
|
string result;
|
|
|
try
|
|
|
@@ -185,6 +186,10 @@ namespace molilian.core
|
|
|
if (!url.Contains("m.tb.cn") && !url.Contains("s.tb.cn"))
|
|
|
return (false, "不是淘宝短网址");
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ if (!_account.enable_deep_url) return (true, url);
|
|
|
+
|
|
|
string desiredUrlPattern = "var url = '(.*?)'";
|
|
|
WebClientUtility client = new()
|
|
|
{
|
|
|
@@ -193,9 +198,11 @@ namespace molilian.core
|
|
|
};
|
|
|
#if DEBUG
|
|
|
client.Proxy = null;
|
|
|
-#endif
|
|
|
+ var response = await client.RequestAsync(url, "GET");
|
|
|
+#else
|
|
|
client.Timeout = GetRequestTimeout(0);
|
|
|
var response = await client.RequestAsync(url, "GET", cancellationToken);
|
|
|
+#endif
|
|
|
|
|
|
var responseBody = response.Body();
|
|
|
result = responseBody;
|
|
|
@@ -396,13 +403,13 @@ namespace molilian.core
|
|
|
result.shortLinkurl = null;
|
|
|
}
|
|
|
|
|
|
- private async Task<TkDataDTO> InternalTextProcessingAsync(string content, TkDataDTO result,
|
|
|
- CancellationToken cancellationToken,
|
|
|
+ public async Task<TkDataDTO> InternalTextProcessingAsync(string content, TkDataDTO result,
|
|
|
+ CancellationToken cancellationToken = default,
|
|
|
Dictionary<string, long> swData = null)
|
|
|
{
|
|
|
bool success;
|
|
|
string resultText;
|
|
|
- LinkTypeEnum link_type = LinkTypeEnum.unknown;
|
|
|
+ result.link_type = LinkTypeEnum.unknown;
|
|
|
|
|
|
//============================== 放弃转链-其他推广链接 ==============================
|
|
|
string url = GetLink(content);
|
|
|
@@ -430,14 +437,16 @@ namespace molilian.core
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
Stopwatch sw = Stopwatch.StartNew();
|
|
|
(success, resultText) = await GetDesiredUrlAsync(url, cancellationToken);
|
|
|
sw.Stop();
|
|
|
// 获取执行时间
|
|
|
result.elapsedTime2 = (int)sw.ElapsedMilliseconds;
|
|
|
swData?.Add("\tGetDesiredUrlAsync", sw.ElapsedMilliseconds);
|
|
|
-
|
|
|
//============================== 放弃转链-请求超时 ==============================
|
|
|
+#if DEBUG
|
|
|
+#else
|
|
|
if (result.elapsedTime2 >= _config.rt_max || (!success && resultText.Contains("was canceled")))
|
|
|
{
|
|
|
result.success = false;
|
|
|
@@ -446,6 +455,7 @@ namespace molilian.core
|
|
|
result.subCode = TkSubCodeEnum.Other;
|
|
|
return result;
|
|
|
}
|
|
|
+#endif
|
|
|
|
|
|
if (success)
|
|
|
{
|
|
|
@@ -473,27 +483,36 @@ namespace molilian.core
|
|
|
result.shortLinkurl = desiredUrl;
|
|
|
return result;
|
|
|
}
|
|
|
- link_type = GetLinkType(desiredUrl);
|
|
|
+ result.link_type = GetLinkType(desiredUrl);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- link_type = GetLinkType(url);
|
|
|
+ result.link_type = GetLinkType(url);
|
|
|
}
|
|
|
|
|
|
- if ((result.content.Contains("霸下通用 web 页面-验证码")))
|
|
|
+ if (result.content.Contains("霸下通用 web 页面-验证码"))
|
|
|
{
|
|
|
- result.subCode = TkSubCodeEnum.Other;
|
|
|
+ result.subCode = TkSubCodeEnum.Captcha;
|
|
|
result.reason = "霸下验证码";
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (result.link_type == LinkTypeEnum.baseDomain)
|
|
|
+ {
|
|
|
+ result.content = content;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ result.reason = "非标准链接";
|
|
|
+ result.subCode = TkSubCodeEnum.NonStdLink;
|
|
|
|
|
|
-
|
|
|
+ }
|
|
|
+ }
|
|
|
result.success = false;
|
|
|
result.message = "放弃转链";
|
|
|
- result.reason = "非标准链接";
|
|
|
- result.subCode = TkSubCodeEnum.NonStdLink;
|
|
|
result.content = resultText;
|
|
|
- result.link_type = link_type;
|
|
|
result.shortLinkurl = url;
|
|
|
+
|
|
|
return result;
|
|
|
//return (false, result, link_type, url);
|
|
|
}
|
|
|
@@ -528,6 +547,8 @@ namespace molilian.core
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(url)) return LinkTypeEnum.unknown;
|
|
|
|
|
|
+ if (url.Contains("m.tb.cn") || url.Contains("s.tb.cn")) return LinkTypeEnum.baseDomain;
|
|
|
+
|
|
|
if (url.StartsWith("https://huodong.m.taobao.com/act/talent/live.html")) return LinkTypeEnum.live;
|
|
|
if (url.StartsWith("https://web.m.taobao.com/app/tnode/web/index")) return LinkTypeEnum.video;
|
|
|
if (url.StartsWith("https://shop.m.taobao.com/shop/shopIndex.htm")) return LinkTypeEnum.profile;
|
|
|
@@ -580,7 +601,12 @@ namespace molilian.core
|
|
|
if (!string.IsNullOrEmpty(_user_agent)) client.UserAgent = _user_agent;
|
|
|
client.Timeout = GetRequestTimeout(result.elapsedTime2);
|
|
|
//var response = client.Request(url);
|
|
|
+
|
|
|
+#if DEBUG
|
|
|
+ var response = await client.RequestAsync(url, "GET");
|
|
|
+#else
|
|
|
var response = await client.RequestAsync(url, "GET", cancellationToken);
|
|
|
+#endif
|
|
|
|
|
|
stopwatch.Stop();
|
|
|
result.elapsedTime3 = (int)stopwatch.ElapsedMilliseconds;
|
|
|
@@ -622,6 +648,14 @@ namespace molilian.core
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
+ _ = new LoggerLibrary("api_error", "fail")
|
|
|
+ .Info(ex.Message, ex.StackTrace)
|
|
|
+ .SaveAsync();
|
|
|
+
|
|
|
+ if (body.Contains("https://g.alicdn.com/sd/punish/waf_block.html"))
|
|
|
+ {
|
|
|
+ throw new Exception("waf_block");
|
|
|
+ }
|
|
|
throw new Exception(body);
|
|
|
}
|
|
|
|
|
|
@@ -751,7 +785,7 @@ namespace molilian.core
|
|
|
result.pic = pic;
|
|
|
result.qrCodeUrl = qrCodeUrl;
|
|
|
}
|
|
|
- catch
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
if (response.ResponseMessage?.StatusCode == System.Net.HttpStatusCode.OK)
|
|
|
{
|