DataokePlus.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. using static dodohold.core.ZTOExpress.CreateOrderArgs;
  7. using System.Xml.Linq;
  8. namespace molilian.core
  9. {
  10. public class ParseUrlDTO
  11. {
  12. public string? skuId { get; set; }
  13. public string? itemUrl { get; set; }
  14. public string? hasCoupon { get; set; }
  15. public string? couponLink { get; set; }
  16. }
  17. public class GoodsDetailDTO
  18. {
  19. public decimal actualPrice { get; set; }
  20. public int cid1 { get; set; }
  21. public string cid1Name { get; set; }
  22. public int cid2 { get; set; }
  23. public string cid2Name { get; set; }
  24. public int cid3 { get; set; }
  25. public string cid3Name { get; set; }
  26. public int comments { get; set; }
  27. public decimal commission { get; set; }
  28. public string commissionEndTime { get; set; }
  29. public decimal commissionShare { get; set; }
  30. public string commissionStartTime { get; set; }
  31. public decimal couponAmount { get; set; }
  32. public string couponConditions { get; set; }
  33. public string couponEndTime { get; set; }
  34. public string couponLink { get; set; }
  35. public int couponReceiveCount { get; set; }
  36. public int couponRemainCount { get; set; }
  37. public string couponStartTime { get; set; }
  38. public int couponTotalCount { get; set; }
  39. public int couponType { get; set; }
  40. public string couponUseStartTime { get; set; }
  41. public string couponUserEndTime { get; set; }
  42. public string[] detailImages { get; set; }
  43. public string extensionContent { get; set; }
  44. public int goodsCommentShare { get; set; }
  45. public int inOrderCount30Days { get; set; }
  46. public int isFlagship { get; set; }
  47. public int isFreeFreightRisk { get; set; }
  48. public int isFreeShipping { get; set; }
  49. public int isOwner { get; set; }
  50. public int isSeckill { get; set; }
  51. public string itemId { get; set; }
  52. public int lowest { get; set; }
  53. public string materialUrl { get; set; }
  54. public decimal originPrice { get; set; }
  55. public string picMain { get; set; }
  56. public decimal plusCommissionShare { get; set; }
  57. public string productIntro { get; set; }
  58. public int shopId { get; set; }
  59. public string shopName { get; set; }
  60. public long skuId { get; set; }
  61. public string skuName { get; set; }
  62. public string[] smallImages { 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, string couponUrl = null)
  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. if (!string.IsNullOrEmpty(couponUrl)) apiParameters.Add("couponUrl", couponUrl);
  82. var log = new LoggerLibrary("dataoke", "promotion-union-convert").Info(unionId, materialId);
  83. string body = app.Get(api, version, apiParameters);
  84. log.Info(body).Save();
  85. //var root = body.Convert2JsonElement();
  86. return body;
  87. }
  88. public GoodsDetailDTO? GetDetails(params string[] skuIds)
  89. {
  90. GoodsDetailDTO? result = null;
  91. string body = string.Empty;
  92. try
  93. {
  94. string version = "v1.0.0";
  95. string api = "https://openapi.dataoke.com/api/dels/jd/goods/get-details";
  96. DtkApp app = new(_app_key, _app_secret);
  97. ApiParameters apiParameters = new();
  98. apiParameters.Add("skuIds", string.Join(',', skuIds));
  99. var log = new LoggerLibrary("dataoke", "details").Info(string.Join(',', skuIds));
  100. body = app.Get(api, version, apiParameters);
  101. log.Info(body).Save();
  102. var root = body.Convert2JsonElement();
  103. int code = root.Read<int>("code", -1);
  104. if (code == 0)
  105. {
  106. var _goods = root.ElementRead("data")[0].GetRawText();
  107. result = _goods.Convert2Object<GoodsDetailDTO>();
  108. }
  109. }
  110. catch (Exception ex)
  111. {
  112. new LoggerLibrary("dtk_error", "fail")
  113. .Info(string.Join(',', skuIds), body)
  114. .Info(ex.Message, ex.StackTrace)
  115. .Save();
  116. NotifyCore.Notify(new NifyMessage
  117. {
  118. message = $"【大淘客异常】\n\n{ex.Message}\n{ex.StackTrace}",
  119. priority = NifyMessagePriority.high,
  120. tags = ["red_circle"]
  121. });
  122. }
  123. return result;
  124. }
  125. public GoodsDetailDTO? GetGoods(string url)
  126. {
  127. ParseUrlDTO? sku_info = ParseUrl(url);
  128. if (sku_info == null) { return null; }
  129. GoodsDetailDTO? result = GetDetails(sku_info.skuId);
  130. return result;
  131. }
  132. public ParseUrlDTO? ParseUrl(string url)
  133. {
  134. ParseUrlDTO? result = null;
  135. try
  136. {
  137. string version = "v1.0.0";
  138. string api = "https://openapi.dataoke.com/api/dels/jd/kit/parseUrl";
  139. DtkApp app = new(_app_key, _app_secret);
  140. ApiParameters apiParameters = new();
  141. apiParameters.Add("url", url);
  142. var log = new LoggerLibrary("dataoke", "parseUrl").Info(url);
  143. string body = app.Get(api, version, apiParameters);
  144. log.Info(body).Save();
  145. var root = body.Convert2JsonElement();
  146. int code = root.Read<int>("code", -1);
  147. if (code == 0)
  148. {
  149. result = new ParseUrlDTO
  150. {
  151. skuId = root.PathRead("data.skuId", string.Empty),
  152. itemUrl = root.PathRead("data.itemUrl", string.Empty),
  153. hasCoupon = root.PathRead("data.hasCoupon", string.Empty),
  154. couponLink = root.PathRead("data.couponLink", string.Empty)
  155. };
  156. }
  157. }
  158. catch (Exception e) { }
  159. return result;
  160. }
  161. }
  162. }