Xmlconfig.cs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. using System;
  2. using System.Xml;
  3. using WHC.OrderWater.Commons;
  4. public class Xmlconfig
  5. {
  6. public static bool ReadXmlnode(string str,string node,string value,out object result)
  7. {
  8. result = "";
  9. try
  10. {
  11. XmlDocument xml = new XmlDocument();
  12. //xml.Load(path);
  13. xml.LoadXml(str);
  14. var b = xml.SelectSingleNode(node);
  15. result = xml.SelectSingleNode(node).SelectSingleNode(value).InnerText;
  16. return true;
  17. }
  18. catch(Exception ex)
  19. {
  20. result = ex.Message;
  21. return false;
  22. }
  23. }
  24. public static bool WriteXmlnode(string path, string node, string value, out object result)
  25. {
  26. result = "";
  27. try
  28. {
  29. XmlDocument xml = new XmlDocument();
  30. xml.Load(path);
  31. xml.SelectSingleNode(node).InnerText = value;
  32. return true;
  33. }
  34. catch (Exception ex)
  35. {
  36. result = ex.Message;
  37. return false;
  38. }
  39. }
  40. public static bool KeyCountXml(string str, string node, string node2,out string code,out string desc,out string value)
  41. {
  42. code = "";
  43. value = "";
  44. try
  45. {
  46. XmlDocument xml = new XmlDocument();
  47. //xml.Load(path);
  48. xml.LoadXml(str);
  49. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  50. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  51. if(code=="200")
  52. {
  53. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText;
  54. return true;
  55. }
  56. return false;
  57. }
  58. catch (Exception ex)
  59. {
  60. desc = ex.Message;
  61. return false;
  62. }
  63. }
  64. public static bool AutoKeyStatusXml(string str, string node, out string code, out string desc)
  65. {
  66. code = "";
  67. try
  68. {
  69. XmlDocument xml = new XmlDocument();
  70. //xml.Load(path);
  71. xml.LoadXml(str);
  72. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  73. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  74. if (code == "200")
  75. {
  76. return true;
  77. }
  78. return false;
  79. }
  80. catch (Exception ex)
  81. {
  82. desc = ex.Message;
  83. return false;
  84. }
  85. }
  86. public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
  87. {
  88. code = "";
  89. value = "";
  90. try
  91. {
  92. XmlDocument xml = new XmlDocument();
  93. //xml.Load(path);
  94. xml.LoadXml(str);
  95. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  96. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  97. if (code == "200")
  98. {
  99. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText;
  100. string CRC32= xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  101. if (CrcUtils.CRC32(value) ==Convert.ToUInt32(CRC32, 16))
  102. {
  103. return true;
  104. }
  105. else
  106. {
  107. desc = "CRC32 error";
  108. return false;
  109. }
  110. }
  111. return false;
  112. }
  113. catch (Exception ex)
  114. {
  115. desc = ex.Message;
  116. return false;
  117. }
  118. }
  119. public static bool GetOthersKeyXml(string str, string node, string node2, out string code, out string desc, out string value, out string md5)
  120. {
  121. md5 = "";
  122. code = "";
  123. value = "";
  124. try
  125. {
  126. XmlDocument xml = new XmlDocument();
  127. //xml.Load(path);
  128. xml.LoadXml(str);
  129. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  130. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  131. if (code == "200")
  132. {
  133. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText;
  134. if (xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("md5value") != null)
  135. md5 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("md5value").InnerText;
  136. string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  137. if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32, 16))
  138. {
  139. return true;
  140. }
  141. else
  142. {
  143. desc = "CRC32 error";
  144. return false;
  145. }
  146. }
  147. return false;
  148. }
  149. catch (Exception ex)
  150. {
  151. desc = ex.Message;
  152. return false;
  153. }
  154. }
  155. public static bool GetWidevineAndAttestationKeyXml(string str,
  156. string node,
  157. out string code,
  158. out string desc,
  159. out bool isAndroidTV,
  160. out string WidevineKey,
  161. out string AttestationKey,
  162. out string AttestationMd5)
  163. {
  164. code = "";
  165. isAndroidTV = false;
  166. WidevineKey = "";
  167. AttestationKey = "";
  168. AttestationMd5 = "";
  169. try
  170. {
  171. XmlDocument xml = new XmlDocument();
  172. //xml.Load(path);
  173. xml.LoadXml(str);
  174. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  175. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  176. isAndroidTV = !xml.SelectSingleNode(node).Attributes.GetNamedItem("androidtv").InnerText.Equals("1");
  177. if (code == "200")
  178. {
  179. WidevineKey = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("value").InnerText;
  180. string CRC32 = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("crc32").InnerText;
  181. if (CrcUtils.CRC32(WidevineKey) != Convert.ToUInt32(CRC32, 16))
  182. {
  183. desc = "widevine CRC32 error";
  184. return false;
  185. }
  186. if (isAndroidTV)
  187. {
  188. #if false
  189. // 判断节点是否存在;
  190. if (xml.GetElementsByTagName("attestation") == null)
  191. {
  192. desc = "isAndroidTV: but attestation node is Null";
  193. return false;
  194. }
  195. #endif
  196. AttestationKey = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("value").InnerText;
  197. CRC32 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("crc32").InnerText;
  198. if (CrcUtils.CRC32(AttestationKey) != Convert.ToUInt32(CRC32, 16))
  199. {
  200. desc = "attestation CRC32 error";
  201. return false;
  202. }
  203. else
  204. {
  205. AttestationMd5 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("md5value").InnerText;
  206. }
  207. }
  208. return true;
  209. }
  210. return false;
  211. }
  212. catch (Exception ex)
  213. {
  214. desc = ex.Message;
  215. return false;
  216. }
  217. }
  218. public static bool ReportXml(string str, string node, out string code, out string desc)
  219. {
  220. code = "";
  221. try
  222. {
  223. XmlDocument xml = new XmlDocument();
  224. //xml.Load(path);
  225. xml.LoadXml(str);
  226. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  227. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  228. if (code == "200")
  229. {
  230. return true;
  231. }
  232. return false;
  233. }
  234. catch (Exception ex)
  235. {
  236. desc = ex.Message;
  237. return false;
  238. }
  239. }
  240. public static bool GetDSNXml(string str, string node, out string code, out string desc, out string value)
  241. {
  242. code = "";
  243. value = "";
  244. try
  245. {
  246. XmlDocument xml = new XmlDocument();
  247. xml.LoadXml(str);
  248. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  249. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  250. if (code == "200")
  251. {
  252. value = xml.SelectSingleNode(node + "//" + "firetvDsn").Attributes.GetNamedItem("dsn").InnerText;
  253. return true;
  254. }
  255. return false;
  256. }
  257. catch (Exception ex)
  258. {
  259. desc = ex.Message;
  260. return false;
  261. }
  262. }
  263. }