DeepleaperPlus.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using dodohold.core;
  2. using Google.Protobuf.WellKnownTypes;
  3. using Org.BouncyCastle.Ocsp;
  4. using Quartz;
  5. using System.Net;
  6. using System.Security.Cryptography;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Xml.Linq;
  10. using TencentCloud.Trtc.V20190722.Models;
  11. namespace molilian.core
  12. {
  13. public partial class DeepleaperPlus
  14. {
  15. private const string SERVER_URL = "https://qianxun.deepleaper.com/v1";
  16. private string _accessKey;
  17. private string _secretKey;
  18. WebProxy? _proxy;
  19. string _proxyName;
  20. public DeepleaperPlus(string nodeName = "", string accessKey = "", string secretKey = "")
  21. {
  22. if (!string.IsNullOrEmpty(nodeName))
  23. {
  24. _proxyName = ProxyNodesCore.GetSelectOne(nodeName);
  25. _proxy = ProxyNodesCore.GetOne(_proxyName);
  26. }
  27. accessKey = "qx-stvlJ2u6M7xsY6az";
  28. secretKey = "MDQ1ZTliZDczODdhNDkzZDk4N2U1YmVjMmNkNDE4NjRscENHWnZ2UA==";
  29. _accessKey = accessKey;
  30. _secretKey = secretKey;
  31. }
  32. private static string GenerateSign(string secretKey, long ts)
  33. {
  34. try
  35. {
  36. string message = ts.ToString();
  37. using (var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secretKey)))
  38. {
  39. byte[] hashBytes = hmac.ComputeHash(Encoding.UTF8.GetBytes(message));
  40. return Convert.ToBase64String(hashBytes);
  41. }
  42. }
  43. catch (Exception ex)
  44. {
  45. throw new Exception("生成签名失败", ex);
  46. }
  47. }
  48. public async Task<TkDataDTO> UnionParseAsync(TkDataDTO result)
  49. {
  50. long ts = DateTime.Now.Convert2UnixTimestamp(true);
  51. var args = new
  52. {
  53. version = "1.0",
  54. endpoint = new
  55. {
  56. device = new
  57. {
  58. oaid = result.oaid,
  59. location = new
  60. {
  61. locationSystem = "BD09LL",
  62. latitude = "",
  63. longitude = ""
  64. }
  65. },
  66. },
  67. header = new
  68. {
  69. type = "IntentRequest",
  70. timestamp = $"{ts}"
  71. },
  72. inquire = new
  73. {
  74. inquireId = $"shopping-shareCodeTkl-{ts}",
  75. intent = new
  76. {
  77. apiKey = "shopping-shareCodeTkl",
  78. slots = new
  79. {
  80. shareCodeTkl = new
  81. {
  82. name = "shareCodeTkl",
  83. values = new[] {
  84. new
  85. {
  86. real = result.content
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. };
  94. string post = args.Convert2Json();
  95. string sign = GenerateSign(_secretKey, ts);
  96. var client = new WebClientUtility();
  97. client.AddHeaders("accessKey", _accessKey);
  98. client.AddHeaders("ts", $"{ts}");
  99. client.AddHeaders("sign", sign);
  100. client.SetContentType("application/json");
  101. client.Post(post);
  102. #if DEBUG
  103. #else
  104. client.Proxy = _proxy;
  105. #endif
  106. var response = await client.RequestAsync(SERVER_URL);
  107. var body = response.Body();
  108. result.remote_response = body;
  109. var root = body.Convert2JsonElement();
  110. var now = DateTime.Now;
  111. var ts2 = now - result.create_time;
  112. result.elapsedTime2 = (int)ts2.TotalMilliseconds;
  113. int error = root.Read<int>("errorCode", 0);
  114. bool success = error == 0;
  115. string message = root.Read("errorMessage", string.Empty);
  116. result.success = false;
  117. //if (message.Contains("该url暂不支持解析"))
  118. //{
  119. // message = "该url暂不支持解析";
  120. //}
  121. // "message": "淘宝口令解析服务异常: Cannot deserialize value of type `java.lang.Integer` from String \"该卖家ID暂不支持\": not a valid `java.lang.Integer` value\n at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.deepleaper.qianxun.model.taobao.QXTbGeneralLinkParseResponse[\"data\"]->com.deepleaper.qianxun.model.taobao.QXTbGeneralLinkParseResponse$Result[\"material_url_list\"]->java.util.ArrayList[0]->com.deepleaper.qianxun.model.taobao.QXTbGeneralLinkParseResponse$Material[\"msg\"])",
  122. result.reason = message;
  123. result.message = "转链失败";
  124. if (error != 0) return result;
  125. try
  126. {
  127. var shoppingInfoItems = root.ElementRead("reply").ElementRead("commands")[0].ElementRead("body").ElementRead("templateContent").ElementRead("items")[0].ElementRead("shoppingInfoItems");
  128. result.itemName = shoppingInfoItems[0].PathRead<string>("name");
  129. result.pic = shoppingInfoItems[0].PathRead<string>("mainImage.large.url");
  130. result.shopTitle = shoppingInfoItems[0].PathRead<string>("storeName");
  131. result.couponAmount = shoppingInfoItems[0].PathRead<int>("couponInfo[0].amount.url");
  132. result.shortLinkurl = shoppingInfoItems[0].PathRead<string>("detailUrl.webURL");
  133. result.deeplink_url = shoppingInfoItems[0].PathRead<string>("detailUrl.deepLink.url");
  134. result.with_middle_page = shoppingInfoItems[0].PathRead<int>("detailUrl.type");
  135. if (result.with_middle_page == 1) { result.commercial = true; }
  136. result.channel = TkChannelEnum.tb;
  137. result.success = success;
  138. result.message = message;
  139. //result.content = content;
  140. return result;
  141. }
  142. catch (Exception ex)
  143. {
  144. result.reason = "undefined";
  145. result.message = "转链失败";
  146. return result;
  147. }
  148. }
  149. }
  150. }