VeapiPlus.cs 9.0 KB

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