V2Method.cs 41 KB

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