CommonMethod.cs 155 KB

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