CommonMethod.cs 131 KB

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