CommonMethod.cs 116 KB

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