CommonMethod.cs 137 KB

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