|
@@ -1,22 +1,4 @@
|
|
|
-using Microsoft.AspNetCore.Http;
|
|
|
|
|
-using Microsoft.AspNetCore.Mvc.Controllers;
|
|
|
|
|
-using Microsoft.AspNetCore.Mvc.Filters;
|
|
|
|
|
-using System;
|
|
|
|
|
-using System.Collections.Generic;
|
|
|
|
|
-using System.Linq;
|
|
|
|
|
-using System.Text;
|
|
|
|
|
-using dodohold.core;
|
|
|
|
|
-using Spire.Pdf.Exporting.XPS.Schema;
|
|
|
|
|
-using System.Xml.Linq;
|
|
|
|
|
-using System.Net;
|
|
|
|
|
-using TencentCloud.Mrs.V20200910.Models;
|
|
|
|
|
-using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
-using Microsoft.AspNetCore.Authentication;
|
|
|
|
|
-using Spire.Pdf.Graphics;
|
|
|
|
|
-using Google.Protobuf.WellKnownTypes;
|
|
|
|
|
-using System.Threading.Channels;
|
|
|
|
|
-using TencentCloud.Weilingwith.V20230427.Models;
|
|
|
|
|
-using System.Threading;
|
|
|
|
|
|
|
+using dodohold.core;
|
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -25,6 +7,7 @@ namespace molilian.core
|
|
|
public partial class TaokeOpenCore
|
|
public partial class TaokeOpenCore
|
|
|
{
|
|
{
|
|
|
static string _test_base64String = string.Empty;
|
|
static string _test_base64String = string.Empty;
|
|
|
|
|
+ public TkConfigDTO _config;
|
|
|
|
|
|
|
|
private static string _end_point;
|
|
private static string _end_point;
|
|
|
static TaokeOpenCore()
|
|
static TaokeOpenCore()
|
|
@@ -32,8 +15,13 @@ namespace molilian.core
|
|
|
_end_point = Environment.GetEnvironmentVariable("EndPoint");
|
|
_end_point = Environment.GetEnvironmentVariable("EndPoint");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public TaokeOpenCore()
|
|
|
|
|
+ {
|
|
|
|
|
+ _config = TkConfigCore.Get();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- public static async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "")
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "")
|
|
|
{
|
|
{
|
|
|
PromotionQueryDTO result = new()
|
|
PromotionQueryDTO result = new()
|
|
|
{
|
|
{
|
|
@@ -118,10 +106,56 @@ namespace molilian.core
|
|
|
oaid = data.Url.GetContentPart("oaid=", "&");
|
|
oaid = data.Url.GetContentPart("oaid=", "&");
|
|
|
string cookies = string.Empty;
|
|
string cookies = string.Empty;
|
|
|
|
|
|
|
|
- (result.SimilarPromotion, cookies) = await taobao.GetRecommendData(TaobaoOpenPlus.RecommendRequestType.first, oaid, cookies);
|
|
|
|
|
- (result.PromotionImg, cookies) = await taobao.GetRecommendData(TaobaoOpenPlus.RecommendRequestType.ori, oaid, cookies);
|
|
|
|
|
- result.similarPromotion = result.SimilarPromotion.Convert2Json();
|
|
|
|
|
- result.promotionImg = result.PromotionImg.Convert2Json();
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ int timeout = _config.similar_timeout;
|
|
|
|
|
+#if DEBUG
|
|
|
|
|
+ timeout = 5000;
|
|
|
|
|
+#endif
|
|
|
|
|
+ using var cts = new CancellationTokenSource();
|
|
|
|
|
+ cts.CancelAfter(timeout);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ var requestTask = Task.Run(async () =>
|
|
|
|
|
+ {
|
|
|
|
|
+ (result.SimilarPromotion, cookies) = await taobao.GetRecommendDataWithRetry(TaobaoOpenPlus.RecommendRequestType.first, oaid, cookies, cts.Token);
|
|
|
|
|
+ (result.PromotionImg, cookies) = await taobao.GetRecommendDataWithRetry(TaobaoOpenPlus.RecommendRequestType.ori, oaid, cookies, cts.Token);
|
|
|
|
|
+ result.similarPromotion = result.SimilarPromotion.Convert2Json();
|
|
|
|
|
+ result.promotionImg = result.PromotionImg.Convert2Json();
|
|
|
|
|
+ return result;
|
|
|
|
|
+
|
|
|
|
|
+ }, cts.Token);
|
|
|
|
|
+
|
|
|
|
|
+ var delayTask = Task.Delay(timeout, cts.Token);
|
|
|
|
|
+ var completedTask = await Task.WhenAny(requestTask, delayTask);
|
|
|
|
|
+ if (completedTask == requestTask)
|
|
|
|
|
+ {
|
|
|
|
|
+ result = await requestTask;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //============================== 放弃转链-请求超时 ==============================
|
|
|
|
|
+ cts.Cancel();
|
|
|
|
|
+ result.success = false;
|
|
|
|
|
+ result.message = "调用失败";
|
|
|
|
|
+ result.reason = "请求超时";
|
|
|
|
|
+ _ = TkLogCore.PromotionImgLogAsync(result);
|
|
|
|
|
+ return new APIResult(new
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success,
|
|
|
|
|
+ result.message,
|
|
|
|
|
+ result.reason,
|
|
|
|
|
+ }, APIResultCodeEnum.OK, new JsonSerializerOptions
|
|
|
|
|
+ {
|
|
|
|
|
+ Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //(result.SimilarPromotion, cookies) = await taobao.GetRecommendData(TaobaoOpenPlus.RecommendRequestType.first, oaid, cookies);
|
|
|
|
|
+ //(result.PromotionImg, cookies) = await taobao.GetRecommendData(TaobaoOpenPlus.RecommendRequestType.ori, oaid, cookies);
|
|
|
|
|
+ //result.similarPromotion = result.SimilarPromotion.Convert2Json();
|
|
|
|
|
+ //result.promotionImg = result.PromotionImg.Convert2Json();
|
|
|
|
|
|
|
|
result.success = true;
|
|
result.success = true;
|
|
|
result.message = "调用成功";
|
|
result.message = "调用成功";
|