V2Method.cs 39 KB

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