CommonMethod.cs 151 KB

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