123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056 |
- using CCWin.SkinControl;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using SufeiUtil;
- using SXLibrary;
- using System;
- using System.Collections.Generic;
- using System.Data.SQLite;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- using System.Windows.Forms;
- using HttpHelper = SufeiUtil.HttpHelper;
- namespace MOKA_Factory_Tools
- {
- internal class V2Method
- {
- private static string url_getDSNFromSmes = "http://smes-app-prod.tclking.com:9006/api/xm/GetXMTVParts?TVSN=";
- public static MidList midList { get; set; }
- private static string url_getMessage = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do";
- public static void SetMexicanConfig(bool bMexican = false)
- {
- if (bMexican)
- url_getMessage = "http://10.138.96.32:81/IDManage/v1/order/getMessage";
- else
- url_getMessage = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do";
-
- if ( TestMode.testMode)
- url_getMessage = "http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do";
- }
- public static void SetGetMessageUrl(string url = "https://cn.uc.qhmoka.com/scbc-server/clientType/getMessage.do")
- {
- url_getMessage = url;
- }
- public static RokuCustomer GetRokuInfo(string strRokuInfo)
- {
- try
- {
- JObject jObject = JObject.Parse(strRokuInfo);
- RokuCustomer rokuCustomer = new RokuCustomer();
- rokuCustomer.id = jObject["id"].ToString().Trim();
- rokuCustomer.ordernum = jObject["ordernum"].ToString().Trim();
- rokuCustomer.brand = jObject["brand"].ToString().Trim();
- rokuCustomer.oemmodel = jObject["oemmodel"].ToString().Trim();
- rokuCustomer.productiondate = jObject["productiondate"].ToString().Trim();
- rokuCustomer.remotetype = jObject["remotetype"].ToString().Trim();
- rokuCustomer.updatetime = jObject["updatetime"].ToString().Trim();
- rokuCustomer.createtime = jObject["createtime"].ToString().Trim();
- rokuCustomer.isdelete = jObject["isdelete"].ToString().Trim();
- if (jObject["data"] != null)
- {
- rokuCustomer.data = new List<RokuData>();
- foreach (var item in jObject["data"])
- {
- RokuData rokuData = new RokuData();
- rokuData.region = item["region"].Value<string>();
- rokuData.supporturl = item["supporturl"].Value<string>();
- rokuData.supportphone = item["supportphone"].Value<string>();
- rokuCustomer.data.Add(rokuData);
- }
- }
- return rokuCustomer;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog(string.Format("解析json失败:{0}", strRokuInfo));
- }
- return null;
- }
- public static RokuCustomer GetRokuFileInfo()
- {
- string fileName = LocalPath.localpath + "roku.info";
- if (File.Exists(fileName))
- {
- Log.WriteInfoLog(string.Format("using roku.info = {0}", fileName));
- StreamReader file = File.OpenText(fileName);
- RokuCustomer roku = GetRokuInfo(file.ReadToEnd());
- file.Close();
- return roku;
- }
- return null;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="url"></param>
- /// <param name="order"></param>
- /// <param name="pcmac"></param>
- /// <param name="sqliteConn"></param>
- /// <param name="mid"></param>
- /// <returns></returns>
- public static bool GetMidInfo(string order, string pcmac, SQLiteConnection sqliteConn, out MidList mid)
- {
- mid = new MidList();
- string postData = string.Format("{{\"bid\":\"{0}\",\"mac\":\"{1}\"}}", order, pcmac);
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- URL = url_getMessage,//URL这里都是测试URl必需项
- Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
- Method = "post",
- Postdata = postData,
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.ContentType = "application/json;charset=utf-8";
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start();
- HttpResult result = http.GetHtml(item);
- stopwatch.Stop();
- string usingtime = stopwatch.ElapsedMilliseconds.ToString();
- stopwatch.Reset();
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nGet MID info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to GetMidInfo:" + result.StatusDescription + result.Html + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
- CommonMethod.ReportErrormsg("Fail to GetMidInfo", result.StatusDescription + result.Html + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- mid.message = jObject["message"].Value<string>();
- mid.code = jObject["code"].Value<string>();
- mid.factoryname = jObject["factoryName"].Value<string>();
- mid.factoryNum = jObject["factoryNum"].Value<string>();
- mid.version = jObject["version"].Value<string>();
- mid.quantity = jObject["quantity"].Value<string>();
- mid.projectid = jObject["projectId"].Value<string>();
- mid.clienttype = jObject["clientType"].Value<string>();
- mid.host = jObject["host"].Value<string>();
- mid.whiteType = jObject["whiteType"].Value<string>();
- string aesEncrypt = jObject["aesEncrypt"] == null ? null : jObject["aesEncrypt"].Value<string>();
- mid.isSmt = jObject["isSmt"] == null ? "0" : jObject["isSmt"].Value<string>();
-
- if (aesEncrypt != null)
- mid.aesEncrypt = aesEncrypt.Equals("yes", StringComparison.OrdinalIgnoreCase);
- object a = jObject["rokuCustomer"];
- if (jObject["rokuCustomer"].ToString().Length > 0)
- {
- mid.rokuCustomer = GetRokuInfo(jObject["rokuCustomer"].ToString());
- }
- //如果订单是整机订单
- mid.keytype = new Dictionary<string, string>();
- if ( mid.isSmt.Equals("0") )
- {// 整机;
-
- foreach (var ss in jObject["obj"]) //查找某个字段与值
- {
- mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
- }
- }
- else
- {// 整机+板卡;
- if ( Main.Is_Smt == "1" )
- {
- foreach (var ss in jObject["obj_smt"]) //查找isSmt某个字段与值
- {
- mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
- }
- }
- else
- {
- foreach (var ss in jObject["obj"]) //查找某个字段与值
- {
- mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());
- }
- }
- }
- if (mid.code == "1000")
- {
- midList = mid;
- return true;
- }
-
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to parse MID info," + ex.Message + ":" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData);
- CommonMethod.ReportErrormsg("Fail to parse MID info", ex.Message + ":" + ParseText + "\r\nAddress:" + url_getMessage + "\r\nPostdata:" + postData, sqliteConn);
- MessageBox.Show("Fail to parse MID info\r\n " + ex.Message);
- }
- return false;
- }
- 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)
- {
- msg = "";
- string code;
- bool result = false;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,
- Method = "post",
- ContentType = "application/json",
- KeepAlive = false
- };
- // 计算函数耗时;
- Stopwatch watch = new Stopwatch();
- watch.Start();
- item.URL = url + "/bind/order";
- item.Postdata = string.Format("{{\"orderNum\":\"{0}\",\"sn\":\"{1}\",\"psn\":\"{2}\",\"orderCode\":\"{3}\",\"clientType\":\"{4}\",\"isSmt\":\"{5}\",\"skipKey\":{6}}}", order, sn, psn, firetv_device_code, midList.clienttype,
- midList.isSmt.Equals("0") ? "0" : Main.Is_Smt , key2Write == null ? "[]" : JsonConvert.SerializeObject(key2Write).ToString());
- HttpResult httpResult = http.GetHtml(item);
- if (httpResult.StatusCode == System.Net.HttpStatusCode.OK)
- {
- try
- {
- JObject jObject = JObject.Parse(httpResult.Html);
- msg = CommonMethod.JSON_SeleteNode(jObject, "msg");
- code = CommonMethod.JSON_SeleteNode(jObject, "code");
- if (code == "0")
- {
- //需要解密
- if (midList != null && midList.aesEncrypt)
- {
- AES_DES Aes = new AES_DES();
- //data解密
- string plainText = CommonMethod.JSON_SeleteNode(jObject, "data");
- string key = AES_DES.AESKey;
- byte[] IV = AES_DES.AESIV;
- string str = AES_DES.DecryptStringFromBytes_Aes(plainText, key, IV);
- Log.WriteInfoLog("解密后:" + str);
- jObject["data"] = str;
- }
- Dictionary<string, string> data = JsonConvert.DeserializeObject<Dictionary<string, string>>(jObject["data"].ToString());
- if (data != null)
- {
- Func<string, string, bool> CheckMD5 = (data, md5) =>
- {
- if (data == null)
- return true;
- if (!GetMD5.GetStrMd5(data).Equals(md5, StringComparison.OrdinalIgnoreCase))
- return false;
- return true;
- };
- if (data.ContainsKey("mac") && data.ContainsKey("mac_md5"))
- {
- keys.Mac.data = data["mac"];
- keys.Mac.md5 = data["mac_md5"];
- if (!CheckMD5(keys.Mac.data, keys.Mac.md5))
- {
- msg = string.Format("Mac Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Mac.data, keys.Mac.md5);
- goto end;
- }
- }
- if (data.ContainsKey("btMac") && data.ContainsKey("btMac_md5"))
- {
- keys.BT_MAC.data = data["btMac"];
- keys.BT_MAC.md5 = data["btMac_md5"];
- if (!CheckMD5(keys.BT_MAC.data, keys.BT_MAC.md5))
- {
- msg = string.Format("BT_MAC Key Value md5 Is Incorrect: data={0}, md5={1}", keys.BT_MAC.data, keys.BT_MAC.md5);
- goto end;
- }
- }
- if (data.ContainsKey("wifiMac") && data.ContainsKey("wifiMac_md5"))
- {
- keys.WiFi_MAC.data = data["wifiMac"];
- keys.WiFi_MAC.md5 = data["wifiMac_md5"];
- if (!CheckMD5(keys.WiFi_MAC.data, keys.WiFi_MAC.md5))
- {
- msg = string.Format("WiFi_MAC Key Value md5 Is Incorrect: data={0}, md5={1}", keys.WiFi_MAC.data, keys.WiFi_MAC.md5);
- goto end;
- }
- }
- if (data.ContainsKey("deviceid") && data.ContainsKey("deviceid_md5"))
- {
- keys.DID.data = data["deviceid"];
- keys.DID.md5 = data["deviceid_md5"];
- if (!CheckMD5(keys.DID.data, keys.DID.md5))
- {
- msg = string.Format("DID Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DID.data, keys.DID.md5);
- goto end;
- }
- }
- if (data.ContainsKey("hdcp") && data.ContainsKey("hdcp_md5"))
- {
- keys.HDCP.data = data["hdcp"];
- keys.HDCP.md5 = data["hdcp_md5"];
- if (!CheckMD5(keys.HDCP.data, keys.HDCP.md5))
- {
- msg = string.Format("HDCP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.HDCP.data, keys.HDCP.md5);
- goto end;
- }
- }
- if (data.ContainsKey("hdcp2") && data.ContainsKey("hdcp2_md5"))
- {
- keys.HDCP22.data = data["hdcp2"];
- keys.HDCP22.md5 = data["hdcp2_md5"];
- if (!CheckMD5(keys.HDCP22.data, keys.HDCP22.md5))
- {
- msg = string.Format("HDCP22 Key Value md5 Is Incorrect: data={0}, md5={1}", keys.HDCP22.data, keys.HDCP22.md5);
- goto end;
- }
- }
- if (data.ContainsKey("ci") && data.ContainsKey("ci_md5"))
- {
- keys.CI_plus.data = data["ci"];
- keys.CI_plus.md5 = data["ci_md5"];
- if (!CheckMD5(keys.CI_plus.data, keys.CI_plus.md5))
- {
- msg = string.Format("CI_plus Key Value md5 Is Incorrect: data={0}, md5={1}", keys.CI_plus.data, keys.CI_plus.md5);
- goto end;
- }
- }
- if (data.ContainsKey("ecp") && data.ContainsKey("ecp_md5"))
- {
- keys.ECP.data = data["ecp"];
- keys.ECP.md5 = data["ecp_md5"];
- if (!CheckMD5(keys.ECP.data, keys.ECP.md5))
- {
- msg = string.Format("ECP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ECP.data, keys.ECP.md5);
- goto end;
- }
- }
- if (data.ContainsKey("acas") && data.ContainsKey("acas_md5"))
- {
- keys.ACASKey_Data.data = data["acas"];
- keys.ACASKey_Data.md5 = data["acas_md5"];
- if (!CheckMD5(keys.ACASKey_Data.data, keys.ACASKey_Data.md5))
- {
- msg = string.Format("ACASKey_Data Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ACASKey_Data.data, keys.ACASKey_Data.md5);
- goto end;
- }
- }
- if (data.ContainsKey("lek") && data.ContainsKey("lek_md5"))
- {
- keys.LEK.data = data["lek"];
- keys.LEK.md5 = data["lek_md5"];
- if (!CheckMD5(keys.LEK.data, keys.LEK.md5))
- {
- msg = string.Format("LEK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.LEK.data, keys.LEK.md5);
- goto end;
- }
- }
- if (data.ContainsKey("pek") && data.ContainsKey("pek_md5"))
- {
- keys.PEK.data = data["pek"];
- keys.PEK.md5 = data["pek_md5"];
- if (!CheckMD5(keys.PEK.data, keys.PEK.md5))
- {
- msg = string.Format("PEK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.PEK.data, keys.PEK.md5);
- goto end;
- }
- }
- if (data.ContainsKey("playready") && data.ContainsKey("playready_md5"))
- {
- keys.Playready.data = data["playready"];
- keys.Playready.md5 = data["playready_md5"];
- if (!CheckMD5(keys.Playready.data, keys.Playready.md5))
- {
- msg = string.Format("Playready Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Playready.data, keys.Playready.md5);
- goto end;
- }
- }
- if (data.ContainsKey("netfilx") && data.ContainsKey("netfilx_md5"))
- {
- keys.ESN.data = data["netfilx"];
- keys.ESN.md5 = data["netfilx_md5"];
- if (!CheckMD5(keys.ESN.data, keys.ESN.md5))
- {
- msg = string.Format("ESN Key Value md5 Is Incorrect: data={0}, md5={1}", keys.ESN.data, keys.ESN.md5);
- goto end;
- }
- }
- if (data.ContainsKey("hash") && data.ContainsKey("hash_md5"))
- {
- keys.Hashkey.data = data["hash"];
- keys.Hashkey.md5 = data["hash_md5"];
- if (!CheckMD5(keys.Hashkey.data, keys.Hashkey.md5))
- {
- msg = string.Format("Hashkey Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Hashkey.data, keys.Hashkey.md5);
- goto end;
- }
- }
- if (data.ContainsKey("mgk") && data.ContainsKey("mgk_md5"))
- {
- keys.MGK.data = data["mgk"];
- keys.MGK.md5 = data["mgk_md5"];
- if (!CheckMD5(keys.MGK.data, keys.MGK.md5))
- {
- msg = string.Format("MGK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.MGK.data, keys.MGK.md5);
- goto end;
- }
- }
- if (data.ContainsKey("youtube") && data.ContainsKey("youtube_md5"))
- {
- keys.YouTube_KEY.data = data["youtube"];
- keys.YouTube_KEY.md5 = data["youtube_md5"];
- if (!CheckMD5(keys.YouTube_KEY.data, keys.YouTube_KEY.md5))
- {
- msg = string.Format("YouTube_KEY Key Value md5 Is Incorrect: data={0}, md5={1}", keys.YouTube_KEY.data, keys.YouTube_KEY.md5);
- goto end;
- }
- }
- if (data.ContainsKey("fairplay") && data.ContainsKey("fairplay_md5"))
- {
- keys.Fairplay.data = data["fairplay"];
- keys.Fairplay.md5 = data["fairplay_md5"];
- if (!CheckMD5(keys.Fairplay.data, keys.Fairplay.md5))
- {
- msg = string.Format("Fairplay Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Fairplay.data, keys.Fairplay.md5);
- goto end;
- }
- }
- if (data.ContainsKey("widevine") && data.ContainsKey("widevine_md5"))
- {
- keys.Widevine.data = data["widevine"];
- keys.Widevine.md5 = data["widevine_md5"];
- if (!CheckMD5(keys.Widevine.data, keys.Widevine.md5))
- {
- msg = string.Format("Widevine Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Widevine.data, keys.Widevine.md5);
- goto end;
- }
- }
- if (data.ContainsKey("attention") && data.ContainsKey("attention_md5"))
- {
- keys.Attestation.data = data["attention"];
- keys.Attestation.md5 = data["attention_md5"];
- if (!CheckMD5(keys.Attestation.data, keys.Attestation.md5))
- {
- msg = string.Format("Attestation Key Value md5 Is Incorrect: data={0}, md5={1}", keys.Attestation.data, keys.Attestation.md5);
- goto end;
- }
- }
- if (data.ContainsKey("dsn") && data.ContainsKey("dsn_md5"))
- {
- keys.DSN.data = data["dsn"];
- keys.DSN.md5 = data["dsn_md5"];
- if (!CheckMD5(keys.DSN.data, keys.DSN.md5))
- {
- msg = string.Format("DSN Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DSN.data, keys.DSN.md5);
- goto end;
- }
- }
- if (data.ContainsKey("dak") && data.ContainsKey("dak_md5"))
- {
- keys.DAK.data = data["dak"];
- keys.DAK.md5 = data["dak_md5"];
- if (!CheckMD5(keys.DAK.data, keys.DAK.md5))
- {
- msg = string.Format("DAK Key Value md5 Is Incorrect: data={0}, md5={1}", keys.DAK.data, keys.DAK.md5);
- goto end;
- }
- }
- if (data.ContainsKey("kfp") && data.ContainsKey("kfp_md5"))
- {
- keys.KFP.data = data["kfp"];
- keys.KFP.md5 = data["kfp_md5"];
- if (!CheckMD5(keys.KFP.data, keys.KFP.md5))
- {
- msg = string.Format("KFP Key Value md5 Is Incorrect: data={0}, md5={1}", keys.KFP.data, keys.KFP.md5);
- goto end;
- }
- }
- //
- if (data.ContainsKey("rmca") && data.ContainsKey("rmca_md5"))
- {
- keys.RMCA.data = data["rmca"];
- keys.RMCA.md5 = data["rmca_md5"];
- if (!CheckMD5(keys.RMCA.data, keys.RMCA.md5))
- {
- msg = string.Format("RMCA Key Value md5 Is Incorrect: data={0}, md5={1}", keys.RMCA.data, keys.RMCA.md5);
- goto end;
- }
- }
- result = true;
- }
- }
- }
- catch(Exception ex)
- {
- msg = ex.Message;
- }
- }
- end:
- watch.Stop();
- Log.WriteInfoLog(string.Format("[GetIDMKeys] order={0},sn={1},Elapsed={2} GetKeys={3}", order, sn, watch.Elapsed.TotalMilliseconds, result ? "成功" : "失败"));
- if (!result)
- CommonMethod.ReportErrormsg("Fail to GetIDMKeys ", msg + "\r\n" + item.URL + "\r\n" + item.Postdata + "\r\n" + httpResult.Html, connection);
- return result;
- }
- public static string GetReportJson(string order, string sn, bool isNodid, string clientType, string swVer, string pid, ref KeyInfo keyinfo, bool bMIEnable, ref MIKey mIKey)
- {
- Func<string, string, JObject, bool> AddJsonItem = (name, value, jobj) =>
- {
- if (name == null || name.Length == 0)
- return false;
- if (value == null || value.Length == 0)
- return false;
- if (jobj == null)
- return false;
- jobj.Add(name, (JToken)value);
- return true;
- };
- Func<KeyData, JObject, bool> AddKeyJson = (keydata, jobj) =>
- {
- if (keydata == null || jobj == null || keydata.data == null)
- return false;
- if (keydata.keyfrom == KEY_FROM.FROM_IDM && keydata.enable)
- {
- jobj.Add(keydata.name, (JToken)keydata.data);
- }
- return true;
- };
- Func<KeyData, JObject, string, bool> AddKeyJson2 = (keydata, jobj, name) =>
- {
- if (keydata == null || jobj == null || keydata.data == null)
- return false;
- if (keydata.keyfrom == KEY_FROM.FROM_IDM && keydata.enable)
- {
- jobj.Add(name, (JToken)keydata.data);
- }
- return true;
- };
- try
- {
- JObject postJson = new JObject();
- AddJsonItem("ordernum", order, postJson);
- AddJsonItem("sn", sn, postJson);
- AddJsonItem("nodid", isNodid.ToString().ToLower(), postJson);
- AddJsonItem("toolVersion", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(), postJson);
- AddJsonItem("clienttype", clientType, postJson);
- AddJsonItem("sversionid", swVer, postJson);
- AddJsonItem("projectid", pid, postJson);
- //上报时增加smtpsn 字段
- //读取PSN
- AddJsonItem("smtPsn",OperationPanel.smtPsn,postJson);
-
- if (keyinfo != null)
- {
- AddKeyJson2(keyinfo.DID, postJson, "deviceid");
- if ( !bMIEnable || (mIKey != null && mIKey.EthernetMac == null))
- AddKeyJson2(keyinfo.Mac, postJson, "mac");
- AddKeyJson2(keyinfo.HDCP, postJson, "hdcpkey");
- AddKeyJson2(keyinfo.HDCP22, postJson, "hdcpkey2");
- AddKeyJson2(keyinfo.ESN, postJson, "netfilxesn");
- AddKeyJson2(keyinfo.Widevine, postJson, "widevine");
- AddKeyJson2(keyinfo.CI_plus, postJson, "cikey");
- AddKeyJson2(keyinfo.Attestation, postJson, "attestation");
- AddKeyJson2(keyinfo.MGK, postJson, "mgk");
- AddKeyJson2(keyinfo.Fairplay, postJson, "fairplay");
- if (!bMIEnable || ( mIKey != null && mIKey.DSN == null))
- AddKeyJson2(keyinfo.DSN, postJson, "dsn");
- if (!bMIEnable || (mIKey != null && mIKey.WIFIMAC == null))
- AddKeyJson2(keyinfo.WiFi_MAC, postJson, "wifimac");
- if (!bMIEnable || (mIKey != null && mIKey.BTMac == null))
- AddKeyJson2(keyinfo.BT_MAC, postJson, "btmac");
- AddKeyJson2(keyinfo.LEK, postJson, "lek");
- AddKeyJson2(keyinfo.PEK, postJson, "pek");
- AddKeyJson2(keyinfo.Playready, postJson, "playready");
- AddKeyJson2(keyinfo.Hashkey, postJson, "hash");
- AddKeyJson2(keyinfo.ECP, postJson, "ecp");
- AddKeyJson2(keyinfo.YouTube_KEY, postJson, "youtubekey");
- AddKeyJson2(keyinfo.ACASKey_Data, postJson, "acas_data");
- AddKeyJson2(keyinfo.DAK, postJson, "dak");
- AddKeyJson2(keyinfo.KFP, postJson, "kfp");
- AddKeyJson2(keyinfo.RMCA, postJson, "rmca");
- }
- string postData = postJson.ToString();
- //需要加密上报的话
- if (midList != null && midList.aesEncrypt)
- {
- AES_DES AES_DES = new AES_DES();
- string key = AES_DES.AESKey;
- byte[] IV = AES_DES.AESIV;
- postData = AES_DES.EncryptStringToBytes_Aes(postData, key, IV);
- //json
- string Data = string.Format("{{\"reportData\":\"{0}\"}}", postData);
- JObject jo = JObject.Parse(Data);
- postData = jo.ToString();
- }
- return postData;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to GetReportJson," + ex.Message + ":" + "\r\nOrder:" + order + "\r\nSN:" + sn);
- }
- return "";
- }
- /// <summary>
- /// 在线抄写完成上报 Key
- /// </summary>
- /// <param name="url"></param>
- /// <param name="order"></param>
- /// <param name="sn"></param>
- /// <param name="isNodid"></param>
- /// <param name="keyinfo"></param>
- /// <param name="sqliteConn"></param>
- /// <param name="msg"></param>
- /// <returns></returns>
- public static bool ReportOnlineData(string url, string order, string postData, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout, bool background = false)
- {
- if ( background )
- {
- return SQLiteHelper.AddReportOnlineData(sqliteConn, url + "/reportData/report", postData);
- }
- if (timeout < 5000)
- timeout = 5000;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
- Method = "post",
- Postdata = postData,
- PostEncoding = Encoding.UTF8,
- Timeout = timeout,
- KeepAlive = false
- };
- item.URL = url + "/reportData/report";
- item.ContentType = "application/json;charset=utf-8";
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- HttpResult result = http.GetHtml(item);
- stopwatch.Stop();
- string usingtime = stopwatch.ElapsedMilliseconds.ToString();
- stopwatch.Reset();
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nReportOnlineData info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string msg = jObject["msg"].Value<string>();
- string code = jObject["code"].Value<string>();
- if (code == "0")
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to ReportOnlineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to ReportOnlineData", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
- }
- if (repeatupload)
- {// 删除记录;
- SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
- }
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to ReportOnlineData:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to ReportOnlineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
- }
- return false;
- }
- public static bool ReportOnlineDataSQL(string url, string postData, int timeout)
- {
- if (timeout < 5000)
- timeout = 5000;
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,//编码格式(utf-8,gb2312,gbk)可选项 默认类会自动识别//Encoding = Encoding.Default,
- Method = "post",
- Postdata = postData,
- PostEncoding = Encoding.UTF8,
- Timeout = timeout,
- KeepAlive = false
- };
- item.URL = url;
- item.ContentType = "application/json;charset=utf-8";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nReportOnlineDataSQL info\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string msg = jObject["msg"].Value<string>();
- string code = jObject["code"].Value<string>();
- if (code == "0")
- return true;
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to ReportOnlineDataSQL," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- }
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to ReportOnlineDataSQL:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- }
- return false;
- }
- //reportData/reportList
- /// <summary>
- /// 离线抄写上报
- /// </summary>
- /// <param name="url"></param>
- /// <param name="copydate"></param>
- /// <param name="SN"></param>
- /// <param name="localDBNow"></param>
- /// <param name="sqliteConn"></param>
- /// <param name="repeatupload"></param>
- /// <param name="id"></param>
- /// <param name="timeout"></param>
- /// <returns></returns>
- public static bool ReportOfflineData(string url, string copydate, string SN, SQLiteConnection localDBNow, SQLiteConnection sqliteConn, bool repeatupload, string id)
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,
- Method = "post",
- Postdata = string.Format("{{\"sn\":\"{0}\",\"date\":\"{1}\"}}", SN, copydate),
- PostEncoding = Encoding.UTF8,
- KeepAlive = false
- };
- item.URL = url + "/reportData/reportList";
- item.ContentType = "application/json;charset=utf-8";
- System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
- stopwatch.Start();
- HttpResult result = http.GetHtml(item);
- stopwatch.Stop();
- string usingtime = stopwatch.ElapsedMilliseconds.ToString();
- stopwatch.Reset();
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- Log.WriteGetKeyLog("\r\nReportOfflineData info\r\nUsing time:" + usingtime + "ms\r\n" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to ReportOfflineData:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to ReportOfflineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
- if (repeatupload)
- return false;
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string msg = jObject["msg"].Value<string>();
- string code = jObject["code"].Value<string>();
- if (code == "0")
- {
- //更新上报内容
- if (SQLiteHelper.UpdateReportStatus(localDBNow, SN))
- {
- //更新成功
- Log.WriteGetKeyLog("\r\nUpdateReportStatus success:\r\n" + url + "/reportlist.do?\r\n" + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText);
- return true;
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to UpdateReportStatus: " + SN);
- return false;
- }
- }
- else
- {
- CommonMethod.ReportErrormsg("Fail to UploadPreloadCopyResult", "Address: " + url + "/reportlist.do?" + "\r\nPostdata: " + "sn=" + SN + "\r\ndate=" + copydate + "\r\n" + ParseText, sqliteConn);
- 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);
- if (repeatupload)
- {
- SQLiteHelper.DeleteDelayCopyReport(sqliteConn, id);
- }
- }
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to ReportOfflineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to ReportOfflineData", ex.Message + ":" + ParseText + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);
- }
- return false;
- }
- public static bool GetOfflineData(string url, string order, SQLiteConnection sqliteConn, out List<MidAddress> midAddressList)
- {
- midAddressList = new List<MidAddress>();
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,
- Method = "post",
- Postdata = string.Format("{{\"ordernum\":\"{0}\",\"mac\":\"{1}\"}}", order, TestMode.MAC),
- KeepAlive = false
- };
- item.URL = url + "/offline/getofflinelist";
- item.ContentType = "application/json;charset=utf-8";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode == System.Net.HttpStatusCode.OK)
- {
- }
- else
- {
- Log.WriteErrorLog("\r\nFail to GetOfflineData:" + result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to GetOfflineData", result.StatusDescription + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- if (jObject["data"] != null)
- {
- foreach (var data in jObject["data"])
- {
- midAddressList.Add(new MidAddress()
- {
- des = CommonMethod.JSON_SeleteNode(jObject, "des"),
- code = CommonMethod.JSON_SeleteNode(jObject, "code"),
- order = data["order_number"].ToObject<string>(),
- number = data["order_quantity"].ToObject<string>(),
- pid = data["project_id"].ToObject<string>(),
- ctype = data["client_type"].ToObject<string>(),
- purl = data["packet_url"].ToObject<string>(),
- psize = data["packet_size"].ToObject<string>(),
- pmd5 = data["packet_md5"].ToObject<string>(),
- version = data["soft_version"].ToObject<string>(),
- host = url
- });
- }
- Log.WriteGetKeyLog("\r\nGet GetOfflineData success:" + "\r\n" + result.Html + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- return true;
- }
- Log.WriteErrorLog("\r\nFail to GetOfflineData," + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- }
- catch (Exception ex)
- {
- Log.WriteErrorLog("\r\nFail to GetOfflineData," + ex.Message + ":" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata);
- CommonMethod.ReportErrormsg("Fail to GetOfflineData", ex.Message + "\r\n" + ParseText + "\r\nAddress:" + item.URL + "\r\nPostdata:" + item.Postdata, sqliteConn);
- MessageBox.Show("Fail to GetOfflineData info\r\n " + ex.Message);
- return false;
- }
- return false;
- }
- public static bool ReportDownloadStatus(string url, string order, SQLiteConnection sqliteConn)
- {
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = null,
- Method = "post",
- Postdata = string.Format("{{\"ordernum\":\"{0}\"}}", order),
- KeepAlive = false
- };
- item.URL = url += "/offline/getreportofflinesn";
- item.ContentType = "application/json;charset=utf-8";
- HttpResult result = http.GetHtml(item);
- string ParseText = result.Html;
- if (result.StatusCode != System.Net.HttpStatusCode.OK)
- {
- Log.WriteErrorLog("\r\nFail to report download status:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
- CommonMethod.ReportErrormsg("Fail to report download status", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
- return false;
- }
- try
- {
- JObject jObject = JObject.Parse(ParseText);
- string msg = CommonMethod.JSON_SeleteNode(jObject, "msg");
- string code = CommonMethod.JSON_SeleteNode(jObject, "code");
-
- if (code != "0")
- {
- Log.WriteErrorLog("\r\nError report download status,should be 1000:" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
- CommonMethod.ReportErrormsg("Error download status code return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
- return false;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- Log.WriteErrorLog("\r\n" + ex.Message + ":" + result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order));
- CommonMethod.ReportErrormsg("Error parse download status return", result.StatusDescription + result.Html + "\r\nAddress:" + url + "/offline/getreportofflinesn" + "\r\nPostdata:" + ("ordernum=" + order), sqliteConn);
- return false;
- }
- return true;
- }
- //北美项目,不抄从idm上获取的DSN,用smse上的
- public static bool GetDSNFromSmes(string SN, out string DSN)
- {
- //如果是墨西哥
- if (CommonMethod.GetLoginAccout().Equals("Mexico", StringComparison.OrdinalIgnoreCase))
- {
- url_getDSNFromSmes = "http://SMES.TMSA.MX:9006/api/xm/GetXMTVParts?TVSN=";
- }
- string msg;
- DSN = "";
- HttpHelper http = new HttpHelper();
- HttpItem item = new HttpItem()
- {
- Encoding = Encoding.UTF8,
- Method = "post",
- ContentType = "application/x-www-form-urlencoded",
- KeepAlive = false
- };
- item.URL = url_getDSNFromSmes + SN;
- HttpResult hResult = http.GetHtml(item);
- if (hResult.StatusCode == System.Net.HttpStatusCode.OK)
- {
- try
- {
- using (JsonTextReader reader = new JsonTextReader(new StringReader(hResult.Html)))
- {
- JObject jObject = (JObject)JToken.ReadFrom(reader);
- reader.Close();
- foreach (var ss in jObject["Tvparts"]) //查找某个字段与值
- {
- //如果里面的TypeCode为MA(主板),读出他的PSN
- if (ss["PartTypeCode"].Value<string>().Equals("DSN-T", StringComparison.OrdinalIgnoreCase))
- {
- DSN = ss["PartSN"].Value<string>();
- break;
- }
- }
- if (DSN == "" || DSN == null)
- {
- Log.WriteInfoLog("Detail message:" + SN+"\r\n" + item.URL + "\r\n"+hResult.Html);
- return false;
- }
- Log.WriteInfoLog("PartSN" + DSN);
- return true;
- }
- }
- catch (Exception e)
- {
- msg = e.Message;
- Log.WriteErrorLog("IsCuringBOM Json-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
- }
- }
- else
- {
- msg = hResult.StatusDescription;
- Log.WriteInfoLog("IsCuringBOM Http-error:" + hResult.StatusDescription + "\r\n" + hResult.Html + "\r\nAddress: " + item.URL + "\r\nPostdata: " + item.Postdata);
- }
- return false;
- }
- };
- };
|