V2Method.cs 49 KB

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