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 { 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(); foreach (var item in jObject["data"]) { RokuData rokuData = new RokuData(); rokuData.region = item["region"].Value(); rokuData.supporturl = item["supporturl"].Value(); rokuData.supportphone = item["supportphone"].Value(); 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; } /// /// /// /// /// /// /// /// /// 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(); mid.code = jObject["code"].Value(); mid.factoryname = jObject["factoryName"].Value(); mid.factoryNum = jObject["factoryNum"].Value(); mid.version = jObject["version"].Value(); mid.quantity = jObject["quantity"].Value(); mid.projectid = jObject["projectId"].Value(); mid.clienttype = jObject["clientType"].Value(); mid.host = jObject["host"].Value(); mid.whiteType = jObject["whiteType"].Value(); mid.aesEncrypt = jObject["aesEncrypt"].Value(); object a = jObject["rokuCustomer"]; if (jObject["rokuCustomer"].ToString().Length > 0) { mid.rokuCustomer = GetRokuInfo(jObject["rokuCustomer"].ToString()); } mid.keytype = new Dictionary(); foreach (var ss in jObject["obj"]) //查找某个字段与值 { mid.keytype.Add(ss["name"].Value(), ss["type"].Value()); } 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 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}\",\"client_type\":\"{4}\",\"skipKey\":{5}}}", order, sn, psn, firetv_device_code, midList.clienttype, 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.Equals("yes", StringComparison.InvariantCultureIgnoreCase)) { 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); jObject["data"] = str; } Dictionary data = JsonConvert.DeserializeObject>(jObject["data"].ToString()); if (data != null) { Func 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 { msg = "解析Json失败"; } } 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 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 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 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); 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"); } return postJson.ToString(); } catch (Exception ex) { Log.WriteErrorLog("\r\nFail to GetReportJson," + ex.Message + ":" + "\r\nOrder:" + order + "\r\nSN:" + sn); } return ""; } /// /// 在线抄写完成上报 Key /// /// /// /// /// /// /// /// /// public static bool ReportOnlineData(string url, string order, string postData, SQLiteConnection sqliteConn, bool repeatupload, string id, int timeout) { if (timeout < 5000) timeout = 5000; HttpHelper http = new HttpHelper(); //需要加密上报的话 if (midList != null && midList.aesEncrypt.Equals("yes", StringComparison.InvariantCultureIgnoreCase)) { 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(); } 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 code = jObject["code"].Value(); 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); if (!repeatupload) { if (CommonMethod.HTTPChecker(item.URL)) SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, url, item.Postdata }); } CommonMethod.ReportErrormsg("Fail to ReportOnlineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn); } return false; } //reportData/reportList /// /// 离线抄写上报 /// /// /// /// /// /// /// /// /// /// 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; if (CommonMethod.HTTPChecker(url)) SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { "preload_mode", url, SN + "@" + copydate }); return false; } try { JObject jObject = JObject.Parse(ParseText); string msg = jObject["msg"].Value(); string code = jObject["code"].Value(); 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 midAddressList) { midAddressList = new List(); 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(), number = data["order_quantity"].ToObject(), pid = data["project_id"].ToObject(), ctype = data["client_type"].ToObject(), purl = data["packet_url"].ToObject(), psize = data["packet_size"].ToObject(), pmd5 = data["packet_md5"].ToObject(), version = data["soft_version"].ToObject(), 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; } }; };