V2Method.cs 41 KB

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