V2Method.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using SufeiUtil;
  4. using SXLibrary;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Data.SQLite;
  8. using System.Diagnostics;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Web;
  13. using System.Windows.Forms;
  14. using HttpHelper = SufeiUtil.HttpHelper;
  15. namespace MOKA_Factory_Tools
  16. {
  17. internal class V2Method
  18. {
  19. #if DEBUG
  20. public static void Test()
  21. {
  22. MidList mid;
  23. bool bRet = GetMidInfo("TEST_WJF", "04-D4-C4-EE-6B-CD", null, out mid);
  24. if (bRet)
  25. {
  26. List<KeyType> key2Write;
  27. string msg;
  28. KeyInfo keys = new KeyInfo();
  29. bRet = GetMidKey(mid.host, "SN0321-test9999", "TEST_WJF", "20220321APSN9999", "BBB", null, null, ref keys, out msg);
  30. List<MidAddress> midlist;
  31. GetOfflineData(mid.host, "TEST_WJF", null, out midlist);
  32. if (bRet)
  33. {
  34. Action<KeyData> SetEnable = (keydata) =>
  35. {
  36. if (keydata != null && keydata.data.Length > 0)
  37. keydata.enable = true;
  38. };
  39. SetEnable(keys.Mac);
  40. SetEnable(keys.HDCP);
  41. SetEnable(keys.DID);
  42. SetEnable(keys.HDCP22);
  43. SetEnable(keys.CI_plus);
  44. SetEnable(keys.Playready);
  45. ReportOnlineData(mid.host, "TEST_WJF", GetReportJson("TEST_WJF", "SN0321-test9999", false, ref keys), null, false, "", 1000);
  46. ReportOfflineData(mid.host, "2022-07-18 14:40:42", "SN0321-test9999", null, null, false, "");
  47. }
  48. }
  49. }
  50. #endif
  51. private static string url_getMessage = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do";
  52. public static void SetMexicanConfig(bool bMexican = false)
  53. {
  54. if (bMexican)
  55. url_getMessage = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do";
  56. if ( TestMode.testMode)
  57. url_getMessage = "http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do";
  58. }
  59. /// <summary>
  60. ///
  61. /// </summary>
  62. /// <param name="url"></param>
  63. /// <param name="order"></param>
  64. /// <param name="pcmac"></param>
  65. /// <param name="sqliteConn"></param>
  66. /// <param name="mid"></param>
  67. /// <returns></returns>
  68. public static bool GetMidInfo(string order, string pcmac, SQLiteConnection sqliteConn, out MidList mid)
  69. {
  70. mid = new MidList();
  71. string postData = string.Format("{{\"bid\":\"{0}\",\"mac\":\"{1}\"}}", order, pcmac);
  72. HttpHelper http = new HttpHelper();
  73. HttpItem item = new HttpItem()
  74. {
  75. URL = url_getMessage,//URL这里都是测试URl必需项
  76. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
  77. Method = "post",
  78. Postdata = postData,
  79. PostEncoding = Encoding.UTF8,
  80. KeepAlive = false
  81. };
  82. item.ContentType = "application/json;charset=utf-8";
  83. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  84. stopwatch.Start();
  85. HttpResult result = http.GetHtml(item);
  86. stopwatch.Stop();
  87. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  88. stopwatch.Reset();
  89. string ParseText = result.Html;
  90. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  91. {
  92. Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
  93. }
  94. else
  95. {
  96. Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
  97. CommonMethod.ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData, sqliteConn);
  98. return false;
  99. }
  100. try
  101. {
  102. JObject jObject = JObject.Parse(ParseText);
  103. mid.message = jObject["message"].Value<string>();
  104. mid.code = jObject["code"].Value<string>();
  105. mid.factoryname = jObject["factoryName"].Value<string>();
  106. mid.factoryNum = jObject["factoryNum"].Value<string>();
  107. mid.version = jObject["version"].Value<string>();
  108. mid.quantity = jObject["quantity"].Value<string>();
  109. mid.projectid = jObject["projectId"].Value<string>();
  110. mid.clienttype = jObject["clientType"].Value<string>();
  111. mid.host = jObject["host"].Value<string>();
  112. mid.whiteType = jObject["whiteType"].Value<string>();
  113. object a = jObject["rokuCustomer"];
  114. if (jObject["rokuCustomer"].ToString().Length > 0)
  115. {
  116. mid.rokuCustomer = new RokuCustomer()
  117. {
  118. id = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "id").Trim(),
  119. ordernum = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "ordernum").Trim(),
  120. brand = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "brand").Trim(),
  121. region = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "region").Trim(),
  122. oemmodel = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "oemmodel").Trim(),
  123. supporturl = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "supporturl").Trim(),
  124. supportphone = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "supportphone").Trim(),
  125. productiondate = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "productiondate").Trim(),
  126. remotetype = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "remotetype").Trim(),
  127. updatetime = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "updatetime").Trim(),
  128. createtime = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "createtime").Trim(),
  129. isdelete = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "isdelete").Trim()
  130. };
  131. }
  132. mid.keytype = new Dictionary<string, string>();
  133. foreach (var ss in jObject["obj"]) //查找某个字段与值
  134. {
  135. mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
  136. }
  137. if (mid.code == "1000")
  138. return true;
  139. }
  140. catch (Exception ex)
  141. {
  142. Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
  143. CommonMethod.ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData, sqliteConn);
  144. MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
  145. }
  146. return false;
  147. }
  148. 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)
  149. {
  150. msg = "";
  151. string code;
  152. bool result = false;
  153. HttpHelper http = new HttpHelper();
  154. HttpItem item = new HttpItem()
  155. {
  156. Encoding = Encoding.UTF8,
  157. Method = "post",
  158. ContentType = "application/json",
  159. KeepAlive = false
  160. };
  161. // 计算函数耗时;
  162. Stopwatch watch = new Stopwatch();
  163. watch.Start();
  164. item.URL = url + "/bind/order";
  165. item.Postdata = string.Format("{{\"orderNum\":\"{0}\",\"sn\":\"{1}\",\"psn\":\"{2}\",\"orderCode\":\"{3}\",\"skipKey\":{4}}}", order, sn, psn, firetv_device_code, key2Write == null ? "[]" : JsonConvert.SerializeObject(key2Write).ToString());
  166. HttpResult httpResult = http.GetHtml(item);
  167. if (httpResult.StatusCode == System.Net.HttpStatusCode.OK)
  168. {
  169. try
  170. {
  171. JObject jObject = JObject.Parse(httpResult.Html);
  172. msg = CommonMethod.JSON_SeleteNode(jObject, "msg");
  173. code = CommonMethod.JSON_SeleteNode(jObject, "code");
  174. if (code == "0")
  175. {
  176. Dictionary<string, string> data = JsonConvert.DeserializeObject<Dictionary<string, string>>(jObject["data"].ToString());
  177. if (data != null)
  178. {
  179. Func<string, string, bool> CheckMD5 = (data, md5) =>
  180. {
  181. if (data == null)
  182. return true;
  183. if (!GetMD5.GetStrMd5(data).Equals(md5, StringComparison.OrdinalIgnoreCase))
  184. return false;
  185. return true;
  186. };
  187. if (data.ContainsKey("mac") && data.ContainsKey("mac_md5"))
  188. {
  189. keys.Mac.data = data["mac"];
  190. keys.Mac.md5 = data["mac_md5"];
  191. if (!CheckMD5(keys.Mac.data, keys.Mac.md5))
  192. {
  193. msg = string.Format("Mac Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Mac.data, keys.Mac.md5);
  194. goto end;
  195. }
  196. }
  197. if (data.ContainsKey("btMac") && data.ContainsKey("btMac_md5"))
  198. {
  199. keys.BT_MAC.data = data["btMac"];
  200. keys.BT_MAC.md5 = data["btMac_md5"];
  201. if (!CheckMD5(keys.BT_MAC.data, keys.BT_MAC.md5))
  202. {
  203. msg = string.Format("BT_MAC Key Value md5 Is Incorrect: data={0}, md5={1}", keys.BT_MAC.data, keys.BT_MAC.md5);
  204. goto end;
  205. }
  206. }
  207. if (data.ContainsKey("wifiMac") && data.ContainsKey("wifiMac_md5"))
  208. {
  209. keys.WiFi_MAC.data = data["wifiMac"];
  210. keys.WiFi_MAC.md5 = data["wifiMac_md5"];
  211. if (!CheckMD5(keys.WiFi_MAC.data, keys.WiFi_MAC.md5))
  212. {
  213. msg = string.Format("WiFi_MAC Key Value md5 Is Incorrect: data={0}, md5={1}", keys.WiFi_MAC.data, keys.WiFi_MAC.md5);
  214. goto end;
  215. }
  216. }
  217. if (data.ContainsKey("deviceid") && data.ContainsKey("deviceid_md5"))
  218. {
  219. keys.DID.data = data["deviceid"];
  220. keys.DID.md5 = data["deviceid_md5"];
  221. if (!CheckMD5(keys.DID.data, keys.DID.md5))
  222. {
  223. msg = string.Format("DID Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DID.data, keys.DID.md5);
  224. goto end;
  225. }
  226. }
  227. if (data.ContainsKey("hdcp") && data.ContainsKey("hdcp_md5"))
  228. {
  229. keys.HDCP.data = data["hdcp"];
  230. keys.HDCP.md5 = data["hdcp_md5"];
  231. if (!CheckMD5(keys.HDCP.data, keys.HDCP.md5))
  232. {
  233. msg = string.Format("HDCP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.HDCP.data, keys.HDCP.md5);
  234. goto end;
  235. }
  236. }
  237. if (data.ContainsKey("hdcp2") && data.ContainsKey("hdcp2_md5"))
  238. {
  239. keys.HDCP22.data = data["hdcp2"];
  240. keys.HDCP22.md5 = data["hdcp2_md5"];
  241. if (!CheckMD5(keys.HDCP22.data, keys.HDCP22.md5))
  242. {
  243. msg = string.Format("HDCP22 Key Value md5 Is Incorrect: data={0}, md5={1}", keys.HDCP22.data, keys.HDCP22.md5);
  244. goto end;
  245. }
  246. }
  247. if (data.ContainsKey("ci") && data.ContainsKey("ci_md5"))
  248. {
  249. keys.CI_plus.data = data["ci"];
  250. keys.CI_plus.md5 = data["ci_md5"];
  251. if (!CheckMD5(keys.CI_plus.data, keys.CI_plus.md5))
  252. {
  253. msg = string.Format("CI_plus Key Value md5 Is Incorrect: data={0}, md5={1}", keys.CI_plus.data, keys.CI_plus.md5);
  254. goto end;
  255. }
  256. }
  257. if (data.ContainsKey("ecp") && data.ContainsKey("ecp_md5"))
  258. {
  259. keys.ECP.data = data["ecp"];
  260. keys.ECP.md5 = data["ecp_md5"];
  261. if (!CheckMD5(keys.ECP.data, keys.ECP.md5))
  262. {
  263. msg = string.Format("ECP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ECP.data, keys.ECP.md5);
  264. goto end;
  265. }
  266. }
  267. if (data.ContainsKey("acas") && data.ContainsKey("acas_md5"))
  268. {
  269. keys.ACASKey_Data.data = data["acas"];
  270. keys.ACASKey_Data.md5 = data["acas_md5"];
  271. if (!CheckMD5(keys.ACASKey_Data.data, keys.ACASKey_Data.md5))
  272. {
  273. msg = string.Format("ACASKey_Data Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ACASKey_Data.data, keys.ACASKey_Data.md5);
  274. goto end;
  275. }
  276. }
  277. if (data.ContainsKey("lek") && data.ContainsKey("lek_md5"))
  278. {
  279. keys.LEK.data = data["lek"];
  280. keys.LEK.md5 = data["lek_md5"];
  281. if (!CheckMD5(keys.LEK.data, keys.LEK.md5))
  282. {
  283. msg = string.Format("LEK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.LEK.data, keys.LEK.md5);
  284. goto end;
  285. }
  286. }
  287. if (data.ContainsKey("pek") && data.ContainsKey("pek_md5"))
  288. {
  289. keys.PEK.data = data["pek"];
  290. keys.PEK.md5 = data["pek_md5"];
  291. if (!CheckMD5(keys.PEK.data, keys.PEK.md5))
  292. {
  293. msg = string.Format("PEK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.PEK.data, keys.PEK.md5);
  294. goto end;
  295. }
  296. }
  297. if (data.ContainsKey("playready") && data.ContainsKey("playready_md5"))
  298. {
  299. keys.Playready.data = data["playready"];
  300. keys.Playready.md5 = data["playready_md5"];
  301. if (!CheckMD5(keys.Playready.data, keys.Playready.md5))
  302. {
  303. msg = string.Format("Playready Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Playready.data, keys.Playready.md5);
  304. goto end;
  305. }
  306. }
  307. if (data.ContainsKey("netfilx") && data.ContainsKey("netfilx_md5"))
  308. {
  309. keys.ESN.data = data["netfilx"];
  310. keys.ESN.md5 = data["netfilx_md5"];
  311. if (!CheckMD5(keys.ESN.data, keys.ESN.md5))
  312. {
  313. msg = string.Format("ESN Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ESN.data, keys.ESN.md5);
  314. goto end;
  315. }
  316. }
  317. if (data.ContainsKey("hash") && data.ContainsKey("hash_md5"))
  318. {
  319. keys.Hashkey.data = data["hash"];
  320. keys.Hashkey.md5 = data["hash_md5"];
  321. if (!CheckMD5(keys.Hashkey.data, keys.Hashkey.md5))
  322. {
  323. msg = string.Format("Hashkey Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Hashkey.data, keys.Hashkey.md5);
  324. goto end;
  325. }
  326. }
  327. if (data.ContainsKey("mgk") && data.ContainsKey("mgk_md5"))
  328. {
  329. keys.MGK.data = data["mgk"];
  330. keys.MGK.md5 = data["mgk_md5"];
  331. if (!CheckMD5(keys.MGK.data, keys.MGK.md5))
  332. {
  333. msg = string.Format("MGK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.MGK.data, keys.MGK.md5);
  334. goto end;
  335. }
  336. }
  337. if (data.ContainsKey("youtube") && data.ContainsKey("youtube_md5"))
  338. {
  339. keys.YouTube_KEY.data = data["youtube"];
  340. keys.YouTube_KEY.md5 = data["youtube_md5"];
  341. if (!CheckMD5(keys.YouTube_KEY.data, keys.YouTube_KEY.md5))
  342. {
  343. msg = string.Format("YouTube_KEY Key Value md5 Is Incorrect: data={0}, md5={1}", keys.YouTube_KEY.data, keys.YouTube_KEY.md5);
  344. goto end;
  345. }
  346. }
  347. if (data.ContainsKey("fairplay") && data.ContainsKey("fairplay_md5"))
  348. {
  349. keys.Fairplay.data = data["fairplay"];
  350. keys.Fairplay.md5 = data["fairplay_md5"];
  351. if (!CheckMD5(keys.Fairplay.data, keys.Fairplay.md5))
  352. {
  353. msg = string.Format("Fairplay Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Fairplay.data, keys.Fairplay.md5);
  354. goto end;
  355. }
  356. }
  357. if (data.ContainsKey("widevine") && data.ContainsKey("widevine_md5"))
  358. {
  359. keys.Widevine.data = data["widevine"];
  360. keys.Widevine.md5 = data["widevine_md5"];
  361. if (!CheckMD5(keys.Widevine.data, keys.Widevine.md5))
  362. {
  363. msg = string.Format("Widevine Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Widevine.data, keys.Widevine.md5);
  364. goto end;
  365. }
  366. }
  367. if (data.ContainsKey("attention") && data.ContainsKey("attention_md5"))
  368. {
  369. keys.Attestation.data = data["attention"];
  370. keys.Attestation.md5 = data["attention_md5"];
  371. if (!CheckMD5(keys.Attestation.data, keys.Attestation.md5))
  372. {
  373. msg = string.Format("Attestation Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Attestation.data, keys.Attestation.md5);
  374. goto end;
  375. }
  376. }
  377. if (data.ContainsKey("dsn") && data.ContainsKey("dsn_md5"))
  378. {
  379. keys.DSN.data = data["dsn"];
  380. keys.DSN.md5 = data["dsn_md5"];
  381. if (!CheckMD5(keys.DSN.data, keys.DSN.md5))
  382. {
  383. msg = string.Format("DSN Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DSN.data, keys.DSN.md5);
  384. goto end;
  385. }
  386. }
  387. if (data.ContainsKey("dak") && data.ContainsKey("dak_md5"))
  388. {
  389. keys.DAK.data = data["dak"];
  390. keys.DAK.md5 = data["dak_md5"];
  391. if (!CheckMD5(keys.DAK.data, keys.DAK.md5))
  392. {
  393. msg = string.Format("DAK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DAK.data, keys.DAK.md5);
  394. goto end;
  395. }
  396. }
  397. result = true;
  398. }
  399. }
  400. }
  401. catch
  402. {
  403. msg = "解析Json失败";
  404. }
  405. }
  406. end:
  407. watch.Stop();
  408. Log.WriteInfoLog(string.Format("[GetIDMKeys] order={0},sn={1},Elapsed={2} GetKeys={3}", order, sn, watch.Elapsed.TotalMilliseconds, result ? "成功" : "失败"));
  409. if (!result)
  410. CommonMethod.ReportErrormsg("Fail to GetIDMKeys ", msg + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + httpResult.Html, connection);
  411. return result;
  412. }
  413. public static string GetReportJson(string order, string sn, bool isNodid, ref KeyInfo keyinfo)
  414. {
  415. Func<string, string, JObject, bool> AddJsonItem = (name, value, jobj) =>
  416. {
  417. if (name == null || name.Length == 0)
  418. return false;
  419. if (value == null || value.Length == 0)
  420. return false;
  421. if (jobj == null)
  422. return false;
  423. jobj.Add(name, (JToken)value);
  424. return true;
  425. };
  426. Func<KeyData, JObject, bool> AddKeyJson = (keydata, jobj) =>
  427. {
  428. if (keydata == null || jobj == null || keydata.data == null)
  429. return false;
  430. if (keydata.keyfrom == KEY_FROM.FROM_IDM && keydata.enable)
  431. {
  432. jobj.Add(keydata.name, (JToken)keydata.data);
  433. }
  434. return true;
  435. };
  436. try
  437. {
  438. JObject postJson = new JObject();
  439. AddJsonItem("ordernum", order, postJson);
  440. AddJsonItem("sn", sn, postJson);
  441. AddJsonItem("nodid", isNodid.ToString().ToLower(), postJson);
  442. if (keyinfo != null)
  443. {
  444. AddKeyJson(keyinfo.MGK, postJson);
  445. AddKeyJson(keyinfo.Mac, postJson);
  446. AddKeyJson(keyinfo.HDCP, postJson);
  447. AddKeyJson(keyinfo.HDCP22, postJson);
  448. AddKeyJson(keyinfo.ESN, postJson);
  449. //AddKeyJson(keyinfo.WiDi, postJson);
  450. AddKeyJson(keyinfo.Widevine, postJson);
  451. AddKeyJson(keyinfo.CI_plus, postJson);
  452. AddKeyJson(keyinfo.Attestation, postJson);
  453. AddKeyJson(keyinfo.MGK, postJson);
  454. AddKeyJson(keyinfo.Fairplay, postJson);
  455. AddKeyJson(keyinfo.DSN, postJson);
  456. AddKeyJson(keyinfo.WiFi_MAC, postJson);
  457. AddKeyJson(keyinfo.BT_MAC, postJson);
  458. AddKeyJson(keyinfo.LEK, postJson);
  459. AddKeyJson(keyinfo.PEK, postJson);
  460. AddKeyJson(keyinfo.Playready, postJson);
  461. AddKeyJson(keyinfo.Hashkey, postJson);
  462. AddKeyJson(keyinfo.ECP, postJson);
  463. AddKeyJson(keyinfo.YouTube_KEY, postJson);
  464. AddKeyJson(keyinfo.EDIDPid, postJson);
  465. AddKeyJson(keyinfo.EDIDModelName, postJson);
  466. AddKeyJson(keyinfo.ACASKey_Data, postJson);
  467. //AddKeyJson(keyinfo.ACASKey_Tool, postJson);//内置
  468. AddKeyJson(keyinfo.DAK, postJson);
  469. //AddKeyJson(keyinfo.FVP, postJson);
  470. }
  471. return postJson.ToString();
  472. }
  473. catch (Exception ex)
  474. {
  475. Log.WriteErrorLog("\r\nFail to GetReportJson," + ex.Message + ":" + "\r\nOrder:" + order + "\r\nSN:" + sn);
  476. }
  477. return "";
  478. }
  479. /// <summary>
  480. /// 在线抄写完成上报 Key
  481. /// </summary>
  482. /// <param name="url"></param>
  483. /// <param name="order"></param>
  484. /// <param name="sn"></param>
  485. /// <param name="isNodid"></param>
  486. /// <param name="keyinfo"></param>
  487. /// <param name="sqliteConn"></param>
  488. /// <param name="msg"></param>
  489. /// <returns></returns>
  490. public static bool ReportOnlineData(string url, string order, string postData, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout)
  491. {
  492. if (timeout < 5000)
  493. timeout = 5000;
  494. HttpHelper http = new HttpHelper();
  495. HttpItem item = new HttpItem()
  496. {
  497. Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
  498. Method = "post",
  499. Postdata = postData,
  500. PostEncoding = Encoding.UTF8,
  501. Timeout = timeout,
  502. KeepAlive = false
  503. };
  504. item.URL = url + "/reportData/report";
  505. item.ContentType = "application/json;charset=utf-8";
  506. Stopwatch stopwatch = new Stopwatch();
  507. stopwatch.Start();
  508. HttpResult result = http.GetHtml(item);
  509. stopwatch.Stop();
  510. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  511. stopwatch.Reset();
  512. string ParseText = result.Html;
  513. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  514. {
  515. Log.WriteGetKeyLog("\r\nReportOnlineData info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  516. try
  517. {
  518. JObject jObject = JObject.Parse(ParseText);
  519. string msg = jObject["msg"].Value<string>();
  520. string code = jObject["code"].Value<string>();
  521. if (code == "0")
  522. return true;
  523. }
  524. catch (Exception ex)
  525. {
  526. Log.WriteErrorLog("\r\nFail to ReportOnlineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  527. CommonMethod.ReportErrormsg("Fail to ReportOnlineData", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  528. }
  529. if (repeatupload)
  530. {// 删除记录;
  531. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  532. }
  533. }
  534. else
  535. {
  536. Log.WriteErrorLog("\r\nFail to ReportOnlineData:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  537. if (!repeatupload)
  538. {
  539. if (CommonMethod.HTTPChecker(item.URL))
  540. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, item.URL, item.Postdata });
  541. }
  542. CommonMethod.ReportErrormsg("Fail to ReportOnlineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  543. }
  544. return false;
  545. }
  546. //reportData/reportList
  547. /// <summary>
  548. /// 离线抄写上报
  549. /// </summary>
  550. /// <param name="url"></param>
  551. /// <param name="copydate"></param>
  552. /// <param name="SN"></param>
  553. /// <param name="localDBNow"></param>
  554. /// <param name="sqliteConn"></param>
  555. /// <param name="repeatupload"></param>
  556. /// <param name="id"></param>
  557. /// <param name="timeout"></param>
  558. /// <returns></returns>
  559. public static bool ReportOfflineData(string url, string copydate, string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
  560. {
  561. HttpHelper http = new HttpHelper();
  562. HttpItem item = new HttpItem()
  563. {
  564. Encoding = Encoding.UTF8,
  565. Method = "post",
  566. Postdata = string.Format("{{\"sn\":\"{0}\",\"date\":\"{1}\"}}", SN, copydate),
  567. PostEncoding = Encoding.UTF8,
  568. KeepAlive = false
  569. };
  570. item.URL = url + "/reportData/reportList";
  571. item.ContentType = "application/json;charset=utf-8";
  572. System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
  573. stopwatch.Start();
  574. HttpResult result = http.GetHtml(item);
  575. stopwatch.Stop();
  576. string usingtime = stopwatch.ElapsedMilliseconds.ToString();
  577. stopwatch.Reset();
  578. string ParseText = result.Html;
  579. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  580. {
  581. Log.WriteGetKeyLog("\r\nReportOfflineData info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  582. }
  583. else
  584. {
  585. Log.WriteErrorLog("\r\nFail to ReportOfflineData:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  586. CommonMethod.ReportErrormsg("Fail to ReportOfflineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  587. if (repeatupload)
  588. return false;
  589. if (CommonMethod.HTTPChecker(url))
  590. SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { "preload_mode", url, SN + "@" + copydate });
  591. return false;
  592. }
  593. try
  594. {
  595. JObject jObject = JObject.Parse(ParseText);
  596. string msg = jObject["msg"].Value<string>();
  597. string code = jObject["code"].Value<string>();
  598. if (code == "0")
  599. {
  600. //更新上报内容
  601. if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
  602. {
  603. //更新成功
  604. Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + url + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
  605. return true;
  606. }
  607. else
  608. {
  609. Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
  610. return false;
  611. }
  612. }
  613. else
  614. {
  615. CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + url + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText, sqliteConn);
  616. 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);
  617. if (repeatupload)
  618. {
  619. SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
  620. }
  621. }
  622. }
  623. catch (Exception ex)
  624. {
  625. Log.WriteErrorLog("\r\nFail to ReportOfflineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
  626. CommonMethod.ReportErrormsg("Fail to ReportOfflineData", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
  627. }
  628. return false;
  629. }
  630. public static bool GetOfflineData(string url, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
  631. {
  632. midAddressList = new List<MidAddress>();
  633. HttpHelper http = new HttpHelper();
  634. HttpItem item = new HttpItem()
  635. {
  636. Encoding = Encoding.UTF8,
  637. Method = "post",
  638. Postdata = string.Format("{{\"ordernum\":\"{0}\",\"mac\":\"{1}\"}}", order, TestMode.MAC),
  639. KeepAlive = false
  640. };
  641. item.URL = url + "/offline/getofflinelist";
  642. item.ContentType = "application/json;charset=utf-8";
  643. HttpResult result = http.GetHtml(item);
  644. string ParseText = result.Html;
  645. if (result.StatusCode == System.Net.HttpStatusCode.OK)
  646. {
  647. }
  648. else
  649. {
  650. Log.WriteErrorLog("\r\nFail to GetOfflineData:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  651. CommonMethod.ReportErrormsg("Fail to GetOfflineData", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  652. return false;
  653. }
  654. try
  655. {
  656. JObject jObject = JObject.Parse(ParseText);
  657. if (jObject["data"] != null)
  658. {
  659. foreach (var data in jObject["data"])
  660. {
  661. midAddressList.Add(new MidAddress()
  662. {
  663. des = CommonMethod.JSON_SeleteNode(jObject, "des"),
  664. code = CommonMethod.JSON_SeleteNode(jObject, "code"),
  665. order = data["order_number"].ToObject<string>(),
  666. number = data["order_quantity"].ToObject<string>(),
  667. pid = data["project_id"].ToObject<string>(),
  668. ctype = data["client_type"].ToObject<string>(),
  669. purl = data["packet_url"].ToObject<string>(),
  670. psize = data["packet_size"].ToObject<string>(),
  671. pmd5 = data["packet_md5"].ToObject<string>(),
  672. version = data["soft_version"].ToObject<string>(),
  673. host = url
  674. });
  675. }
  676. Log.WriteGetKeyLog("\r\nGet GetOfflineData success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  677. return true;
  678. }
  679. Log.WriteErrorLog("\r\nFail to GetOfflineData," + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  680. }
  681. catch (Exception ex)
  682. {
  683. Log.WriteErrorLog("\r\nFail to GetOfflineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
  684. CommonMethod.ReportErrormsg("Fail to GetOfflineData", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
  685. MessageBox.Show("Fail to GetOfflineData info\r\n " + ex.Message);
  686. return false;
  687. }
  688. return false;
  689. }
  690. public static bool ReportDownloadStatus(string url, string order, SQLiteConnection sqliteConn)
  691. {
  692. HttpHelper http = new HttpHelper();
  693. HttpItem item = new HttpItem()
  694. {
  695. Encoding = null,
  696. Method = "post",
  697. Postdata = string.Format("{{\"ordernum\":\"{0}\"}}", order),
  698. KeepAlive = false
  699. };
  700. item.URL = url += "/offline/getreportofflinesn";
  701. item.ContentType = "application/json;charset=utf-8";
  702. HttpResult result = http.GetHtml(item);
  703. string ParseText = result.Html;
  704. if (result.StatusCode != System.Net.HttpStatusCode.OK)
  705. {
  706. Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
  707. CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
  708. return false;
  709. }
  710. try
  711. {
  712. JObject jObject = JObject.Parse(ParseText);
  713. string msg = CommonMethod.JSON_SeleteNode(jObject, "msg");
  714. string code = CommonMethod.JSON_SeleteNode(jObject, "code");
  715. if (code != "0")
  716. {
  717. Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
  718. CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
  719. return false;
  720. }
  721. }
  722. catch (Exception ex)
  723. {
  724. MessageBox.Show(ex.Message);
  725. Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
  726. CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
  727. return false;
  728. }
  729. return true;
  730. }
  731. };
  732. };