CommonMethod.cs 154 KB

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