CommonMethod.cs 139 KB

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