| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860 | 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.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_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 SetTestUrl()        {            if (TestMode.testMode)                url_getMessage = "http://test.scbc.qhmoka.com/scbc-server/clientType/getMessage.do";        }        public static RokuCustomer GetRokuInfo(string strRokuInfo)        {            try            {                JObject jObject = JObject.Parse(strRokuInfo);                RokuCustomer rokuCustomer = new RokuCustomer();                rokuCustomer.id = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "id").Trim();                rokuCustomer.ordernum = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "ordernum").Trim();                rokuCustomer.brand = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "brand").Trim();                rokuCustomer.region = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "region").Trim();                rokuCustomer.oemmodel = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "oemmodel").Trim();                rokuCustomer.productiondate = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "productiondate").Trim();                rokuCustomer.remotetype = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "remotetype").Trim();                rokuCustomer.updatetime = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "updatetime").Trim();                rokuCustomer.createtime = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "createtime").Trim();                rokuCustomer.isdelete = CommonMethod.JSON_SeleteNode(jObject["rokuCustomer"], "isdelete").Trim();                if (jObject["rokuCustomer"]["data"] != null)                {                    rokuCustomer.rokuData = new List<RokuData>();                    foreach (var item in jObject["rokuCustomer"]["data"])                    {                        RokuData rokuData = new RokuData();                        rokuData.name = item["name"].Value<string>();                        rokuData.supporturl = item["supporturl"].Value<string>();                        rokuData.supportphone = item["supportphone"].Value<string>();                        rokuCustomer.rokuData.Add(rokuData);                    }                }                return rokuCustomer;            }            catch (Exception ex)            {                Log.WriteErrorLog(string.Format("解析json失败:{0}", strRokuInfo));            }            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>();                object a = jObject["rokuCustomer"];                if (jObject["rokuCustomer"].ToString().Length > 0)                {                    mid.rokuCustomer = GetRokuInfo(jObject["rokuCustomer"].ToString());                }                mid.keytype = new Dictionary<string, string>();                foreach (var ss in jObject["obj"])  //查找某个字段与值                {                    mid.keytype.Add(ss["name"].Value<string>(), ss["type"].Value<string>());                }                if (mid.code == "1000")                    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}\",\"skipKey\":{4}}}", order, sn, psn, firetv_device_code, 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")                    {                        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                {                    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<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);                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.DAK, postJson, "kfp");                }                return postJson.ToString();            }            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)        {            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);                if (!repeatupload)                {                    if (CommonMethod.HTTPChecker(item.URL))                        SQLiteHelper.InsertDelayCopyReport(sqliteConn, new object[] { order, item.URL, item.Postdata });                }                CommonMethod.ReportErrormsg("Fail to ReportOnlineData", result.StatusDescription + result.Html + "\r\nAddress:" + url + "\r\nPostdata:" + item.Postdata, sqliteConn);            }                        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;                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>();                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;        }    };};
 |