V2Method.cs 40 KB

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