CommonMethod.cs 127 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using SufeiUtil;
  4. using SXLibrary;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Configuration;
  9. using System.Data.SQLite;
  10. using System.Globalization;
  11. using System.IO;
  12. using System.Management;
  13. using System.Net;
  14. using System.Text;
  15. using System.Text.RegularExpressions;
  16. using System.Windows.Forms;
  17. using System.Xml;
  18. using WHC.OrderWater.Commons;
  19. using HttpHelper = SufeiUtil.HttpHelper;
  20. using System.Web;
  21. using System.Security.Cryptography.X509Certificates;
  22. using System.Net.Security;
  23. using System.Runtime.InteropServices;
  24. using System.Diagnostics;
  25. namespace MOKA_Factory_Tools
  26. {
  27. class CommonMethod
  28. {
  29. [DllImport("kernel32")]
  30. public static extern bool GetProfileString(string lpApplicationName, string lpKeyName, string lpDefault, StringBuilder lpReturnedString, int nSize);
  31. [DllImport("kernel32")]
  32. public static extern bool WriteProfileString(string lpApplicationName, string lpKeyName, string lpString);
  33. public static string FactoryName = "Unknown";
  34. private static string lastOrder = "";
  35. private static List<string> ListACASSN = new List<string>();
  36. //public static string LocalMacAddress = GetMacAddress();
  37. /// <summary>
  38. /// 获取活动网卡硬件地址
  39. /// </summary>
  40. /// <returns></returns>
  41. public static string GetMacAddress()
  42. {
  43. string mac = "";
  44. using (ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration"))
  45. {
  46. ManagementObjectCollection moc = mc.GetInstances();
  47. int i = 0;
  48. int j = 0;
  49. foreach (ManagementObject mo in moc)
  50. {
  51. if (mo["MacAddress"] != null)
  52. {
  53. if (Convert.ToBoolean(mo["IPEnabled"]))
  54. {
  55. if (j < 2)
  56. {
  57. mac = mo["MacAddress"].ToString() + "&" + mac;
  58. j++;
  59. }
  60. }
  61. else
  62. {
  63. if (i < 1)
  64. {
  65. mac += mo["MacAddress"].ToString() + "&";
  66. i++;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. return mac.Replace(":", "-");
  73. //return "C0-B6-F9-44-D7-BB";
  74. }
  75. /// <summary>
  76. /// 获取订单信息
  77. /// </summary>
  78. /// <param name="url"></param>
  79. /// <param name="order"></param>
  80. /// <param name="pcmac"></param>
  81. /// <param name="iptvip"></param>
  82. /// <param name="version"></param>
  83. /// <param name="sqliteConn"></param>
  84. /// <param name="mid"></param>
  85. /// <returns></returns>
  86. public static bool GetMidInfo(string url, string order, string pcmac, string iptvip, string version, SQLiteConnection sqliteConn, out MidList mid)
  87. {
  88. mid = new MidList();
  89. OrderInput orderInput1 = new OrderInput { bid = order, mac = pcmac, version = "", clientType = "" };//"74-27-EA-6E-DA-9F"
  90. string jsonorder = JsonConvert.SerializeObject(orderInput1, Newtonsoft.Json.Formatting.Indented);
  91. HttpHelper http = new HttpHelper();
  92. HttpItem item = new HttpItem()
  93. {
  94. URL = url,//URL这里都是测试URl   必需项
  95. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  96. //Encoding = Encoding.Default,
  97. Method = "post",//URL     可选项 默认为Get
  98. Postdata = jsonorder,
  99. PostEncoding = Encoding.UTF8,
  100. KeepAlive = false
  101. };
  102. item.ContentType = "application/json;charset=utf-8";
  103. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  104. stopwatch.Start();
  105. HttpResult result = http.GetHtml(item);
  106. stopwatch.Stop();
  107. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  108. stopwatch.Reset();
  109. string ParseText = result.Html;
  110. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  111. {
  112. Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  113. }
  114. else
  115. {
  116. Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  117. ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  118. return false;
  119. }
  120. try
  121. {
  122. JObject jObject = JObject.Parse(ParseText);
  123. mid.message = jObject["message"].Value<string>();
  124. mid.code = jObject["code"].Value<string>();
  125. mid.factoryname = jObject["factoryName"].Value<string>();
  126. mid.factoryNum = jObject["factoryNum"].Value<string>();
  127. mid.version = jObject["version"].Value<string>();
  128. mid.quantity = jObject["quantity"].Value<string>();
  129. mid.projectid = jObject["projectId"].Value<string>();
  130. mid.clienttype = jObject["clientType"].Value<string>();
  131. mid.host = jObject["host"].Value<string>();
  132. mid.whiteType = jObject["whiteType"].Value<string>();
  133. object a = jObject["rokuCustomer"];
  134. if (jObject["rokuCustomer"].ToString().Length > 0)
  135. mid.rokuCustomer = new RokuCustomer()
  136. {
  137. id = JSON_SeleteNode(jObject["rokuCustomer"], "id").Trim(),
  138. ordernum = JSON_SeleteNode(jObject["rokuCustomer"], "ordernum").Trim(),
  139. brand = JSON_SeleteNode(jObject["rokuCustomer"], "brand").Trim(),
  140. region = JSON_SeleteNode(jObject["rokuCustomer"], "region").Trim(),
  141. oemmodel = JSON_SeleteNode(jObject["rokuCustomer"], "oemmodel").Trim(),
  142. supporturl = JSON_SeleteNode(jObject["rokuCustomer"], "supporturl").Trim(),
  143. supportphone = JSON_SeleteNode(jObject["rokuCustomer"], "supportphone").Trim(),
  144. productiondate = JSON_SeleteNode(jObject["rokuCustomer"], "productiondate").Trim(),
  145. remotetype = JSON_SeleteNode(jObject["rokuCustomer"], "remotetype").Trim(),
  146. updatetime = JSON_SeleteNode(jObject["rokuCustomer"], "updatetime").Trim(),
  147. createtime = JSON_SeleteNode(jObject["rokuCustomer"], "createtime").Trim(),
  148. isdelete = JSON_SeleteNode(jObject["rokuCustomer"], "isdelete").Trim()
  149. };
  150. mid.keytype = new Dictionary<string, string>();
  151. foreach (var ss in jObject["obj"]) //查找某个字段与值
  152. {
  153. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  154. }
  155. if (url == Serverurl.Testurl)
  156. mid.host = "http://test.idmanage.qhmoka.com/IDManage";
  157. if (mid.code == "1000")
  158. return true;
  159. else
  160. return false;
  161. }
  162. catch (Exception ex)
  163. {
  164. Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  165. ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  166. MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
  167. return false;
  168. }
  169. }
  170. /// <summary>
  171. /// 获取预绑定模式下的key包地址
  172. /// </summary>
  173. /// <param name="midInfo"></param>
  174. /// <param name="order"></param>
  175. /// <param name="sqliteConn"></param>
  176. /// <param name="midAddress"></param>
  177. /// <returns></returns>
  178. public static bool GetMidAddress(MidList midInfo, string order, SQLiteConnection sqliteConn, out MidAddress midAddress)
  179. {
  180. midAddress = new MidAddress();
  181. HttpHelper http = new HttpHelper();
  182. HttpItem item = new HttpItem()
  183. {
  184. URL = midInfo.host + "/getofflinelist.do?",//URL这里都是测试URl   必需项
  185. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  186. //Encoding = Encoding.Default,
  187. Method = "post",//URL     可选项 默认为Get
  188. Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
  189. KeepAlive = false
  190. };
  191. item.ContentType = "application/x-www-form-urlencoded";
  192. HttpResult result = http.GetHtml(item);
  193. string ParseText = result.Html;
  194. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  195. {
  196. }
  197. else
  198. {
  199. Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  200. CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  201. return false;
  202. }
  203. try
  204. {
  205. JObject jObject = JObject.Parse(ParseText);
  206. midAddress.des = JSON_SeleteNode(jObject, "des");
  207. midAddress.code = JSON_SeleteNode(jObject, "code");
  208. midAddress.order = JSON_SeleteNode(jObject, "order_number");
  209. midAddress.number = JSON_SeleteNode(jObject, "order_quantity");
  210. midAddress.pid = JSON_SeleteNode(jObject, "project_id");
  211. midAddress.ctype = JSON_SeleteNode(jObject, "client_type");
  212. midAddress.purl = JSON_SeleteNode(jObject, "packet_url");
  213. midAddress.psize = JSON_SeleteNode(jObject, "packet_size");
  214. midAddress.pmd5 = JSON_SeleteNode(jObject, "packet_md5");
  215. midAddress.version = JSON_SeleteNode(jObject, "soft_version");
  216. midAddress.host = midInfo.host;
  217. Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  218. return true;
  219. }
  220. catch (Exception ex)
  221. {
  222. Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  223. CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  224. MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
  225. return false;
  226. }
  227. }
  228. /// <summary>
  229. /// 获取预绑定模式下的key包地址
  230. /// </summary>
  231. /// <param name="midInfo"></param>
  232. /// <param name="order"></param>
  233. /// <param name="sqliteConn"></param>
  234. /// <param name="midAddress"></param>
  235. /// <returns></returns>
  236. public static bool GetMidAddress2(MidList midInfo, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
  237. {
  238. midAddressList = new List<MidAddress>();
  239. HttpHelper http = new HttpHelper();
  240. HttpItem item = new HttpItem()
  241. {
  242. URL = midInfo.host + "/getofflinelist.do?",//URL这里都是测试URl   必需项
  243. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  244. //Encoding = Encoding.Default,
  245. Method = "post",//URL     可选项 默认为Get
  246. Postdata = ("orderNumber=" + order + "&mac=" + HttpUtility.UrlEncode(TestMode.MAC)),
  247. KeepAlive = false
  248. };
  249. item.ContentType = "application/x-www-form-urlencoded";
  250. HttpResult result = http.GetHtml(item);
  251. string ParseText = result.Html;
  252. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  253. {
  254. }
  255. else
  256. {
  257. Log.WriteErrorLog("\r\nFail to get Mid address:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  258. CommonMethod.ReportErrormsg("Fail to get Mid address", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  259. return false;
  260. }
  261. try
  262. {
  263. JObject jObject = JObject.Parse(ParseText);
  264. if (jObject["data"] != null)
  265. {
  266. foreach (var data in jObject["data"])
  267. {
  268. midAddressList.Add(new MidAddress()
  269. {
  270. des = JSON_SeleteNode(jObject, "des"),
  271. code = JSON_SeleteNode(jObject, "code"),
  272. order = data["order_number"].ToObject<string>(),
  273. number = data["order_quantity"].ToObject<string>(),
  274. pid = data["project_id"].ToObject<string>(),
  275. ctype = data["client_type"].ToObject<string>(),
  276. purl = data["packet_url"].ToObject<string>(),
  277. psize = data["packet_size"].ToObject<string>(),
  278. pmd5 = data["packet_md5"].ToObject<string>(),
  279. version = data["soft_version"].ToObject<string>(),
  280. host = midInfo.host
  281. });
  282. }
  283. }
  284. Log.WriteGetKeyLog("\r\nGet Mid address success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  285. return true;
  286. }
  287. catch (Exception ex)
  288. {
  289. Log.WriteErrorLog("\r\nFail to parse MID address," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  290. CommonMethod.ReportErrormsg("Fail to parse MID address", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  291. MessageBox.Show("Fail to parse MIDAddress info\r\n " + ex.Message);
  292. return false;
  293. }
  294. }
  295. /// <summary>
  296. /// 解析XML格式的DID
  297. /// </summary>
  298. /// <param name="str"></param>
  299. /// <param name="node"></param>
  300. /// <param name="node2"></param>
  301. /// <param name="code"></param>
  302. /// <param name="desc"></param>
  303. /// <param name="value"></param>
  304. /// <returns></returns>
  305. public static bool GetDIDKeyXml(string str, string node, string node2, out string code, out string desc, out string value)
  306. {
  307. code = "";
  308. value = "";
  309. try
  310. {
  311. XmlDocument xml = new XmlDocument();
  312. //xml.Load(path);
  313. xml.LoadXml(str);
  314. code = xml.SelectSingleNode(node).Attributes.GetNamedItem("code").InnerText;
  315. desc = xml.SelectSingleNode(node).Attributes.GetNamedItem("desc").InnerText;
  316. if (code == "200")
  317. {
  318. value = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("deviceid").InnerText;
  319. string CRC32 = xml.SelectSingleNode(node + "//" + node2).Attributes.GetNamedItem("crc32").InnerText;
  320. if (CrcUtils.CRC32(value) == Convert.ToUInt32(CRC32))
  321. {
  322. return true;
  323. }
  324. else
  325. {
  326. desc = "CRC32 error";
  327. return false;
  328. }
  329. }
  330. return false;
  331. }
  332. catch (Exception ex)
  333. {
  334. desc = ex.Message;
  335. return false;
  336. }
  337. }
  338. /// <summary>
  339. /// 解析其他keys
  340. /// </summary>
  341. /// <param name="url"></param>
  342. /// <param name="keymessage"></param>
  343. /// <param name="keytype"></param>
  344. /// <param name="sqliteConn"></param>
  345. /// <param name="key"></param>
  346. /// <param name="error"></param>
  347. /// <returns></returns>
  348. public static bool GetKeys(string url, string keymessage, string sn, string keytype, SQLiteConnection sqliteConn, out string key, out string error, string order, out string md5)
  349. {
  350. string code;
  351. string desc;
  352. error = "";
  353. key = "";
  354. md5 = "";
  355. HttpHelper http = new HttpHelper();
  356. HttpItem item = new HttpItem()
  357. {
  358. Encoding = Encoding.Default,
  359. Method = "post",
  360. ContentType = "application/x-www-form-urlencoded",
  361. KeepAlive = false
  362. };
  363. // 计算函数耗时;
  364. Stopwatch watch = new Stopwatch();
  365. watch.Start();
  366. switch (keymessage)
  367. {
  368. case "DeviceID":
  369. {
  370. item.URL = url + "/getid.do?";
  371. item.Postdata = "devicetype=tcl_unknown_model" + "&sn=" + sn;
  372. if (sn.Trim().Length > 0)
  373. item.Postdata += "&order=" + order;
  374. HttpResult result = http.GetHtml(item);
  375. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  376. {
  377. Log.WriteGetKeyLog("\r\nGetDeviceID:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  378. if (Xmlconfig.GetDIDKeyXml(result.Html, "response", "id", out code, out desc, out key))
  379. {
  380. //
  381. }
  382. else
  383. {
  384. error = desc;
  385. ReportErrormsg("Fail to parse DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  386. return false;
  387. }
  388. }
  389. else
  390. {
  391. error = result.StatusDescription;
  392. ReportErrormsg("Fail to get DID", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  393. return false;
  394. }
  395. break;
  396. }
  397. case "MAC":
  398. {
  399. item.URL = url + "/getmac.do?";
  400. item.Postdata = "typeString=" + keytype + "&sn=" + sn;
  401. if (sn.Trim().Length > 0)
  402. item.Postdata += "&order=" + order;
  403. HttpResult result = http.GetHtml(item);
  404. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  405. {
  406. Log.WriteGetKeyLog("\r\nGetMac:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  407. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "mac", out code, out desc, out key, out md5))
  408. {
  409. }
  410. else
  411. {
  412. error = desc;
  413. ReportErrormsg("Fail to parse Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  414. return false;
  415. }
  416. }
  417. else
  418. {
  419. error = result.StatusDescription;
  420. ReportErrormsg("Fail to get Mac", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  421. return false;
  422. }
  423. break;
  424. }
  425. case "HDCP_KEY":
  426. {
  427. item.URL = url + "/gethdcpkey.do?";
  428. item.Postdata = "type=" + keytype + "&sn=" + sn;
  429. if (sn.Trim().Length > 0)
  430. item.Postdata += "&order=" + order;
  431. HttpResult result = http.GetHtml(item);
  432. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  433. {
  434. Log.WriteGetKeyLog("\r\nGetHDCP_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  435. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  436. {
  437. }
  438. else
  439. {
  440. error = desc;
  441. ReportErrormsg("Fail to parse hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  442. return false;
  443. }
  444. }
  445. else
  446. {
  447. error = result.StatusDescription;
  448. ReportErrormsg("Fail to get hdcp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  449. return false;
  450. }
  451. break;
  452. }
  453. case "CI_PLUS_KEY":
  454. {
  455. item.URL = url + "/getcikey.do?";
  456. item.Postdata = "type=" + keytype + "&sn=" + sn;
  457. if (sn.Trim().Length > 0)
  458. item.Postdata += "&order=" + order;
  459. HttpResult result = http.GetHtml(item);
  460. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  461. {
  462. Log.WriteGetKeyLog("\r\nGetCI_PLUS_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  463. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  464. {
  465. }
  466. else
  467. {
  468. error = desc;
  469. ReportErrormsg("Fail to parse ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  470. return false;
  471. }
  472. }
  473. else
  474. {
  475. error = result.StatusDescription;
  476. ReportErrormsg("Fail to get ciplus", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  477. return false;
  478. }
  479. break;
  480. }
  481. case "WiDi":
  482. {
  483. item.URL = url + "/getwidi.do?";
  484. item.Postdata = "type=" + keytype + "&sn=" + sn;
  485. if (sn.Trim().Length > 0)
  486. item.Postdata += "&order=" + order;
  487. HttpResult result = http.GetHtml(item);
  488. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  489. {
  490. Log.WriteGetKeyLog("\r\nGetWiDi:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  491. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  492. {
  493. }
  494. else
  495. {
  496. error = desc;
  497. ReportErrormsg("Fail to parse widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  498. return false;
  499. }
  500. }
  501. else
  502. {
  503. error = result.StatusDescription;
  504. ReportErrormsg("Fail to get widi", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  505. return false;
  506. }
  507. break;
  508. }
  509. case "HDCP2.2_KEY":
  510. {
  511. item.URL = url + "/gethdcpkey2.do?";
  512. item.Postdata = "type=" + keytype + "&sn=" + sn;
  513. if (sn.Trim().Length > 0)
  514. item.Postdata += "&order=" + order;
  515. HttpResult result = http.GetHtml(item);
  516. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  517. {
  518. Log.WriteGetKeyLog("\r\nGetHDCP2.2_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  519. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  520. {
  521. }
  522. else
  523. {
  524. error = desc;
  525. ReportErrormsg("Fail to parse hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  526. return false;
  527. }
  528. }
  529. else
  530. {
  531. error = result.StatusDescription;
  532. ReportErrormsg("Fail to get hdcp22", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  533. return false;
  534. }
  535. break;
  536. }
  537. case "NETFILX_ESN":
  538. {
  539. item.URL = url + "/getnetfilxesn.do?";
  540. item.Postdata = "type=" + keytype + "&sn=" + sn;
  541. if (sn.Trim().Length > 0)
  542. item.Postdata += "&order=" + order;
  543. HttpResult result = http.GetHtml(item);
  544. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  545. {
  546. Log.WriteGetKeyLog("\r\nGetNETFILX_ESN:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  547. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "esn", out code, out desc, out key, out md5))
  548. {
  549. }
  550. else
  551. {
  552. error = desc;
  553. ReportErrormsg("Fail to parse esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  554. return false;
  555. }
  556. }
  557. else
  558. {
  559. error = result.StatusDescription;
  560. ReportErrormsg("Fail to get esn", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  561. return false;
  562. }
  563. break;
  564. }
  565. case "MGK_KEY":
  566. {
  567. item.URL = url + "/getmgk.do?";
  568. item.Postdata = "type=" + keytype + "&sn=" + sn;
  569. if (sn.Trim().Length > 0)
  570. item.Postdata += "&order=" + order;
  571. HttpResult result = http.GetHtml(item);
  572. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  573. {
  574. Log.WriteGetKeyLog("\r\nGetMGK:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  575. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "key", out code, out desc, out key, out md5))
  576. {
  577. }
  578. else
  579. {
  580. error = desc;
  581. ReportErrormsg("Fail to parse MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  582. return false;
  583. }
  584. }
  585. else
  586. {
  587. error = result.StatusDescription;
  588. ReportErrormsg("Fail to get MGK", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  589. return false;
  590. }
  591. break;
  592. }
  593. case "Fairplay_KEY":
  594. {
  595. item.URL = url + "/getfairplay.do?";
  596. item.Postdata = "type=" + keytype + "&sn=" + sn;
  597. if (sn.Trim().Length > 0)
  598. item.Postdata += "&order=" + order;
  599. HttpResult result = http.GetHtml(item);
  600. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  601. {
  602. Log.WriteGetKeyLog("\r\nGetFairplay:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  603. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "fairplay", out code, out desc, out key, out md5))
  604. {
  605. }
  606. else
  607. {
  608. error = desc;
  609. ReportErrormsg("Fail to parse Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  610. return false;
  611. }
  612. }
  613. else
  614. {
  615. error = result.StatusDescription;
  616. ReportErrormsg("Fail to get Fairplay", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  617. return false;
  618. }
  619. break;
  620. }
  621. case "ECP_KEY":
  622. {
  623. item.URL = url + "/getecp.do?";
  624. item.Postdata = "type=" + keytype + "&sn=" + sn;
  625. if (sn.Trim().Length > 0)
  626. item.Postdata += "&order=" + order;
  627. HttpResult result = http.GetHtml(item);
  628. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  629. {
  630. Log.WriteGetKeyLog("\r\nGetecp:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  631. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "ecp", out code, out desc, out key, out md5))
  632. {
  633. }
  634. else
  635. {
  636. error = desc;
  637. ReportErrormsg("Fail to parse ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  638. return false;
  639. }
  640. }
  641. else
  642. {
  643. error = result.StatusDescription;
  644. ReportErrormsg("Fail to get ecp", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  645. return false;
  646. }
  647. break;
  648. }
  649. case "LEK":
  650. {
  651. item.URL = url + "/getlek.do?";
  652. item.Postdata = "type=" + keytype + "&sn=" + sn;
  653. if (sn.Trim().Length > 0)
  654. item.Postdata += "&order=" + order;
  655. HttpResult result = http.GetHtml(item);
  656. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  657. {
  658. Log.WriteGetKeyLog("\r\nGetlek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  659. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "lek", out code, out desc, out key, out md5))
  660. {
  661. }
  662. else
  663. {
  664. error = desc;
  665. ReportErrormsg("Fail to parse lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  666. return false;
  667. }
  668. }
  669. else
  670. {
  671. error = result.StatusDescription;
  672. ReportErrormsg("Fail to get lek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  673. return false;
  674. }
  675. break;
  676. }
  677. case "PEK":
  678. {
  679. item.URL = url + "/getpek.do?";
  680. item.Postdata = "type=" + keytype + "&sn=" + sn;
  681. if (sn.Trim().Length > 0)
  682. item.Postdata += "&order=" + order;
  683. HttpResult result = http.GetHtml(item);
  684. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  685. {
  686. Log.WriteGetKeyLog("\r\nGetpek:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  687. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "pek", out code, out desc, out key, out md5))
  688. {
  689. }
  690. else
  691. {
  692. error = desc;
  693. ReportErrormsg("Fail to parse pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  694. return false;
  695. }
  696. }
  697. else
  698. {
  699. error = result.StatusDescription;
  700. ReportErrormsg("Fail to get pek", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  701. return false;
  702. }
  703. break;
  704. }
  705. case "PlayReady_key":
  706. {
  707. item.URL = url + "/getplayready.do?";
  708. item.Postdata = "type=" + keytype + "&sn=" + sn;
  709. if (sn.Trim().Length > 0)
  710. item.Postdata += "&order=" + order;
  711. HttpResult result = http.GetHtml(item);
  712. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  713. {
  714. Log.WriteGetKeyLog("\r\nGetplayready:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  715. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "playReady", out code, out desc, out key, out md5))
  716. {
  717. }
  718. else
  719. {
  720. error = desc;
  721. ReportErrormsg("Fail to parse playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  722. return false;
  723. }
  724. }
  725. else
  726. {
  727. error = result.StatusDescription;
  728. ReportErrormsg("Fail to get playready", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  729. return false;
  730. }
  731. break;
  732. }
  733. case "Hashkey":
  734. {
  735. item.URL = url + "/gethash.do?";
  736. item.Postdata = "type=" + keytype + "&sn=" + sn;
  737. if (sn.Trim().Length > 0)
  738. item.Postdata += "&order=" + order;
  739. HttpResult result = http.GetHtml(item);
  740. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  741. {
  742. Log.WriteGetKeyLog("\r\nGethash:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  743. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "hash", out code, out desc, out key, out md5))
  744. {
  745. }
  746. else
  747. {
  748. error = desc;
  749. ReportErrormsg("Fail to parse hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  750. return false;
  751. }
  752. }
  753. else
  754. {
  755. error = result.StatusDescription;
  756. ReportErrormsg("Fail to get hash", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  757. return false;
  758. }
  759. break;
  760. }
  761. case "YouTube_KEY":
  762. {
  763. item.URL = url + "/getYoutubeKey.do?";
  764. item.Postdata = "type=" + keytype + "&sn=" + sn;
  765. if (sn.Trim().Length > 0)
  766. item.Postdata += "&order=" + order;
  767. HttpResult result = http.GetHtml(item);
  768. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  769. {
  770. Log.WriteGetKeyLog("\r\nGet youtube key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  771. if (Xmlconfig.GetOthersKeyXml(result.Html, "response", "youtubeKey", out code, out desc, out key, out md5))
  772. {
  773. }
  774. else
  775. {
  776. error = desc;
  777. ReportErrormsg("Fail to parse youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  778. return false;
  779. }
  780. }
  781. else
  782. {
  783. error = result.StatusDescription;
  784. ReportErrormsg("Fail to get youtube key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  785. return false;
  786. }
  787. break;
  788. }
  789. }
  790. watch.Stop();
  791. Log.WriteInfoLog(string.Format("[GetKeys] order={0},sn={1},keytype={2},keymessage={3}, Elapsed={4}", order,sn,keytype,keymessage,watch.Elapsed.TotalMilliseconds));
  792. return true;
  793. }
  794. public static bool GetWidevineAnAttestationKey(
  795. string url,
  796. string sn,
  797. string keytype,
  798. SQLiteConnection sqliteConn,
  799. out bool isAndroidTV,
  800. out string Widevinekey,
  801. out string Attestationkey,
  802. out string error,
  803. string order,
  804. out string AttestationMd5)
  805. {
  806. string code;
  807. string desc;
  808. isAndroidTV = false;
  809. error = "";
  810. Widevinekey = "";
  811. Attestationkey = "";
  812. AttestationMd5 = "";
  813. HttpHelper http = new HttpHelper();
  814. HttpItem item = new HttpItem()
  815. {
  816. Encoding = Encoding.Default,
  817. Method = "post",
  818. ContentType = "application/x-www-form-urlencoded",
  819. KeepAlive = false
  820. };
  821. // 计算函数耗时;
  822. Stopwatch watch = new Stopwatch();
  823. watch.Start();
  824. item.URL = url + "/getWidevineAndAttestation.do?";
  825. item.Postdata = "type=" + keytype + "&order=" + order + "&sn=" + sn;
  826. HttpResult result = http.GetHtml(item);
  827. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  828. {
  829. Log.WriteGetKeyLog("\r\nGetWidevine_KEY:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  830. if (!Xmlconfig.GetWidevineAndAttestationKeyXml(result.Html, "response", out code, out desc, out isAndroidTV, out Widevinekey, out Attestationkey, out AttestationMd5))
  831. {
  832. error = desc;
  833. ReportErrormsg("Fail to parse widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  834. return false;
  835. }
  836. }
  837. else
  838. {
  839. error = result.StatusDescription;
  840. ReportErrormsg("Fail to get widevineAndAttestation", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  841. return false;
  842. }
  843. watch.Stop();
  844. Log.WriteInfoLog(string.Format("[getWidevineAndAttestation] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
  845. return true;
  846. }
  847. public static bool GetAcasKey(string url, string keymessage, string sn, string keytype, SQLiteConnection sqliteConn, string order, out string acaskey_data, out string acaskey_datamd5, out string acaskey_tool, out string acaskey_toolmd5, out string error)
  848. {
  849. string code;
  850. string desc;
  851. error = "";
  852. acaskey_data = "";
  853. acaskey_datamd5 = "";
  854. acaskey_tool = "";
  855. acaskey_toolmd5 = "";
  856. HttpHelper http = new HttpHelper();
  857. HttpItem item = new HttpItem()
  858. {
  859. Encoding = Encoding.Default,
  860. Method = "post",
  861. ContentType = "application/x-www-form-urlencoded",
  862. KeepAlive = false
  863. };
  864. // 计算函数耗时;
  865. Stopwatch watch = new Stopwatch();
  866. watch.Start();
  867. item.URL = url + "/getAcasKey.do?";
  868. item.Postdata = "type=" + keytype + "&sn=" + sn;
  869. if (sn.Trim().Length > 0)
  870. item.Postdata += "&order=" + order;
  871. HttpResult result = http.GetHtml(item);
  872. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  873. {
  874. Log.WriteGetKeyLog("\r\nGet ACAS key:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  875. if (Xmlconfig.Get2KeyInfoFromXml(result.Html, "acasKey_data", "acasKey_tool", out code, out desc, out acaskey_data, out acaskey_datamd5, out acaskey_tool, out acaskey_toolmd5))
  876. {
  877. }
  878. else
  879. {
  880. error = desc;
  881. ReportErrormsg("Fail to parse ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  882. return false;
  883. }
  884. }
  885. else
  886. {
  887. error = result.StatusDescription;
  888. ReportErrormsg("Fail to get ACAS key", error + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html, sqliteConn);
  889. return false;
  890. }
  891. watch.Stop();
  892. Log.WriteInfoLog(string.Format("[getAcasKey] order={0},sn={1},keytype={2},Elapsed={3}", order, sn, keytype, watch.Elapsed.TotalMilliseconds));
  893. return true;
  894. }
  895. /// <summary>
  896. /// 异常上报
  897. /// </summary>
  898. /// <param name="reportType"></param>
  899. /// <param name="reportData"></param>
  900. /// <param name="sqliteConn"></param>
  901. /// <returns></returns>
  902. public static bool ReportErrormsg(string reportType, string reportData, SQLiteConnection sqliteConn)
  903. {
  904. // 计算函数耗时;
  905. Stopwatch watch = new Stopwatch();
  906. watch.Start();
  907. ErrorInfo ErrorInfo1 = new ErrorInfo { reportType = reportType, reportData = reportData.Replace("'", ""), version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), factory = FactoryName, mac = TestMode.MAC, reportTime = System.DateTime.Now.ToString(("yyyy-MM-dd HH:mm:ss")) };
  908. string jsonError = Newtonsoft.Json.JsonConvert.SerializeObject(ErrorInfo1, Newtonsoft.Json.Formatting.Indented);
  909. HttpHelper http = new HttpHelper();
  910. HttpItem item = new HttpItem()
  911. {
  912. URL = TestMode.errorreportServerurl,//URL这里都是测试URl   必需项
  913. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  914. //Encoding = Encoding.Default,
  915. Method = "post",//URL     可选项 默认为Get
  916. Postdata = jsonError,
  917. PostEncoding = Encoding.UTF8,
  918. KeepAlive = false
  919. };
  920. item.ContentType = "application/json;charset=utf-8";
  921. HttpResult result = http.GetHtml(item);
  922. string ParseText = result.Html;
  923. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  924. {
  925. Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  926. }
  927. else
  928. {
  929. if (HTTPChecker(item.URL))
  930. SQLiteHelper.InsertDelayErrorReport(sqliteConn, new object[] { item.URL, item.Postdata });
  931. Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  932. return false;
  933. }
  934. try
  935. {
  936. JObject jObject = JObject.Parse(ParseText);
  937. string message = jObject["message"].Value<string>();
  938. string code = jObject["code"].Value<string>();
  939. if (code != "1000")
  940. {
  941. Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  942. return false;
  943. }
  944. watch.Stop();
  945. Log.WriteInfoLog(string.Format("[ReportErrormsg] Elapsed={0}", watch.Elapsed.TotalMilliseconds));
  946. return true;
  947. }
  948. catch (Exception ex)
  949. {
  950. Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + jsonError);
  951. return false;
  952. }
  953. }
  954. /// <summary>
  955. /// 上报预绑定包下载结果
  956. /// </summary>
  957. /// <param name="url"></param>
  958. /// <param name="order"></param>
  959. /// <param name="sqliteConn"></param>
  960. /// <returns></returns>
  961. public static bool ReportDownloadStatus(string url, string order, SQLiteConnection sqliteConn)
  962. {
  963. HttpHelper http = new HttpHelper();
  964. HttpItem item = new HttpItem()
  965. {
  966. URL = url + "/getreportofflinesn.do?",//URL这里都是测试URl   必需项
  967. Encoding = null,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  968. //Encoding = Encoding.Default,
  969. Method = "post",//URL     可选项 默认为Get
  970. Postdata = ("orderNumber =" + order),
  971. KeepAlive = false
  972. };
  973. item.ContentType = "application/x-www-form-urlencoded";
  974. HttpResult result = http.GetHtml(item);
  975. string ParseText = result.Html;
  976. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  977. {
  978. //
  979. }
  980. else
  981. {
  982. Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  983. CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  984. return false;
  985. }
  986. try
  987. {
  988. JObject jObject = JObject.Parse(ParseText);
  989. string des = JSON_SeleteNode(jObject, "des");
  990. string code = JSON_SeleteNode(jObject, "code");
  991. string data = JSON_SeleteNode(jObject, "data");
  992. if (code == "1000")
  993. return true;
  994. else
  995. {
  996. Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  997. CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  998. return false;
  999. }
  1000. }
  1001. catch (Exception ex)
  1002. {
  1003. MessageBox.Show(ex.Message);
  1004. Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order));
  1005. CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/getreportofflinesn.do?" + "\r\nPostdata:" + ("orderNumber =" + order), sqliteConn);
  1006. return false;
  1007. }
  1008. }
  1009. /// <summary>
  1010. /// 生成DB格式key json字符串
  1011. /// </summary>
  1012. /// <param name="keyInfo"></param>
  1013. /// <param name="keydata"></param>
  1014. /// <param name="error"></param>
  1015. /// <returns></returns>
  1016. public static bool CreateDBkeyString(KeyInfo keyInfo, out string keydata, out string error)
  1017. {
  1018. keydata = "";
  1019. error = "";
  1020. try
  1021. {
  1022. DBKeysStringFormat DBKeysStringFormat1 = new DBKeysStringFormat { cikey = keyInfo.CI_plus == null ? "" : keyInfo.CI_plus, esn = keyInfo.ESN == null ? "" : keyInfo.ESN, hdcp = keyInfo.HDCP == null ? "" : keyInfo.HDCP, widevine = keyInfo.Widevine == null ? "" : keyInfo.Widevine, hdcp22 = keyInfo.HDCP22 == null ? "" : keyInfo.HDCP22, did = keyInfo.DID == null ? "" : keyInfo.DID, mac = keyInfo.Mac == null ? "" : keyInfo.Mac, widi = keyInfo.WiDi == null ? "" : keyInfo.WiDi, attestation = keyInfo.Attestation == null ? "" : keyInfo.Attestation, mgk = keyInfo.MGK == null ? "" : keyInfo.MGK };
  1023. keydata = Newtonsoft.Json.JsonConvert.SerializeObject(DBKeysStringFormat1, Newtonsoft.Json.Formatting.Indented);
  1024. return true;
  1025. }
  1026. catch (Exception ex)
  1027. {
  1028. error = ex.Message;
  1029. return false;
  1030. }
  1031. }
  1032. /// <summary>
  1033. /// 获取相应json子节点的值
  1034. /// </summary>
  1035. /// <param name="childnodelist"></param>
  1036. public static string JSON_SeleteNode(JToken json, string ReName)
  1037. {
  1038. try
  1039. {
  1040. string result = "";
  1041. //这里6.0版块可以用正则匹配
  1042. var node = json.SelectToken("$.." + ReName);
  1043. if (node != null)
  1044. {
  1045. //判断节点类型
  1046. if (node.Type == JTokenType.String || node.Type == JTokenType.Integer || node.Type == JTokenType.Float)
  1047. {
  1048. //返回string值
  1049. result = node.Value<object>().ToString();
  1050. }
  1051. }
  1052. return result;
  1053. }
  1054. catch (Exception ex)
  1055. {
  1056. return "";
  1057. }
  1058. }
  1059. /// <summary>
  1060. /// 确认是否为有效的url(检测开头是否为http://或者https://)
  1061. /// </summary>
  1062. /// <param name="Value"></param>
  1063. /// <returns></returns>
  1064. public static bool HTTPChecker(string Value)
  1065. {
  1066. try
  1067. {
  1068. if ((Value.Substring(0, 7) == "http://") || (Value.Substring(0, 8) == "https://"))
  1069. {
  1070. return true;
  1071. }
  1072. else
  1073. return false;
  1074. }
  1075. catch (Exception ex)
  1076. {
  1077. return false;
  1078. }
  1079. }
  1080. /// <summary>
  1081. /// 检查是否能正常访问网络
  1082. /// </summary>
  1083. /// <param name="url"></param>
  1084. /// <returns></returns>
  1085. public static bool CheckUrlConnection(string url)
  1086. {
  1087. try
  1088. {
  1089. HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
  1090. myRequest.Method = "HEAD"; //设置提交方式可以为"get","head"等
  1091. myRequest.Timeout = 10000; //设置网页响应时间长度
  1092. myRequest.AllowAutoRedirect = false;//是否允许自动重定向
  1093. myRequest.UseDefaultCredentials = true;
  1094. HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
  1095. myRequest.UseDefaultCredentials = true;//权限设置
  1096. return (myResponse.StatusCode == HttpStatusCode.OK);//返回响应的状态
  1097. }
  1098. catch (Exception ex)
  1099. {
  1100. return false;
  1101. }
  1102. }
  1103. /// <summary>
  1104. /// 指定目录创建文件夹
  1105. /// </summary>
  1106. /// <param name="path"></param>
  1107. public static void CreateDirectory(string path)
  1108. {
  1109. if (!Directory.Exists(path))//如果不存在就创建file文件夹
  1110. {
  1111. Directory.CreateDirectory(path);
  1112. }
  1113. }
  1114. /// <summary>
  1115. /// 在线下载抄写模式抄写的上报
  1116. /// </summary>
  1117. /// <param name="content"></param>
  1118. /// <returns></returns>
  1119. public static bool UploadCopyResult(string content, string url, SQLiteConnection sqliteConn, string order, bool repeatupload, string id, int timeout)
  1120. {
  1121. if (timeout < 5000)
  1122. timeout = 5000;
  1123. HttpHelper http = new HttpHelper();
  1124. HttpItem item = new HttpItem()
  1125. {
  1126. Encoding = Encoding.UTF8,
  1127. Method = "post",
  1128. ContentType = "application/x-www-form-urlencoded",
  1129. Timeout = timeout,
  1130. KeepAlive = false
  1131. };
  1132. item.PostEncoding = Encoding.UTF8;
  1133. item.URL = url;
  1134. item.Postdata = content;
  1135. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  1136. stopwatch.Start();
  1137. HttpResult result = http.GetHtml(item);
  1138. stopwatch.Stop();
  1139. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  1140. stopwatch.Reset();
  1141. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1142. {
  1143. if (Xmlconfig.ReportXml(result.Html, "response", out string code, out string desc))
  1144. {
  1145. Log.WriteGetKeyLog("\r\nUpload copy status success:\r\nUsing time:" + usingtime + "ms\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  1146. return true;
  1147. }
  1148. else
  1149. {
  1150. CommonMethod.ReportErrormsg("Fail to parse copy result return", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
  1151. Log.WriteErrorLog(code + "Error");
  1152. if (repeatupload)
  1153. {
  1154. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1155. }
  1156. return false;
  1157. }
  1158. }
  1159. else
  1160. {
  1161. if (repeatupload)
  1162. return false;
  1163. if (CommonMethod.HTTPChecker(item.URL))
  1164. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, item.URL, item.Postdata });
  1165. CommonMethod.ReportErrormsg("Fail to upload copy result", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, sqliteConn);
  1166. return true;
  1167. }
  1168. }
  1169. /// <summary>
  1170. /// 本地DB存储的异常重新上报
  1171. /// </summary>
  1172. /// <param name="reportType"></param>
  1173. /// <param name="reportData"></param>
  1174. /// <param name="sqliteConn"></param>
  1175. /// <returns></returns>
  1176. public static bool ReportErrormsg2(string url, string content, out bool mark)
  1177. {
  1178. mark = false;
  1179. HttpHelper http = new HttpHelper();
  1180. HttpItem item = new HttpItem()
  1181. {
  1182. URL = url,//URL这里都是测试URl   必需项
  1183. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1184. //Encoding = Encoding.Default,
  1185. Method = "post",//URL     可选项 默认为Get
  1186. Postdata = content,
  1187. PostEncoding = Encoding.UTF8,
  1188. KeepAlive = false
  1189. };
  1190. item.ContentType = "application/json;charset=utf-8";
  1191. HttpResult result = http.GetHtml(item);
  1192. string ParseText = result.Html;
  1193. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1194. {
  1195. mark = true;
  1196. Log.WriteGetKeyLog("\r\nReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1197. }
  1198. else
  1199. {
  1200. Log.WriteErrorLog("\r\nFail to ReportErrormsg:\r\n" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1201. return false;
  1202. }
  1203. try
  1204. {
  1205. JObject jObject = JObject.Parse(ParseText);
  1206. string message = jObject["message"].Value<string>();
  1207. string code = jObject["code"].Value<string>();
  1208. if (code == "1000")
  1209. return true;
  1210. else
  1211. {
  1212. Log.WriteErrorLog("\r\nError report return error:\r\n" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1213. return false;
  1214. }
  1215. }
  1216. catch (Exception ex)
  1217. {
  1218. Log.WriteErrorLog("\r\nFail to parse Error report return info," + ex.Message + ":" + ParseText + "\r\nAddress:" + TestMode.errorreportServerurl + "\r\nPostdata:" + content);
  1219. return false;
  1220. }
  1221. }
  1222. /// <summary>
  1223. /// 判断目标字符串是否只有数字和字母
  1224. /// </summary>
  1225. /// <param name="value">目标字符串</param>
  1226. /// <returns></returns>
  1227. public static bool IsNumberAndWord(string value)
  1228. {
  1229. if (value is null)
  1230. return false;
  1231. Regex r = new Regex(@"^[a-zA-Z0-9]+$");
  1232. return r.Match(value).Success;
  1233. }
  1234. public static bool InsertJsonConfig(string node, string key)
  1235. {
  1236. JObject jObject;
  1237. using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
  1238. {
  1239. using (JsonTextReader reader = new JsonTextReader(file))
  1240. {
  1241. jObject = (JObject)JToken.ReadFrom(reader);
  1242. jObject[node][key] = true;
  1243. }
  1244. }
  1245. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1246. {
  1247. writer.Write(jObject.ToString());
  1248. }
  1249. return true;
  1250. }
  1251. public static bool AddJsonConfig(string key, object value)
  1252. {
  1253. JObject jObject;
  1254. using (StreamReader file = new StreamReader(LocalPath.localpath + "\\Config.json"))
  1255. {
  1256. using (JsonTextReader reader = new JsonTextReader(file))
  1257. {
  1258. jObject = (JObject)JToken.ReadFrom(reader);
  1259. jObject.Add(key, (JToken)value);
  1260. }
  1261. }
  1262. using (StreamWriter writer = new StreamWriter(LocalPath.localpath + "\\Config.json"))
  1263. {
  1264. writer.Write(jObject.ToString());
  1265. }
  1266. return false;
  1267. }
  1268. /// <summary>
  1269. /// 预下载模式抄写的上报
  1270. /// </summary>
  1271. /// <param name="copydate">烧录时间</param>
  1272. /// <returns></returns>
  1273. public static bool UploadPreloadCopyResult(string host, string copydate, string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout)
  1274. {
  1275. string ParseText = "";
  1276. bool status;
  1277. try
  1278. {
  1279. List<PostDateClass> postList = new List<PostDateClass>();
  1280. postList.Add(new PostDateClass("sn", SN));
  1281. postList.Add(new PostDateClass("date", copydate));
  1282. ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status, timeout);
  1283. if (status)
  1284. {
  1285. JObject jObject = JObject.Parse(ParseText);
  1286. string des = CommonMethod.JSON_SeleteNode(jObject, "des");
  1287. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  1288. string data = JSON_SeleteNode(jObject, "data");
  1289. if (code == "1000")
  1290. {
  1291. //更新上报内容
  1292. if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
  1293. {
  1294. //更新成功
  1295. Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + host + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
  1296. return true;
  1297. }
  1298. else
  1299. {
  1300. Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
  1301. return false;
  1302. }
  1303. }
  1304. else
  1305. {
  1306. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText, sqliteConn);
  1307. Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + SN + ":" + ParseText + "\r\nAddress:" + host + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate);
  1308. if (repeatupload)
  1309. {
  1310. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1311. }
  1312. return false;
  1313. }
  1314. }
  1315. else
  1316. {
  1317. if (repeatupload)
  1318. return false;
  1319. if (CommonMethod.HTTPChecker(host))
  1320. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { "preload_mode", host, SN + "@" + copydate });
  1321. return false;
  1322. }
  1323. }
  1324. catch (Exception ex)
  1325. {
  1326. Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + SN + ":" + ParseText);
  1327. return false;
  1328. }
  1329. }
  1330. /// <summary>
  1331. /// 预下载模式抄写的批量上报
  1332. /// </summary>
  1333. /// <param name="host"></param>
  1334. /// <param name="postList"></param>
  1335. /// <param name="localDBNow"></param>
  1336. /// <param name="sqliteConn"></param>
  1337. /// <param name="repeatupload"></param>
  1338. /// <param name="id"></param>
  1339. /// <returns></returns>
  1340. public static bool UploadPreloadCopyResultList(string host, List<PostDateClass> postList, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
  1341. {
  1342. string ParseText = "";
  1343. bool status;
  1344. try
  1345. {
  1346. ParseText = FormPost.postFileMessage(host + "/reportlist.do?", postList, out status, 30000);
  1347. if (status)
  1348. {
  1349. JObject jObject = JObject.Parse(ParseText);
  1350. string des = CommonMethod.JSON_SeleteNode(jObject, "des");
  1351. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  1352. string data = JSON_SeleteNode(jObject, "data");
  1353. if (code == "1000")
  1354. {
  1355. Log.WriteGetKeyLog("UploadPreloadCopyResult successful\r\nAddress: " + host + "/reportlist.do?" + ParseText);
  1356. return true;
  1357. }
  1358. else
  1359. {
  1360. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + host + "/reportlist.do?" + ParseText, sqliteConn);
  1361. Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + ParseText + "\r\nAddress:" + host + "/reportlist.do?");
  1362. if (repeatupload)
  1363. {
  1364. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  1365. }
  1366. return false;
  1367. }
  1368. }
  1369. else
  1370. {
  1371. Log.WriteErrorLog("Fail to UploadPreloadCopyResult\r\nAddress: " + host + "/reportlist.do?" + ParseText);
  1372. return false;
  1373. }
  1374. }
  1375. catch (Exception ex)
  1376. {
  1377. Log.WriteErrorLog("\r\nFail to parse UpdateReportStatus return: " + ex.Message + "\r\n" + ParseText);
  1378. return false;
  1379. }
  1380. }
  1381. /// <summary>
  1382. /// byte[]数组到int转换
  1383. /// </summary>
  1384. /// <param name="value"></param>
  1385. /// <returns></returns>
  1386. public static int BytelisttoInt(byte[] value)
  1387. {
  1388. Array.Reverse(value);
  1389. int result = 0;
  1390. for (int i = 0; i < value.Length; i++)
  1391. {
  1392. result += value[i] << i * 8;
  1393. }
  1394. return result;
  1395. }
  1396. /// <summary>
  1397. /// int类型到byte[]数组转换
  1398. /// </summary>
  1399. /// <param name="value"></param>
  1400. /// <returns></returns>
  1401. public static byte[] InttoBytelist(int value)
  1402. {
  1403. byte[] bytes = BitConverter.GetBytes(value);
  1404. Array.Reverse(bytes);
  1405. if (value == 0)
  1406. return bytes;
  1407. List<byte> list = new List<byte>();
  1408. list.AddRange(bytes);
  1409. while (true)
  1410. {
  1411. if (list[0] != 0)
  1412. break;
  1413. else
  1414. list.RemoveAt(0);
  1415. }
  1416. bytes = list.ToArray();
  1417. return bytes;
  1418. }
  1419. /// <summary>
  1420. /// 升级检查
  1421. /// </summary>
  1422. /// <param name="url"></param>
  1423. /// <param name="FactoryNum"></param>
  1424. /// <param name="sqliteConn"></param>
  1425. /// <param name="upmid"></param>
  1426. /// <returns></returns>
  1427. public static bool UpgradeCheck(string url, string FactoryNum, SQLiteConnection sqliteConn, out UpgradeMsgList upmid)
  1428. {
  1429. upmid = new UpgradeMsgList();
  1430. UpgradeCheckInput UpgradeCheckInput1 = new UpgradeCheckInput { appid = "SCBC_Factory_Tools", devicemodel = "SCBC_Factory_Tools", dnum = FactoryNum, ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), type = "pc" };//System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
  1431. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
  1432. HttpHelper http = new HttpHelper();
  1433. HttpItem item = new HttpItem()
  1434. {
  1435. URL = url,//URL这里都是测试URl   必需项
  1436. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1437. //Encoding = Encoding.Default,
  1438. Method = "post",//URL     可选项 默认为Get
  1439. Postdata = jsonorder,
  1440. PostEncoding = Encoding.UTF8,
  1441. KeepAlive = false
  1442. };
  1443. item.ContentType = "application/json;charset=utf-8";
  1444. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
  1445. | SecurityProtocolType.Tls
  1446. | SecurityProtocolType.Tls11//(SecurityProtocolType)0x300 //Tls11
  1447. | SecurityProtocolType.Tls12;//(SecurityProtocolType)0xC00; //Tls12
  1448. HttpResult result = http.GetHtml(item);
  1449. string ParseText = result.Html;
  1450. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1451. {
  1452. Log.WriteGetKeyLog("\r\nUpgrade check," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1453. }
  1454. else
  1455. {
  1456. Log.WriteErrorLog("\r\nFail to upgrade check:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1457. ReportErrormsg("Fail to upgrade check", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1458. return false;
  1459. }
  1460. try
  1461. {
  1462. JObject jObject = JObject.Parse(ParseText);
  1463. upmid.servertime = jObject["servertime"].Value<string>();
  1464. upmid.callid = jObject["callid"].Value<string>();
  1465. upmid.state = jObject["state"].Value<string>();
  1466. upmid.note = jObject["note"].Value<string>();
  1467. upmid.language = jObject["language"].Value<string>();
  1468. upmid.apiversion = jObject["apiversion"].Value<string>();
  1469. upmid.upgrade = new UpgradeMsgList2()
  1470. {
  1471. type = JSON_SeleteNode(jObject, "type"),
  1472. appid = JSON_SeleteNode(jObject, "appid"),
  1473. apptype = JSON_SeleteNode(jObject, "apptype"),
  1474. version = JSON_SeleteNode(jObject, "version"),
  1475. verid = JSON_SeleteNode(jObject, "verid"),
  1476. md5 = JSON_SeleteNode(jObject, "md5"),
  1477. size = JSON_SeleteNode(jObject, "size"),
  1478. minicon = JSON_SeleteNode(jObject, "minicon"),
  1479. midicon = JSON_SeleteNode(jObject, "midicon"),
  1480. fileurl = JSON_SeleteNode(jObject, "fileurl"),
  1481. increment = JSON_SeleteNode(jObject, "increment"),
  1482. appendver = JSON_SeleteNode(jObject, "appendver"),
  1483. updatetime = JSON_SeleteNode(jObject, "updatetime")
  1484. };
  1485. if (upmid.state == "0000")
  1486. return true;
  1487. else
  1488. {
  1489. return false;
  1490. }
  1491. }
  1492. catch (Exception ex)
  1493. {
  1494. Log.WriteErrorLog("\r\nFail to parse upgrade check info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1495. ReportErrormsg("Fail to parse upgrade check info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1496. MessageBox.Show("Fail to parse upgrade check info\r\n " + ex.Message);
  1497. return false;
  1498. }
  1499. }
  1500. /// <summary>
  1501. /// 升级上报
  1502. /// </summary>
  1503. /// <param name="url"></param>
  1504. /// <param name="FactoryNum"></param>
  1505. /// <param name="Result"></param>
  1506. /// <param name="sqliteConn"></param>
  1507. /// <returns></returns>
  1508. public static bool UpgradeReport(string url, string FactoryNum, string Result, SQLiteConnection sqliteConn)
  1509. {
  1510. UpgradeReportInput UpgradeCheckInput1 = new UpgradeReportInput { appid = "SCBC_Factory_Tools", devmodel = "SCBC_Factory_Tools", dnum = FactoryNum, ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), type = "pc", result = Result };
  1511. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(UpgradeCheckInput1, Newtonsoft.Json.Formatting.Indented);
  1512. HttpHelper http = new HttpHelper();
  1513. HttpItem item = new HttpItem()
  1514. {
  1515. URL = url,//URL这里都是测试URl   必需项
  1516. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1517. //Encoding = Encoding.Default,
  1518. Method = "post",//URL     可选项 默认为Get
  1519. Postdata = jsonorder,
  1520. PostEncoding = Encoding.UTF8,
  1521. KeepAlive = false
  1522. };
  1523. item.ContentType = "application/json;charset=utf-8";
  1524. ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
  1525. | SecurityProtocolType.Tls
  1526. | (SecurityProtocolType)0x300 //Tls11
  1527. | (SecurityProtocolType)0xC00; //Tls12
  1528. HttpResult result = http.GetHtml(item);
  1529. string ParseText = result.Html;
  1530. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1531. {
  1532. Log.WriteGetKeyLog("\r\nUpgrade report," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1533. }
  1534. else
  1535. {
  1536. Log.WriteErrorLog("\r\nFail to upgrade report:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1537. ReportErrormsg("Fail to upgrade report", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1538. return false;
  1539. }
  1540. try
  1541. {
  1542. JObject jObject = JObject.Parse(ParseText);
  1543. return true;
  1544. }
  1545. catch (Exception ex)
  1546. {
  1547. Log.WriteErrorLog("\r\nFail to parse upgrade report info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1548. ReportErrormsg("Fail to parse upgrade report info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1549. MessageBox.Show("Fail to parse upgrade report info\r\n " + ex.Message);
  1550. return false;
  1551. }
  1552. }
  1553. /// <summary>
  1554. /// 比较本地文件的MD5值
  1555. /// </summary>
  1556. /// <param name="filename"></param>
  1557. /// <param name="filetype"></param>
  1558. /// <param name="filemd5"></param>
  1559. /// <param name="error"></param>
  1560. /// <returns></returns>
  1561. public static bool CompareLocalkey(string filename, string filetype, string filemd5, out string error, out string filefullname)
  1562. {
  1563. error = "";
  1564. filefullname = "";
  1565. try
  1566. {
  1567. string filepath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\" + filename + "\\" + filetype;
  1568. if (!Directory.Exists(filepath))
  1569. {
  1570. Directory.CreateDirectory(filepath);
  1571. }
  1572. DirectoryInfo Getkeyfile = new DirectoryInfo(filepath);
  1573. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  1574. {
  1575. string FileMD5 = GetMD5.GetMD5HashFromFile(keyfile.Name);
  1576. if (FileMD5 == filemd5)
  1577. {
  1578. Log.WriteGetKeyLog("Check md5file success,file md5:" + FileMD5 + "\r\nfile:" + keyfile.FullName);
  1579. filefullname = keyfile.FullName;
  1580. return true;
  1581. }
  1582. else
  1583. {
  1584. Log.WriteErrorLog("Check md5file error,delete file:" + keyfile.FullName + "\r\nfile md5" + FileMD5);
  1585. File.Delete(keyfile.FullName);
  1586. }
  1587. }
  1588. return false;
  1589. }
  1590. catch (Exception ex)
  1591. {
  1592. error = ex.Message;
  1593. return false;
  1594. }
  1595. }
  1596. /// <summary>
  1597. /// 数据MD5核对。当数据头为"MD5="时,key内容比对改为key内容MD5比对
  1598. /// </summary>
  1599. /// <param name="key"></param>
  1600. /// <param name="data"></param>
  1601. /// <param name="md5"></param>
  1602. /// <returns></returns>
  1603. public static bool CompareMD5(byte[] key, byte[] data)
  1604. {
  1605. string strdata = Encoding.ASCII.GetString(data);
  1606. Console.WriteLine(strdata);
  1607. if (strdata.StartsWith("MD5="))
  1608. {
  1609. string md5 = GetMD5.GetMD5Hash(key);
  1610. Console.WriteLine(md5);
  1611. return strdata.Remove(0, 4).Equals(md5);
  1612. }
  1613. return false;
  1614. }
  1615. /// <summary>
  1616. /// 将16进制字符串转为对应字节流写入生成key文件
  1617. /// </summary>
  1618. /// <param name="path"></param>
  1619. /// <param name="data"></param>
  1620. /// <param name="error"></param>
  1621. /// <returns></returns>
  1622. public static bool GetCreateHexkey(string path, string data, out string error)
  1623. {
  1624. error = "";
  1625. try
  1626. {
  1627. string filepath = path + ".bin";
  1628. byte[] bytedata = SerialInit.HexToByte(data);
  1629. //创建一个文件流
  1630. FileStream fs = new FileStream(filepath, FileMode.Create);
  1631. fs.Write(bytedata, 0, bytedata.Length);
  1632. fs.Close();
  1633. Log.WriteGetKeyLog("save key:" + filepath);
  1634. return true;
  1635. }
  1636. catch (Exception ex)
  1637. {
  1638. error = ex.Message;
  1639. Log.WriteErrorLog("save key error:" + error);
  1640. return false;
  1641. }
  1642. }
  1643. /// <summary>
  1644. /// 读取key文件内容转换为16进制字符串
  1645. /// </summary>
  1646. /// <param name="filepath"></param>
  1647. /// <param name="data"></param>
  1648. /// <param name="error"></param>
  1649. /// <returns></returns>
  1650. public static bool ReadHexFile(string filepath, out string data, out string error)
  1651. {
  1652. data = "";
  1653. error = "";
  1654. try
  1655. {
  1656. using FileStream fskey = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.None);
  1657. {
  1658. using BinaryReader brkey = new BinaryReader(fskey);
  1659. {
  1660. data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
  1661. data = data.Replace(" ", "");
  1662. return true;
  1663. }
  1664. }
  1665. }
  1666. catch (Exception ex)
  1667. {
  1668. error = ex.Message;
  1669. return false;
  1670. }
  1671. }
  1672. /// <summary>
  1673. /// 账号登录
  1674. /// </summary>
  1675. /// <param name="url"></param>
  1676. /// <param name="account"></param>
  1677. /// <param name="password"></param>
  1678. /// <param name="pcmac"></param>
  1679. /// <param name="sqliteConn"></param>
  1680. /// <param name="loginOutput1"></param>
  1681. /// <returns></returns>
  1682. public static bool UserLogin(string url, string account, string password, string pcmac, SQLiteConnection sqliteConn, out LoginOutput loginOutput1)
  1683. {
  1684. loginOutput1 = new LoginOutput();
  1685. LoginInput LoginInput1 = new LoginInput { account = account, password = password, mac = pcmac };
  1686. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(LoginInput1, Newtonsoft.Json.Formatting.Indented);
  1687. HttpHelper http = new HttpHelper();
  1688. HttpItem item = new HttpItem()
  1689. {
  1690. URL = url,//URL这里都是测试URl   必需项
  1691. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1692. //Encoding = Encoding.Default,
  1693. Method = "post",//URL     可选项 默认为Get
  1694. Postdata = jsonorder,
  1695. PostEncoding = Encoding.UTF8,
  1696. KeepAlive = false
  1697. };
  1698. item.ContentType = "application/json;charset=utf-8";
  1699. ServicePointManager.ServerCertificateValidationCallback = ValidateServerCertificate;//
  1700. HttpResult result = http.GetHtml(item);
  1701. string ParseText = result.Html;
  1702. if (result.StatusCode == HttpStatusCode.OK)
  1703. {
  1704. Log.WriteGetKeyLog("\r\nLogin," + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1705. }
  1706. else
  1707. {
  1708. Log.WriteErrorLog("\r\nFail to login:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1709. ReportErrormsg("Fail to login", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1710. return false;
  1711. }
  1712. try
  1713. {
  1714. JObject jObject = JObject.Parse(ParseText);
  1715. loginOutput1.msg = jObject["msg"].Value<string>();
  1716. loginOutput1.code = jObject["code"].Value<string>();
  1717. loginOutput1.factoryname = JSON_SeleteNode(jObject, "factoryName");
  1718. loginOutput1.factorynum = JSON_SeleteNode(jObject, "factoryNum");
  1719. if (loginOutput1.code == "1000")
  1720. return true;
  1721. else
  1722. return false;
  1723. }
  1724. catch (Exception ex)
  1725. {
  1726. Log.WriteErrorLog("\r\nFail to login," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1727. ReportErrormsg("Fail to login", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1728. MessageBox.Show("Fail to parse login return\r\n " + ex.Message);
  1729. return false;
  1730. }
  1731. }
  1732. /// <summary>
  1733. /// 获取指定日期,在为一年中为第几周
  1734. /// </summary>
  1735. /// <param name="dt">指定时间</param>
  1736. /// <reutrn>返回第几周</reutrn>
  1737. public static int GetWeekOfYear(DateTime dt)
  1738. {
  1739. GregorianCalendar gc = new GregorianCalendar();
  1740. int weekOfYear = gc.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
  1741. return weekOfYear;
  1742. }
  1743. /// <summary>
  1744. /// 版本号比较:new_version>=old_version
  1745. /// </summary>
  1746. /// <param name="new_version">8.4.0</param>
  1747. /// <param name="old_version">8.3.10</param>
  1748. /// <returns></returns>
  1749. public static bool CompareVersion(string new_version, string old_version)
  1750. {
  1751. try
  1752. {
  1753. if (string.IsNullOrEmpty(new_version) || string.IsNullOrEmpty(old_version))
  1754. return false;
  1755. Version v_new = new Version(new_version);
  1756. Version v_old = new Version(old_version);
  1757. if (v_new >= v_old)
  1758. return true;
  1759. return false;
  1760. }
  1761. catch (Exception ex)
  1762. {
  1763. throw ex;
  1764. }
  1765. }
  1766. /// <summary>
  1767. /// 获取白平衡信息
  1768. /// </summary>
  1769. /// <param name="url"></param>
  1770. /// <param name="order"></param>
  1771. /// <param name="pcmac"></param>
  1772. /// <param name="sqliteConn"></param>
  1773. /// <param name="WBList"></param>
  1774. /// <returns></returns>
  1775. public static bool GetWhiteBalanceInfo(string url, string order, string pcmac, SQLiteConnection sqliteConn, out WhiteBalanceList WBList)
  1776. {
  1777. WBList = new WhiteBalanceList();
  1778. WhiteBalanceInput WBInput1 = new WhiteBalanceInput { bid = order, mac = pcmac };//"74-27-EA-6E-DA-9F"
  1779. string jsonorder = Newtonsoft.Json.JsonConvert.SerializeObject(WBInput1, Newtonsoft.Json.Formatting.Indented);
  1780. HttpHelper http = new HttpHelper();
  1781. HttpItem item = new HttpItem()
  1782. {
  1783. URL = url,//URL这里都是测试URl   必需项
  1784. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)     可选项 默认类会自动识别
  1785. //Encoding = Encoding.Default,
  1786. Method = "post",//URL     可选项 默认为Get
  1787. Postdata = jsonorder,
  1788. PostEncoding = Encoding.UTF8,
  1789. KeepAlive = false
  1790. };
  1791. item.ContentType = "application/json;charset=utf-8";
  1792. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  1793. stopwatch.Start();
  1794. HttpResult result = http.GetHtml(item);
  1795. stopwatch.Stop();
  1796. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  1797. stopwatch.Reset();
  1798. string ParseText = result.Html;
  1799. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1800. {
  1801. Log.WriteGetKeyLog("\r\nGet WB info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1802. }
  1803. else
  1804. {
  1805. Log.WriteErrorLog("\r\nFail to WBinfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1806. ReportErrormsg("Fail to WBinfo", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1807. return false;
  1808. }
  1809. try
  1810. {
  1811. JObject jObject = JObject.Parse(ParseText);
  1812. WBList.message = jObject["message"].Value<string>();
  1813. WBList.code = jObject["code"].Value<string>();
  1814. object a = jObject["obj"];
  1815. if (jObject["obj"].ToString().Length > 0)
  1816. WBList.whiteBalanceInfo = new WhiteBalanceInfo()
  1817. {
  1818. id = JSON_SeleteNode(jObject["obj"], "id"),
  1819. ordernum = JSON_SeleteNode(jObject["obj"], "ordernum"),
  1820. hdmirgain = JSON_SeleteNode(jObject["obj"], "hdmirgain"),
  1821. hdmiggain = JSON_SeleteNode(jObject["obj"], "hdmiggain"),
  1822. hdmibgain = JSON_SeleteNode(jObject["obj"], "hdmibgain"),
  1823. nrgain = JSON_SeleteNode(jObject["obj"], "nrgain"),
  1824. nggain = JSON_SeleteNode(jObject["obj"], "nggain"),
  1825. nbgain = JSON_SeleteNode(jObject["obj"], "nbgain"),
  1826. lrgain = JSON_SeleteNode(jObject["obj"], "lrgain"),
  1827. lggain = JSON_SeleteNode(jObject["obj"], "lggain"),
  1828. lbgain = JSON_SeleteNode(jObject["obj"], "lbgain"),
  1829. updatetime = JSON_SeleteNode(jObject["obj"], "updatetime"),
  1830. createtime = JSON_SeleteNode(jObject["obj"], "createtime"),
  1831. isdelete = JSON_SeleteNode(jObject["obj"], "isdelete"),
  1832. isExemption = JSON_SeleteNode(jObject["obj"], "isExemption")
  1833. };
  1834. if (WBList.code == "1000")
  1835. return true;
  1836. else
  1837. return false;
  1838. }
  1839. catch (Exception ex)
  1840. {
  1841. Log.WriteErrorLog("\r\nFail to parse WB info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder);
  1842. ReportErrormsg("Fail to parse WB info", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + jsonorder, sqliteConn);
  1843. MessageBox.Show("Fail to parse WB info\r\n " + ex.Message);
  1844. return false;
  1845. }
  1846. }
  1847. private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
  1848. {
  1849. return true;
  1850. }
  1851. public static bool AutoGetKey(string url, string order, string key, string keytype, SQLiteConnection errorDBNow)
  1852. {
  1853. string code;
  1854. string desc;
  1855. HttpHelper http = new HttpHelper();
  1856. HttpItem item = new HttpItem()
  1857. {
  1858. Encoding = Encoding.Default,
  1859. Method = "post",
  1860. ContentType = "application/x-www-form-urlencoded",
  1861. KeepAlive = false
  1862. };
  1863. url += "/autogetkey.do?";
  1864. item.URL = url;
  1865. item.Postdata = string.Format("order={0}&key={1}&keytype={2}&mac={3}", order, key, keytype, HttpUtility.UrlEncode(TestMode.MAC));
  1866. HttpResult result = http.GetHtml(item);
  1867. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1868. {
  1869. Log.WriteGetKeyLog("\r\nAutoquestKey :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1870. if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
  1871. {
  1872. return true;
  1873. }
  1874. else
  1875. {
  1876. CommonMethod.ReportErrormsg("Auto get key error", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  1877. return false;
  1878. }
  1879. }
  1880. else
  1881. {
  1882. CommonMethod.ReportErrormsg("Auto get key error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  1883. return false;
  1884. }
  1885. }
  1886. public static bool AutoGetKeyStatus(string url, string key, string keytype, SQLiteConnection errorDBNow)
  1887. {
  1888. string code;
  1889. string desc;
  1890. HttpHelper http = new HttpHelper();
  1891. HttpItem item = new HttpItem()
  1892. {
  1893. Encoding = Encoding.Default,
  1894. Method = "post",
  1895. ContentType = "application/x-www-form-urlencoded",
  1896. KeepAlive = false
  1897. };
  1898. url += "/autogetkeystatus.do?";
  1899. item.URL = url;
  1900. item.Postdata = string.Format("key={0}&keytype={1}", key, keytype);
  1901. HttpResult result = http.GetHtml(item);
  1902. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1903. {
  1904. Log.WriteGetKeyLog("\r\nAutoGetKeyStatus :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1905. if (Xmlconfig.AutoKeyStatusXml(result.Html, "response", out code, out desc))
  1906. {
  1907. return true;
  1908. }
  1909. else
  1910. {
  1911. return false;
  1912. }
  1913. }
  1914. else
  1915. {
  1916. CommonMethod.ReportErrormsg("Auto get key status error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  1917. return false;
  1918. }
  1919. }
  1920. public static bool GetFireTVDsn(string url, string ordernum, string deviceCode, string FSN, string PSN, out string dsn, out string error, SQLiteConnection errorDBNow)
  1921. {
  1922. // 计算函数耗时;
  1923. Stopwatch watch = new Stopwatch();
  1924. watch.Start();
  1925. dsn = "";
  1926. error = "";
  1927. HttpHelper http = new HttpHelper();
  1928. HttpItem item = new HttpItem()
  1929. {
  1930. Encoding = null, // 编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别Encoding = Encoding.Default,
  1931. Method = "GET", // URL 可选项 默认为Get
  1932. KeepAlive = false
  1933. };
  1934. item.URL = string.Format("{0}/getFiretvDsn.do?ordernum={1}&fsn={2}&psn={3}&deviceCode={4}&mac={5}", url, ordernum, FSN, PSN, deviceCode, HttpUtility.UrlEncode(TestMode.MAC));
  1935. HttpResult result = http.GetHtml(item);
  1936. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  1937. {
  1938. string code;
  1939. string desc;
  1940. Log.WriteGetKeyLog("\r\nGetFireTVDsn :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  1941. if (Xmlconfig.GetDSNXml(result.Html, "response", out code, out desc, out dsn))
  1942. {
  1943. Log.WriteGetKeyLog(string.Format("\r\nDSN= {0}\r\nHttp Get Dsn Elapsed = {1}", dsn, watch.Elapsed.TotalMilliseconds));
  1944. return true;
  1945. }
  1946. else
  1947. {
  1948. error = desc;
  1949. CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
  1950. return false;
  1951. }
  1952. }
  1953. else
  1954. {
  1955. error = "Communication with server failed";
  1956. CommonMethod.ReportErrormsg("GetFireTVDsn error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL, errorDBNow);
  1957. return false;
  1958. }
  1959. }
  1960. /// <summary>
  1961. /// 导出日本的SN与ACASID到文本中;
  1962. /// </summary>
  1963. /// <param name="ordernum"></param>
  1964. /// <param name="sn"></param>
  1965. /// <param name="acasid"></param>
  1966. public static void ExportSNACASID(string ordernum, string sn, string acasid)
  1967. {
  1968. string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\SN-ACAS";
  1969. if (!Directory.Exists(path))
  1970. {
  1971. Directory.CreateDirectory(path);
  1972. }
  1973. if (!lastOrder.Equals(ordernum))
  1974. {
  1975. lastOrder = ordernum;
  1976. ListACASSN.Clear();
  1977. }
  1978. string msg = string.Format("{0};{1}", sn, acasid);
  1979. if (ListACASSN.Contains(msg))
  1980. {
  1981. return;
  1982. }
  1983. ListACASSN.Add(msg);
  1984. string fileName = path + "\\" + ordernum + ".txt";
  1985. var stream = new StreamWriter(fileName, true);
  1986. stream.WriteLine(msg);
  1987. stream.Close();
  1988. stream.Dispose();
  1989. }
  1990. /// <summary>
  1991. /// 是否抄写EDID;
  1992. /// </summary>
  1993. /// <param name="midInfo"></param>
  1994. /// <returns></returns>
  1995. public static bool IsEDIDCopy(MidList midInfo)
  1996. {
  1997. if (midInfo == null || midInfo.keytype == null)
  1998. return false;
  1999. if (!midInfo.keytype.ContainsKey("edid_pid") && !midInfo.keytype.ContainsKey("edid_model_name"))
  2000. return false;
  2001. return true;
  2002. }
  2003. #region G客户NTF功能:GetMaInfo
  2004. public static bool GetMaInfo(string sn, out MaInfo maInfo, SQLiteConnection errorDBNow)
  2005. {
  2006. string desc;
  2007. maInfo = null;
  2008. string strPost = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
  2009. "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
  2010. "<soap:Body>"+
  2011. "<GetMaInfo xmlns=\"http://tempuri.org/\">"+
  2012. "<sn>"+sn+"</sn>"+
  2013. "</GetMaInfo>"+
  2014. "</soap:Body>"+
  2015. "</soap:Envelope>";
  2016. HttpHelper http = new HttpHelper();
  2017. HttpItem item = new HttpItem()
  2018. {
  2019. Encoding = Encoding.Default,
  2020. Method = "post",
  2021. ContentType = "text/xml",
  2022. KeepAlive = false
  2023. };
  2024. item.URL = "http://smes-prd-app01.tclking.com:9002/SAPService.asmx";
  2025. item.Postdata = strPost;
  2026. HttpResult result = http.GetHtml(item);
  2027. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2028. {
  2029. Log.WriteGetKeyLog("\r\nGetMaInfo :\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2030. if (!Xmlconfig.GetMaInfoXml(result.Html, out maInfo, out desc))
  2031. {
  2032. CommonMethod.ReportErrormsg("GetMaInfo error", desc + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  2033. return false;
  2034. }
  2035. }
  2036. else
  2037. {
  2038. CommonMethod.ReportErrormsg("GetMaInfo error", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata, errorDBNow);
  2039. return false;
  2040. }
  2041. return true;
  2042. }
  2043. #endregion
  2044. }
  2045. /// <summary>
  2046. /// CRC32
  2047. /// </summary>
  2048. class CRC32
  2049. {
  2050. //生成CRC32码表
  2051. static uint[] Crc32Table;
  2052. public static void GetCRC32Table()
  2053. {
  2054. uint Crc;
  2055. Crc32Table = new uint[256];
  2056. int i, j;
  2057. for (i = 0; i < 256; i++)
  2058. {
  2059. Crc = (uint)i;
  2060. for (j = 8; j > 0; j--)
  2061. {
  2062. if ((Crc & 1) == 1)
  2063. Crc = (Crc >> 1) ^ 0xEDB88320;
  2064. else
  2065. Crc >>= 1;
  2066. }
  2067. Crc32Table[i] = Crc;
  2068. }
  2069. }
  2070. public static uint GetCRC32(byte[] bytes)
  2071. {
  2072. GetCRC32Table();
  2073. uint value = 0xffffffff;
  2074. int len = bytes.Length;
  2075. for (int i = 0; i < len; i++)
  2076. {
  2077. value = (value >> 8) ^ Crc32Table[(value & 0xFF) ^ bytes[i]];
  2078. }
  2079. return value ^ 0xffffffff;
  2080. }
  2081. }
  2082. /// <summary>
  2083. /// 本地抄写模式方法
  2084. /// </summary>
  2085. public class GetLocalKeyCount
  2086. {
  2087. static string LocalKeyPath = AppDomain.CurrentDomain.BaseDirectory + "\\Keys\\";
  2088. public static bool GetLocalDidCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
  2089. {
  2090. num = 0;
  2091. try
  2092. {
  2093. string DIDpath = LocalKeyPath + order + "\\DeviceID";
  2094. if (Directory.Exists(DIDpath) == false)
  2095. return false;
  2096. else
  2097. {
  2098. DirectoryInfo GetDIDfile = new DirectoryInfo(DIDpath);
  2099. foreach (FileInfo keyfile in GetDIDfile.GetFiles())
  2100. {
  2101. string filename = keyfile.FullName;
  2102. if (keyfile.Name.Contains("Online"))
  2103. {
  2104. if (localmidList.host == null)
  2105. {
  2106. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2107. {
  2108. ;
  2109. }
  2110. else
  2111. {
  2112. num = -1;
  2113. return true;
  2114. }
  2115. }
  2116. HttpHelper http = new HttpHelper();
  2117. HttpItem item = new HttpItem()
  2118. {
  2119. Encoding = Encoding.Default,
  2120. Method = "post",
  2121. ContentType = "application/x-www-form-urlencoded"
  2122. };
  2123. string url1 = localmidList.host + "/statdeviceid.do?";
  2124. item.URL = url1;
  2125. item.Postdata = "devicetype=tcl_unknown_model";
  2126. HttpResult result = http.GetHtml(item);
  2127. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2128. {
  2129. Log.WriteGetKeyLog("\r\nGetDeviceID count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2130. if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
  2131. {
  2132. num = Convert.ToInt32(count.Replace(",", ""));
  2133. return true;
  2134. }
  2135. else
  2136. {
  2137. num = -1;
  2138. return true;
  2139. }
  2140. }
  2141. else
  2142. {
  2143. num = -1;
  2144. return true;
  2145. }
  2146. }
  2147. else
  2148. {
  2149. num = GetDIDfile.GetFiles().Length;
  2150. return true;
  2151. }
  2152. }
  2153. return true;
  2154. }
  2155. }
  2156. catch (Exception ex)
  2157. {
  2158. num = -1;
  2159. return true;
  2160. }
  2161. }
  2162. public static bool GetLocalMacCount(string order, out int num, ref MidList localmidList, SQLiteConnection errorDBNow)
  2163. {
  2164. num = 0;
  2165. try
  2166. {
  2167. string MACpath = LocalKeyPath + order + "\\MAC";
  2168. if (Directory.Exists(MACpath) == false)
  2169. return false;
  2170. else
  2171. {
  2172. DirectoryInfo GetMACfile = new DirectoryInfo(MACpath);
  2173. foreach (FileInfo keyfile in GetMACfile.GetFiles())
  2174. {
  2175. string filename = keyfile.FullName;
  2176. if (keyfile.Name.Contains("Online"))
  2177. {
  2178. if (localmidList.host == null)
  2179. {
  2180. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2181. {
  2182. ;
  2183. }
  2184. else
  2185. {
  2186. num = -1;
  2187. return true;
  2188. }
  2189. }
  2190. HttpHelper http = new HttpHelper();
  2191. HttpItem item = new HttpItem()
  2192. {
  2193. Encoding = Encoding.Default,
  2194. Method = "post",
  2195. ContentType = "application/x-www-form-urlencoded"
  2196. };
  2197. string url1 = localmidList.host + "/statmac.do?";
  2198. item.URL = url1;
  2199. item.Postdata = "typeString=" + localmidList.keytype["MAC"];
  2200. HttpResult result = http.GetHtml(item);
  2201. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  2202. {
  2203. Log.WriteGetKeyLog("\r\nGetMac count:\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + result.Html);
  2204. if (Xmlconfig.KeyCountXml(result.Html, "response", "count", out string code, out string desc, out string count))
  2205. {
  2206. num = Convert.ToInt32(count.Replace(",", ""));
  2207. return true;
  2208. }
  2209. else
  2210. {
  2211. num = -1;
  2212. return true;
  2213. }
  2214. }
  2215. else
  2216. {
  2217. num = -1;
  2218. return true;
  2219. }
  2220. }
  2221. else
  2222. {
  2223. num = GetMACfile.GetFiles().Length;
  2224. return true;
  2225. }
  2226. }
  2227. return true;
  2228. }
  2229. }
  2230. catch (Exception ex)
  2231. {
  2232. num = -1;
  2233. return true;
  2234. }
  2235. }
  2236. public static bool GetLocalHDCPKEYCount(string order, out int num)
  2237. {
  2238. num = 0;
  2239. try
  2240. {
  2241. string HDCPKEYpath = LocalKeyPath + order + "\\HDCPKEY";
  2242. if (Directory.Exists(HDCPKEYpath) == false)
  2243. return false;
  2244. else
  2245. {
  2246. DirectoryInfo GetHDCPKEYfile = new DirectoryInfo(HDCPKEYpath);
  2247. num = GetHDCPKEYfile.GetFiles().Length;
  2248. return true;
  2249. }
  2250. }
  2251. catch (Exception ex)
  2252. {
  2253. num = -1;
  2254. return true;
  2255. }
  2256. }
  2257. public static bool GetLocalHDCPKEY22Count(string order, out int num)
  2258. {
  2259. num = 0;
  2260. try
  2261. {
  2262. string HDCPKEY22path = LocalKeyPath + order + "\\HDCPKEY22";
  2263. if (Directory.Exists(HDCPKEY22path) == false)
  2264. return false;
  2265. else
  2266. {
  2267. DirectoryInfo GetHDCPKEY22file = new DirectoryInfo(HDCPKEY22path);
  2268. num = GetHDCPKEY22file.GetFiles().Length;
  2269. return true;
  2270. }
  2271. }
  2272. catch (Exception ex)
  2273. {
  2274. num = -1;
  2275. return true;
  2276. }
  2277. }
  2278. public static bool GetLocalWiDiCount(string order, out int num)
  2279. {
  2280. num = 0;
  2281. try
  2282. {
  2283. string WiDipath = LocalKeyPath + order + "\\WiDi";
  2284. if (Directory.Exists(WiDipath) == false)
  2285. return false;
  2286. else
  2287. {
  2288. DirectoryInfo GetWiDifile = new DirectoryInfo(WiDipath);
  2289. num = GetWiDifile.GetFiles().Length;
  2290. return true;
  2291. }
  2292. }
  2293. catch (Exception ex)
  2294. {
  2295. num = -1;
  2296. return true;
  2297. }
  2298. }
  2299. public static bool GetLocalWidevineCount(string order, out int num)
  2300. {
  2301. num = 0;
  2302. try
  2303. {
  2304. string Widevinepath = LocalKeyPath + order + "\\Widevine";
  2305. if (Directory.Exists(Widevinepath) == false)
  2306. return false;
  2307. else
  2308. {
  2309. DirectoryInfo GetWidevinefile = new DirectoryInfo(Widevinepath);
  2310. num = GetWidevinefile.GetFiles().Length;
  2311. return true;
  2312. }
  2313. }
  2314. catch (Exception ex)
  2315. {
  2316. num = -1;
  2317. return true;
  2318. }
  2319. }
  2320. public static bool GetLocalESNCount(string order, out int num)
  2321. {
  2322. num = 0;
  2323. try
  2324. {
  2325. string ESNpath = LocalKeyPath + order + "\\ESN";
  2326. if (Directory.Exists(ESNpath) == false)
  2327. return false;
  2328. else
  2329. {
  2330. DirectoryInfo GetESNfile = new DirectoryInfo(ESNpath);
  2331. num = GetESNfile.GetFiles().Length;
  2332. return true;
  2333. }
  2334. }
  2335. catch (Exception ex)
  2336. {
  2337. num = -1;
  2338. return true;
  2339. }
  2340. }
  2341. public static bool GetLocalMGKCount(string order, out int num)
  2342. {
  2343. num = 0;
  2344. try
  2345. {
  2346. string MGKpath = LocalKeyPath + order + "\\MGK";
  2347. if (Directory.Exists(MGKpath) == false)
  2348. return false;
  2349. else
  2350. {
  2351. DirectoryInfo GetMGKfile = new DirectoryInfo(MGKpath);
  2352. num = GetMGKfile.GetFiles().Length;
  2353. return true;
  2354. }
  2355. }
  2356. catch (Exception ex)
  2357. {
  2358. num = -1;
  2359. return true;
  2360. }
  2361. }
  2362. public static bool GetLocalFairplayCount(string order, out int num)
  2363. {
  2364. num = 0;
  2365. try
  2366. {
  2367. string Fairplaypath = LocalKeyPath + order + "\\Fairplay";
  2368. if (Directory.Exists(Fairplaypath) == false)
  2369. return false;
  2370. else
  2371. {
  2372. DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
  2373. num = GetFairplayfile.GetFiles().Length;
  2374. return true;
  2375. }
  2376. }
  2377. catch (Exception ex)
  2378. {
  2379. num = -1;
  2380. return true;
  2381. }
  2382. }
  2383. public static bool GetLocalFolderKeyCount(string order, string keyname, out int num)
  2384. {
  2385. num = 0;
  2386. try
  2387. {
  2388. string Fairplaypath = LocalKeyPath + order + "\\" + keyname;
  2389. if (Directory.Exists(Fairplaypath) == false)
  2390. return false;
  2391. else
  2392. {
  2393. DirectoryInfo GetFairplayfile = new DirectoryInfo(Fairplaypath);
  2394. num = GetFairplayfile.GetFiles().Length;
  2395. return true;
  2396. }
  2397. }
  2398. catch (Exception ex)
  2399. {
  2400. num = -1;
  2401. return true;
  2402. }
  2403. }
  2404. public static bool GetLocalAttestationCount(string order, out int num)
  2405. {
  2406. num = 0;
  2407. try
  2408. {
  2409. string Attestationpath = LocalKeyPath + order + "\\Attestation";
  2410. if (Directory.Exists(Attestationpath) == false)
  2411. return false;
  2412. else
  2413. {
  2414. DirectoryInfo GetAttestationfile = new DirectoryInfo(Attestationpath);
  2415. num = GetAttestationfile.GetFiles().Length;
  2416. return true;
  2417. }
  2418. }
  2419. catch (Exception ex)
  2420. {
  2421. num = -1;
  2422. return true;
  2423. }
  2424. }
  2425. public static bool GetLocalCIKEYCount(string order, out int num)
  2426. {
  2427. num = 0;
  2428. try
  2429. {
  2430. string CIKEYpath = LocalKeyPath + order + "\\CIKEY";
  2431. if (Directory.Exists(CIKEYpath) == false)
  2432. return false;
  2433. else
  2434. {
  2435. DirectoryInfo GetCIKEYfile = new DirectoryInfo(CIKEYpath);
  2436. num = GetCIKEYfile.GetFiles().Length;
  2437. return true;
  2438. }
  2439. }
  2440. catch (Exception ex)
  2441. {
  2442. num = -1;
  2443. return true;
  2444. }
  2445. }
  2446. public static bool GetLocalStringKeys(string order, string keytype, int filesize, out FileStream fskey, out StreamReader brkey, out string data, out string filename, out string error, SQLiteConnection errorDBNow, ref MidList localmidList, string SN)
  2447. {
  2448. data = "";
  2449. filename = "";
  2450. error = "";
  2451. brkey = null;
  2452. fskey = null;
  2453. try
  2454. {
  2455. string keypath = LocalKeyPath + order + "\\" + keytype;
  2456. if (Directory.Exists(keypath) == false)
  2457. {
  2458. error = "File not exist";
  2459. return false;
  2460. }
  2461. else
  2462. {
  2463. DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
  2464. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  2465. {
  2466. filename = keyfile.FullName;
  2467. if (keyfile.Name.Contains("Online"))
  2468. {
  2469. try
  2470. {
  2471. if (localmidList.host == null)
  2472. {
  2473. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2474. {
  2475. ;
  2476. }
  2477. else
  2478. {
  2479. return false;
  2480. }
  2481. }
  2482. if (keytype == "DeviceID")
  2483. localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
  2484. else if (keytype == "MAC")
  2485. keytype = "MAC";
  2486. else if (keytype == "HDCPKEY")
  2487. keytype = "HDCP_KEY";
  2488. else if (keytype == "HDCPKEY22")
  2489. keytype = "HDCP2.2_KEY";
  2490. else if (keytype == "ESN")
  2491. keytype = "NETFILX_ESN";
  2492. else if (keytype == "Widevine")
  2493. keytype = "Widevine_KEY";
  2494. else if (keytype == "WiDi")
  2495. keytype = "WiDi";
  2496. else if (keytype == "CIKEY")
  2497. keytype = "CI_PLUS_KEY";
  2498. if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
  2499. {
  2500. data = did;
  2501. Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
  2502. return true;
  2503. }
  2504. else
  2505. {
  2506. return false;
  2507. }
  2508. }
  2509. catch (Exception ex)
  2510. {
  2511. error = ex.Message;
  2512. return false;
  2513. }
  2514. }
  2515. else
  2516. {
  2517. try
  2518. {
  2519. fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.ReadWrite, FileShare.None);
  2520. {
  2521. brkey = new StreamReader(fskey);
  2522. {
  2523. if (fskey.Length == filesize || filesize == -1)
  2524. {
  2525. data = brkey.ReadToEnd();
  2526. return true;
  2527. }
  2528. else
  2529. {
  2530. error = "File size error.\r\nFilename:" + keyfile.Name + "\r\nFilesize:" + fskey.Length.ToString();
  2531. return false;
  2532. }
  2533. }
  2534. }
  2535. }
  2536. catch
  2537. {
  2538. ;
  2539. }
  2540. }
  2541. }
  2542. return false;
  2543. }
  2544. }
  2545. catch (Exception ex)
  2546. {
  2547. error = ex.Message;
  2548. return false;
  2549. }
  2550. }
  2551. public static bool GetLocalHexKeys(string order, string keytype, int filesize, out FileStream fskey, out BinaryReader brkey, out string data, out string filename, out string error, SQLiteConnection errorDBNow, ref MidList localmidList, string SN)
  2552. {
  2553. data = "";
  2554. filename = "";
  2555. error = "";
  2556. brkey = null;
  2557. fskey = null;
  2558. try
  2559. {
  2560. string keypath = LocalKeyPath + order + "\\" + keytype;
  2561. if (Directory.Exists(keypath) == false)
  2562. {
  2563. error = "File not exist";
  2564. return false;
  2565. }
  2566. else
  2567. {
  2568. DirectoryInfo Getkeyfile = new DirectoryInfo(keypath);
  2569. foreach (FileInfo keyfile in Getkeyfile.GetFiles())
  2570. {
  2571. filename = keyfile.FullName;
  2572. if (keyfile.Name.Contains("Online"))
  2573. {
  2574. try
  2575. {
  2576. if (localmidList.host == null)
  2577. {
  2578. if (CommonMethod.GetMidInfo(TestMode.serverurl, order, TestMode.MAC, "", "", errorDBNow, out localmidList))
  2579. {
  2580. ;
  2581. }
  2582. else
  2583. {
  2584. return false;
  2585. }
  2586. }
  2587. if (keytype == "DeviceID")
  2588. localmidList.keytype["DeviceID"] = "devicetype=tcl_unknown_model";
  2589. else if (keytype == "MAC")
  2590. keytype = "MAC";
  2591. else if (keytype == "HDCPKEY")
  2592. keytype = "HDCP_KEY";
  2593. else if (keytype == "HDCPKEY22")
  2594. keytype = "HDCP2.2_KEY";
  2595. else if (keytype == "ESN")
  2596. keytype = "NETFILX_ESN";
  2597. else if (keytype == "Widevine")
  2598. keytype = "Widevine_KEY";
  2599. else if (keytype == "WiDi")
  2600. keytype = "WiDi";
  2601. else if (keytype == "CIKEY")
  2602. keytype = "CI_PLUS_KEY";
  2603. else if (keytype == "MGK")
  2604. keytype = "MGK_KEY";
  2605. else if (keytype == "Attestation")
  2606. keytype = "Attestation";
  2607. else if (keytype == "Fairplay")
  2608. keytype = "Fairplay_KEY";
  2609. if (CommonMethod.GetKeys(localmidList.host, keytype, SN, localmidList.keytype[keytype], errorDBNow, out string did, out error, order, out string md5))
  2610. {
  2611. data = did;
  2612. Log.WriteGetKeyLog("\r\n" + keytype + "= " + data);
  2613. return true;
  2614. }
  2615. else
  2616. {
  2617. return false;
  2618. }
  2619. }
  2620. catch (Exception ex)
  2621. {
  2622. error = ex.Message;
  2623. return false;
  2624. }
  2625. }
  2626. else
  2627. {
  2628. try
  2629. {
  2630. fskey = new FileStream(keyfile.FullName.ToString(), FileMode.Open, FileAccess.Read, FileShare.None);
  2631. {
  2632. brkey = new BinaryReader(fskey);
  2633. {
  2634. if (fskey.Length == filesize || filesize == -1)
  2635. {
  2636. data = SerialInit.ByteToHex(brkey.ReadBytes((int)fskey.Length));
  2637. data = data.Replace(" ", "");
  2638. return true;
  2639. }
  2640. else
  2641. {
  2642. error = "File size error.\r\nFilename: " + keyfile.Name + "\r\nFilesize: " + fskey.Length.ToString();
  2643. return false;
  2644. }
  2645. }
  2646. }
  2647. }
  2648. catch
  2649. {
  2650. ;
  2651. }
  2652. }
  2653. }
  2654. return false;
  2655. }
  2656. }
  2657. catch (Exception ex)
  2658. {
  2659. error = ex.Message;
  2660. return false;
  2661. }
  2662. }
  2663. public static bool DeleteLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
  2664. {
  2665. try
  2666. {
  2667. if (filelist.Count == Reader.Count)
  2668. {
  2669. for (int i = 0; i < filelist.Count; i++)
  2670. {
  2671. if (filelist[i].ToString().Contains("DeviceID"))
  2672. ((StreamReader)Reader[i]).Dispose();
  2673. else
  2674. ((BinaryReader)Reader[i]).Dispose();
  2675. ((FileStream)Stream[i]).Dispose();
  2676. File.Delete(filelist[i].ToString());
  2677. }
  2678. return true;
  2679. }
  2680. else
  2681. return false;
  2682. }
  2683. catch (Exception ex)
  2684. {
  2685. for (int i = 0; i < Reader.Count; i++)
  2686. {
  2687. if (filelist[i].ToString().Contains("DeviceID"))
  2688. ((StreamReader)Reader[i]).Dispose();
  2689. else
  2690. ((BinaryReader)Reader[i]).Dispose();
  2691. ((FileStream)Stream[i]).Dispose();
  2692. }
  2693. return false;
  2694. }
  2695. }
  2696. public static bool UnlockLocalKeys(ArrayList filelist, ArrayList Stream, ArrayList Reader)
  2697. {
  2698. for (int i = 0; i < Reader.Count; i++)
  2699. {
  2700. if (filelist[i].ToString().Contains("DeviceID"))
  2701. ((StreamReader)Reader[i]).Dispose();
  2702. else
  2703. ((BinaryReader)Reader[i]).Dispose();
  2704. ((FileStream)Stream[i]).Dispose();
  2705. }
  2706. return true;
  2707. }
  2708. }
  2709. /// <summary>
  2710. /// 本地缓存记录
  2711. /// </summary>
  2712. public class LocalTxtRecord
  2713. {
  2714. public static bool LocalRecord(string record, string name)
  2715. {
  2716. try
  2717. {
  2718. string order = name + ".txt";
  2719. if (File.Exists(@order))
  2720. {
  2721. FileStream fs = new FileStream(@order, FileMode.Append);
  2722. byte[] data = System.Text.Encoding.Default.GetBytes("\r\n" + record);
  2723. fs.Write(data, 0, data.Length);
  2724. fs.Flush();
  2725. fs.Close();
  2726. }
  2727. else
  2728. {
  2729. FileStream fs = new FileStream(@order, FileMode.Create);
  2730. byte[] data = System.Text.Encoding.Default.GetBytes(record);
  2731. fs.Write(data, 0, data.Length);
  2732. fs.Flush();
  2733. fs.Close();
  2734. }
  2735. return true;
  2736. }
  2737. catch (Exception ex)
  2738. {
  2739. return false;
  2740. }
  2741. }
  2742. }
  2743. }