CommonMethod.cs 153 KB

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