aliyun.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using dodohold.core;
  2. using Microsoft.AspNetCore.Mvc;
  3. using StackExchange.Redis;
  4. using System.Diagnostics;
  5. using System.Text.Json;
  6. using TencentCloud.Tcm.V20210413.Models;
  7. namespace molilian.core
  8. {
  9. public partial class AlimamaPlus
  10. {
  11. public async Task<TkDataDTO> endpoint_aliyun(string content, TkDataDTO result, CancellationToken cancellationToken = default)
  12. {
  13. if (content.Contains("霸下通用 web 页面-验证码"))
  14. {
  15. _ = new LoggerLibrary("endpoint", "aliyun")
  16. .Info("霸下通用 web 页面-验证码")
  17. .SaveAsync();
  18. result.channel = TkChannelEnum.tb;
  19. result.link_type = LinkTypeEnum.unknown;
  20. result.success = false;
  21. result.message = "放弃转链";
  22. result.reason = "霸下风控";
  23. return result;
  24. }
  25. string item_id = content.GetContentPart("item.htm?id=", "");
  26. if (string.IsNullOrEmpty(item_id))
  27. {
  28. _ = new LoggerLibrary("endpoint", "aliyun")
  29. .Info(content, "response null")
  30. .SaveAsync();
  31. result.channel = TkChannelEnum.tb;
  32. result.link_type = LinkTypeEnum.unknown;
  33. result.success = false;
  34. result.message = "放弃转链";
  35. result.reason = "无效商品id";
  36. return result;
  37. }
  38. var plus = new AliyunPlus(_account.appkey, _account.appSecret);
  39. var response = await plus.GetProductInfoByIds(item_id, _account.open_pid);
  40. if (response == null)
  41. {
  42. _ = new LoggerLibrary("endpoint", "aliyun")
  43. .Info(content, "response null")
  44. .SaveAsync();
  45. result.channel = TkChannelEnum.tb;
  46. result.link_type = LinkTypeEnum.unknown;
  47. result.success = false;
  48. result.message = "fail";
  49. result.reason = "接口异常";
  50. return result;
  51. }
  52. result.success = (bool)response.Body.Success;
  53. if (!result.success)
  54. {
  55. result.message = "fail";
  56. result.reason = $"{response.Body.Code}:{response.Body.Message}";
  57. _ = new LoggerLibrary("endpoint", "aliyun")
  58. .Info(content, result.reason)
  59. .SaveAsync();
  60. result.channel = TkChannelEnum.tb;
  61. result.link_type = LinkTypeEnum.unknown;
  62. result.success = false;
  63. return result;
  64. }
  65. if (response.Body.Data.Auctions.Count == 0)
  66. {
  67. _ = new LoggerLibrary("endpoint", "aliyun")
  68. .Info(content, "response null")
  69. .SaveAsync();
  70. result.channel = TkChannelEnum.tb;
  71. result.link_type = LinkTypeEnum.unknown;
  72. result.success = false;
  73. result.message = "result empty";
  74. result.reason = string.Empty;
  75. result.subCode = TkSubCodeEnum.NoConvert;
  76. return result;
  77. }
  78. var data = response.Body.Data.Auctions[0].Result;
  79. result.itemId = data.InputItemId;
  80. result.couponAmount = (decimal)data.CouponAmount;
  81. result.couponEffectiveStartTime = data.CouponStartTime;
  82. result.couponEffectiveEndTime = data.CouponEndTime;
  83. result.taoToken = string.Empty;
  84. string url = data.Url;
  85. if (url.StartsWith("//")) url = $"https:{url}";
  86. result.shortLinkurl = url;
  87. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  88. result.item_url = url;
  89. result.item_deeplink_url = result.deeplink_url;
  90. string couponShareUrl = data.CouponShareUrl;
  91. if (_account.useCouponLinkFirst && !string.IsNullOrEmpty(couponShareUrl))
  92. {
  93. if (couponShareUrl.StartsWith("//")) couponShareUrl = $"https:{couponShareUrl}";
  94. result.shortLinkurl = couponShareUrl;
  95. result.deeplink_url = GetDeeplink(couponShareUrl);
  96. }
  97. result.mktId = data.ItemId;
  98. result.itemName = data.Title;
  99. if (decimal.TryParse(data.PriceAfterCoupon, out decimal promotionPrice))
  100. {
  101. result.promotionPrice = promotionPrice;
  102. }
  103. if (decimal.TryParse(data.ReservePrice, out decimal reservePrice))
  104. {
  105. result.reservePrice = reservePrice;
  106. }
  107. if (decimal.TryParse(data.ZkFinalPrice, out decimal zkFinalPrice))
  108. {
  109. result.zkFinalPrice = zkFinalPrice;
  110. }
  111. result.sellerNickName = data.Nick;
  112. result.shopTitle = data.ShopTitle;
  113. string picUrl = data.PicUrl;
  114. if (picUrl.StartsWith("//")) picUrl = $"https:{picUrl}";
  115. result.pic = picUrl;
  116. return result;
  117. }
  118. }
  119. }