tkActivity.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. using System.Text;
  2. using dodohold.core;
  3. using System.Text.RegularExpressions;
  4. using System.Net;
  5. using System.Security.Cryptography;
  6. using TencentCloud.Ecm.V20190719.Models;
  7. namespace molilian.core
  8. {
  9. public partial class AlimamaPlus
  10. {
  11. public async Task<TkActivityDTO> TkActivityAsync(TkActivityDTO result, CancellationToken cancellationToken = default)
  12. {
  13. TkDataDTO data = new();
  14. //format=json&sign_method=md5&adzone_id=116102700359&target_item=%7B%22item_id_list%22%3A+%5B%22top%3ApJZdQkbf2C6Zrxn0KxT5aAIptm-kPVnNrKI8PQmnQxXFk2%22%5D%7D&page_id_list=20150318020016140
  15. var plus = new AliyunPlus(_account.appkey, _account.appSecret);
  16. long.TryParse(_account.open_pid.Split('_')[^1], out long adzone);
  17. var response = await plus.TaobaoTbkDgGeneralLinkConvert(adzone, result.page_id, [result.item_id]);
  18. if (response == null)
  19. {
  20. _ = new LoggerLibrary("endpoint", "aliyun")
  21. .Info(result.item_id, result.page_id)
  22. .Info("response null")
  23. .SaveAsync();
  24. result.channel = TkChannelEnum.tb;
  25. result.success = false;
  26. result.message = "fail";
  27. result.reason = "接口异常";
  28. return result;
  29. }
  30. string cps_short_url = response?.Data?.EventUrlList?[0]?.LinkInfoDto?.CpsShortUrl;
  31. //-----
  32. result.channel = data.channel;
  33. result.success = data.success;
  34. result.reason = data.reason;
  35. result.message = data.success ? "OK" : data.message;
  36. if (result.success)
  37. {
  38. result.deeplink_url = GetDeeplink(cps_short_url);
  39. //todo 补充其他基础信息
  40. result = await aliyun_same(result.raw_item_id, result, cancellationToken);
  41. //if (data.couponAmount == 0)
  42. //{
  43. // result.success = false;
  44. // result.message = "没有优惠券";
  45. // result.reason = "";
  46. // result.deeplink_url = string.Empty;
  47. //}
  48. //else
  49. //{
  50. // result.deeplink_url = data.deeplink_url;
  51. // result.couponAmount = data.couponAmount;
  52. // //result.couponEffectiveStartTime = data.couponEffectiveStartTime;
  53. // //result.couponEffectiveEndTime = data.couponEffectiveEndTime;
  54. // //result.itemId = data.itemId;
  55. // //result.pic = data.pic;
  56. //}
  57. }
  58. return result;
  59. }
  60. public async Task<TkActivityDTO> aliyun_same(string item_id, TkActivityDTO result, CancellationToken cancellationToken = default)
  61. {
  62. if (string.IsNullOrEmpty(item_id))
  63. {
  64. _ = new LoggerLibrary("endpoint", "aliyun")
  65. .Info(item_id, "response null")
  66. .SaveAsync();
  67. result.channel = TkChannelEnum.tb;
  68. result.success = false;
  69. result.message = "放弃转链";
  70. result.reason = "无效商品id";
  71. return result;
  72. }
  73. var plus = new AliyunPlus(_account.appkey2, _account.appSecret2);
  74. var response = await plus.GetProductInfoByIds(item_id, _account.open_pid2);
  75. if (response == null)
  76. {
  77. _ = new LoggerLibrary("endpoint", "aliyun")
  78. .Info(item_id, "response null")
  79. .SaveAsync();
  80. result.channel = TkChannelEnum.tb;
  81. result.success = false;
  82. result.message = "fail";
  83. result.reason = "接口异常";
  84. return result;
  85. }
  86. result.success = (bool)response.Body.Success;
  87. if (!result.success)
  88. {
  89. result.message = "fail";
  90. result.reason = $"{response.Body.Code}:{response.Body.Message}";
  91. _ = new LoggerLibrary("endpoint", "aliyun")
  92. .Info(item_id, result.reason)
  93. .SaveAsync();
  94. result.channel = TkChannelEnum.tb;
  95. result.success = false;
  96. return result;
  97. }
  98. if (response.Body.Data.Auctions.Count == 0)
  99. {
  100. _ = new LoggerLibrary("endpoint", "aliyun")
  101. .Info(item_id, "response null")
  102. .SaveAsync();
  103. result.channel = TkChannelEnum.tb;
  104. result.success = false;
  105. result.message = "result empty";
  106. result.reason = string.Empty;
  107. return result;
  108. }
  109. var data = response.Body.Data.Auctions[0].Result;
  110. result.maxCommission = decimal.TryParse(data.MaxCommission?.MaxCommissionRate?.ToString(), out var maxCommission) ? maxCommission : 0;
  111. result.zkFinalPrice = decimal.TryParse(data.ZkFinalPrice?.ToString(), out var zkFinalPrice) ? zkFinalPrice : 0;
  112. result.reservePrice = decimal.TryParse(data.ReservePrice?.ToString(), out var reservePrice) ? reservePrice : 0;
  113. result.title = data.Title?.ToString() ?? string.Empty;
  114. string picUrl = data.PicUrl?.ToString();
  115. if (!string.IsNullOrEmpty(picUrl) && picUrl.StartsWith("//")) picUrl = $"https:{picUrl}";
  116. result.picUrl = result.picUrl;
  117. result.shortTitle = data.ShortTitle?.ToString() ?? string.Empty;
  118. result.priceAfterCoupon = decimal.TryParse(data.PriceAfterCoupon?.ToString(), out var priceAfterCoupon) ? priceAfterCoupon : 0;
  119. result.commissionRate = decimal.TryParse(data.CommissionRate?.ToString(), out var commissionRate) ? commissionRate : 0;
  120. result.couponAmount = decimal.TryParse(data.CouponAmount?.ToString(), out var couponAmount) ? couponAmount : 0;
  121. result.estimatedCommission = result.priceAfterCoupon * result.commissionRate * 0.0001m;
  122. return result;
  123. }
  124. }
  125. }