12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- 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;
- }
- }
- 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");
- }
- 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)
- {
- 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)
- {
- MessageBox.Show("查不到该SN对应的主板DSN号");
- 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;
- }
- };
- };
|