VeapiPlus.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using dodohold.core;
  2. namespace molilian.core
  3. {
  4. public partial class VeapiPlus
  5. {
  6. private string _accountName;
  7. private string _key;
  8. private string _sessionKey;
  9. public VeapiPlus(string accountName, string key, string sessionKey)
  10. {
  11. _accountName = accountName;
  12. _key = key;
  13. _sessionKey = sessionKey;
  14. }
  15. public TkDataDTO UnionParse(string content, ref TkDataDTO result)
  16. {
  17. string para = content.UrlEncode();
  18. string url = $"http://api.veapi.cn/tbk/hcapi?vekey={_key}&sessionkey={_sessionKey}&para={para}";
  19. var response = new WebClientUtility().Request(url);
  20. var body = response.Body();
  21. var root = body.Convert2JsonElement();
  22. int error = root.Read<int>("error", 0);
  23. bool success = error == 0;
  24. string message = root.Read("msg", string.Empty);
  25. string taoToken = root.PathRead("data.ios_tbk_pwd", string.Empty);
  26. string num_iid = root.PathRead("data.num_iid", string.Empty);
  27. decimal couponAmount = root.PathRead<decimal>("data.coupon_amount", 0);
  28. string shortLinkurl = root.PathRead("data.coupon_short_url", string.Empty);
  29. string shortLink = AlimamaPlus.GetLink(taoToken);
  30. content = AlimamaPlus.ReplaceUrls(content, shortLink);
  31. if (!success)
  32. {
  33. shortLinkurl = AlimamaPlus.GetLink(content);
  34. }
  35. string deeplink_url = AlimamaPlus.GetDeeplink(shortLinkurl);
  36. result.channel = TkChannelEnum.tb;
  37. result.accountName = _accountName;
  38. result.success = success;
  39. result.message = message;
  40. result.content = content;
  41. result.couponAmount = couponAmount;
  42. result.taoToken = taoToken;
  43. result.shortLinkurl = shortLinkurl;
  44. result.deeplink_url = deeplink_url;
  45. result.num_iid = num_iid;
  46. return result;
  47. }
  48. public PromotionQueryDTO picSimilaritem(string pic, ref PromotionQueryDTO result)
  49. {
  50. string url = $"http://api.veapi.cn/tbk/picsimilaritem";
  51. string base64 = $"data:image/jpeg;base64,{pic}";
  52. var client = new WebClientUtility();
  53. client.SetContentType("application/x-www-form-urlencoded");
  54. client.Post("vekey", _key);
  55. client.Post("pic", base64);
  56. var response = client.Request(url);
  57. var body = response.Body();
  58. var root = body.Convert2JsonElement();
  59. int error = root.Read<int>("error", 0);
  60. bool success = error == 0;
  61. string message = root.Read("msg", string.Empty);
  62. result.success = success;
  63. if (!success)
  64. {
  65. result.message = "调用失败";
  66. result.reason = message;
  67. return result;
  68. }
  69. List<PromotionQueryItemDTO> arr = [];
  70. var list = root.ElementRead("data");
  71. foreach (var e in list.EnumerateArray())
  72. {
  73. var item = e.ElementRead("Result");
  74. string itemId = item.Read<string>("ItemId", string.Empty);
  75. string h5_url = $"https://uland.taobao.com/item/edetail?id={itemId}";
  76. string deeplink_url = AlimamaPlus.GetDeeplink(h5_url);
  77. PromotionQueryItemDTO newItem = new PromotionQueryItemDTO();
  78. newItem.itemId = itemId;
  79. newItem.h5_url = h5_url;
  80. newItem.deeplink_url = deeplink_url;
  81. newItem.userType = item.Read<string>("UserType", string.Empty);
  82. newItem.shopTitle = item.Read<string>("ShopTitle", string.Empty);
  83. newItem.itemName = item.Read<string>("Title", string.Empty);
  84. newItem.pic = item.Read<string>("PicUrl", string.Empty);
  85. newItem.price = item.Read<string>("ReservePrice", string.Empty);
  86. newItem.promotionPrice = item.Read<string>("PriceAfterCoupon", string.Empty);
  87. newItem.couponAmount = item.Read<string>("CouponAmount", string.Empty);
  88. newItem.couponEffectiveStartTime = item.Read<string>("CouponStartTime", string.Empty);
  89. newItem.couponEffectiveEndTime = item.Read<string>("CouponEndTime", string.Empty);
  90. newItem.sellCountStr = item.Read<string>("sellCountStr", string.Empty);
  91. newItem.provcity = item.Read<string>("Provcity", string.Empty);
  92. arr.Add(newItem);
  93. }
  94. result.message = "OK";
  95. result.reason = string.Empty;
  96. result.PromotionImg = arr;
  97. //PromotionImg
  98. /*
  99. *
  100. public string h5_url { get; set; } = string.Empty;
  101. public string deeplink_url { get; set; } = string.Empty;
  102. /// <summary>
  103. /// 店铺信息-卖家类型:1天猫,0淘宝,3淘特
  104. /// </summary>
  105. public string userType { get; set; } = string.Empty;
  106. public string shopTitle { get; set; } = string.Empty;
  107. public string itemId { get; set; } = string.Empty;
  108. public string itemName { get; set; } = string.Empty;
  109. public string pic { get; set; } = string.Empty;
  110. public string price { get; set; } = string.Empty;
  111. public string promotionPrice { get; set; } = string.Empty;
  112. public string couponAmount { get; set; } = string.Empty;
  113. public string couponEffectiveStartTime { get; set; } = string.Empty;
  114. public string couponEffectiveEndTime { get; set; } = string.Empty;
  115. public string sellCountStr { get; set; } = string.Empty;
  116. public string provcity { get; set; } = string.Empty;
  117. {
  118. "error": "0",
  119. "msg": "查询成功",
  120. "data": [
  121. {
  122. "RankScore": "0.8065",
  123. "Result": {
  124. "CategoryName": "跑步鞋",
  125. "CommissionRate": "135",
  126. "CouponAmount": 50,
  127. "CouponEndTime": "2025-01-31",
  128. "CouponInfo": "满99.0元减50.0元",
  129. "CouponRemainCount": 99656,
  130. "CouponStartFee": "99.0",
  131. "CouponStartTime": "2024-12-24",
  132. "CouponTotalCount": "100000",
  133. "ItemId": "jOZk7gxcAfJZ6zGz8bFKjwSJte-Z9Z023UAg5djJmJSRp",
  134. "LevelOneCategoryName": "运动鞋new",
  135. "MaxCommission": {},
  136. "Nick": "",
  137. "PicUrl": "https://img.alicdn.com/i2/1994113638/O1CN015M0Aqf1ckFs5UI2eJ_!!0-item_pic.jpg",
  138. "PriceAfterCoupon": "109.00",
  139. "Provcity": "福建 泉州",
  140. "ReservePrice": "259.00",
  141. "SellerId": "1994113638",
  142. "ShopTitle": "361度户外旗舰店",
  143. "ShortTitle": "加绒保暖老爹鞋361女鞋运动鞋女",
  144. "SubTitle": "新款加绒女鞋运动鞋",
  145. "Title": "361女鞋运动鞋女2024冬季新款加绒保暖棉鞋轻便老爹鞋休闲跑步鞋",
  146. "UserType": 1,
  147. "Volume": 10,
  148. "ZkFinalPrice": "159"
  149. }
  150. }
  151. ]
  152. ],
  153. "request_id": "4eZfpBu"
  154. }
  155. */
  156. return result;
  157. }
  158. public async Task<TkDataDTO> UnionParseAsync(string content, TkDataDTO result, CancellationToken cancellationToken)
  159. {
  160. string para = content.UrlEncode();
  161. string url = $"http://api.veapi.cn/tbk/hcapi?vekey={_key}&sessionkey={_sessionKey}&para={para}";
  162. var response = await new WebClientUtility().RequestAsync(url, "GET", cancellationToken);
  163. var body = response.Body();
  164. var root = body.Convert2JsonElement();
  165. int error = root.Read<int>("error", 0);
  166. bool success = error == 0;
  167. string message = root.Read("msg", string.Empty);
  168. string taoToken = root.PathRead("data.ios_tbk_pwd", string.Empty);
  169. string num_iid = root.PathRead("data.num_iid", string.Empty);
  170. decimal couponAmount = root.PathRead<decimal>("data.coupon_amount", 0);
  171. string shortLinkurl = root.PathRead("data.coupon_short_url", string.Empty);
  172. string shortLink = AlimamaPlus.GetLink(taoToken);
  173. content = AlimamaPlus.ReplaceUrls(content, shortLink);
  174. if (!success)
  175. {
  176. shortLinkurl = AlimamaPlus.GetLink(content);
  177. }
  178. string deeplink_url = AlimamaPlus.GetDeeplink(shortLinkurl);
  179. result.channel = TkChannelEnum.tb;
  180. result.accountName = _accountName;
  181. result.success = success;
  182. result.message = message;
  183. result.content = content;
  184. result.couponAmount = couponAmount;
  185. result.taoToken = taoToken;
  186. result.shortLinkurl = shortLinkurl;
  187. result.deeplink_url = deeplink_url;
  188. result.num_iid = num_iid;
  189. return result;
  190. }
  191. }
  192. }