Xmlconfig.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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)
  120. {
  121. code = "";
  122. value = "";
  123. try
  124. {
  125. XmlDocument xml = new XmlDocument();
  126. //xml.Load(path);
  127. xml.LoadXml(str);
  128. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  129. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  130. if (code == "200")
  131. {
  132. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText;
  133. string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  134. if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32, 16))
  135. {
  136. return true;
  137. }
  138. else
  139. {
  140. desc = "CRC32 error";
  141. return false;
  142. }
  143. }
  144. return false;
  145. }
  146. catch (Exception ex)
  147. {
  148. desc = ex.Message;
  149. return false;
  150. }
  151. }
  152. public static bool GetWidevineAndAttestationKeyXml(string str,
  153. string node,
  154. out string code,
  155. out string desc,
  156. out bool isAndroidTV,
  157. out string WidevineKey,
  158. out string AttestationKey,
  159. out string AttestationMd5)
  160. {
  161. code = "";
  162. isAndroidTV = false;
  163. WidevineKey = "";
  164. AttestationKey = "";
  165. AttestationMd5 = "";
  166. try
  167. {
  168. XmlDocument xml = new XmlDocument();
  169. //xml.Load(path);
  170. xml.LoadXml(str);
  171. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  172. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  173. isAndroidTV = !xml.SelectSingleNode(node).Attributes.GetNamedItem("androidtv").InnerText.Equals("1");
  174. if (code == "200")
  175. {
  176. WidevineKey = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("value").InnerText;
  177. string CRC32 = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("crc32").InnerText;
  178. if (CrcUtils.CRC32(WidevineKey) != Convert.ToUInt32(CRC32, 16))
  179. {
  180. desc = "widevine CRC32 error";
  181. return false;
  182. }
  183. if (isAndroidTV)
  184. {
  185. #if false
  186. // 判断节点是否存在;
  187. if (xml.GetElementsByTagName("attestation") == null)
  188. {
  189. desc = "isAndroidTV: but attestation node is Null";
  190. return false;
  191. }
  192. #endif
  193. AttestationKey = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("value").InnerText;
  194. CRC32 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("crc32").InnerText;
  195. if (CrcUtils.CRC32(AttestationKey) != Convert.ToUInt32(CRC32, 16))
  196. {
  197. desc = "attestation CRC32 error";
  198. return false;
  199. }
  200. else
  201. {
  202. AttestationMd5 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("md5value").InnerText;
  203. }
  204. }
  205. return true;
  206. }
  207. return false;
  208. }
  209. catch (Exception ex)
  210. {
  211. desc = ex.Message;
  212. return false;
  213. }
  214. }
  215. public static bool ReportXml(string str, string node, out string code, out string desc)
  216. {
  217. code = "";
  218. try
  219. {
  220. XmlDocument xml = new XmlDocument();
  221. //xml.Load(path);
  222. xml.LoadXml(str);
  223. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  224. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  225. if (code == "200")
  226. {
  227. return true;
  228. }
  229. return false;
  230. }
  231. catch (Exception ex)
  232. {
  233. desc = ex.Message;
  234. return false;
  235. }
  236. }
  237. public static bool GetDSNXml(string str, string node, out string code, out string desc, out string value)
  238. {
  239. code = "";
  240. value = "";
  241. try
  242. {
  243. XmlDocument xml = new XmlDocument();
  244. xml.LoadXml(str);
  245. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  246. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  247. if (code == "200")
  248. {
  249. value = xml.SelectSingleNode(node + "//" + "firetvDsn").Attributes.GetNamedItem("dsn").InnerText;
  250. return true;
  251. }
  252. return false;
  253. }
  254. catch (Exception ex)
  255. {
  256. desc = ex.Message;
  257. return false;
  258. }
  259. }
  260. }