CommonMethod.cs 118 KB

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