CommonMethod.cs 139 KB

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