V2Method.cs 42 KB

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