aliyun.cs 3.7 KB

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