CommonMethod.cs 121 KB

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