CommonMethod.cs 152 KB

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