|
@@ -24,6 +24,166 @@ namespace molilian.core
|
|
|
_config = TkConfigCore.Get();
|
|
_config = TkConfigCore.Get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public async Task<(APIResult, PromotionQueryDTO)> PromotionQueryByItemIdAsync(string itemid, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ PromotionQueryDTO result = new()
|
|
|
|
|
+ {
|
|
|
|
|
+ end_point = _end_point,
|
|
|
|
|
+ ip = ip,
|
|
|
|
|
+ oaid = oaid,
|
|
|
|
|
+ scene = scene,
|
|
|
|
|
+ itemid = itemid
|
|
|
|
|
+ };
|
|
|
|
|
+ if (string.IsNullOrEmpty(oaid))
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success = false;
|
|
|
|
|
+ result.message = "调用失败";
|
|
|
|
|
+ result.reason = "无效OAID";
|
|
|
|
|
+ _ = TkLogCore.PromotionImgLogAsync(result);
|
|
|
|
|
+ return (new APIResult(new
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success,
|
|
|
|
|
+ result.message,
|
|
|
|
|
+ result.reason,
|
|
|
|
|
+ }, APIResultCodeEnum.OK, new JsonSerializerOptions
|
|
|
|
|
+ {
|
|
|
|
|
+ Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
|
|
|
+ }), null);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (string.IsNullOrEmpty(itemid))
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success = false;
|
|
|
|
|
+ result.message = "调用失败";
|
|
|
|
|
+ result.reason = "无效商品ID";
|
|
|
|
|
+ _ = TkLogCore.PromotionImgLogAsync(result);
|
|
|
|
|
+ return (new APIResult(new
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success,
|
|
|
|
|
+ result.message,
|
|
|
|
|
+ result.reason,
|
|
|
|
|
+ }, APIResultCodeEnum.OK, new JsonSerializerOptions
|
|
|
|
|
+ {
|
|
|
|
|
+ Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
|
|
|
+ }), null);
|
|
|
|
|
+ }
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ TkPoolDTO account;
|
|
|
|
|
+ if (aid == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ account = await TkPoolCore.GetOneAsync(TkPoolCore.TkAction.promotionQuery, false, string.Empty, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ account = await TkPoolCore.GetOneAsync(aid);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (account == null)
|
|
|
|
|
+ {
|
|
|
|
|
+ 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ string nodeName = ProxyNodesCore.GetSelectOne(account.nodeName);
|
|
|
|
|
+ var proxy = ProxyNodesCore.GetOne(nodeName);
|
|
|
|
|
+ TaobaoOpenPlus taobao = new(account.appkey, account.appSecret, account.open_pid, debug, proxy);
|
|
|
|
|
+ int timeout = _config.similar_timeout;
|
|
|
|
|
+#if DEBUG
|
|
|
|
|
+ timeout = 50000;
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ result.accountId = account.id;
|
|
|
|
|
+ result.accountName = account.name;
|
|
|
|
|
+
|
|
|
|
|
+ result.proxy_nodename = nodeName;
|
|
|
|
|
+ result.proxy_node = proxy?.Address?.Host;
|
|
|
|
|
+
|
|
|
|
|
+ using var cts = new CancellationTokenSource();
|
|
|
|
|
+ cts.CancelAfter(timeout);
|
|
|
|
|
+
|
|
|
|
|
+ DateTime stime = DateTime.Now;
|
|
|
|
|
+
|
|
|
|
|
+#if DEBUG
|
|
|
|
|
+ account.api_id = 17;
|
|
|
|
|
+ account.api = "aliyun";
|
|
|
|
|
+ account.refpid = "mm_6695915495_3161300068_115818650332";
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ result.proxy_nodename = null;
|
|
|
|
|
+ result.proxy_node = null;
|
|
|
|
|
+
|
|
|
|
|
+ AliyunCore api;
|
|
|
|
|
+ if (account.api_id == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ api = new AliyunCore(account.appkey, account.appSecret);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ api = new AliyunCore(account.api_id);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var aliDelayTask = Task.Delay(1500, cts.Token);
|
|
|
|
|
+ var aliRequestTask = api.itemSimilaritemAsync(itemid, account.open_pid, result);
|
|
|
|
|
+
|
|
|
|
|
+ var aliCompletedTask = await Task.WhenAny(aliDelayTask, aliRequestTask);
|
|
|
|
|
+ if (aliCompletedTask == aliRequestTask)
|
|
|
|
|
+ {
|
|
|
|
|
+ result = await aliRequestTask;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success = false;
|
|
|
|
|
+ result.message = "调用失败";
|
|
|
|
|
+ result.reason = "请求超时";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ var ts2 = DateTime.Now - stime;
|
|
|
|
|
+ result.elapsedTime2 = (int)ts2.TotalMilliseconds;
|
|
|
|
|
+
|
|
|
|
|
+ _ = TkLogCore.PromotionImgLogAsync(result);
|
|
|
|
|
+ return (new APIResult(new
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success,
|
|
|
|
|
+ result.message,
|
|
|
|
|
+ result.reason,
|
|
|
|
|
+ promotionImg = result.PromotionImg,
|
|
|
|
|
+ exposeTracks = $"https://api.molilian.com/tracks/track?track_id=7&unique_id=",
|
|
|
|
|
+ clickTracks = $"https://api.molilian.com/tracks/track?track_id=8&unique_id="
|
|
|
|
|
+ }, APIResultCodeEnum.OK, new JsonSerializerOptions
|
|
|
|
|
+ {
|
|
|
|
|
+ Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
|
|
|
|
+ }), result);
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception ex)
|
|
|
|
|
+ {
|
|
|
|
|
+ result.success = false;
|
|
|
|
|
+ result.message = "调用失败";
|
|
|
|
|
+ result.reason = ex.Message;
|
|
|
|
|
+ _ = 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);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
public async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0)
|
|
public async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "", string scene = "", bool recommand = true, bool debug = false, int aid = 0)
|
|
|
{
|
|
{
|