tkActivity.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. Topsdk.Top.Defaultability.Domain.TaobaoTbkDgGeneralLinkConvertEventUrlList urlList = response?.Data?.EventUrlList?[0];
  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. string cps_short_url = urlList?.LinkInfoDto?.CpsShortUrl;
  37. if (result.success && urlList != null && urlList.Code == null)
  38. {
  39. result.deeplink_url = GetDeeplink(cps_short_url);
  40. //todo 补充其他基础信息
  41. result = await aliyun_same(result.raw_item_id, result, cancellationToken);
  42. //if (data.couponAmount == 0)
  43. //{
  44. // result.success = false;
  45. // result.message = "没有优惠券";
  46. // result.reason = "";
  47. // result.deeplink_url = string.Empty;
  48. //}
  49. //else
  50. //{
  51. // result.deeplink_url = data.deeplink_url;
  52. // result.couponAmount = data.couponAmount;
  53. // //result.couponEffectiveStartTime = data.couponEffectiveStartTime;
  54. // //result.couponEffectiveEndTime = data.couponEffectiveEndTime;
  55. // //result.itemId = data.itemId;
  56. // //result.pic = data.pic;
  57. //}
  58. }
  59. return result;
  60. }
  61. public async Task<TkActivityDTO> aliyun_same(string item_id, TkActivityDTO result, CancellationToken cancellationToken = default)
  62. {
  63. if (string.IsNullOrEmpty(item_id))
  64. {
  65. _ = new LoggerLibrary("endpoint", "aliyun")
  66. .Info(item_id, "response null")
  67. .SaveAsync();
  68. result.channel = TkChannelEnum.tb;
  69. result.success = false;
  70. result.message = "放弃转链";
  71. result.reason = "无效商品id";
  72. return result;
  73. }
  74. var plus = new AliyunPlus(_account.appkey2, _account.appSecret2);
  75. var response = await plus.GetProductInfoByIds(item_id, _account.open_pid2);
  76. if (response == null)
  77. {
  78. _ = new LoggerLibrary("endpoint", "aliyun")
  79. .Info(item_id, "response null")
  80. .SaveAsync();
  81. result.channel = TkChannelEnum.tb;
  82. result.success = false;
  83. result.message = "fail";
  84. result.reason = "接口异常";
  85. return result;
  86. }
  87. result.success = (bool)response.Body.Success;
  88. if (!result.success)
  89. {
  90. result.message = "fail";
  91. result.reason = $"{response.Body.Code}:{response.Body.Message}";
  92. _ = new LoggerLibrary("endpoint", "aliyun")
  93. .Info(item_id, result.reason)
  94. .SaveAsync();
  95. result.channel = TkChannelEnum.tb;
  96. result.success = false;
  97. return result;
  98. }
  99. if (response.Body.Data.Auctions.Count == 0)
  100. {
  101. _ = new LoggerLibrary("endpoint", "aliyun")
  102. .Info(item_id, "response null")
  103. .SaveAsync();
  104. result.channel = TkChannelEnum.tb;
  105. result.success = false;
  106. result.message = "result empty";
  107. result.reason = string.Empty;
  108. return result;
  109. }
  110. var data = response.Body.Data.Auctions[0].Result;
  111. result.maxCommission = decimal.TryParse(data.MaxCommission?.MaxCommissionRate?.ToString(), out var maxCommission) ? maxCommission : 0;
  112. result.zkFinalPrice = decimal.TryParse(data.ZkFinalPrice?.ToString(), out var zkFinalPrice) ? zkFinalPrice : 0;
  113. result.reservePrice = decimal.TryParse(data.ReservePrice?.ToString(), out var reservePrice) ? reservePrice : 0;
  114. result.title = data.Title?.ToString() ?? string.Empty;
  115. string picUrl = data.PicUrl?.ToString();
  116. if (!string.IsNullOrEmpty(picUrl) && picUrl.StartsWith("//")) picUrl = $"https:{picUrl}";
  117. result.picUrl = result.picUrl;
  118. result.shortTitle = data.ShortTitle?.ToString() ?? string.Empty;
  119. result.priceAfterCoupon = decimal.TryParse(data.PriceAfterCoupon?.ToString(), out var priceAfterCoupon) ? priceAfterCoupon : 0;
  120. result.commissionRate = decimal.TryParse(data.CommissionRate?.ToString(), out var commissionRate) ? commissionRate : 0;
  121. result.couponAmount = decimal.TryParse(data.CouponAmount?.ToString(), out var couponAmount) ? couponAmount : 0;
  122. result.estimatedCommission = result.priceAfterCoupon * result.commissionRate * 0.0001m;
  123. return result;
  124. }
  125. }
  126. }