CommonMethod.cs 140 KB

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