CommonMethod.cs 137 KB

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