V2Method.cs 42 KB

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