TkActivityCore.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using dodohold.core;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Spire.Xls.Charts;
  4. using TencentCloud.Bsca.V20210811.Models;
  5. namespace molilian.core
  6. {
  7. public partial class TkActivityCore
  8. {
  9. private static string _end_point;
  10. static TkActivityCore()
  11. {
  12. _end_point = Environment.GetEnvironmentVariable("EndPoint");
  13. }
  14. public static async Task<ActionResult> ParseAsync(string page_id, string prefix, string item_id, string strategy_id, string ip, string oaid)
  15. {
  16. AlimamaPlus alimama = null;
  17. TkActivityDTO result = new()
  18. {
  19. channel = TkChannelEnum.tb,
  20. page_id = page_id,
  21. raw_item_id = item_id,
  22. item_id = $"{prefix}:{item_id}",
  23. end_point = _end_point,
  24. ip = ip,
  25. oaid = oaid
  26. };
  27. if (string.IsNullOrEmpty(page_id) || string.IsNullOrEmpty(item_id))
  28. {
  29. result.success = false;
  30. result.message = "放弃转链";
  31. result.reason = "无效的参数";
  32. _ = TkLogCore.TkActivityLogAsync(result);
  33. return new APIResult(new
  34. {
  35. result.success,
  36. result.reason,
  37. result.message,
  38. channel = result.channel.ToString(),
  39. });
  40. }
  41. try
  42. {
  43. string reason;
  44. UnionParseRequest request = new()
  45. {
  46. Ip = ip,
  47. Oaid = oaid,
  48. RiskStrategy = string.Empty,
  49. LaunchScene = 0,
  50. };
  51. if (AlimamaPlus.ShouldIgnoreRequest(request, out reason))
  52. {
  53. result.success = false;
  54. result.message = "放弃转链";
  55. result.reason = reason;
  56. _ = TkLogCore.TkActivityLogAsync(result);
  57. return new APIResult(new
  58. {
  59. result.success,
  60. result.message,
  61. result.reason,
  62. channel = result.channel.ToString(),
  63. });
  64. }
  65. var account = await TkPoolCore.GetOneAsync(TkPoolCore.TkAction.activity, false, string.Empty, 0, string.Empty, strategy_id);
  66. if (account == null)
  67. {
  68. result.success = false;
  69. result.message = "放弃转链";
  70. result.reason = "没有匹配账号";
  71. _ = TkLogCore.TkActivityLogAsync(result);
  72. return new APIResult(new
  73. {
  74. result.success,
  75. result.message,
  76. result.reason,
  77. channel = result.channel.ToString(),
  78. });
  79. }
  80. result.accountId = account.id;
  81. result.accountName = account.name;
  82. alimama = new AlimamaPlus(account);
  83. result = await alimama.TkActivityAsync(result);
  84. }
  85. catch (Exception ex)
  86. {
  87. if (ex.Message.Contains("was canceled"))
  88. {
  89. result.success = false;
  90. result.message = "放弃转链";
  91. result.reason = "请求超时";
  92. }
  93. else
  94. {
  95. _ = new LoggerLibrary("unionCoupon", "tb_error")
  96. .Info(ip, oaid)
  97. .Info(page_id, result.item_id)
  98. .Info(ex.Message, ex.StackTrace)
  99. .SaveAsync();
  100. NotifyCore.Notify(new NifyMessage
  101. {
  102. message = $"【转链异常TB】\n{page_id}\t{result.item_id}\n\n{ex.Message}\n{ex.StackTrace}",
  103. priority = NifyMessagePriority.high,
  104. tags = ["red_circle"]
  105. });
  106. result.success = false;
  107. result.message = "放弃转链";
  108. result.reason = "转链接口异常";
  109. }
  110. }
  111. _ = TkLogCore.TkActivityLogAsync(result);
  112. if (!result.success)
  113. {
  114. return new APIResult(new
  115. {
  116. result.success,
  117. result.message,
  118. result.reason,
  119. channel = result?.channel.ToString(),
  120. });
  121. }
  122. return new APIResult(new
  123. {
  124. result.success,
  125. result.message,
  126. channel = result?.channel.ToString(),
  127. result.deeplink_url,
  128. input_item_id = item_id,
  129. input_page_id = page_id,
  130. result.estimatedCommission,
  131. result.maxCommission,
  132. price = result.reservePrice,
  133. result.reservePrice,
  134. result.title,
  135. result.picUrl,
  136. result.shortTitle,
  137. result.priceAfterCoupon,
  138. result.commissionRate,
  139. result.couponAmount,
  140. exposeTracks = $"https://api.molilian.com/tracks/track?track_id=11&unique_id={item_id}",
  141. clickTracks = $"https://api.molilian.com/tracks/track?track_id=12&unique_id={item_id}"
  142. });
  143. }
  144. }
  145. }