DataokePlus.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using dodohold.core;
  2. using Dataoke;
  3. using TencentCloud.Scf.V20180416.Models;
  4. using System.Text.RegularExpressions;
  5. using TencentCloud.Teo.V20220901.Models;
  6. namespace molilian.core
  7. {
  8. public class ParseUrlDTO
  9. {
  10. public string? skuId { get; set; }
  11. public string? itemUrl { get; set; }
  12. public string? hasCoupon { get; set; }
  13. public string? couponLink { get; set; }
  14. }
  15. public class GoodsDetailDTO
  16. {
  17. public int actualPrice { get; set; }
  18. public int cid1 { get; set; }
  19. public string cid1Name { get; set; }
  20. public int cid2 { get; set; }
  21. public string cid2Name { get; set; }
  22. public int cid3 { get; set; }
  23. public string cid3Name { get; set; }
  24. public int comments { get; set; }
  25. public double commission { get; set; }
  26. public string commissionEndTime { get; set; }
  27. public double commissionShare { get; set; }
  28. public string commissionStartTime { get; set; }
  29. public int couponAmount { get; set; }
  30. public string couponConditions { get; set; }
  31. public string couponEndTime { get; set; }
  32. public string couponLink { get; set; }
  33. public int couponReceiveCount { get; set; }
  34. public int couponRemainCount { get; set; }
  35. public string couponStartTime { get; set; }
  36. public int couponTotalCount { get; set; }
  37. public int couponType { get; set; }
  38. public string couponUseStartTime { get; set; }
  39. public string couponUserEndTime { get; set; }
  40. public string[] detailImages { get; set; }
  41. public string extensionContent { get; set; }
  42. public int goodsCommentShare { get; set; }
  43. public int inOrderCount30Days { get; set; }
  44. public int isFlagship { get; set; }
  45. public int isFreeFreightRisk { get; set; }
  46. public int isFreeShipping { get; set; }
  47. public int isOwner { get; set; }
  48. public int isSeckill { get; set; }
  49. public string itemId { get; set; }
  50. public int lowest { get; set; }
  51. public string materialUrl { get; set; }
  52. public int originPrice { get; set; }
  53. public string picMain { get; set; }
  54. public double plusCommissionShare { get; set; }
  55. public string productIntro { get; set; }
  56. public object promotionLabelList { get; set; }
  57. public int shopId { get; set; }
  58. public string shopName { get; set; }
  59. public long skuId { get; set; }
  60. public string skuName { get; set; }
  61. public string[] smallImages { get; set; }
  62. public object[] videoUrlList { get; set; }
  63. }
  64. public partial class DataokePlus
  65. {
  66. string _app_key = string.Empty;
  67. string _app_secret = string.Empty;
  68. public DataokePlus(string app_key, string app_secret)
  69. {
  70. _app_key = app_key;
  71. _app_secret = app_secret;
  72. }
  73. public string JDParse(string unionId, string materialId)
  74. {
  75. string version = "v1.0.0";
  76. string api = "https://openapi.dataoke.com/api/dels/jd/kit/promotion-union-convert";
  77. DtkApp app = new(_app_key, _app_secret);
  78. ApiParameters apiParameters = new();
  79. apiParameters.Add("unionId", unionId);
  80. apiParameters.Add("materialId", materialId);
  81. var log = new LoggerLibrary("dataoke", "promotion-union-convert").Info(unionId, materialId);
  82. string body = app.Get(api, version, apiParameters);
  83. log.Info(body).Save();
  84. //var root = body.Convert2JsonElement();
  85. return body;
  86. }
  87. public GoodsDetailDTO? GetDetails(params string[] skuIds)
  88. {
  89. GoodsDetailDTO? result = null;
  90. try
  91. {
  92. string version = "v1.0.0";
  93. string api = "https://openapi.dataoke.com/api/dels/jd/goods/get-details";
  94. DtkApp app = new(_app_key, _app_secret);
  95. ApiParameters apiParameters = new();
  96. apiParameters.Add("skuIds", string.Join(',', skuIds));
  97. var log = new LoggerLibrary("dataoke", "parseUrl").Info(string.Join(',', skuIds));
  98. string body = app.Get(api, version, apiParameters);
  99. log.Info(body).Save();
  100. var root = body.Convert2JsonElement();
  101. int code = root.Read<int>("code", -1);
  102. if (code == 0)
  103. {
  104. var _goods = root.ElementRead("data")[0].Convert2Json();
  105. result = _goods.Convert2Object<GoodsDetailDTO>();
  106. }
  107. }
  108. catch (Exception e) { }
  109. return result;
  110. }
  111. public GoodsDetailDTO? GetGoods(string url)
  112. {
  113. ParseUrlDTO? sku_info = ParseUrl(url);
  114. if (sku_info == null) { return null; }
  115. GoodsDetailDTO? result = GetDetails(sku_info.skuId);
  116. return result;
  117. }
  118. public ParseUrlDTO? ParseUrl(string url)
  119. {
  120. ParseUrlDTO? result = null;
  121. try
  122. {
  123. string version = "v1.0.0";
  124. string api = "https://openapi.dataoke.com/api/dels/jd/kit/parseUrl";
  125. DtkApp app = new(_app_key, _app_secret);
  126. ApiParameters apiParameters = new();
  127. apiParameters.Add("url", url);
  128. var log = new LoggerLibrary("dataoke", "parseUrl").Info(url);
  129. string body = app.Get(api, version, apiParameters);
  130. log.Info(body).Save();
  131. var root = body.Convert2JsonElement();
  132. int code = root.Read<int>("code", -1);
  133. if (code == 0)
  134. {
  135. result = new ParseUrlDTO
  136. {
  137. skuId = root.PathRead("data.skuId", string.Empty),
  138. itemUrl = root.PathRead("data.itemUrl", string.Empty),
  139. hasCoupon = root.PathRead("data.hasCoupon", string.Empty),
  140. couponLink = root.PathRead("data.couponLink", string.Empty)
  141. };
  142. }
  143. }
  144. catch (Exception e) { }
  145. return result;
  146. }
  147. }
  148. }