OtherApiPlus.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. using dodohold.core;
  2. using Org.BouncyCastle.Ocsp;
  3. using System.Text.RegularExpressions;
  4. namespace molilian.core
  5. {
  6. public partial class OtherApiPlus
  7. {
  8. private string _accountName;
  9. private string _key;
  10. private string _sessionKey;
  11. private string _style;
  12. private string _api_url;
  13. public OtherApiPlus(string accountName, string key, string sessionKey, string style, string api_url)
  14. {
  15. _accountName = accountName;
  16. _key = key;
  17. _sessionKey = sessionKey;
  18. _style = style;
  19. _api_url = api_url;
  20. }
  21. public TkDataDTO UnionParse(string content, ref TkDataDTO result)
  22. {
  23. string para = content.UrlEncode();
  24. string url = $"http://api.veapi.cn/tbk/hcapi?vekey={_key}&sessionkey={_sessionKey}&para={para}";
  25. var response = new WebClientUtility().Request(url);
  26. var body = response.Body();
  27. var root = body.Convert2JsonElement();
  28. int error = root.Read<int>("error", 0);
  29. bool success = error == 0;
  30. string message = root.Read("msg", string.Empty);
  31. string taoToken = root.PathRead("data.ios_tbk_pwd", string.Empty);
  32. string num_iid = root.PathRead("data.num_iid", string.Empty);
  33. decimal couponAmount = root.PathRead<decimal>("data.coupon_amount", 0);
  34. string shortLinkurl = root.PathRead("data.coupon_short_url", string.Empty);
  35. string shortLink = AlimamaPlus.GetLink(taoToken);
  36. content = AlimamaPlus.ReplaceUrls(content, shortLink);
  37. if (!success)
  38. {
  39. shortLinkurl = AlimamaPlus.GetLink(content);
  40. }
  41. string deeplink_url = AlimamaPlus.GetDeeplink(shortLinkurl);
  42. result.channel = TkChannelEnum.tb;
  43. result.accountName = _accountName;
  44. result.success = success;
  45. result.message = message;
  46. result.content = content;
  47. result.couponAmount = couponAmount;
  48. result.taoToken = taoToken;
  49. result.shortLinkurl = shortLinkurl;
  50. result.deeplink_url = deeplink_url;
  51. result.num_iid = num_iid;
  52. return result;
  53. }
  54. public PromotionQueryDTO picSimilaritem(string pic, ref PromotionQueryDTO result)
  55. {
  56. string url = $"http://api.veapi.cn/tbk/picsimilaritem";
  57. string base64 = $"data:image/jpeg;base64,{pic}";
  58. var client = new WebClientUtility();
  59. client.SetContentType("application/x-www-form-urlencoded");
  60. client.Post("vekey", _key);
  61. client.Post("pic", base64);
  62. var response = client.Request(url);
  63. var body = response.Body();
  64. var root = body.Convert2JsonElement();
  65. int error = root.Read<int>("error", 0);
  66. bool success = error == 0;
  67. string message = root.Read("msg", string.Empty);
  68. result.success = success;
  69. if (!success)
  70. {
  71. result.message = "调用失败";
  72. result.reason = message;
  73. return result;
  74. }
  75. List<PromotionQueryItemDTO> arr = [];
  76. var list = root.ElementRead("data");
  77. foreach (var e in list.EnumerateArray())
  78. {
  79. var item = e.ElementRead("Result");
  80. string itemId = item.Read<string>("ItemId", string.Empty);
  81. string h5_url = $"https://uland.taobao.com/item/edetail?id={itemId}";
  82. string deeplink_url = AlimamaPlus.GetDeeplink(h5_url);
  83. PromotionQueryItemDTO newItem = new PromotionQueryItemDTO();
  84. newItem.itemId = itemId;
  85. newItem.h5_url = h5_url;
  86. newItem.deeplink_url = deeplink_url;
  87. newItem.userType = item.Read<string>("UserType", string.Empty);
  88. newItem.shopTitle = item.Read<string>("ShopTitle", string.Empty);
  89. newItem.itemName = item.Read<string>("Title", string.Empty);
  90. newItem.pic = item.Read<string>("PicUrl", string.Empty);
  91. newItem.price = item.Read<string>("ReservePrice", string.Empty);
  92. newItem.promotionPrice = item.Read<string>("PriceAfterCoupon", string.Empty);
  93. newItem.couponAmount = item.Read<string>("CouponAmount", string.Empty);
  94. newItem.couponEffectiveStartTime = item.Read<string>("CouponStartTime", string.Empty);
  95. newItem.couponEffectiveEndTime = item.Read<string>("CouponEndTime", string.Empty);
  96. newItem.sellCountStr = item.Read<string>("sellCountStr", string.Empty);
  97. newItem.provcity = item.Read<string>("Provcity", string.Empty);
  98. newItem.exposeTracks = $"https://api.molilian.com/tracks/track?track_id=7&unique_id={itemId}";
  99. newItem.clickTracks = $"https://api.molilian.com/tracks/track?track_id=8&unique_id={itemId}";
  100. arr.Add(newItem);
  101. }
  102. result.message = "OK";
  103. result.reason = string.Empty;
  104. result.PromotionImg = arr;
  105. //PromotionImg
  106. /*
  107. *
  108. public string h5_url { get; set; } = string.Empty;
  109. public string deeplink_url { get; set; } = string.Empty;
  110. /// <summary>
  111. /// 店铺信息-卖家类型:1天猫,0淘宝,3淘特
  112. /// </summary>
  113. public string userType { get; set; } = string.Empty;
  114. public string shopTitle { get; set; } = string.Empty;
  115. public string itemId { get; set; } = string.Empty;
  116. public string itemName { get; set; } = string.Empty;
  117. public string pic { get; set; } = string.Empty;
  118. public string price { get; set; } = string.Empty;
  119. public string promotionPrice { get; set; } = string.Empty;
  120. public string couponAmount { get; set; } = string.Empty;
  121. public string couponEffectiveStartTime { get; set; } = string.Empty;
  122. public string couponEffectiveEndTime { get; set; } = string.Empty;
  123. public string sellCountStr { get; set; } = string.Empty;
  124. public string provcity { get; set; } = string.Empty;
  125. {
  126. "error": "0",
  127. "msg": "查询成功",
  128. "data": [
  129. {
  130. "RankScore": "0.8065",
  131. "Result": {
  132. "CategoryName": "跑步鞋",
  133. "CommissionRate": "135",
  134. "CouponAmount": 50,
  135. "CouponEndTime": "2025-01-31",
  136. "CouponInfo": "满99.0元减50.0元",
  137. "CouponRemainCount": 99656,
  138. "CouponStartFee": "99.0",
  139. "CouponStartTime": "2024-12-24",
  140. "CouponTotalCount": "100000",
  141. "ItemId": "jOZk7gxcAfJZ6zGz8bFKjwSJte-Z9Z023UAg5djJmJSRp",
  142. "LevelOneCategoryName": "运动鞋new",
  143. "MaxCommission": {},
  144. "Nick": "",
  145. "PicUrl": "https://img.alicdn.com/i2/1994113638/O1CN015M0Aqf1ckFs5UI2eJ_!!0-item_pic.jpg",
  146. "PriceAfterCoupon": "109.00",
  147. "Provcity": "福建 泉州",
  148. "ReservePrice": "259.00",
  149. "SellerId": "1994113638",
  150. "ShopTitle": "361度户外旗舰店",
  151. "ShortTitle": "加绒保暖老爹鞋361女鞋运动鞋女",
  152. "SubTitle": "新款加绒女鞋运动鞋",
  153. "Title": "361女鞋运动鞋女2024冬季新款加绒保暖棉鞋轻便老爹鞋休闲跑步鞋",
  154. "UserType": 1,
  155. "Volume": 10,
  156. "ZkFinalPrice": "159"
  157. }
  158. }
  159. ]
  160. ],
  161. "request_id": "4eZfpBu"
  162. }
  163. */
  164. return result;
  165. }
  166. public async Task<TkDataDTO> UnionParseAsync(string content, string pid, TkDataDTO result, CancellationToken cancellationToken)
  167. {
  168. switch (_style)
  169. {
  170. case "ddx":
  171. return await DdxParseAsync(content, pid, result, cancellationToken);
  172. case "veapi":
  173. default:
  174. return await VeapiParseAsync(content, pid, result, cancellationToken);
  175. }
  176. }
  177. private async Task<TkDataDTO> VeapiParseAsync(string content, string pid, TkDataDTO result, CancellationToken cancellationToken)
  178. {
  179. string para = content.UrlEncode();
  180. string url = $"http://api.veapi.cn/tbk/generalconvert?vekey={_key}&para={para}&pid={pid}";
  181. if (!string.IsNullOrEmpty(_api_url))
  182. {
  183. url = _api_url;
  184. url = url.Replace("{apikey}", _key);
  185. url = url.Replace("{pid}", pid);
  186. url = url.Replace("{content}", para);
  187. }
  188. var response = await new WebClientUtility().RequestAsync(url, "GET", cancellationToken);
  189. var body = response.Body();
  190. var root = body.Convert2JsonElement();
  191. int error = root.Read<int>("error", 0);
  192. bool success = error == 0;
  193. string message = root.Read("msg", string.Empty);
  194. var data = root.ElementRead("data");
  195. result.channel = TkChannelEnum.tb;
  196. result.accountName = _accountName;
  197. result.success = success;
  198. result.message = message;
  199. if (success)
  200. {
  201. result.content = content;
  202. result.message = string.Empty;
  203. result.commercial = true;
  204. result.couponAmount = data.Read<decimal>("coupon_amount", 0);
  205. result.mktId = data.Read<string>("isv_mktid", string.Empty);
  206. result.itemId = data.Read<string>("item_id", string.Empty);
  207. result.itemId = content.GetContentPart("item.htm?id=", "");
  208. // veapi 缺少商品pic 和 promotionPrice
  209. result.taoToken = data.Read<string>("cps_full_tpwd", string.Empty);
  210. result.item_url = AlimamaPlus.GetLink(result.taoToken);
  211. result.item_deeplink_url = AlimamaPlus.GetDeeplink(result.shortLinkurl);
  212. string coupon_full_tpwd = data.Read<string>("coupon_full_tpwd", string.Empty);
  213. if (!string.IsNullOrEmpty(coupon_full_tpwd)) result.taoToken = coupon_full_tpwd;
  214. result.shortLinkurl = AlimamaPlus.GetLink(result.taoToken);
  215. result.deeplink_url = AlimamaPlus.GetDeeplink(result.shortLinkurl);
  216. result.itemName = result.taoToken.GetContentPart(result.shortLinkurl, "").Trim();
  217. return result;
  218. }
  219. else
  220. {
  221. result.message = "转链失败";
  222. result.reason = message;
  223. }
  224. return result;
  225. }
  226. private async Task<TkDataDTO> DdxParseAsync(string content, string pid, TkDataDTO result, CancellationToken cancellationToken)
  227. {
  228. string para = result.rawContent.UrlEncode();
  229. string url = $"https://api.tbk.dingdanxia.com/tbk/tkl_privilege?apikey={_key}&pid={pid}&relation_id=3197256735&activityId=&extspk=&tb_auth_id=&tkl=XXX+{para}";
  230. if (!string.IsNullOrEmpty(_api_url))
  231. {
  232. url = _api_url;
  233. url = url.Replace("{apikey}", _key);
  234. url = url.Replace("{pid}", pid);
  235. url = url.Replace("{content}", para);
  236. }
  237. var client = new WebClientUtility();
  238. #if DEBUG
  239. var response = await client.RequestAsync(url, "GET");
  240. #else
  241. var response = await client.RequestAsync(url, "GET", cancellationToken);
  242. #endif
  243. var body = response.Body();
  244. var root = body.Convert2JsonElement();
  245. int code = root.Read<int>("code", 0);
  246. bool success = code == 200;
  247. string message = root.Read("msg", string.Empty);
  248. if (message.StartsWith("数据返回失败【"))
  249. {
  250. message = message.GetContentPart("数据返回失败【", "】");
  251. }
  252. var data = root.ElementRead("data");
  253. result.channel = TkChannelEnum.tb;
  254. result.accountName = _accountName;
  255. result.success = success;
  256. result.message = message;
  257. if (success)
  258. {
  259. result.content = content;
  260. result.message = string.Empty;
  261. result.commercial = true;
  262. result.couponAmount = data.Read<decimal>("coupon", 0);
  263. result.couponEffectiveStartTime = data.Read<string>("coupon_start_time", string.Empty);
  264. result.couponEffectiveEndTime = data.Read<string>("coupon_end_time", string.Empty);
  265. result.mktId = data.Read<string>("item_id", string.Empty);
  266. result.itemId = content.GetContentPart("item.htm?id=", "");
  267. result.pic = data.PathRead<string>("itemInfo.pict_url", string.Empty);
  268. result.sellerNickName = data.PathRead<string>("itemInfo.nick", string.Empty);
  269. result.promotionPrice = data.PathRead<decimal>("itemInfo.qh_final_price", 0);
  270. if (result.promotionPrice == 0)
  271. {
  272. result.promotionPrice = data.PathRead<decimal>("itemInfo.zk_final_price", 0);
  273. }
  274. result.taoToken = data.Read<string>("long_item_tpwd", string.Empty);
  275. //string long_coupon_tpwd = data.Read<string>("long_coupon_tpwd", string.Empty);
  276. //if (!string.IsNullOrEmpty(long_coupon_tpwd)) result.taoToken = long_coupon_tpwd;
  277. result.shortLinkurl = AlimamaPlus.GetLink(result.taoToken);
  278. result.itemName = result.taoToken.GetContentPart(result.shortLinkurl, "").Trim();
  279. result.deeplink_url = AlimamaPlus.GetDeeplink(result.shortLinkurl);
  280. return result;
  281. }
  282. else
  283. {
  284. result.content = result.rawContent;
  285. switch (message)
  286. {
  287. case "该口令无效,请检查后重新提交":
  288. case "该商品已下架":
  289. result.message = "转链失败";
  290. result.reason = message;
  291. result.subCode = TkSubCodeEnum.NoConvert;
  292. break;
  293. default:
  294. result.message = "转链失败";
  295. result.reason = message;
  296. result.subCode = TkSubCodeEnum.NetError;
  297. break;
  298. }
  299. return result;
  300. }
  301. }
  302. }
  303. }