aliyun.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. string item_id = content.GetContentPart("item.htm?id=", "");
  14. if (string.IsNullOrEmpty(item_id))
  15. {
  16. _ = new LoggerLibrary("endpoint", "aliyun")
  17. .Info(content, "response null")
  18. .SaveAsync();
  19. result.channel = TkChannelEnum.tb;
  20. result.link_type = LinkTypeEnum.unknown;
  21. result.success = false;
  22. result.message = "放弃转链";
  23. result.reason = "无效商品id";
  24. return result;
  25. }
  26. var plus = new AliyunPlus(_account.appkey, _account.appSecret);
  27. var response = await plus.GetProductInfoByIds(item_id, _account.open_pid);
  28. if (response == null)
  29. {
  30. _ = new LoggerLibrary("endpoint", "aliyun")
  31. .Info(content, "response null")
  32. .SaveAsync();
  33. result.channel = TkChannelEnum.tb;
  34. result.link_type = LinkTypeEnum.unknown;
  35. result.success = false;
  36. result.message = "fail";
  37. result.reason = "接口异常";
  38. return result;
  39. }
  40. result.success = (bool)response.Body.Success;
  41. if (!result.success)
  42. {
  43. result.message = "fail";
  44. result.reason = $"{response.Body.Code}:{response.Body.Message}";
  45. _ = new LoggerLibrary("endpoint", "aliyun")
  46. .Info(content, result.reason)
  47. .SaveAsync();
  48. result.channel = TkChannelEnum.tb;
  49. result.link_type = LinkTypeEnum.unknown;
  50. result.success = false;
  51. return result;
  52. }
  53. if (response.Body.Data.Auctions.Count == 0)
  54. {
  55. _ = new LoggerLibrary("endpoint", "aliyun")
  56. .Info(content, "response null")
  57. .SaveAsync();
  58. result.channel = TkChannelEnum.tb;
  59. result.link_type = LinkTypeEnum.unknown;
  60. result.success = false;
  61. result.message = "result empty";
  62. result.reason = string.Empty;
  63. result.subCode = TkSubCodeEnum.NoConvert;
  64. return result;
  65. }
  66. var data = response.Body.Data.Auctions[0].Result;
  67. result.itemId = data.InputItemId;
  68. result.couponAmount = (decimal)data.CouponAmount;
  69. result.couponEffectiveStartTime = data.CouponStartTime;
  70. result.couponEffectiveEndTime = data.CouponEndTime;
  71. result.taoToken = string.Empty;
  72. string url = data.Url;
  73. if (url.StartsWith("//")) url = $"https:{url}";
  74. result.shortLinkurl = url;
  75. result.deeplink_url = GetDeeplink(result.shortLinkurl);
  76. result.item_url = url;
  77. result.item_deeplink_url = result.deeplink_url;
  78. string couponShareUrl = data.CouponShareUrl;
  79. if (_account.useCouponLinkFirst && !string.IsNullOrEmpty(couponShareUrl))
  80. {
  81. if (couponShareUrl.StartsWith("//")) couponShareUrl = $"https:{couponShareUrl}";
  82. result.shortLinkurl = couponShareUrl;
  83. result.deeplink_url = GetDeeplink(couponShareUrl);
  84. }
  85. result.mktId = data.ItemId;
  86. result.itemName = data.Title;
  87. if (decimal.TryParse(data.PriceAfterCoupon, out decimal promotionPrice))
  88. {
  89. result.promotionPrice = promotionPrice;
  90. }
  91. result.sellerNickName = data.Nick;
  92. result.shopTitle = data.ShopTitle;
  93. string picUrl = data.PicUrl;
  94. if (picUrl.StartsWith("//")) picUrl = $"https:{picUrl}";
  95. result.pic = picUrl;
  96. return result;
  97. }
  98. }
  99. }