V2Method.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. using CCWin.SkinControl;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using SufeiUtil;
  5. using SXLibrary;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data.SQLite;
  9. using System.Diagnostics;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Web;
  15. using System.Windows.Forms;
  16. using HttpHelper = SufeiUtil.HttpHelper;
  17. namespace MOKA_Factory_Tools
  18. {
  19. internal class V2Method
  20. {
  21. private static string url_getDSNFromSmes = "http://smes-app-prod.tclking.com:9006/api/xm/GetXMTVParts?TVSN=";
  22. public static MidList midList { get; set; }
  23. private static string url_getMessage = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do";
  24. public static void SetMexicanConfig(bool bMexican = false)
  25. {
  26. if (bMexican)
  27. url_getMessage = "http://10.138.96.32:81/IDManage/v1/order/getMessage";
  28. else
  29. url_getMessage = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do";
  30. if ( TestMode.testMode)
  31. url_getMessage = "http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do";
  32. }
  33. public static void SetGetMessageUrl(string url = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do")
  34. {
  35. url_getMessage = url;
  36. }
  37. public static RokuCustomer GetRokuInfo(string strRokuInfo)
  38. {
  39. try
  40. {
  41. JObject jObject = JObject.Parse(strRokuInfo);
  42. RokuCustomer rokuCustomer = new RokuCustomer();
  43. rokuCustomer.id = jObject["id"].ToString().Trim();
  44. rokuCustomer.ordernum = jObject["ordernum"].ToString().Trim();
  45. rokuCustomer.brand = jObject["brand"].ToString().Trim();
  46. rokuCustomer.oemmodel = jObject["oemmodel"].ToString().Trim();
  47. rokuCustomer.productiondate = jObject["productiondate"].ToString().Trim();
  48. rokuCustomer.remotetype = jObject["remotetype"].ToString().Trim();
  49. rokuCustomer.updatetime = jObject["updatetime"].ToString().Trim();
  50. rokuCustomer.createtime = jObject["createtime"].ToString().Trim();
  51. rokuCustomer.isdelete = jObject["isdelete"].ToString().Trim();
  52. if (jObject["data"] != null)
  53. {
  54. rokuCustomer.data = new List<RokuData>();
  55. foreach (var item in jObject["data"])
  56. {
  57. RokuData rokuData = new RokuData();
  58. rokuData.region = item["region"].Value<string>();
  59. rokuData.supporturl = item["supporturl"].Value<string>();
  60. rokuData.supportphone = item["supportphone"].Value<string>();
  61. rokuCustomer.data.Add(rokuData);
  62. }
  63. }
  64. return rokuCustomer;
  65. }
  66. catch (Exception ex)
  67. {
  68. Log.WriteErrorLog(string.Format("解析json失败:{0}", strRokuInfo));
  69. }
  70. return null;
  71. }
  72. public static RokuCustomer GetRokuFileInfo()
  73. {
  74. string fileName = LocalPath.localpath + "roku.info";
  75. if (File.Exists(fileName))
  76. {
  77. Log.WriteInfoLog(string.Format("using roku.info = {0}", fileName));
  78. StreamReader file = File.OpenText(fileName);
  79. RokuCustomer roku = GetRokuInfo(file.ReadToEnd());
  80. file.Close();
  81. return roku;
  82. }
  83. return null;
  84. }
  85. /// <summary>
  86. ///
  87. /// </summary>
  88. /// <param name="url"></param>
  89. /// <param name="order"></param>
  90. /// <param name="pcmac"></param>
  91. /// <param name="sqliteConn"></param>
  92. /// <param name="mid"></param>
  93. /// <returns></returns>
  94. public static bool GetMidInfo(string order, string pcmac, SQLiteConnection sqliteConn, out MidList mid)
  95. {
  96. mid = new MidList();
  97. string postData = string.Format("{{\"bid\":\"{0}\",\"mac\":\"{1}\"}}", order, pcmac);
  98. HttpHelper http = new HttpHelper();
  99. HttpItem item = new HttpItem()
  100. {
  101. URL = url_getMessage,//URL这里都是测试URl必需项
  102. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
  103. Method = "post",
  104. Postdata = postData,
  105. PostEncoding = Encoding.UTF8,
  106. KeepAlive = false
  107. };
  108. item.ContentType = "application/json;charset=utf-8";
  109. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  110. stopwatch.Start();
  111. HttpResult result = http.GetHtml(item);
  112. stopwatch.Stop();
  113. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  114. stopwatch.Reset();
  115. string ParseText = result.Html;
  116. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  117. {
  118. Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
  119. }
  120. else
  121. {
  122. Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
  123. CommonMethod.ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData, sqliteConn);
  124. return false;
  125. }
  126. try
  127. {
  128. JObject jObject = JObject.Parse(ParseText);
  129. mid.message = jObject["message"].Value<string>();
  130. mid.code = jObject["code"].Value<string>();
  131. mid.factoryname = jObject["factoryName"].Value<string>();
  132. mid.factoryNum = jObject["factoryNum"].Value<string>();
  133. mid.version = jObject["version"].Value<string>();
  134. mid.quantity = jObject["quantity"].Value<string>();
  135. mid.projectid = jObject["projectId"].Value<string>();
  136. mid.clienttype = jObject["clientType"].Value<string>();
  137. mid.host = jObject["host"].Value<string>();
  138. mid.whiteType = jObject["whiteType"].Value<string>();
  139. string aesEncrypt = jObject["aesEncrypt"] == null ? null : jObject["aesEncrypt"].Value<string>();
  140. mid.isSmt = jObject["isSmt"] == null ? "0" : jObject["isSmt"].Value<string>();
  141. if (aesEncrypt != null)
  142. mid.aesEncrypt = aesEncrypt.Equals("yes", StringComparison.OrdinalIgnoreCase);
  143. object a = jObject["rokuCustomer"];
  144. if (jObject["rokuCustomer"].ToString().Length > 0)
  145. {
  146. mid.rokuCustomer = GetRokuInfo(jObject["rokuCustomer"].ToString());
  147. }
  148. //如果订单是整机订单
  149. mid.keytype = new Dictionary<string, string>();
  150. if ( mid.isSmt.Equals("0") )
  151. {// 整机;
  152. foreach (var ss in jObject["obj"]) //查找某个字段与值
  153. {
  154. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  155. }
  156. }
  157. else
  158. {// 整机+板卡;
  159. if ( Main.Is_Smt == "1" )
  160. {
  161. foreach (var ss in jObject["obj_smt"]) //查找isSmt某个字段与值
  162. {
  163. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  164. }
  165. }
  166. else
  167. {
  168. foreach (var ss in jObject["obj"]) //查找某个字段与值
  169. {
  170. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  171. }
  172. }
  173. }
  174. if (mid.code == "1000")
  175. {
  176. midList = mid;
  177. return true;
  178. }
  179. }
  180. catch (Exception ex)
  181. {
  182. Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
  183. CommonMethod.ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData, sqliteConn);
  184. MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
  185. }
  186. return false;
  187. }
  188. public static bool GetMidKey(string url, string sn, string order, string psn, string firetv_device_code, List<KeyType> key2Write, SQLiteConnection connection, ref KeyInfo keys, out string msg)
  189. {
  190. msg = "";
  191. string code;
  192. bool result = false;
  193. HttpHelper http = new HttpHelper();
  194. HttpItem item = new HttpItem()
  195. {
  196. Encoding = Encoding.UTF8,
  197. Method = "post",
  198. ContentType = "application/json",
  199. KeepAlive = false
  200. };
  201. // 计算函数耗时;
  202. Stopwatch watch = new Stopwatch();
  203. watch.Start();
  204. item.URL = url + "/bind/order";
  205. item.Postdata = string.Format("{{\"orderNum\":\"{0}\",\"sn\":\"{1}\",\"psn\":\"{2}\",\"orderCode\":\"{3}\",\"clientType\":\"{4}\",\"isSmt\":\"{5}\",\"skipKey\":{6}}}", order, sn, psn, firetv_device_code, midList.clienttype,
  206. midList.isSmt.Equals("0") ? "0" : Main.Is_Smt , key2Write == null ? "[]" : JsonConvert.SerializeObject(key2Write).ToString());
  207. HttpResult httpResult = http.GetHtml(item);
  208. if (httpResult.StatusCode == System.Net.HttpStatusCode.OK)
  209. {
  210. try
  211. {
  212. JObject jObject = JObject.Parse(httpResult.Html);
  213. msg = CommonMethod.JSON_SeleteNode(jObject, "msg");
  214. code = CommonMethod.JSON_SeleteNode(jObject, "code");
  215. if (code == "0")
  216. {
  217. //需要解密
  218. if (midList != null && midList.aesEncrypt)
  219. {
  220. AES_DES Aes = new AES_DES();
  221. //data解密
  222. string plainText = CommonMethod.JSON_SeleteNode(jObject, "data");
  223. string key = AES_DES.AESKey;
  224. byte[] IV = AES_DES.AESIV;
  225. string str = AES_DES.DecryptStringFromBytes_Aes(plainText, key, IV);
  226. Log.WriteInfoLog("解密后:" + str);
  227. jObject["data"] = str;
  228. }
  229. Dictionary<string, string> data = JsonConvert.DeserializeObject<Dictionary<string, string>>(jObject["data"].ToString());
  230. if (data != null)
  231. {
  232. Func<string, string, bool> CheckMD5 = (data, md5) =>
  233. {
  234. if (data == null)
  235. return true;
  236. if (!GetMD5.GetStrMd5(data).Equals(md5, StringComparison.OrdinalIgnoreCase))
  237. return false;
  238. return true;
  239. };
  240. if (data.ContainsKey("mac") && data.ContainsKey("mac_md5"))
  241. {
  242. keys.Mac.data = data["mac"];
  243. keys.Mac.md5 = data["mac_md5"];
  244. if (!CheckMD5(keys.Mac.data, keys.Mac.md5))
  245. {
  246. msg = string.Format("Mac Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Mac.data, keys.Mac.md5);
  247. goto end;
  248. }
  249. }
  250. if (data.ContainsKey("btMac") && data.ContainsKey("btMac_md5"))
  251. {
  252. keys.BT_MAC.data = data["btMac"];
  253. keys.BT_MAC.md5 = data["btMac_md5"];
  254. if (!CheckMD5(keys.BT_MAC.data, keys.BT_MAC.md5))
  255. {
  256. msg = string.Format("BT_MAC Key Value md5 Is Incorrect: data={0}, md5={1}", keys.BT_MAC.data, keys.BT_MAC.md5);
  257. goto end;
  258. }
  259. }
  260. if (data.ContainsKey("wifiMac") && data.ContainsKey("wifiMac_md5"))
  261. {
  262. keys.WiFi_MAC.data = data["wifiMac"];
  263. keys.WiFi_MAC.md5 = data["wifiMac_md5"];
  264. if (!CheckMD5(keys.WiFi_MAC.data, keys.WiFi_MAC.md5))
  265. {
  266. msg = string.Format("WiFi_MAC Key Value md5 Is Incorrect: data={0}, md5={1}", keys.WiFi_MAC.data, keys.WiFi_MAC.md5);
  267. goto end;
  268. }
  269. }
  270. if (data.ContainsKey("deviceid") && data.ContainsKey("deviceid_md5"))
  271. {
  272. keys.DID.data = data["deviceid"];
  273. keys.DID.md5 = data["deviceid_md5"];
  274. if (!CheckMD5(keys.DID.data, keys.DID.md5))
  275. {
  276. msg = string.Format("DID Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DID.data, keys.DID.md5);
  277. goto end;
  278. }
  279. }
  280. if (data.ContainsKey("hdcp") && data.ContainsKey("hdcp_md5"))
  281. {
  282. keys.HDCP.data = data["hdcp"];
  283. keys.HDCP.md5 = data["hdcp_md5"];
  284. if (!CheckMD5(keys.HDCP.data, keys.HDCP.md5))
  285. {
  286. msg = string.Format("HDCP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.HDCP.data, keys.HDCP.md5);
  287. goto end;
  288. }
  289. }
  290. if (data.ContainsKey("hdcp2") && data.ContainsKey("hdcp2_md5"))
  291. {
  292. keys.HDCP22.data = data["hdcp2"];
  293. keys.HDCP22.md5 = data["hdcp2_md5"];
  294. if (!CheckMD5(keys.HDCP22.data, keys.HDCP22.md5))
  295. {
  296. msg = string.Format("HDCP22 Key Value md5 Is Incorrect: data={0}, md5={1}", keys.HDCP22.data, keys.HDCP22.md5);
  297. goto end;
  298. }
  299. }
  300. if (data.ContainsKey("ci") && data.ContainsKey("ci_md5"))
  301. {
  302. keys.CI_plus.data = data["ci"];
  303. keys.CI_plus.md5 = data["ci_md5"];
  304. if (!CheckMD5(keys.CI_plus.data, keys.CI_plus.md5))
  305. {
  306. msg = string.Format("CI_plus Key Value md5 Is Incorrect: data={0}, md5={1}", keys.CI_plus.data, keys.CI_plus.md5);
  307. goto end;
  308. }
  309. }
  310. if (data.ContainsKey("ecp") && data.ContainsKey("ecp_md5"))
  311. {
  312. keys.ECP.data = data["ecp"];
  313. keys.ECP.md5 = data["ecp_md5"];
  314. if (!CheckMD5(keys.ECP.data, keys.ECP.md5))
  315. {
  316. msg = string.Format("ECP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ECP.data, keys.ECP.md5);
  317. goto end;
  318. }
  319. }
  320. if (data.ContainsKey("acas") && data.ContainsKey("acas_md5"))
  321. {
  322. keys.ACASKey_Data.data = data["acas"];
  323. keys.ACASKey_Data.md5 = data["acas_md5"];
  324. if (!CheckMD5(keys.ACASKey_Data.data, keys.ACASKey_Data.md5))
  325. {
  326. msg = string.Format("ACASKey_Data Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ACASKey_Data.data, keys.ACASKey_Data.md5);
  327. goto end;
  328. }
  329. }
  330. if (data.ContainsKey("lek") && data.ContainsKey("lek_md5"))
  331. {
  332. keys.LEK.data = data["lek"];
  333. keys.LEK.md5 = data["lek_md5"];
  334. if (!CheckMD5(keys.LEK.data, keys.LEK.md5))
  335. {
  336. msg = string.Format("LEK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.LEK.data, keys.LEK.md5);
  337. goto end;
  338. }
  339. }
  340. if (data.ContainsKey("pek") && data.ContainsKey("pek_md5"))
  341. {
  342. keys.PEK.data = data["pek"];
  343. keys.PEK.md5 = data["pek_md5"];
  344. if (!CheckMD5(keys.PEK.data, keys.PEK.md5))
  345. {
  346. msg = string.Format("PEK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.PEK.data, keys.PEK.md5);
  347. goto end;
  348. }
  349. }
  350. if (data.ContainsKey("playready") && data.ContainsKey("playready_md5"))
  351. {
  352. keys.Playready.data = data["playready"];
  353. keys.Playready.md5 = data["playready_md5"];
  354. if (!CheckMD5(keys.Playready.data, keys.Playready.md5))
  355. {
  356. msg = string.Format("Playready Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Playready.data, keys.Playready.md5);
  357. goto end;
  358. }
  359. }
  360. if (data.ContainsKey("netfilx") && data.ContainsKey("netfilx_md5"))
  361. {
  362. keys.ESN.data = data["netfilx"];
  363. keys.ESN.md5 = data["netfilx_md5"];
  364. if (!CheckMD5(keys.ESN.data, keys.ESN.md5))
  365. {
  366. msg = string.Format("ESN Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ESN.data, keys.ESN.md5);
  367. goto end;
  368. }
  369. }
  370. if (data.ContainsKey("hash") && data.ContainsKey("hash_md5"))
  371. {
  372. keys.Hashkey.data = data["hash"];
  373. keys.Hashkey.md5 = data["hash_md5"];
  374. if (!CheckMD5(keys.Hashkey.data, keys.Hashkey.md5))
  375. {
  376. msg = string.Format("Hashkey Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Hashkey.data, keys.Hashkey.md5);
  377. goto end;
  378. }
  379. }
  380. if (data.ContainsKey("mgk") && data.ContainsKey("mgk_md5"))
  381. {
  382. keys.MGK.data = data["mgk"];
  383. keys.MGK.md5 = data["mgk_md5"];
  384. if (!CheckMD5(keys.MGK.data, keys.MGK.md5))
  385. {
  386. msg = string.Format("MGK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.MGK.data, keys.MGK.md5);
  387. goto end;
  388. }
  389. }
  390. if (data.ContainsKey("youtube") && data.ContainsKey("youtube_md5"))
  391. {
  392. keys.YouTube_KEY.data = data["youtube"];
  393. keys.YouTube_KEY.md5 = data["youtube_md5"];
  394. if (!CheckMD5(keys.YouTube_KEY.data, keys.YouTube_KEY.md5))
  395. {
  396. msg = string.Format("YouTube_KEY Key Value md5 Is Incorrect: data={0}, md5={1}", keys.YouTube_KEY.data, keys.YouTube_KEY.md5);
  397. goto end;
  398. }
  399. }
  400. if (data.ContainsKey("fairplay") && data.ContainsKey("fairplay_md5"))
  401. {
  402. keys.Fairplay.data = data["fairplay"];
  403. keys.Fairplay.md5 = data["fairplay_md5"];
  404. if (!CheckMD5(keys.Fairplay.data, keys.Fairplay.md5))
  405. {
  406. msg = string.Format("Fairplay Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Fairplay.data, keys.Fairplay.md5);
  407. goto end;
  408. }
  409. }
  410. if (data.ContainsKey("widevine") && data.ContainsKey("widevine_md5"))
  411. {
  412. keys.Widevine.data = data["widevine"];
  413. keys.Widevine.md5 = data["widevine_md5"];
  414. if (!CheckMD5(keys.Widevine.data, keys.Widevine.md5))
  415. {
  416. msg = string.Format("Widevine Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Widevine.data, keys.Widevine.md5);
  417. goto end;
  418. }
  419. }
  420. if (data.ContainsKey("attention") && data.ContainsKey("attention_md5"))
  421. {
  422. keys.Attestation.data = data["attention"];
  423. keys.Attestation.md5 = data["attention_md5"];
  424. if (!CheckMD5(keys.Attestation.data, keys.Attestation.md5))
  425. {
  426. msg = string.Format("Attestation Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Attestation.data, keys.Attestation.md5);
  427. goto end;
  428. }
  429. }
  430. if (data.ContainsKey("dsn") && data.ContainsKey("dsn_md5"))
  431. {
  432. keys.DSN.data = data["dsn"];
  433. keys.DSN.md5 = data["dsn_md5"];
  434. if (!CheckMD5(keys.DSN.data, keys.DSN.md5))
  435. {
  436. msg = string.Format("DSN Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DSN.data, keys.DSN.md5);
  437. goto end;
  438. }
  439. }
  440. if (data.ContainsKey("dak") && data.ContainsKey("dak_md5"))
  441. {
  442. keys.DAK.data = data["dak"];
  443. keys.DAK.md5 = data["dak_md5"];
  444. if (!CheckMD5(keys.DAK.data, keys.DAK.md5))
  445. {
  446. msg = string.Format("DAK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DAK.data, keys.DAK.md5);
  447. goto end;
  448. }
  449. }
  450. if (data.ContainsKey("kfp") && data.ContainsKey("kfp_md5"))
  451. {
  452. keys.KFP.data = data["kfp"];
  453. keys.KFP.md5 = data["kfp_md5"];
  454. if (!CheckMD5(keys.KFP.data, keys.KFP.md5))
  455. {
  456. msg = string.Format("KFP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.KFP.data, keys.KFP.md5);
  457. goto end;
  458. }
  459. }
  460. result = true;
  461. }
  462. }
  463. }
  464. catch(Exception ex)
  465. {
  466. msg = ex.Message;
  467. }
  468. }
  469. end:
  470. watch.Stop();
  471. Log.WriteInfoLog(string.Format("[GetIDMKeys] order={0},sn={1},Elapsed={2} GetKeys={3}", order, sn, watch.Elapsed.TotalMilliseconds, result ? "成功" : "失败"));
  472. if (!result)
  473. CommonMethod.ReportErrormsg("Fail to GetIDMKeys ", msg + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + httpResult.Html, connection);
  474. return result;
  475. }
  476. public static string GetReportJson(string order, string sn, bool isNodid, string clientType, string swVer, string pid, ref KeyInfo keyinfo, bool bMIEnable, ref MIKey mIKey)
  477. {
  478. Func<string, string, JObject, bool> AddJsonItem = (name, value, jobj) =>
  479. {
  480. if (name == null || name.Length == 0)
  481. return false;
  482. if (value == null || value.Length == 0)
  483. return false;
  484. if (jobj == null)
  485. return false;
  486. jobj.Add(name, (JToken)value);
  487. return true;
  488. };
  489. Func<KeyData, JObject, bool> AddKeyJson = (keydata, jobj) =>
  490. {
  491. if (keydata == null || jobj == null || keydata.data == null)
  492. return false;
  493. if (keydata.keyfrom == KEY_FROM.FROM_IDM && keydata.enable)
  494. {
  495. jobj.Add(keydata.name, (JToken)keydata.data);
  496. }
  497. return true;
  498. };
  499. Func<KeyData, JObject, string, bool> AddKeyJson2 = (keydata, jobj, name) =>
  500. {
  501. if (keydata == null || jobj == null || keydata.data == null)
  502. return false;
  503. if (keydata.keyfrom == KEY_FROM.FROM_IDM && keydata.enable)
  504. {
  505. jobj.Add(name, (JToken)keydata.data);
  506. }
  507. return true;
  508. };
  509. try
  510. {
  511. JObject postJson = new JObject();
  512. AddJsonItem("ordernum", order, postJson);
  513. AddJsonItem("sn", sn, postJson);
  514. AddJsonItem("nodid", isNodid.ToString().ToLower(), postJson);
  515. AddJsonItem("toolVersion", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), postJson);
  516. AddJsonItem("clienttype", clientType, postJson);
  517. AddJsonItem("sversionid", swVer, postJson);
  518. AddJsonItem("projectid", pid, postJson);
  519. //上报时增加smtpsn 字段
  520. //读取PSN
  521. AddJsonItem("smtPsn",OperationPanel.smtPsn,postJson);
  522. if (keyinfo != null)
  523. {
  524. AddKeyJson2(keyinfo.DID, postJson, "deviceid");
  525. if ( !bMIEnable || (mIKey != null && mIKey.EthernetMac == null))
  526. AddKeyJson2(keyinfo.Mac, postJson, "mac");
  527. AddKeyJson2(keyinfo.HDCP, postJson, "hdcpkey");
  528. AddKeyJson2(keyinfo.HDCP22, postJson, "hdcpkey2");
  529. AddKeyJson2(keyinfo.ESN, postJson, "netfilxesn");
  530. AddKeyJson2(keyinfo.Widevine, postJson, "widevine");
  531. AddKeyJson2(keyinfo.CI_plus, postJson, "cikey");
  532. AddKeyJson2(keyinfo.Attestation, postJson, "attestation");
  533. AddKeyJson2(keyinfo.MGK, postJson, "mgk");
  534. AddKeyJson2(keyinfo.Fairplay, postJson, "fairplay");
  535. if (!bMIEnable || ( mIKey != null && mIKey.DSN == null))
  536. AddKeyJson2(keyinfo.DSN, postJson, "dsn");
  537. if (!bMIEnable || (mIKey != null && mIKey.WIFIMAC == null))
  538. AddKeyJson2(keyinfo.WiFi_MAC, postJson, "wifimac");
  539. if (!bMIEnable || (mIKey != null && mIKey.BTMac == null))
  540. AddKeyJson2(keyinfo.BT_MAC, postJson, "btmac");
  541. AddKeyJson2(keyinfo.LEK, postJson, "lek");
  542. AddKeyJson2(keyinfo.PEK, postJson, "pek");
  543. AddKeyJson2(keyinfo.Playready, postJson, "playready");
  544. AddKeyJson2(keyinfo.Hashkey, postJson, "hash");
  545. AddKeyJson2(keyinfo.ECP, postJson, "ecp");
  546. AddKeyJson2(keyinfo.YouTube_KEY, postJson, "youtubekey");
  547. AddKeyJson2(keyinfo.ACASKey_Data, postJson, "acas_data");
  548. AddKeyJson2(keyinfo.DAK, postJson, "dak");
  549. AddKeyJson2(keyinfo.KFP, postJson, "kfp");
  550. }
  551. string postData = postJson.ToString();
  552. //需要加密上报的话
  553. if (midList != null && midList.aesEncrypt)
  554. {
  555. AES_DES AES_DES = new AES_DES();
  556. string key = AES_DES.AESKey;
  557. byte[] IV = AES_DES.AESIV;
  558. postData = AES_DES.EncryptStringToBytes_Aes(postData, key, IV);
  559. //json
  560. string Data = string.Format("{{\"reportData\":\"{0}\"}}", postData);
  561. JObject jo = JObject.Parse(Data);
  562. postData = jo.ToString();
  563. }
  564. return postData;
  565. }
  566. catch (Exception ex)
  567. {
  568. Log.WriteErrorLog("\r\nFail to GetReportJson," + ex.Message + ":" + "\r\nOrder:" + order + "\r\nSN:" + sn);
  569. }
  570. return "";
  571. }
  572. /// <summary>
  573. /// 在线抄写完成上报 Key
  574. /// </summary>
  575. /// <param name="url"></param>
  576. /// <param name="order"></param>
  577. /// <param name="sn"></param>
  578. /// <param name="isNodid"></param>
  579. /// <param name="keyinfo"></param>
  580. /// <param name="sqliteConn"></param>
  581. /// <param name="msg"></param>
  582. /// <returns></returns>
  583. public static bool ReportOnlineData(string url, string order, string postData, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout, bool background = false)
  584. {
  585. if ( background )
  586. {
  587. return SQLiteHelper.AddReportOnlineData(sqliteConn, url + "/reportData/report", postData);
  588. }
  589. if (timeout < 5000)
  590. timeout = 5000;
  591. HttpHelper http = new HttpHelper();
  592. HttpItem item = new HttpItem()
  593. {
  594. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
  595. Method = "post",
  596. Postdata = postData,
  597. PostEncoding = Encoding.UTF8,
  598. Timeout = timeout,
  599. KeepAlive = false
  600. };
  601. item.URL = url + "/reportData/report";
  602. item.ContentType = "application/json;charset=utf-8";
  603. Stopwatch stopwatch = new Stopwatch();
  604. stopwatch.Start();
  605. HttpResult result = http.GetHtml(item);
  606. stopwatch.Stop();
  607. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  608. stopwatch.Reset();
  609. string ParseText = result.Html;
  610. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  611. {
  612. Log.WriteGetKeyLog("\r\nReportOnlineData info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  613. try
  614. {
  615. JObject jObject = JObject.Parse(ParseText);
  616. string msg = jObject["msg"].Value<string>();
  617. string code = jObject["code"].Value<string>();
  618. if (code == "0")
  619. return true;
  620. }
  621. catch (Exception ex)
  622. {
  623. Log.WriteErrorLog("\r\nFail to ReportOnlineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  624. CommonMethod.ReportErrormsg("Fail to ReportOnlineData", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  625. }
  626. if (repeatupload)
  627. {// 删除记录;
  628. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  629. }
  630. }
  631. else
  632. {
  633. Log.WriteErrorLog("\r\nFail to ReportOnlineData:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  634. CommonMethod.ReportErrormsg("Fail to ReportOnlineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  635. }
  636. return false;
  637. }
  638. public static bool ReportOnlineDataSQL(string url, string postData, int timeout)
  639. {
  640. if (timeout < 5000)
  641. timeout = 5000;
  642. HttpHelper http = new HttpHelper();
  643. HttpItem item = new HttpItem()
  644. {
  645. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
  646. Method = "post",
  647. Postdata = postData,
  648. PostEncoding = Encoding.UTF8,
  649. Timeout = timeout,
  650. KeepAlive = false
  651. };
  652. item.URL = url;
  653. item.ContentType = "application/json;charset=utf-8";
  654. HttpResult result = http.GetHtml(item);
  655. string ParseText = result.Html;
  656. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  657. {
  658. Log.WriteGetKeyLog("\r\nReportOnlineDataSQL info\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  659. try
  660. {
  661. JObject jObject = JObject.Parse(ParseText);
  662. string msg = jObject["msg"].Value<string>();
  663. string code = jObject["code"].Value<string>();
  664. if (code == "0")
  665. return true;
  666. }
  667. catch (Exception ex)
  668. {
  669. Log.WriteErrorLog("\r\nFail to ReportOnlineDataSQL," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  670. }
  671. }
  672. else
  673. {
  674. Log.WriteErrorLog("\r\nFail to ReportOnlineDataSQL:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  675. }
  676. return false;
  677. }
  678. //reportData/reportList
  679. /// <summary>
  680. /// 离线抄写上报
  681. /// </summary>
  682. /// <param name="url"></param>
  683. /// <param name="copydate"></param>
  684. /// <param name="SN"></param>
  685. /// <param name="localDBNow"></param>
  686. /// <param name="sqliteConn"></param>
  687. /// <param name="repeatupload"></param>
  688. /// <param name="id"></param>
  689. /// <param name="timeout"></param>
  690. /// <returns></returns>
  691. public static bool ReportOfflineData(string url, string copydate, string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
  692. {
  693. HttpHelper http = new HttpHelper();
  694. HttpItem item = new HttpItem()
  695. {
  696. Encoding = Encoding.UTF8,
  697. Method = "post",
  698. Postdata = string.Format("{{\"sn\":\"{0}\",\"date\":\"{1}\"}}", SN, copydate),
  699. PostEncoding = Encoding.UTF8,
  700. KeepAlive = false
  701. };
  702. item.URL = url + "/reportData/reportList";
  703. item.ContentType = "application/json;charset=utf-8";
  704. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  705. stopwatch.Start();
  706. HttpResult result = http.GetHtml(item);
  707. stopwatch.Stop();
  708. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  709. stopwatch.Reset();
  710. string ParseText = result.Html;
  711. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  712. {
  713. Log.WriteGetKeyLog("\r\nReportOfflineData info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  714. }
  715. else
  716. {
  717. Log.WriteErrorLog("\r\nFail to ReportOfflineData:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  718. CommonMethod.ReportErrormsg("Fail to ReportOfflineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  719. if (repeatupload)
  720. return false;
  721. return false;
  722. }
  723. try
  724. {
  725. JObject jObject = JObject.Parse(ParseText);
  726. string msg = jObject["msg"].Value<string>();
  727. string code = jObject["code"].Value<string>();
  728. if (code == "0")
  729. {
  730. //更新上报内容
  731. if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
  732. {
  733. //更新成功
  734. Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + url + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
  735. return true;
  736. }
  737. else
  738. {
  739. Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
  740. return false;
  741. }
  742. }
  743. else
  744. {
  745. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + url + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText, sqliteConn);
  746. Log.WriteErrorLog("\r\nUpdateReportStatus code return error,should be 1000 " + "\r\n" + SN + ":" + ParseText + "\r\nAddress:" + url + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate);
  747. if (repeatupload)
  748. {
  749. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  750. }
  751. }
  752. }
  753. catch (Exception ex)
  754. {
  755. Log.WriteErrorLog("\r\nFail to ReportOfflineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  756. CommonMethod.ReportErrormsg("Fail to ReportOfflineData", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  757. }
  758. return false;
  759. }
  760. public static bool GetOfflineData(string url, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
  761. {
  762. midAddressList = new List<MidAddress>();
  763. HttpHelper http = new HttpHelper();
  764. HttpItem item = new HttpItem()
  765. {
  766. Encoding = Encoding.UTF8,
  767. Method = "post",
  768. Postdata = string.Format("{{\"ordernum\":\"{0}\",\"mac\":\"{1}\"}}", order, TestMode.MAC),
  769. KeepAlive = false
  770. };
  771. item.URL = url + "/offline/getofflinelist";
  772. item.ContentType = "application/json;charset=utf-8";
  773. HttpResult result = http.GetHtml(item);
  774. string ParseText = result.Html;
  775. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  776. {
  777. }
  778. else
  779. {
  780. Log.WriteErrorLog("\r\nFail to GetOfflineData:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  781. CommonMethod.ReportErrormsg("Fail to GetOfflineData", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  782. return false;
  783. }
  784. try
  785. {
  786. JObject jObject = JObject.Parse(ParseText);
  787. if (jObject["data"] != null)
  788. {
  789. foreach (var data in jObject["data"])
  790. {
  791. midAddressList.Add(new MidAddress()
  792. {
  793. des = CommonMethod.JSON_SeleteNode(jObject, "des"),
  794. code = CommonMethod.JSON_SeleteNode(jObject, "code"),
  795. order = data["order_number"].ToObject<string>(),
  796. number = data["order_quantity"].ToObject<string>(),
  797. pid = data["project_id"].ToObject<string>(),
  798. ctype = data["client_type"].ToObject<string>(),
  799. purl = data["packet_url"].ToObject<string>(),
  800. psize = data["packet_size"].ToObject<string>(),
  801. pmd5 = data["packet_md5"].ToObject<string>(),
  802. version = data["soft_version"].ToObject<string>(),
  803. host = url
  804. });
  805. }
  806. Log.WriteGetKeyLog("\r\nGet GetOfflineData success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  807. return true;
  808. }
  809. Log.WriteErrorLog("\r\nFail to GetOfflineData," + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  810. }
  811. catch (Exception ex)
  812. {
  813. Log.WriteErrorLog("\r\nFail to GetOfflineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  814. CommonMethod.ReportErrormsg("Fail to GetOfflineData", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  815. MessageBox.Show("Fail to GetOfflineData info\r\n " + ex.Message);
  816. return false;
  817. }
  818. return false;
  819. }
  820. public static bool ReportDownloadStatus(string url, string order, SQLiteConnection sqliteConn)
  821. {
  822. HttpHelper http = new HttpHelper();
  823. HttpItem item = new HttpItem()
  824. {
  825. Encoding = null,
  826. Method = "post",
  827. Postdata = string.Format("{{\"ordernum\":\"{0}\"}}", order),
  828. KeepAlive = false
  829. };
  830. item.URL = url += "/offline/getreportofflinesn";
  831. item.ContentType = "application/json;charset=utf-8";
  832. HttpResult result = http.GetHtml(item);
  833. string ParseText = result.Html;
  834. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  835. {
  836. Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
  837. CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
  838. return false;
  839. }
  840. try
  841. {
  842. JObject jObject = JObject.Parse(ParseText);
  843. string msg = CommonMethod.JSON_SeleteNode(jObject, "msg");
  844. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  845. if (code != "0")
  846. {
  847. Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
  848. CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
  849. return false;
  850. }
  851. }
  852. catch (Exception ex)
  853. {
  854. MessageBox.Show(ex.Message);
  855. Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
  856. CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
  857. return false;
  858. }
  859. return true;
  860. }
  861. //北美项目,不抄从idm上获取的DSN,用smse上的
  862. public static bool GetDSNFromSmes(string SN, out string DSN)
  863. {
  864. string msg;
  865. DSN = "";
  866. HttpHelper http = new HttpHelper();
  867. HttpItem item = new HttpItem()
  868. {
  869. Encoding = Encoding.UTF8,
  870. Method = "post",
  871. ContentType = "application/x-www-form-urlencoded",
  872. KeepAlive = false
  873. };
  874. item.URL = url_getDSNFromSmes + SN;
  875. HttpResult hResult = http.GetHtml(item);
  876. if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
  877. {
  878. try
  879. {
  880. using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
  881. {
  882. JObject jObject = (JObject)JToken.ReadFrom(reader);
  883. reader.Close();
  884. foreach (var ss in jObject["Tvparts"]) //查找某个字段与值
  885. {
  886. //如果里面的TypeCode为MA(主板),读出他的PSN
  887. if (ss["PartTypeCode"].Value<string>().Equals("DSN-T", StringComparison.OrdinalIgnoreCase))
  888. {
  889. DSN = ss["PartSN"].Value<string>();
  890. break;
  891. }
  892. }
  893. if (DSN == "" || DSN == null)
  894. {
  895. MessageBox.Show("查不到该SN对应的主板DSN号");
  896. return false;
  897. }
  898. Log.WriteInfoLog("PartSN" + DSN);
  899. return true;
  900. }
  901. }
  902. catch (Exception e)
  903. {
  904. msg = e.Message;
  905. Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  906. }
  907. }
  908. else
  909. {
  910. msg = hResult.StatusDescription;
  911. Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
  912. }
  913. return false;
  914. }
  915. };
  916. };