using Newtonsoft.Json; using System; using System.IO; using System.Net; using System.Security.Cryptography; using System.Text; namespace HL_FristAidPlatform_Public { public class Util { /// /// /// /// MD5计算值 /// 业务代码 /// 参数 /// public static string GetECG(string summaryValue, string serviceCode, string parameter) { try { string guid = Guid.NewGuid().ToString(); string authorKey = Information.Hospital.Ecg_AuthorKey; string appId = Information.Hospital.Ecg_AppId; string token = Information.Hospital.Ecg_Token; string Url = Information.Hospital.Ecg_URL; string postText = "header[authorKey]=" + authorKey + "&header[appId]=" + appId + "&header[token]=" + token + "&header[ssid]" + "=" + guid + "&header[service]=" + serviceCode + "&header[summary]=" + summaryValue; postText += parameter; string responseString = Util.ECGPost(Url, postText); return responseString; } catch (Exception ex) { PublicClass.WriteErrorLog("Util", "GetECG:\r\n" + ex); return ""; } } /// /// MD5加密 /// /// /// public static string Encryption(string text) { try { //初始化MD5对象 MD5 md5 = MD5.Create(); //将源字符串转化为byte数组 byte[] soucebyte = Encoding.UTF8.GetBytes(text); //soucebyte转化为mf5的byte数组 byte[] md5bytes = md5.ComputeHash(soucebyte); //将md5的byte数组再转化为MD5数组 StringBuilder sb = new StringBuilder(); foreach (Byte b in md5bytes) { //x表示16进制,2表示2位 sb.Append(b.ToString("x2")); } return sb.ToString(); } catch (Exception ex) { PublicClass.WriteErrorLog("Util", "Encryption:\r\n" + ex); return ""; } } /// /// Post /// /// /// /// public static string ECGPost(string url, string postText) { try { var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; //在转换字节时指定编码格式 byte[] byteData = Encoding.UTF8.GetBytes(postText); var length = byteData.Length; request.ContentLength = length; var writer = request.GetRequestStream(); writer.Write(byteData, 0, length); writer.Close(); //接收数据 var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")).ReadToEnd(); return responseString; } catch (Exception ex) { PublicClass.WriteErrorLog("Util", "ECGPost:\r\n" + ex); return ""; } } public static string ECGPostEncoding(string url, string postText) { try { var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8"; //在转换字节时指定编码格式 byte[] byteData = Encoding.UTF8.GetBytes(postText); var length = byteData.Length; request.ContentLength = length; var writer = request.GetRequestStream(); writer.Write(byteData, 0, length); writer.Close(); //接收数据 var response = (HttpWebResponse)request.GetResponse(); string responseString = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("UTF-8")).ReadToEnd(); responseString = JsonConvert.DeserializeObject(responseString).ToString(); return responseString; } catch (Exception ex) { PublicClass.WriteErrorLog("Util", "ECGPost:\r\n" + ex); return ""; } } public enum ServiceCode { /// /// 表示上传静态心电数据 /// UPLOADEDATA, /// /// 表示获取心电图的判读和报告 /// GETEREPORT, /// /// 提交心电医疗订单 /// POSTMEDICALFORM, /// /// 查询心电片段截图(代理模式) /// QUERYHEARTPICBYPROXY, /// /// 查询心电图报告(代理模式) /// QUERYHEARTREPORTBYPROXY, /// /// 获取动态密钥 /// GETTOKEN, /// /// 获取设备列表 /// GETEQMTLIST, /// /// 通过代理商获取服务机构 /// GETSERVICEORGLIST, /// /// 通过代理商获取动态报告 /// GETDYNAMICREPORT, /// /// 通过代理商获取动态合同 /// GETDYNAMICWARDSHIP, /// /// 通过代理商获取动态业务统计信息 /// GETDYNAMICBSSTATIS, /// /// 上传存储报告记录 /// UPLOADSTOREREPORT, /// /// 查询存储报告记录 /// QUERYSTOREREPORT } } }