/// <summary> /// 获取客户端验证图片扩展名是否有效的正则表达式 /// </summary> /// <returns></returns> public static string GetCheckValidImageRegExp() { string[] allowedExtensions = ConfigClass.GetConfigString("UsedCar", "ImgFlieExt").Split(','); System.Text.StringBuilder regexp = new System.Text.StringBuilder(); regexp.Append("\\.("); if (allowedExtensions.Length > 0) { string old = null; string clone = null; string format = "[{0}{1}]"; foreach (string s in allowedExtensions) { old = s.Replace(".", "").ToLower(); clone = string.Copy(old.ToUpper()); for (int i = 0; i < old.Length; i++) { regexp.AppendFormat(format, old[i], clone[i]); } regexp.Append("|"); } regexp.Remove(regexp.Length - 1, 1); } else { regexp.Append("[^.]*"); } regexp.Append(")$"); return(regexp.ToString()); }
/// <summary> /// 验证用户上传的车辆图片是否在指定的文件类型范围内,或者指定的文件大小内 /// </summary> /// <param name="file"></param> /// <returns>验证信息</returns> public static string IsValidUploadImage(HttpPostedFile file) { string msg = string.Empty; bool fileExtensionOK = false; string fileExtension = System.IO.Path.GetExtension(file.FileName).ToLower(); //String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" }; string[] allowedExtensions = ConfigClass.GetConfigString("UsedCar", "ImgFlieExt").Split(','); for (int i = 0; i < allowedExtensions.Length; i++) { if (fileExtension == allowedExtensions[i]) { fileExtensionOK = true; } } bool fileMimeOK = false; string fileMime = file.ContentType.ToLower(); string expectedFileMime = GetMimeTypeByFileExtension(fileExtension); string[] allowMime = new string[allowedExtensions.Length]; for (int i = 0; i < allowMime.Length; i++) { allowMime[i] = GetMimeTypeByFileExtension(allowedExtensions[i]); } if (expectedFileMime.IndexOf(fileMime) != -1) { for (int i = 0; i < allowMime.Length; i++) { if (allowMime[i].IndexOf(fileMime) != -1) { fileMimeOK = true; } } } if (!fileExtensionOK || !fileMimeOK) { msg += "不是预期的文件类型,只能上传.gif,.png,.jpeg,.jpg文件."; } bool fileSizeOK = false; int maxFileSize = 200 * 1024; int fileSize = file.ContentLength; if (fileSize <= maxFileSize) { fileSizeOK = true; } if (!fileSizeOK) { msg += "文件大小不能超过200KB."; } return(msg); }
/// <summary> /// 初始化系统信息实体 /// </summary> /// <returns></returns> private TicketSystemModel InitSysModel() { TicketSystemModel sysModel = new TicketSystemModel(); sysModel.TicketInterfaceUrl = ConfigClass.GetConfigString("Ticket", "TicketInterfaceUrl"); sysModel.Sign = ConfigClass.GetConfigString("Ticket", "Sign"); sysModel.CompanyCode = ConfigClass.GetConfigString("Ticket", "CompanyCode"); sysModel.cpcode = ConfigClass.GetConfigString("Ticket", "cpcode"); sysModel.sysPath = ConfigClass.GetConfigString("Ticket", "sysPath"); return(sysModel); }
/// <summary> /// 构造要跳转的URL /// </summary> /// <param name="model"></param> /// <param name="sysModel"></param> /// <returns></returns> private Adpost.Ticket.Model.TicketQueryResult QueryURL(Adpost.Ticket.Model.TicketModel model, TicketSystemModel sysModel) { Adpost.Ticket.Model.TicketQueryResult result = new Adpost.Ticket.Model.TicketQueryResult(); result.IsSuccess = true; result.TicketGotoUrl = ""; #region 表单验证 if (String.IsNullOrEmpty(sysModel.TicketInterfaceUrl)) { result.ErrorInfo.Append("请填写机票接口网址。\n"); result.IsSuccess = false; } if (!result.IsSuccess) { return(result); } #endregion #region 构造URL StringBuilder str = new StringBuilder(); Hashtable parameters = new Hashtable(); if (FXUser.ContainsKey(model.User.UserName)) { sysModel.cpcode = FXUser[model.User.UserName].ToString(); } str.AppendFormat("&CompanyCode={0}", sysModel.CompanyCode); str.AppendFormat("&cpcode={0}", sysModel.cpcode); str.AppendFormat("&sysPath={0}", sysModel.sysPath); str.AppendFormat("&sign={0}", sysModel.Sign); if (!String.IsNullOrEmpty(model.User.UserName)) { str.AppendFormat("&UserAccount={0}", HttpUtility.UrlEncodeUnicode(model.User.UserName)); str.AppendFormat("&UserID={0}", HttpUtility.UrlEncodeUnicode(sysModel.cpcode + "." + model.User.UserName)); str.AppendFormat("&UserName={0}", HttpUtility.UrlEncodeUnicode(model.User.UserName)); } str.AppendFormat("&MobilePhone={0}", "15356126700"); str.AppendFormat("&CompanyName={0}", HttpUtility.UrlEncodeUnicode(model.User.CorpName)); str.AppendFormat("&Email={0}", "*****@*****.**"); str.AppendFormat("&LinkMan={0}", HttpUtility.UrlEncodeUnicode("徐晟")); //parameters.Add("DoubleTrip", Convert.ToInt32(model.Flight.VoyageSet).ToString()); model.Flight.FromCity = "HGH"; model.Flight.ToCity = "PEK"; model.Flight.TakeOffDate = DateTime.Now; //if (!String.IsNullOrEmpty(model.Flight.FromCity)) //{ // parameters.Add("FromCityCode", model.Flight.FromCity); //} //if (!String.IsNullOrEmpty(model.Flight.ToCity)) //{ // parameters.Add("DestCityCode", model.Flight.ToCity); //} //if (model.Flight.TakeOffDate.HasValue) //{ // parameters.Add("LeaveDate", model.Flight.TakeOffDate.Value.ToString("yyyy-MM-dd")); //} //if (model.Flight.ReturnDate.HasValue) //{ // parameters.Add("ReturnDate", model.Flight.ReturnDate.Value.ToString("yyyy-MM-dd")); //} //else //{ // parameters.Add("ReturnDate", string.Empty); //} if (string.IsNullOrEmpty(Request.QueryString["url"])) { str.AppendFormat("&action={0}", HttpUtility.UrlEncode(ConfigClass.GetConfigString("Ticket", "QueryURL") + "?" + Sign(parameters) + "")); } else { str.AppendFormat("&action={0}", HttpUtility.UrlEncode(Request.QueryString["url"] + "?" + Sign(parameters) + "")); } string strURL = str.ToString(); if (strURL.StartsWith("&")) { strURL = strURL.Substring(1); } #endregion result.IsSuccess = true; result.TicketGotoUrl = sysModel.TicketInterfaceUrl + "?" + strURL; return(result); }