V2Method.cs 40 KB

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