123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Xml;
- using WHC.OrderWater.Commons;
- using MOKA_Factory_Tools;
- 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;
- }
- }
- /// <summary>
- /// 解析并获取返回2个key的xml.
- /// </summary>
- /// <returns></returns>
- 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)
- {
- acaskey_data = "";
- acaskey_tool = "";
- code = "";
- acaskey_datamd5 = "";
- acaskey_toolmd5 = "";
- try
- {
- XmlDocument xml = new XmlDocument();
- xml.LoadXml(str);
- code = xml.SelectSingleNode("response").Attributes.GetNamedItem("code").InnerText;
- desc = xml.SelectSingleNode("response").Attributes.GetNamedItem("desc").InnerText;
- if (code == "200")
- {
- acaskey_data = xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("value").InnerText;
- if (xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("md5value") != null)
- acaskey_datamd5 = xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("md5value").InnerText;
- bool bCRC321 = false;
- string CRC321 = "";
- if (xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("crc32") != null)
- {
- bCRC321 = true;
- CRC321 = xml.SelectSingleNode("response//" + dataKey).Attributes.GetNamedItem("crc32").InnerText;
- }
- acaskey_tool = xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("value").InnerText;
- if (xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("md5value") != null)
- acaskey_toolmd5 = xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("md5value").InnerText;
- bool bCRC322 = false;
- string CRC322 = "";
- if (xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("crc32") != null)
- {
- bCRC322 = true;
- CRC322 = xml.SelectSingleNode("response//" + toolKey).Attributes.GetNamedItem("crc32").InnerText;
- }
- if (bCRC321)
- {
- if (CrcUtils.CRC32(acaskey_data) != Convert.ToUInt32(CRC321, 16))
- {
- desc = "CRC32 error";
- return false;
- }
- }
- if (bCRC322)
- {
- if (CrcUtils.CRC32(acaskey_tool) != Convert.ToUInt32(CRC322, 16))
- {
- desc = "CRC32 error";
- return false;
- }
- }
- }
- return true;
- }
- 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;
- }
- }
- #region G客户NTF统计功能
- public static bool GetMaInfoXml(string str, out MaInfo maInfo, out string desc)
- {
- desc = "";
- maInfo = null;
- try
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(str);
- XmlNamespaceManager nsp = new XmlNamespaceManager(doc.NameTable);
- nsp.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
- XmlNode node = doc.SelectSingleNode("//soap:Envelope//soap:Body", nsp);
- if ( node != null)
- {
- JObject jObject = JObject.Parse(node.InnerText);
- if ( jObject["IsSuccess"].Value<bool>() )
- {
- maInfo = JsonConvert.DeserializeObject<MaInfo>(jObject["Msg"].ToString());
- }
- else
- {
- return false;
- }
- }
- }
- catch (Exception ex)
- {
- desc = ex.Message;
- return false;
- }
- return true;
- }
- #endregion
- }
|