using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Configuration; using System.IO; using System.Net; using System.Security.Cryptography; using System.Text; using XCommon.Log; using RestSharp; namespace XCommon { /// ///作用: Http数据传输类 public class HttpWebHelper { /// /// 请求超时时间 /// private const int Timeout = 1000 * 10 * 60; /// /// 请求成功CODE /// private const string SucesscCode = "0"; /// /// Post文件到服务器 /// /// /// public static string PostFile(string fileLocalPath) { string result = string.Empty; MemoryStream memoryStream = null; try { LoggerHelper.InfoLog(string.Format("[PostFile]:LocalPath = {0}", fileLocalPath)); string boundary = DateTime.Now.Ticks.ToString("x"); //边界符 byte[] beginBoundaryBytes = Encoding.UTF8.GetBytes("--" + boundary + "\r\n"); byte[] endBoundaryBytes = Encoding.UTF8.GetBytes("\r\n--" + boundary + "--\r\n"); memoryStream = new MemoryStream(); const string filePartHeaderTemplate = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n"; FileInfo fileInfo = new FileInfo(fileLocalPath); string fileName = fileInfo.Name; string fileHeaderItem = string.Format(filePartHeaderTemplate, "files", fileName); byte[] fileHeaderItemBytes = Encoding.UTF8.GetBytes(fileHeaderItem); memoryStream.Write(beginBoundaryBytes, 0, beginBoundaryBytes.Length); memoryStream.Write(fileHeaderItemBytes, 0, fileHeaderItemBytes.Length); int bytesRead; byte[] buffer = new byte[1024]; FileStream fileStream = new FileStream(fileLocalPath, FileMode.Open, FileAccess.Read); while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { memoryStream.Write(buffer, 0, bytesRead); // 将文件流写入FormData项中 } memoryStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length); // 创建请求 string requestURL = ConfigurationManager.AppSettings["FileUpLoadServer"].ToString(); HttpWebRequest request = WebRequest.Create(requestURL) as HttpWebRequest; request.Method = "POST"; request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary); request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"; request.Accept = "*/*"; //request.Referer = this.Referer; request.ContentLength = memoryStream.Length; //request.CookieContainer = this.CookieContainer; memoryStream.Position = 0; byte[] tempBuffer = new byte[memoryStream.Length]; memoryStream.Read(tempBuffer, 0, tempBuffer.Length); using (var streamWriter = request.GetRequestStream()) { streamWriter.Write(tempBuffer, 0, tempBuffer.Length); } HttpWebResponse response = request.GetResponse() as HttpWebResponse; using (Stream resStream = response.GetResponseStream()) { using (StreamReader streamReader = new StreamReader(resStream, Encoding.UTF8)) { string resContent = streamReader.ReadToEnd().ToString(); JObject jObj = JObject.Parse(resContent); //if (jObj.Value("code") != null) //{ // if (jObj.Value("code") == 200) // { // JArray resArray = jObj.Value("data"); // List lst = resArray.ToObject>(); // if (lst.Count > 0) // { // result = lst[0]; // } // } //} if (jObj.Value("status") != null) { if (jObj.Value("status").Equals("0")) { JArray resArray = jObj.Value("data"); List lst = resArray.ToObject>(); if (lst.Count > 0) { result = lst[0]; LoggerHelper.InfoLog(string.Format("[PostFile]:UpLoad OK! ServerPath = {0}", result)); } } else { LoggerHelper.InfoLog(string.Format("[PostFile]:UpLoad failed!!! Return:{0}", resContent)); } } } } } catch (Exception ex) { LoggerHelper.ErrorLog("[PostFile]:[ERROR] ", ex); } finally { if (memoryStream != null) { memoryStream.Close(); } } return result; } /// /// 从Minio服务器获取文件 /// /// /// /// /// public static string GetFile(string fileServerPath, string fileLocalPath, string fileLocalName) { WebResponse response = null; Stream stream = null; string fileLocalFullPath = string.Empty; try { LoggerHelper.InfoLog( string.Format("[GetFile]:======= 从服务器下载文件 ======= fileServerPath:{0}, fileLocalPath:{1}, fileLocalName:{2}", fileServerPath, fileLocalPath, fileLocalName)); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fileServerPath); response = request.GetResponse(); stream = response.GetResponseStream(); if (!response.ContentType.ToLower().StartsWith("text/plain")) { if (!Directory.Exists(fileLocalPath)) { Directory.CreateDirectory(fileLocalPath); } // 文件名加时间戳 string fileExtension = Path.GetExtension(fileLocalName); string fileName = Path.GetFileNameWithoutExtension(fileLocalName); fileLocalName = string.Format("{0}_{1}{2}", fileName, DateTime.Now.ToString("yyyyMMddHHmmssfff"), fileExtension); // 另存文件到本地 fileLocalFullPath = string.Format("{0}\\{1}", fileLocalPath, fileLocalName); SaveBinaryFile(response, fileLocalFullPath); LoggerHelper.InfoLog(string.Format("[GetFile]:======= 文件下载成功! ======= ")); } } catch (Exception ex) { LoggerHelper.ErrorLog("CALL API:[ERROR] ", ex); //MessageBox.Show(ex.Message, "Tips"); } finally { if (stream != null) { stream.Close(); stream = null; } if (response != null) { response.Close(); response = null; } } return fileLocalFullPath; } /* /// /// Get方式获取数据 /// /// /// /// /// public static string GetData(string url, Dictionary dicVal, bool isOutLog = true) { string result = string.Empty; try { StringBuilder builder = new StringBuilder(); builder.Append(url); if (dicVal.Count > 0) { builder.Append("?"); int i = 0; foreach (var item in dicVal) { if (i > 0) { builder.Append("&"); } builder.AppendFormat("{0}={1}", item.Key, item.Value); i++; } } RestClient client = new RestClient(builder.ToString()); //client.Timeout = -1; client.Timeout = Timeout; RestRequest request = new RestRequest(Method.GET); AddRequestHeardInfo(request); //if (isOutLog) //{ LoggerHelper.InfoLog("CALL API:[GetData] URL: " + builder.ToString()); //} IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { result = response.Content; } //if (isOutLog) //{ LoggerHelper.InfoLog("CALL API:[GetData] URL: " + builder.ToString() + " Result: " + result); //} } catch (Exception ex) { LoggerHelper.ErrorLog("CALL API:[ERROR] ", ex); } //finally //{ // if (null != sr) // { // sr.Close(); // sr = null; // } // if (null != response) // { // response.Close(); // response = null; // } //} return result; } /// /// Post方式传输数据 /// /// /// /// public static string PostData(string url, string jsonParam) { #region DEL //HttpWebRequest request = null; //Stream postStream = null; //HttpWebResponse response = null; //StreamReader sr = null; //string result = string.Empty; //try //{ // request = WebRequest.Create(url) as HttpWebRequest; // request.Method = "POST"; // request.ContentType = "application/json"; // //request.Timeout = TimeOut; // //创建参数 // byte[] byteData = UTF8Encoding.UTF8.GetBytes(jsonParam); // request.ContentLength = byteData.Length; // // 添加请求头信息 // AddRequestHeardInfo(request.Headers); // PubConstant.Logger.Print("[PostData]:URL: " + url); // PubConstant.Logger.Print("[PostData]:JsonParam: " + jsonParam); // // 以流的形式附加参数 // postStream = request.GetRequestStream(); // postStream.Write(byteData, 0, byteData.Length); // // 接收应答 // response = (HttpWebResponse)request.GetResponse(); // if (response.StatusCode == HttpStatusCode.OK) // { // sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); // result = sr.ReadToEnd(); // } // PubConstant.Logger.Print("[PostData]:Result: " + result); // #region DEL // //RestClient client = new RestClient(url); // //client.Timeout = -1; // //RestRequest request = new RestRequest(Method.POST); // //request.AddHeader("appId", "wangdongyao"); // //request.AddHeader("timeStamp", "1658457295981"); // //request.AddHeader("sign", "27D714F3878368B50152FE315D32D6E8"); // ////AddRequestHeardInfo(request); // //request.AddHeader("Content-Type", "application/json"); // //request.AddParameter("application/json", jsonParam, ParameterType.RequestBody); // //IRestResponse response = client.Execute(request); // //if (response.StatusCode == HttpStatusCode.OK) // //{ // // result = response.Content; // //} // #endregion //} //catch (Exception ex) //{ // LoggerUtil.WriteErrorLog("CALL API:[ERROR] ", ex); // MessageBox.Show(ex.Message, "Tips"); //} //finally //{ // if (null != sr) // { // sr.Close(); // sr = null; // } // if (null != response) // { // response.Close(); // response = null; // } // if (null != postStream) // { // postStream.Close(); // postStream = null; // } //} //return result; #endregion string result = string.Empty; try { RestClient client = new RestClient(url); //client.Timeout = -1; client.Timeout = Timeout; RestRequest request = new RestRequest(Method.POST); AddRequestHeardInfo(request); request.AddParameter("application/json", jsonParam, ParameterType.RequestBody); LoggerHelper.InfoLog("CALL API:[PostData] URL: " + url); LoggerHelper.InfoLog("CALL API:[PostData] JsonParam: " + jsonParam); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { result = response.Content; } LoggerHelper.InfoLog("CALL API:[PostData] Result: " + result); } catch (Exception ex) { LoggerHelper.ErrorLog("CALL API:[ERROR] ", ex); } return result; } /// /// Put方式传输数据 /// /// /// /// public static string PutData(string url, string jsonParam) { #region DEL //HttpWebRequest request = null; //Stream postStream = null; //HttpWebResponse response = null; //StreamReader sr = null; //string result = string.Empty; //try //{ // request = WebRequest.Create(url) as HttpWebRequest; // request.Method = "PUT"; // request.ContentType = "application/json"; // //创建参数 // byte[] byteData = UTF8Encoding.UTF8.GetBytes(jsonParam); // request.ContentLength = byteData.Length; // request.Timeout = TimeOut; // // 添加请求头信息 // AddRequestHeardInfo(request.Headers); // PubConstant.Logger.Print("[PutData]:URL: " + url); // PubConstant.Logger.Print("[PutData]:JsonParam: " + jsonParam); // // 以流的形式附加参数 // postStream = request.GetRequestStream(); // postStream.Write(byteData, 0, byteData.Length); // // 接收应答 // response = (HttpWebResponse)request.GetResponse(); // if (response.StatusCode == HttpStatusCode.OK) // { // sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8); // result = sr.ReadToEnd(); // } // PubConstant.Logger.Print("[PutData]:Result: " + result); //} //catch (Exception ex) //{ // PubConstant.Logger.Print("[ERROR] " + ex.ToString()); // MessageBox.Show(ex.Message, "Tips"); //} //finally //{ // if (null != sr) // { // sr.Close(); // sr = null; // } // if (null != response) // { // response.Close(); // response = null; // } // if (null != postStream) // { // postStream.Close(); // postStream = null; // } //} #endregion string result = string.Empty; try { RestClient client = new RestClient(url); //client.Timeout = -1; client.Timeout = Timeout; RestRequest request = new RestRequest(Method.PUT); // 添加请求头信息 AddRequestHeardInfo(request); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", jsonParam, ParameterType.RequestBody); LoggerHelper.InfoLog("CALL API:[PutData] URL: " + url); LoggerHelper.InfoLog("CALL API:[PutData] JsonParam: " + jsonParam); IRestResponse response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { result = response.Content; } LoggerHelper.InfoLog("CALL API:[PostData] Result: " + result); } catch (Exception ex) { LoggerHelper.ErrorLog("CALL API:[ERROR] ", ex); } return result; } */ /// /// 另存文件到本地 /// /// /// /// private static void SaveBinaryFile(WebResponse response, string fileFullPath) { byte[] buffer = new byte[1024*1024]; int nReadLength = 0; Stream inStream = null; Stream outStream = null; try { // 本地如有重复的文件,先删除本地 if (File.Exists(fileFullPath)) { File.Delete(fileFullPath); } inStream = File.Create(fileFullPath); outStream = response.GetResponseStream(); do { nReadLength = outStream.Read(buffer, 0, buffer.Length); if (nReadLength > 0) { inStream.Write(buffer, 0, nReadLength); } } while (nReadLength > 0); } catch(Exception ex) { LoggerHelper.ErrorLog("SaveBinaryFile error", ex); } finally { if (inStream != null) { inStream.Close(); } if (outStream != null) { outStream.Close(); } } } /* //public static string UrlEncode(string str) //{ // StringBuilder sb = new StringBuilder(); // byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str) // for (int i = 0; i < byStr.Length; i++) // { // sb.Append(@"%" + Convert.ToString(byStr[i], 16)); // } // return (sb.ToString()); //} ///// ///// 添加请求头信息 ///// ///// //private static void AddRequestHeardInfo(RestRequest restRequest) //{ // string strAppId = Shared.AppId; // string strAppSecret = Shared.AppSecret; // long time = GetTimeStamp(); // string strEncryptAgo = string.Format("appId={0}&appSecret={1}&timeStamp={2}", strAppId, strAppSecret, time); // // 32位MD5加密大写 // string strEncrypt = Encrypt(strEncryptAgo); // restRequest.AddHeader("appId", strAppId); // restRequest.AddHeader("timeStamp", time.ToString()); // restRequest.AddHeader("sign", strEncrypt); //} /// /// 添加请求头信息 /// /// private static void AddRequestHeardInfo(WebHeaderCollection headers) { string strAppId = Shared.AppId; string strAppSecret = Shared.AppSecret; long time = GetTimeStamp(); string strEncryptAgo = string.Format("appId={0}&appSecret={1}&timeStamp={2}", strAppId, strAppSecret, time); // 32位MD5加密大写 string strEncrypt = Encrypt(strEncryptAgo); headers.Add("appId", strAppId); headers.Add("timeStamp", time.ToString()); headers.Add("sign", strEncrypt); } /// /// 添加请求头信息 /// /// private static void AddRequestHeardInfo(RestRequest restRequest) { string strAppId = Shared.AppId; string strAppSecret = Shared.AppSecret; long time = GetTimeStamp(); string strEncryptAgo = string.Format("appId={0}&appSecret={1}&timeStamp={2}", strAppId, strAppSecret, time); // 32位MD5加密大写 string strEncrypt = Encrypt(strEncryptAgo); restRequest.AddHeader("appId", strAppId); restRequest.AddHeader("timeStamp", time.ToString()); restRequest.AddHeader("sign", strEncrypt); restRequest.AddHeader("Content-Type", "application/json"); } /// /// 获取时间戳 /// /// private static long GetTimeStamp() { TimeSpan mTimeSpan = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0); //得到精确到毫秒的时间戳(长度13位) long time = (long)mTimeSpan.TotalMilliseconds; return time; } /// /// 32位MD5加密大写 /// /// /// public static string Encrypt(string str) { MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider(); byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(str)); StringBuilder sBuilder = new StringBuilder(); for (int i = 0; i < data.Length; i++) { sBuilder.Append(data[i].ToString("X2"));//转化为大写的16进制 } return sBuilder.ToString(); } /// /// 另存文件到本地 /// /// /// /// private static void SaveBinaryFile(WebResponse response, string fileFullPath) { byte[] buffer = new byte[1024]; int nReadLength = 0; Stream inStream = null; Stream outStream = null; try { // 本地如有重复的文件,先删除本地 if (File.Exists(fileFullPath)) { File.Delete(fileFullPath); } inStream = File.Create(fileFullPath); outStream = response.GetResponseStream(); do { nReadLength = outStream.Read(buffer, 0, buffer.Length); if (nReadLength > 0) { inStream.Write(buffer, 0, nReadLength); } } while (nReadLength > 0); } finally { if (inStream != null) { inStream.Close(); } if (outStream != null) { outStream.Close(); } } } /// /// 根据返回代码判断是否成功 /// /// /// public static void JudgeResultCode(BsCommonResult comResult) { if (comResult == null) { throw new Exception("API返回结果为NULL"); } else if (!SucesscCode.Equals(comResult.code)) { LoggerUtil.WriteDebugLog("CALL API:[ERROR] " + comResult.GetType().ToString()); throw new Exception(comResult.message); } } /// /// 新增实验API /// /// /// public static AddExperimentRes AddExperimentReq(AddExperimentReq addExperimentReq) { // 新增实验 string strJson = JsonHelper.SerializeObject(addExperimentReq); string strResult = HttpWebHelper.PostData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.AddExperiment), strJson); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 新增子实验API /// /// /// public static BsCommonResult AddSubExperimentReq(AddSubExperimentReq addSubExperimentReq) { // 新增子实验 string strJson = JsonHelper.SerializeObject(addSubExperimentReq); string strResult = HttpWebHelper.PostData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.AddSubExperiment), strJson); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject; } /// /// 变量赋值API /// /// /// public static object SetVariables(List lstSetVariablesReq) { // 变量赋值 string strJson = JsonHelper.SerializeObject(lstSetVariablesReq); string strResult = HttpWebHelper.PostData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.Variables), strJson); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 查询实验模板API /// /// /// /// public static List GetTemplates(string experimentCode = "", string experimentName = "") { Dictionary dicVal = new Dictionary(); if (!string.IsNullOrEmpty(experimentCode)) { dicVal.Add("experimentCode", experimentCode); } if (!string.IsNullOrEmpty(experimentName)) { dicVal.Add("experimentName", experimentName); } dicVal.Add("hasVariable", false); string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.GetTemplates), dicVal); BsCommonResult> resultObject = JsonHelper.DeserializeObject>>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode>(resultObject); return resultObject.data; } /// /// 运行实验API /// /// /// public static StartExperimentRes StartExperiment(string batchId) { StartExperimentReq startReq = new StartExperimentReq(); startReq.batchId = batchId; startReq._operator = Shared.UserName; startReq.workflows = new List(); string jsonParam = JsonHelper.SerializeObject(startReq); // 运行实验API //string strResult = HttpWebHelper.PutData(string.Format("{0}{1}", Shared.ApiBaseUrl, string.Format(Shared.StartExperiment, batchId)), jsonParam); string strResult = HttpWebHelper.PutData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.StartExperiment), jsonParam); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 暂停实验API /// /// /// public static PauseExperimentRes PauseExperiment(string batchId) { PauseExperimentReq pauseReq = new PauseExperimentReq(); pauseReq.batchId = batchId; pauseReq._operator = Shared.UserName; string jsonParam = JsonHelper.SerializeObject(pauseReq); // 运行实验API string strResult = HttpWebHelper.PutData(string.Format("{0}{1}", Shared.ApiBaseUrl, string.Format(Shared.PauseExperiment, batchId)), jsonParam); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 唤醒实验API /// /// /// public static AwakeExperimentRes AwakeExperiment(string batchId) { AwakeExperimentReq awakeReq = new AwakeExperimentReq(); awakeReq.batchId = batchId; awakeReq._operator = Shared.UserName; string jsonParam = JsonHelper.SerializeObject(awakeReq); // 运行实验API string strResult = HttpWebHelper.PutData(string.Format("{0}{1}", Shared.ApiBaseUrl, string.Format(Shared.AwakeExperiment, batchId)), jsonParam); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 停止实验API /// /// /// public static StopExperimentRes StopExperiment(string batchId) { StopExperimentReq StopReq = new StopExperimentReq(); StopReq.batchId = batchId; StopReq._operator = Shared.UserName; string jsonParam = JsonHelper.SerializeObject(StopReq); // 运行实验API string strResult = HttpWebHelper.PutData(string.Format("{0}{1}", Shared.ApiBaseUrl, string.Format(Shared.StopExperiment, batchId)), jsonParam); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 查询实验详情API /// /// /// public static ExperimentsDetailRes GetExperimentsDetail(string batchId = "") { Dictionary dicVal = new Dictionary(); if (!string.IsNullOrEmpty(batchId)) { dicVal.Add("batchId", batchId); } string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, string.Format(Shared.GetExperimentDetail, batchId)), dicVal, false); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 查询实验返回结果API /// /// /// public static ExperimentResultsRes GetExperimentResults(string batchId) { Dictionary dicVal = new Dictionary(); if (!string.IsNullOrEmpty(batchId)) { dicVal.Add("batchId", batchId); } string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, string.Format(Shared.ExperimentResults, batchId)), dicVal); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 查询设备信息API /// /// /// public static List GetDevices() { List lstDevicesRes = new List(); try { Dictionary dicVal = new Dictionary(); dicVal.Add("islandCode", Shared.IslandCode); string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.Devices), dicVal, false); BsCommonResult> resultObject = JsonHelper.DeserializeObject>>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode>(resultObject); lstDevicesRes = resultObject.data; } catch (Exception ex) { LoggerUtil.WriteErrorLog("CALL API:[ERROR] ", ex); } return lstDevicesRes; } /// /// 查询错误信息API /// /// /// public static ErrorRes GetErrorList(string errorSource = "") { Dictionary dicVal = new Dictionary(); if (!string.IsNullOrEmpty(errorSource)) { dicVal.Add("errorSource", errorSource); } string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.ErrorList), dicVal, false); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 执行错误命令API /// /// /// /// public static BsCommonResult ExecuteCommand(string command = "", string errorLogId = "") { Dictionary dicVal = new Dictionary(); if (!string.IsNullOrEmpty(command)) { dicVal.Add("command", command); } if (!string.IsNullOrEmpty(errorLogId)) { dicVal.Add("errorLogId", errorLogId); } string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.ExecuteCommand), dicVal); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject; } /// /// 获取培养箱占用的位置API /// /// public static T SendDeviceCommand(SendDeviceCommandReq sendDeviceCommandReq) { // 变量赋值 string strJson = JsonHelper.SerializeObject(sendDeviceCommandReq); string strResult = HttpWebHelper.PostData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.SendDeviceCommand), strJson); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); return resultObject.data; } /// /// 清除所有告警信息API /// /// public static CleanAllWarningRes CleanAllWarning() { CleanAllWarningRes res = null; try { Dictionary dicVal = new Dictionary(); string strResult = HttpWebHelper.GetData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.CleanAllWarning), dicVal, false); BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // 根据返回代码判断是否成功 HttpWebHelper.JudgeResultCode(resultObject); res = resultObject.data; } catch (Exception ex) { LoggerUtil.WriteErrorLog("CALL API:[ERROR] ", ex); } return res; } */ ///// ///// 开启FFU API ///// ///// //public static T StartRank(SendDeviceCommandReq sendDeviceCommandReq) //{ // // 变量赋值 // string strJson = JsonHelper.SerializeObject(sendDeviceCommandReq); // string strResult = HttpWebHelper.PostData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.SendDeviceCommand), strJson); // BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // // 根据返回代码判断是否成功 // HttpWebHelper.JudgeResultCode(resultObject); // return resultObject.data; //} ///// ///// 关闭FFU API ///// ///// //public static T StopRank(SendDeviceCommandReq sendDeviceCommandReq) //{ // // 变量赋值 // string strJson = JsonHelper.SerializeObject(sendDeviceCommandReq); // string strResult = HttpWebHelper.PostData(string.Format("{0}{1}", Shared.ApiBaseUrl, Shared.SendDeviceCommand), strJson); // BsCommonResult resultObject = JsonHelper.DeserializeObject>(strResult); // // 根据返回代码判断是否成功 // HttpWebHelper.JudgeResultCode(resultObject); // return resultObject.data; //} } }