TkActivityCore.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. if (AlimamaPlus.ShouldIgnoreRequest(ip, oaid, string.Empty, 0, out reason))
  45. {
  46. result.success = false;
  47. result.message = "放弃转链";
  48. result.reason = reason;
  49. _ = TkLogCore.TkActivityLogAsync(result);
  50. return new APIResult(new
  51. {
  52. result.success,
  53. result.message,
  54. result.reason,
  55. channel = result.channel.ToString(),
  56. });
  57. }
  58. var account = await TkPoolCore.GetOneAsync(TkPoolCore.TkAction.activity, false, string.Empty, 0, string.Empty, strategy_id);
  59. if (account == null)
  60. {
  61. result.success = false;
  62. result.message = "放弃转链";
  63. result.reason = "没有匹配账号";
  64. _ = TkLogCore.TkActivityLogAsync(result);
  65. return new APIResult(new
  66. {
  67. result.success,
  68. result.message,
  69. result.reason,
  70. channel = result.channel.ToString(),
  71. });
  72. }
  73. result.accountId = account.id;
  74. result.accountName = account.name;
  75. alimama = new AlimamaPlus(account);
  76. result = await alimama.TkActivityAsync(result);
  77. }
  78. catch (Exception ex)
  79. {
  80. if (ex.Message.Contains("was canceled"))
  81. {
  82. result.success = false;
  83. result.message = "放弃转链";
  84. result.reason = "请求超时";
  85. }
  86. else
  87. {
  88. _ = new LoggerLibrary("unionCoupon", "tb_error")
  89. .Info(ip, oaid)
  90. .Info(page_id, result.item_id)
  91. .Info(ex.Message, ex.StackTrace)
  92. .SaveAsync();
  93. NotifyCore.Notify(new NifyMessage
  94. {
  95. message = $"【转链异常TB】\n{page_id}\t{result.item_id}\n\n{ex.Message}\n{ex.StackTrace}",
  96. priority = NifyMessagePriority.high,
  97. tags = ["red_circle"]
  98. });
  99. result.success = false;
  100. result.message = "放弃转链";
  101. result.reason = "转链接口异常";
  102. }
  103. }
  104. _ = TkLogCore.TkActivityLogAsync(result);
  105. if (!result.success)
  106. {
  107. return new APIResult(new
  108. {
  109. result.success,
  110. result.message,
  111. result.reason,
  112. channel = result?.channel.ToString(),
  113. });
  114. }
  115. return new APIResult(new
  116. {
  117. result.success,
  118. result.message,
  119. channel = result?.channel.ToString(),
  120. result.deeplink_url,
  121. input_item_id = item_id,
  122. input_page_id = page_id,
  123. result.estimatedCommission,
  124. result.maxCommission,
  125. result.zkFinalPrice,
  126. result.reservePrice,
  127. result.title,
  128. result.picUrl,
  129. result.shortTitle,
  130. result.priceAfterCoupon,
  131. result.commissionRate,
  132. result.couponAmount,
  133. exposeTracks = $"https://api.molilian.com/tracks/track?track_id=11&unique_id={item_id}",
  134. clickTracks = $"https://api.molilian.com/tracks/track?track_id=12&unique_id={item_id}"
  135. });
  136. }
  137. }
  138. }