Xmlconfig.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Xml;
  5. using WHC.OrderWater.Commons;
  6. using MOKA_Factory_Tools;
  7. public class Xmlconfig
  8. {
  9. public static bool ReadXmlnode(string str,string node,string value,out object result)
  10. {
  11. result = "";
  12. try
  13. {
  14. XmlDocument xml = new XmlDocument();
  15. //xml.Load(path);
  16. xml.LoadXml(str);
  17. var b = xml.SelectSingleNode(node);
  18. result = xml.SelectSingleNode(node).SelectSingleNode(value).InnerText;
  19. return true;
  20. }
  21. catch(Exception ex)
  22. {
  23. result = ex.Message;
  24. return false;
  25. }
  26. }
  27. public static bool WriteXmlnode(string path, string node, string value, out object result)
  28. {
  29. result = "";
  30. try
  31. {
  32. XmlDocument xml = new XmlDocument();
  33. xml.Load(path);
  34. xml.SelectSingleNode(node).InnerText = value;
  35. return true;
  36. }
  37. catch (Exception ex)
  38. {
  39. result = ex.Message;
  40. return false;
  41. }
  42. }
  43. public static bool KeyCountXml(string str, string node, string node2,out string code,out string desc,out string value)
  44. {
  45. code = "";
  46. value = "";
  47. try
  48. {
  49. XmlDocument xml = new XmlDocument();
  50. //xml.Load(path);
  51. xml.LoadXml(str);
  52. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  53. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  54. if(code=="200")
  55. {
  56. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText;
  57. return true;
  58. }
  59. return false;
  60. }
  61. catch (Exception ex)
  62. {
  63. desc = ex.Message;
  64. return false;
  65. }
  66. }
  67. public static bool AutoKeyStatusXml(string str, string node, out string code, out string desc)
  68. {
  69. code = "";
  70. try
  71. {
  72. XmlDocument xml = new XmlDocument();
  73. //xml.Load(path);
  74. xml.LoadXml(str);
  75. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  76. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  77. if (code == "200")
  78. {
  79. return true;
  80. }
  81. return false;
  82. }
  83. catch (Exception ex)
  84. {
  85. desc = ex.Message;
  86. return false;
  87. }
  88. }
  89. public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
  90. {
  91. code = "";
  92. value = "";
  93. try
  94. {
  95. XmlDocument xml = new XmlDocument();
  96. //xml.Load(path);
  97. xml.LoadXml(str);
  98. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  99. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  100. if (code == "200")
  101. {
  102. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText;
  103. string CRC32= xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  104. if (CrcUtils.CRC32(value) ==Convert.ToUInt32(CRC32, 16))
  105. {
  106. return true;
  107. }
  108. else
  109. {
  110. desc = "CRC32 error";
  111. return false;
  112. }
  113. }
  114. return false;
  115. }
  116. catch (Exception ex)
  117. {
  118. desc = ex.Message;
  119. return false;
  120. }
  121. }
  122. public static bool GetOthersKeyXml(string str, string node, string node2, out string code, out string desc, out string value, out string md5)
  123. {
  124. md5 = "";
  125. code = "";
  126. value = "";
  127. try
  128. {
  129. XmlDocument xml = new XmlDocument();
  130. //xml.Load(path);
  131. xml.LoadXml(str);
  132. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  133. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  134. if (code == "200")
  135. {
  136. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText;
  137. if (xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("md5value") != null)
  138. md5 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("md5value").InnerText;
  139. string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  140. if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32, 16))
  141. {
  142. return true;
  143. }
  144. else
  145. {
  146. desc = "CRC32 error";
  147. return false;
  148. }
  149. }
  150. return false;
  151. }
  152. catch (Exception ex)
  153. {
  154. desc = ex.Message;
  155. return false;
  156. }
  157. }
  158. /// <summary>
  159. /// 解析并获取返回2个key的xml.
  160. /// </summary>
  161. /// <returns></returns>
  162. public static bool Get2KeyInfoFromXml(string str, string dataKey, string toolKey, out string code, out string desc, out string acaskey_data, out string acaskey_datamd5, out string acaskey_tool, out string acaskey_toolmd5)
  163. {
  164. acaskey_data = "";
  165. acaskey_tool = "";
  166. code = "";
  167. acaskey_datamd5 = "";
  168. acaskey_toolmd5 = "";
  169. try
  170. {
  171. XmlDocument xml = new XmlDocument();
  172. xml.LoadXml(str);
  173. code = xml.SelectSingleNode("response").Attributes.GetNamedItem("code").InnerText;
  174. desc = xml.SelectSingleNode("response").Attributes.GetNamedItem("desc").InnerText;
  175. if (code == "200")
  176. {
  177. acaskey_data = xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("value").InnerText;
  178. if (xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("md5value") != null)
  179. acaskey_datamd5 = xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("md5value").InnerText;
  180. bool bCRC321 = false;
  181. string CRC321 = "";
  182. if (xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("crc32") != null)
  183. {
  184. bCRC321 = true;
  185. CRC321 = xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("crc32").InnerText;
  186. }
  187. acaskey_tool = xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("value").InnerText;
  188. if (xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("md5value") != null)
  189. acaskey_toolmd5 = xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("md5value").InnerText;
  190. bool bCRC322 = false;
  191. string CRC322 = "";
  192. if (xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("crc32") != null)
  193. {
  194. bCRC322 = true;
  195. CRC322 = xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("crc32").InnerText;
  196. }
  197. if (bCRC321)
  198. {
  199. if (CrcUtils.CRC32(acaskey_data) != Convert.ToUInt32(CRC321, 16))
  200. {
  201. desc = "CRC32 error";
  202. return false;
  203. }
  204. }
  205. if (bCRC322)
  206. {
  207. if (CrcUtils.CRC32(acaskey_tool) != Convert.ToUInt32(CRC322, 16))
  208. {
  209. desc = "CRC32 error";
  210. return false;
  211. }
  212. }
  213. }
  214. return true;
  215. }
  216. catch (Exception ex)
  217. {
  218. desc = ex.Message;
  219. return false;
  220. }
  221. }
  222. public static bool GetWidevineAndAttestationKeyXml(string str,
  223. string node,
  224. out string code,
  225. out string desc,
  226. out bool isAndroidTV,
  227. out string WidevineKey,
  228. out string AttestationKey,
  229. out string AttestationMd5)
  230. {
  231. code = "";
  232. isAndroidTV = false;
  233. WidevineKey = "";
  234. AttestationKey = "";
  235. AttestationMd5 = "";
  236. try
  237. {
  238. XmlDocument xml = new XmlDocument();
  239. //xml.Load(path);
  240. xml.LoadXml(str);
  241. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  242. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  243. isAndroidTV = !xml.SelectSingleNode(node).Attributes.GetNamedItem("androidtv").InnerText.Equals("1");
  244. if (code == "200")
  245. {
  246. WidevineKey = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("value").InnerText;
  247. string CRC32 = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("crc32").InnerText;
  248. if (CrcUtils.CRC32(WidevineKey) != Convert.ToUInt32(CRC32, 16))
  249. {
  250. desc = "widevine CRC32 error";
  251. return false;
  252. }
  253. if (isAndroidTV)
  254. {
  255. #if false
  256. // 判断节点是否存在;
  257. if (xml.GetElementsByTagName("attestation") == null)
  258. {
  259. desc = "isAndroidTV: but attestation node is Null";
  260. return false;
  261. }
  262. #endif
  263. AttestationKey = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("value").InnerText;
  264. CRC32 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("crc32").InnerText;
  265. if (CrcUtils.CRC32(AttestationKey) != Convert.ToUInt32(CRC32, 16))
  266. {
  267. desc = "attestation CRC32 error";
  268. return false;
  269. }
  270. else
  271. {
  272. AttestationMd5 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("md5value").InnerText;
  273. }
  274. }
  275. return true;
  276. }
  277. return false;
  278. }
  279. catch (Exception ex)
  280. {
  281. desc = ex.Message;
  282. return false;
  283. }
  284. }
  285. public static bool ReportXml(string str, string node, out string code, out string desc)
  286. {
  287. code = "";
  288. try
  289. {
  290. XmlDocument xml = new XmlDocument();
  291. //xml.Load(path);
  292. xml.LoadXml(str);
  293. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  294. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  295. if (code == "200")
  296. {
  297. return true;
  298. }
  299. return false;
  300. }
  301. catch (Exception ex)
  302. {
  303. desc = ex.Message;
  304. return false;
  305. }
  306. }
  307. public static bool GetDSNXml(string str, string node, out string code, out string desc, out string value)
  308. {
  309. code = "";
  310. value = "";
  311. try
  312. {
  313. XmlDocument xml = new XmlDocument();
  314. xml.LoadXml(str);
  315. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  316. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  317. if (code == "200")
  318. {
  319. value = xml.SelectSingleNode(node + "//" + "firetvDsn").Attributes.GetNamedItem("dsn").InnerText;
  320. return true;
  321. }
  322. return false;
  323. }
  324. catch (Exception ex)
  325. {
  326. desc = ex.Message;
  327. return false;
  328. }
  329. }
  330. #region G客户NTF统计功能
  331. public static bool GetMaInfoXml(string str, out MaInfo maInfo, out string desc)
  332. {
  333. desc = "";
  334. maInfo = null;
  335. try
  336. {
  337. XmlDocument doc = new XmlDocument();
  338. doc.LoadXml(str);
  339. XmlNamespaceManager nsp = new XmlNamespaceManager(doc.NameTable);
  340. nsp.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
  341. XmlNode node = doc.SelectSingleNode("//soap:Envelope//soap:Body", nsp);
  342. if ( node != null)
  343. {
  344. JObject jObject = JObject.Parse(node.InnerText);
  345. if ( jObject["IsSuccess"].Value<bool>() )
  346. {
  347. maInfo = JsonConvert.DeserializeObject<MaInfo>(jObject["Msg"].ToString());
  348. }
  349. else
  350. {
  351. return false;
  352. }
  353. }
  354. }
  355. catch (Exception ex)
  356. {
  357. desc = ex.Message;
  358. return false;
  359. }
  360. return true;
  361. }
  362. #endregion
  363. }