|
@@ -75,9 +75,7 @@ namespace molilian.core
|
|
|
return result.link_type == LinkTypeEnum.other_aff;
|
|
return result.link_type == LinkTypeEnum.other_aff;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public async Task<TkDataDTO> UnionParseAsync(string ip, string oaid, string content, int commerceType, TkDataDTO result,
|
|
|
|
|
- bool isTaobaoUrl, string riskStrategy, int launchScene,
|
|
|
|
|
- CancellationToken cancellationToken = default,
|
|
|
|
|
|
|
+ public async Task<TkDataDTO> UnionParseAsync(UnionParseRequest request, string content, TkDataDTO result, bool isTaobaoUrl, CancellationToken cancellationToken = default,
|
|
|
Dictionary<string, long> swData = null)
|
|
Dictionary<string, long> swData = null)
|
|
|
{
|
|
{
|
|
|
result.itemName = "点击打开淘宝APP";
|
|
result.itemName = "点击打开淘宝APP";
|
|
@@ -135,7 +133,7 @@ namespace molilian.core
|
|
|
|
|
|
|
|
//============================== 放弃转链-地区过滤 ==============================
|
|
//============================== 放弃转链-地区过滤 ==============================
|
|
|
|
|
|
|
|
- bool is_ignore2 = FlowControlIgnoreRequest(ip, oaid, riskStrategy, launchScene, out string reason);
|
|
|
|
|
|
|
+ bool is_ignore2 = FlowControlIgnoreRequest(request.Ip, request.Oaid, request.RiskStrategy, request.LaunchScene, out string reason);
|
|
|
string message = "放弃转链";
|
|
string message = "放弃转链";
|
|
|
if (is_ignore2)
|
|
if (is_ignore2)
|
|
|
{
|
|
{
|
|
@@ -151,13 +149,13 @@ namespace molilian.core
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- switch (commerceType)
|
|
|
|
|
|
|
+ switch (request.CommerceType)
|
|
|
{
|
|
{
|
|
|
case 1:
|
|
case 1:
|
|
|
case 2:
|
|
case 2:
|
|
|
result.success = false;
|
|
result.success = false;
|
|
|
result.message = "放弃转链";
|
|
result.message = "放弃转链";
|
|
|
- result.reason = $"厂商放弃{commerceType}";
|
|
|
|
|
|
|
+ result.reason = $"厂商放弃{request.CommerceType}";
|
|
|
result.subCode = TkSubCodeEnum.PartnersDrop;
|
|
result.subCode = TkSubCodeEnum.PartnersDrop;
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
@@ -236,6 +234,13 @@ namespace molilian.core
|
|
|
result.retry_count = try_count;
|
|
result.retry_count = try_count;
|
|
|
result.commercial = result.success;
|
|
result.commercial = result.success;
|
|
|
|
|
|
|
|
|
|
+ if (result.success && "brwsimilar".Equals(request.RiskStrategy))
|
|
|
|
|
+ {
|
|
|
|
|
+ // 需要搜同款才进入这个逻辑
|
|
|
|
|
+ result.PromotionImg = await InternalCallPromotionQuery(result.pic, request.Oaid, request.Ip);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
if (!result.success)
|
|
if (!result.success)
|
|
|
{
|
|
{
|
|
|
result.itemName = "点击打开淘宝APP";
|
|
result.itemName = "点击打开淘宝APP";
|
|
@@ -247,6 +252,103 @@ namespace molilian.core
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private async Task<List<PromotionQueryItemDTO>> InternalCallPromotionQuery(string pic, string oaid, string ip)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (string.IsNullOrWhiteSpace(pic))
|
|
|
|
|
+ {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ static bool TryParseItems(JsonElement element, out List<PromotionQueryItemDTO> items)
|
|
|
|
|
+ {
|
|
|
|
|
+ items = [];
|
|
|
|
|
+ if (element.ValueKind == JsonValueKind.Array)
|
|
|
|
|
+ {
|
|
|
|
|
+ items = JsonSerializer.Deserialize<List<PromotionQueryItemDTO>>(element.GetRawText()) ?? [];
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (element.ValueKind != JsonValueKind.Object)
|
|
|
|
|
+ {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (element.TryGetProperty("promotionImg", out var promotionImg) && promotionImg.ValueKind == JsonValueKind.Array)
|
|
|
|
|
+ {
|
|
|
|
|
+ items = JsonSerializer.Deserialize<List<PromotionQueryItemDTO>>(promotionImg.GetRawText()) ?? [];
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (element.TryGetProperty("PromotionImg", out promotionImg) && promotionImg.ValueKind == JsonValueKind.Array)
|
|
|
|
|
+ {
|
|
|
|
|
+ items = JsonSerializer.Deserialize<List<PromotionQueryItemDTO>>(promotionImg.GetRawText()) ?? [];
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ static List<PromotionQueryItemDTO> RemoveFirstItem(List<PromotionQueryItemDTO> items)
|
|
|
|
|
+ {
|
|
|
|
|
+ return items.Count > 0 ? items.Skip(1).ToList() : [];
|
|
|
|
|
+ }
|
|
|
|
|
+ string requestUrl = "https://similar.molilian.com/api/unsafePromotionQuery";
|
|
|
|
|
+ string targetPic = pic.StartsWith("//") ? $"https:{pic}" : pic;
|
|
|
|
|
+ object postData = new
|
|
|
|
|
+ {
|
|
|
|
|
+ url = targetPic,
|
|
|
|
|
+ oaid,
|
|
|
|
|
+ ip,
|
|
|
|
|
+ recommand = false
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ string post = postData.Convert2Json();
|
|
|
|
|
+
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ var client = new WebClientUtility().SetContentType("application/json")
|
|
|
|
|
+ .Post(post);
|
|
|
|
|
+ var response = await client.RequestAsync(requestUrl, "POST");
|
|
|
|
|
+ var body = response.Body();
|
|
|
|
|
+
|
|
|
|
|
+ if (string.IsNullOrWhiteSpace(body))
|
|
|
|
|
+ {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var root = body.Convert2JsonElement();
|
|
|
|
|
+ if (TryParseItems(root, out var result))
|
|
|
|
|
+ {
|
|
|
|
|
+ return RemoveFirstItem(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (root.ValueKind == JsonValueKind.Object)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (root.TryGetProperty("data", out var data) && TryParseItems(data, out result))
|
|
|
|
|
+ {
|
|
|
|
|
+ return RemoveFirstItem(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (root.TryGetProperty("result", out var resultNode) && TryParseItems(resultNode, out result))
|
|
|
|
|
+ {
|
|
|
|
|
+ return RemoveFirstItem(result);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ _ = new LoggerLibrary("AlimamaPlus", "InternalCallPromotionQuery")
|
|
|
|
|
+ .Info(post, body)
|
|
|
|
|
+ .SaveAsync();
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ _ = new LoggerLibrary("AlimamaPlus", "InternalCallPromotionQuery")
|
|
|
|
|
+ .Info(requestUrl, post)
|
|
|
|
|
+ .Info(ex.Message, ex.StackTrace)
|
|
|
|
|
+ .SaveAsync();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public static bool ContainsTaobaoId(string content, string rawContent)
|
|
public static bool ContainsTaobaoId(string content, string rawContent)
|
|
|
{
|
|
{
|
|
|
var match = Regex.Match(content, @"(?<=[?&]id=)\d+(?=&|$)");
|
|
var match = Regex.Match(content, @"(?<=[?&]id=)\d+(?=&|$)");
|
|
@@ -623,10 +725,27 @@ namespace molilian.core
|
|
|
}
|
|
}
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ public static bool IsDigitsOnly(string? s)
|
|
|
|
|
+ {
|
|
|
|
|
+ return !string.IsNullOrEmpty(s)
|
|
|
|
|
+ && s.AsSpan().IndexOfAnyExceptInRange('0', '9') < 0;
|
|
|
|
|
+ }
|
|
|
public static TkDataDTO GetFormattedObject(UnionParseRequest request)
|
|
public static TkDataDTO GetFormattedObject(UnionParseRequest request)
|
|
|
{
|
|
{
|
|
|
- string shortLinkurl = GetTaobaoLink(request.Content);
|
|
|
|
|
|
|
+ string content = request.Content;
|
|
|
|
|
+
|
|
|
|
|
+ switch (request.RiskStrategy)
|
|
|
|
|
+ {
|
|
|
|
|
+ case "brwsimilar":
|
|
|
|
|
+ case "tbpush":
|
|
|
|
|
+ if (IsDigitsOnly(content))
|
|
|
|
|
+ {
|
|
|
|
|
+ content = $"https://item.taobao.com/item.htm?id={content}";
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ string shortLinkurl = GetTaobaoLink(content);
|
|
|
string deeplink_url = GetDeeplink(shortLinkurl);
|
|
string deeplink_url = GetDeeplink(shortLinkurl);
|
|
|
return new TkDataDTO()
|
|
return new TkDataDTO()
|
|
|
{
|
|
{
|
|
@@ -635,7 +754,8 @@ namespace molilian.core
|
|
|
channel = TkChannelEnum.tb,
|
|
channel = TkChannelEnum.tb,
|
|
|
accountName = string.Empty,
|
|
accountName = string.Empty,
|
|
|
success = false,
|
|
success = false,
|
|
|
- content = request.Content,
|
|
|
|
|
|
|
+ content = content,
|
|
|
|
|
+ rawContent = request.Content,
|
|
|
link_type = LinkTypeEnum.unknown,
|
|
link_type = LinkTypeEnum.unknown,
|
|
|
ip = request.Ip,
|
|
ip = request.Ip,
|
|
|
oaid = request.Oaid,
|
|
oaid = request.Oaid,
|