CommonMethod.cs 136 KB

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