using System; using System.Xml; using WHC.OrderWater.Commons; public class Xmlconfig { public static bool ReadXmlnode(string str,string node,string value,out object result) { result = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); var b = xml.SelectSingleNode(node); result = xml.SelectSingleNode(node).SelectSingleNode(value).InnerText; return true; } catch(Exception ex) { result = ex.Message; return false; } } public static bool WriteXmlnode(string path, string node, string value, out object result) { result = ""; try { XmlDocument xml = new XmlDocument(); xml.Load(path); xml.SelectSingleNode(node).InnerText = value; return true; } catch (Exception ex) { result = ex.Message; return false; } } public static bool KeyCountXml(string str, string node, string node2,out string code,out string desc,out string value) { code = ""; value = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; if(code=="200") { value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText; return true; } return false; } catch (Exception ex) { desc = ex.Message; return false; } } public static bool AutoKeyStatusXml(string str, string node, out string code, out string desc) { code = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; if (code == "200") { return true; } return false; } catch (Exception ex) { desc = ex.Message; return false; } } public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value) { code = ""; value = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; if (code == "200") { value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText; string CRC32= xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText; if (CrcUtils.CRC32(value) ==Convert.ToUInt32(CRC32, 16)) { return true; } else { desc = "CRC32 error"; return false; } } return false; } catch (Exception ex) { desc = ex.Message; return false; } } public static bool GetOthersKeyXml(string str, string node, string node2, out string code, out string desc, out string value, out string md5) { md5 = ""; code = ""; value = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; if (code == "200") { value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("value").InnerText; if (xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("md5value") != null) md5 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("md5value").InnerText; string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText; if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32, 16)) { return true; } else { desc = "CRC32 error"; return false; } } return false; } catch (Exception ex) { desc = ex.Message; return false; } } public static bool GetWidevineAndAttestationKeyXml(string str, string node, out string code, out string desc, out bool isAndroidTV, out string WidevineKey, out string AttestationKey, out string AttestationMd5) { code = ""; isAndroidTV = false; WidevineKey = ""; AttestationKey = ""; AttestationMd5 = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; isAndroidTV = !xml.SelectSingleNode(node).Attributes.GetNamedItem("androidtv").InnerText.Equals("1"); if (code == "200") { WidevineKey = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("value").InnerText; string CRC32 = xml.SelectSingleNode(node + "//widevine").Attributes.GetNamedItem("crc32").InnerText; if (CrcUtils.CRC32(WidevineKey) != Convert.ToUInt32(CRC32, 16)) { desc = "widevine CRC32 error"; return false; } if (isAndroidTV) { #if false // 判断节点是否存在; if (xml.GetElementsByTagName("attestation") == null) { desc = "isAndroidTV: but attestation node is Null"; return false; } #endif AttestationKey = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("value").InnerText; CRC32 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("crc32").InnerText; if (CrcUtils.CRC32(AttestationKey) != Convert.ToUInt32(CRC32, 16)) { desc = "attestation CRC32 error"; return false; } else { AttestationMd5 = xml.SelectSingleNode(node + "//attestation").Attributes.GetNamedItem("md5value").InnerText; } } return true; } return false; } catch (Exception ex) { desc = ex.Message; return false; } } public static bool ReportXml(string str, string node, out string code, out string desc) { code = ""; try { XmlDocument xml = new XmlDocument(); //xml.Load(path); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; if (code == "200") { return true; } return false; } catch (Exception ex) { desc = ex.Message; return false; } } public static bool GetDSNXml(string str, string node, out string code, out string desc, out string value) { code = ""; value = ""; try { XmlDocument xml = new XmlDocument(); xml.LoadXml(str); code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText; desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText; if (code == "200") { value = xml.SelectSingleNode(node + "//" + "firetvDsn").Attributes.GetNamedItem("dsn").InnerText; return true; } return false; } catch (Exception ex) { desc = ex.Message; return false; } } }