美容院预约小程序软件开发
微信小程序的出现,代表新一代的互联网的出现.在之前,门店的模式销售全部依托平台;类似美团,饿了么等互联网平台。门店自己运营开发产品成本太高。所以。云商根据微信小程序围绕着云中心化去解决这个问题;
什么叫去中心化?
那当然不是一些代码就能解决的。而是需要靠思想;现在非常火热的区块链,去中心化,数字货币等这些新词。全部都和 比特币 混合着一起去思考了。其实不然。
去中心化;就是去掉中心平台的。自己独立运营自己的平台。老板娘可以自己做一个自己的平台。里面的奖励制度和平台模式如何设计。都是根据自己的想法来走。
并不需要像传统一样的。等着客人过来。用着最原始的发传单的方式推广。而是主动出击。让客人变成自己的业务员。让客人带客人过来。这只是门店的拓客系统一部分。
像美容院最重要的改革是:在线预约;在线预约最大的特点。是今天可以知道后面几天的业绩;而且更重要的是:客人一键预约。直接导航定位。不用再通过电话或者短信一步一步的告诉客人怎么来店消费;
技师预约系统功能包含:
1.微信小程序自带功能:附近小程序搜索到您的门店小程序
2.小程序分为:商户端 和 客户端
3.项目技师预约系统
4.店铺商品售卖系统
5.店铺信息展示功能
6.客人卡项功能
7.店内营销功能(充卡送余额或者充卡送卡项)
8.客人在线充值功能
9.统计统计功能
10.技师预览功能
如果您对我的互联网分析之《美容院技师预约小程序系统》感兴趣;可直接来电咨询:①③④②⑧⑧⑧④⑦①⑧
或者加我二维码:
另赠送一套.Net开发人员工具代码库
/// <summary> /// 常用方法 /// </summary> public sealed partial class Utils { #region 系统版本 /// <summary> /// 版本信息类 /// </summary> public class VersionInfo { public int FileMajorPart { get { return 1; } } public int FileMinorPart { get { return 0; } } public int FileBuildPart { get { return 0; } } public string ProductName { get { return "ERP1.0"; } } public int ProductType { get { return 1; } } } public static string GetVersion() { return "1.0"; } #endregion #region 对象转换处理 /// <summary> /// 判断对象是否为Int32类型的数字 /// </summary> /// <param name="Expression"></param> /// <returns></returns> public static bool IsNumeric(object expression) { if (expression != null) return IsNumeric(expression.ToString()); return false; } /// <summary> /// 判断对象是否为Int32类型的数字 /// </summary> /// <param name="Expression"></param> /// <returns></returns> public static bool IsNumeric(string expression) { if (expression != null) { string str = expression; if (str.Length > 0 && str.Length <= 11 && Regex.IsMatch(str, @"^[-]?[0-9]*[.]?[0-9]*$")) { if ((str.Length < 10) || (str.Length == 10 && str[0] == '1') || (str.Length == 11 && str[0] == '-' && str[1] == '1')) return true; } } return false; } /// <summary> /// 截取字符串长度,超出部分使用后缀suffix代替,比如abcdevfddd取前3位,后面使用...代替 /// </summary> /// <param name="orginStr"></param> /// <param name="length"></param> /// <param name="suffix"></param> /// <returns></returns> public static string SubStrAddSuffix(string orginStr, int length, string suffix) { string ret = orginStr; if (orginStr.Length > length) { ret = orginStr.Substring(0, length) + suffix; } return ret; } /// <summary> /// 是否为Double类型 /// </summary> /// <param name="expression"></param> /// <returns></returns> public static bool IsDouble(object expression) { if (expression != null) return Regex.IsMatch(expression.ToString(), @"^([0-9])[0-9]*(\.\w*)?$"); return false; } /// <summary> /// 检测是否符合email格式 /// </summary> /// <param name="strEmail">要判断的email字符串</param> /// <returns>判断结果</returns> public static bool IsValidEmail(string strEmail) { return Regex.IsMatch(strEmail, @"^[\w\.]+([-]\w+)*@[A-Za-z0-9-_]+[\.][A-Za-z0-9-_]"); } public static bool IsValidDoEmail(string strEmail) { return Regex.IsMatch(strEmail, @"^@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); } /// <summary> /// 检测是否是正确的Url /// </summary> /// <param name="strUrl">要验证的Url</param> /// <returns>判断结果</returns> public static bool IsURL(string strUrl) { return Regex.IsMatch(strUrl, @"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$"); } /// <summary> /// 将字符串转换为数组 /// </summary> /// <param name="str">字符串</param> /// <returns>字符串数组</returns> public static string[] GetStrArray(string str) { return str.Split(new char[',']); } /// <summary> /// 将数组转换为字符串 /// </summary> /// <param name="list">List</param> /// <param name="speater">分隔符</param> /// <returns>String</returns> public static string GetArrayStr(List<string> list, string speater) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.Count; i++) { if (i == list.Count - 1) { sb.Append(list[i]); } else { sb.Append(list[i]); sb.Append(speater); } } return sb.ToString(); } /// <summary> /// object型转换为bool型 /// </summary> /// <param name="strValue">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的bool类型结果</returns> public static bool StrToBool(object expression, bool defValue) { if (expression != null) return StrToBool(expression, defValue); return defValue; } /// <summary> /// string型转换为bool型 /// </summary> /// <param name="strValue">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的bool类型结果</returns> public static bool StrToBool(string expression, bool defValue) { if (expression != null) { if (string.Compare(expression, "true", true) == 0) return true; else if (string.Compare(expression, "false", true) == 0) return false; } return defValue; } /// <summary> /// 将对象转换为Int32类型 /// </summary> /// <param name="expression">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的int类型结果</returns> public static int ObjToInt(object expression, int defValue) { if (expression != null) return StrToInt(expression.ToString(), defValue); return defValue; } /// <summary> /// 将字符串转换为Int32类型 /// </summary> /// <param name="expression">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的int类型结果</returns> public static int StrToInt(string expression, int defValue) { if (string.IsNullOrEmpty(expression) || expression.Trim().Length >= 11 || !Regex.IsMatch(expression.Trim(), @"^([-]|[0-9])[0-9]*(\.\w*)?$")) return defValue; int rv; if (Int32.TryParse(expression, out rv)) return rv; return Convert.ToInt32(StrToFloat(expression, defValue)); } /// <summary> /// Object型转换为decimal型 /// </summary> /// <param name="strValue">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的decimal类型结果</returns> public static decimal ObjToDecimal(object expression, decimal defValue) { if (expression != null) return StrToDecimal(expression.ToString(), defValue); return defValue; } /// <summary> /// string型转换为decimal型 /// </summary> /// <param name="strValue">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的decimal类型结果</returns> public static decimal StrToDecimal(string expression, decimal defValue) { if ((expression == null) || (expression.Length > 10)) return defValue; decimal intValue = defValue; if (expression != null) { bool IsDecimal = Regex.IsMatch(expression, @"^([-]|[0-9])[0-9]*(\.\w*)?$"); if (IsDecimal) decimal.TryParse(expression, out intValue); } return intValue; } /// <summary> /// Object型转换为float型 /// </summary> /// <param name="strValue">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的int类型结果</returns> public static float ObjToFloat(object expression, float defValue) { if (expression != null) return StrToFloat(expression.ToString(), defValue); return defValue; } /// <summary> /// string型转换为float型 /// </summary> /// <param name="strValue">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的int类型结果</returns> public static float StrToFloat(string expression, float defValue) { if ((expression == null) || (expression.Length > 10)) return defValue; float intValue = defValue; if (expression != null) { bool IsFloat = Regex.IsMatch(expression, @"^([-]|[0-9])[0-9]*(\.\w*)?$"); if (IsFloat) float.TryParse(expression, out intValue); } return intValue; } /// <summary> /// 将对象转换为日期时间类型 /// </summary> /// <param name="str">要转换的字符串</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的int类型结果</returns> public static DateTime StrToDateTime(string str, DateTime defValue) { if (!string.IsNullOrEmpty(str)) { DateTime dateTime; if (DateTime.TryParse(str, out dateTime)) return dateTime; } return defValue; } /// <summary> /// 将对象转换为日期时间类型 /// </summary> /// <param name="str">要转换的字符串</param> /// <returns>转换后的int类型结果</returns> public static DateTime StrToDateTime(string str) { return StrToDateTime(str, DateTime.Now); } /// <summary> /// 将对象转换为日期时间类型 /// </summary> /// <param name="obj">要转换的对象</param> /// <returns>转换后的int类型结果</returns> public static DateTime ObjectToDateTime(object obj) { return StrToDateTime(obj.ToString()); } /// <summary> /// 将对象转换为日期时间类型 /// </summary> /// <param name="obj">要转换的对象</param> /// <param name="defValue">缺省值</param> /// <returns>转换后的int类型结果</returns> public static DateTime ObjectToDateTime(object obj, DateTime defValue) { return StrToDateTime(obj.ToString(), defValue); } /// <summary> /// 将对象转换为字符串 /// </summary> /// <param name="obj">要转换的对象</param> /// <returns>转换后的string类型结果</returns> public static string ObjectToStr(object obj) { if (obj == null) return ""; return obj.ToString().Trim(); } /// <summary> /// 将对象转换为Int类型 /// </summary> /// <param name="o"></param> /// <returns></returns> public static int ObjToInt(object obj) { if (isNumber(obj)) { return int.Parse(obj.ToString()); } else { return 0; } } /// <summary> /// 判断对象是否可以转成int型 /// </summary> /// <param name="o"></param> /// <returns></returns> public static bool isNumber(object o) { int tmpInt; if (o == null) { return false; } if (o.ToString().Trim().Length == 0) { return false; } if (!int.TryParse(o.ToString(), out tmpInt)) { return false; } else { return true; } } #endregion #region 分割字符串 /// <summary> /// 分割字符串 /// </summary> public static string[] SplitString(string strContent, string strSplit) { if (!string.IsNullOrEmpty(strContent)) { if (strContent.IndexOf(strSplit) < 0) return new string[] { strContent }; return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase); } else return new string[0] { }; } /// <summary> /// 分割字符串 /// </summary> /// <returns></returns> public static string[] SplitString(string strContent, string strSplit, int count) { string[] result = new string[count]; string[] splited = SplitString(strContent, strSplit); for (int i = 0; i < count; i++) { if (i < splited.Length) result[i] = splited[i]; else result[i] = string.Empty; } return result; } #endregion #region 删除最后结尾的一个逗号 /// <summary> /// 删除最后结尾的一个逗号 /// </summary> public static string DelLastComma(string str) { if (str.Length < 1) { return ""; } return str.Substring(0, str.LastIndexOf(",")); } #endregion #region 删除最后结尾的指定字符后的字符 /// <summary> /// 删除最后结尾的指定字符后的字符 /// </summary> public static string DelLastChar(string str, string strchar) { if (string.IsNullOrEmpty(str)) return ""; if (str.LastIndexOf(strchar) >= 0 && str.LastIndexOf(strchar) == str.Length - 1) { return str.Substring(0, str.LastIndexOf(strchar)); } return str; } #endregion #region 生成指定长度的字符串 /// <summary> /// 生成指定长度的字符串,即生成strLong个str字符串 /// </summary> /// <param name="strLong">生成的长度</param> /// <param name="str">以str生成字符串</param> /// <returns></returns> public static string StringOfChar(int strLong, string str) { string ReturnStr = ""; for (int i = 0; i < strLong; i++) { ReturnStr += str; } return ReturnStr; } #endregion #region 生成日期随机码 /// <summary> /// 生成日期随机码 每毫秒 /// </summary> /// <returns></returns> public static string GetRamCode() { #region return DateTime.Now.ToString("yyyyMMddHHmmssffff"); #endregion } /// <summary> /// 生成日期随机码 每分钟 /// </summary> /// <returns></returns> public static string GetDateCode() { #region return DateTime.Now.ToString("yyyyMMddHH"); #endregion } #endregion #region 生成随机字母或数字 /// <summary> /// 生成随机数字 /// </summary> /// <param name="length">生成长度</param> /// <returns></returns> public static string Number(int Length) { return Number(Length, false); } /// <summary> /// 生成随机数字 /// </summary> /// <param name="Length">生成长度</param> /// <param name="Sleep">是否要在生成前将当前线程阻止以避免重复</param> /// <returns></returns> public static string Number(int Length, bool Sleep) { if (Sleep) System.Threading.Thread.Sleep(3); string result = ""; System.Random random = new Random(); for (int i = 0; i < Length; i++) { result += random.Next(10).ToString(); } return result; } /// <summary> /// 生成随机字母字符串(数字字母混和) /// </summary> /// <param name="codeCount">待生成的位数</param> public static string GetCheckCode(int codeCount) { string str = string.Empty; int rep = 0; long num2 = DateTime.Now.Ticks + rep; rep++; Random random = new Random(((int)(((ulong)num2) & 0xffffffffL)) | ((int)(num2 >> rep))); for (int i = 0; i < codeCount; i++) { char ch; int num = random.Next(); if ((num % 2) == 0) { ch = (char)(0x30 + ((ushort)(num % 10))); } else { ch = (char)(0x41 + ((ushort)(num % 0x1a))); } str = str + ch.ToString(); } return str; } /// <summary> /// 根据日期和随机码生成订单号 /// </summary> /// <returns></returns> public static string GetOrderNumber() { string num = DateTime.Now.ToString("yyMMddHHmmss");//yyyyMMddHHmmssms return num + Number(2, true).ToString(); } private static int Next(int numSeeds, int length) { byte[] buffer = new byte[length]; System.Security.Cryptography.RNGCryptoServiceProvider Gen = new System.Security.Cryptography.RNGCryptoServiceProvider(); Gen.GetBytes(buffer); uint randomResult = 0x0;//这里用uint作为生成的随机数 for (int i = 0; i < length; i++) { randomResult |= ((uint)buffer[i] << ((length - 1 - i) * 8)); } return (int)(randomResult % numSeeds); } #endregion #region 截取字符长度 /// <summary> /// 截取字符长度,带"..." /// </summary> /// <param name="inputString">字符</param> /// <param name="len">长度</param> /// <returns></returns> public static string CutString(string inputString, int len) { if (string.IsNullOrEmpty(inputString)) return ""; inputString = DropHTML(inputString); ASCIIEncoding ascii = new ASCIIEncoding(); int tempLen = 0; string tempString = ""; byte[] s = ascii.GetBytes(inputString); for (int i = 0; i < s.Length; i++) { if ((int)s[i] == 63) { tempLen += 2; } else { tempLen += 1; } try { tempString += inputString.Substring(i, 1); } catch { break; } if (tempLen > len) break; } //如果截过则加上半个省略号 byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString); if (mybyte.Length > len) tempString += "…"; return tempString; } /// <summary> /// 截取指定长度字符,可指定超出部分的后缀 /// </summary> /// <param name="inputString"></param> /// <param name="len"></param> /// <param name="str"></param> /// <returns></returns> public static string CutString(string inputString, int len, string str) { if (string.IsNullOrEmpty(inputString)) return ""; inputString = DropHTML(inputString); ASCIIEncoding ascii = new ASCIIEncoding(); int tempLen = 0; string tempString = ""; byte[] s = ascii.GetBytes(inputString); for (int i = 0; i < s.Length; i++) { if ((int)s[i] == 63) { tempLen += 2; } else { tempLen += 1; } try { tempString += inputString.Substring(i, 1); } catch { break; } if (tempLen > len) break; } byte[] mybyte = System.Text.Encoding.Default.GetBytes(inputString); if (mybyte.Length > len) tempString += str; return tempString; } #endregion #region 清除HTML标记 public static string DropHTML(string Htmlstring) { if (string.IsNullOrEmpty(Htmlstring)) return ""; //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除HTML Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase); Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase); Htmlstring.Replace("<", ""); Htmlstring.Replace(">", ""); Htmlstring.Replace("\r\n", ""); Htmlstring.Replace(" ", ""); Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim(); return Htmlstring; } #endregion #region 清除HTML标记且返回相应的长度 public static string DropHTML(string Htmlstring, int strLen) { return CutString(DropHTML(Htmlstring), strLen); } #endregion #region TXT代码转换成HTML格式 /// <summary> /// 字符串字符处理 /// </summary> /// <param name="chr">等待处理的字符串</param> /// <returns>处理后的字符串</returns> /// //把TXT代码转换成HTML格式 public static String ToHtml(string Input) { StringBuilder sb = new StringBuilder(Input); sb.Replace("'", "'"); sb.Replace("&", "&"); sb.Replace("<", "<"); sb.Replace(">", ">"); sb.Replace("\r\n", "<br />"); sb.Replace("\n", "<br />"); sb.Replace("\t", " "); //sb.Replace(" ", " "); return sb.ToString(); } #endregion #region HTML代码转换成TXT格式 /// <summary> /// 字符串字符处理 /// </summary> /// <param name="chr">等待处理的字符串</param> /// <returns>处理后的字符串</returns> /// //把HTML代码转换成TXT格式 public static String ToTxt(String Input) { StringBuilder sb = new StringBuilder(Input); sb.Replace(" ", " "); sb.Replace("<br>", "\r\n"); sb.Replace("<br>", "\n"); sb.Replace("<br />", "\n"); sb.Replace("<br />", "\r\n"); sb.Replace("<", "<"); sb.Replace(">", ">"); sb.Replace("&", "&"); return sb.ToString(); } #endregion #region 检测是否有Sql危险字符 /// <summary> /// 检测是否有Sql危险字符 /// </summary> /// <param name="str">要判断字符串</param> /// <returns>判断结果</returns> public static bool IsSafeSqlString(string str) { return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']"); } /// <summary> /// 检查危险字符 /// </summary> /// <param name="Input"></param> /// <returns></returns> public static string Filter(string sInput) { if (sInput == null || sInput == "") return null; string sInput1 = sInput.ToLower(); string output = sInput; string pattern = @"*|and|exec|insert|select|delete|update|count|master|truncate|declare|char(|mid(|chr(|'"; if (Regex.Match(sInput1, Regex.Escape(pattern), RegexOptions.Compiled | RegexOptions.IgnoreCase).Success) { throw new Exception("字符串中含有非法字符!"); } else { output = output.Replace("'", "''"); } return output; } /// <summary> /// 检查过滤设定的危险字符 /// </summary> /// <param name="InText">要过滤的字符串 </param> /// <returns>如果参数存在不安全字符,则返回true </returns> public static bool SqlFilter(string word, string InText) { if (InText == null) return false; foreach (string i in word.Split('|')) { if ((InText.ToLower().IndexOf(i + " ") > -1) || (InText.ToLower().IndexOf(" " + i) > -1)) { return true; } } return false; } #endregion #region 过滤特殊字符 /// <summary> /// 过滤特殊字符 /// </summary> /// <param name="Input"></param> /// <returns></returns> public static string Htmls(string Input) { if (Input != string.Empty && Input != null) { string ihtml = Input.ToLower(); ihtml = ihtml.Replace("<script", "<script"); ihtml = ihtml.Replace("script>", "script>"); ihtml = ihtml.Replace("<%", "<%"); ihtml = ihtml.Replace("%>", "%>"); ihtml = ihtml.Replace("<$", "<$"); ihtml = ihtml.Replace("$>", "$>"); return ihtml; } else { return string.Empty; } } #endregion #region 检查是否为IP地址 /// <summary> /// 是否为ip /// </summary> /// <param name="ip"></param> /// <returns></returns> public static bool IsIP(string ip) { return Regex.IsMatch(ip, @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"); } #endregion #region 获得当前绝对路径 /// <summary> /// 获得当前绝对路径 /// </summary> /// <param name="strPath">指定的路径</param> /// <returns>绝对路径</returns> public static string GetMapPath(string strPath) { if (strPath.ToLower().StartsWith("http://")) { return strPath; } if (HttpContext.Current != null) { return HttpContext.Current.Server.MapPath(strPath); } else //非web程序引用 { strPath = strPath.Replace("/", "\\"); if (strPath.StartsWith("\\")) { strPath = strPath.Substring(strPath.IndexOf('\\', 1)).TrimStart('\\'); } return System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, strPath); } } #endregion #region 文件操作 /// <summary> /// 删除单个文件 /// </summary> /// <param name="_filepath">文件相对路径</param> public static bool DeleteFile(string _filepath) { if (string.IsNullOrEmpty(_filepath)) { return false; } string fullpath = GetMapPath(_filepath); if (File.Exists(fullpath)) { File.Delete(fullpath); return true; } return false; } /// <summary> /// 删除上传的文件(及缩略图) /// </summary> /// <param name="_filepath"></param> public static void DeleteUpFile(string _filepath) { if (string.IsNullOrEmpty(_filepath)) { return; } string fullpath = GetMapPath(_filepath); //原图 if (File.Exists(fullpath)) { File.Delete(fullpath); } if (_filepath.LastIndexOf("/") >= 0) { string thumbnailpath = _filepath.Substring(0, _filepath.LastIndexOf("/")) + "mall_" + _filepath.Substring(_filepath.LastIndexOf("/") + 1); string fullTPATH = GetMapPath(thumbnailpath); //宿略图 if (File.Exists(fullTPATH)) { File.Delete(fullTPATH); } } } /// <summary> /// 删除内容图片 /// </summary> /// <param name="content">内容</param> /// <param name="startstr">匹配开头字符串</param> public static void DeleteContentPic(string content, string startstr) { if (string.IsNullOrEmpty(content)) { return; } Regex reg = new Regex("IMG[^>]*?src\\s*=\\s*(?:\"(?<1>[^\"]*)\"|'(?<1>[^\']*)')", RegexOptions.IgnoreCase); MatchCollection m = reg.Matches(content); foreach (Match math in m) { string imgUrl = math.Groups[1].Value; string fullPath = GetMapPath(imgUrl); try { if (imgUrl.ToLower().StartsWith(startstr.ToLower()) && File.Exists(fullPath)) { File.Delete(fullPath); } } catch { } } } /// <summary> /// 删除指定文件夹 /// </summary> /// <param name="_dirpath">文件相对路径</param> public static bool DeleteDirectory(string _dirpath) { if (string.IsNullOrEmpty(_dirpath)) { return false; } string fullpath = GetMapPath(_dirpath); if (Directory.Exists(fullpath)) { Directory.Delete(fullpath, true); return true; } return false; } /// <summary> /// 修改指定文件夹名称 /// </summary> /// <param name="old_dirpath">旧相对路径</param> /// <param name="new_dirpath">新相对路径</param> /// <returns>bool</returns> public static bool MoveDirectory(string old_dirpath, string new_dirpath) { if (string.IsNullOrEmpty(old_dirpath)) { return false; } string fulloldpath = GetMapPath(old_dirpath); string fullnewpath = GetMapPath(new_dirpath); if (Directory.Exists(fulloldpath)) { Directory.Move(fulloldpath, fullnewpath); return true; } return false; } /// <summary> /// 返回文件大小KB /// </summary> /// <param name="_filepath">文件相对路径</param> /// <returns>int</returns> public static int GetFileSize(string _filepath) { if (string.IsNullOrEmpty(_filepath)) { return 0; } string fullpath = GetMapPath(_filepath); if (File.Exists(fullpath)) { FileInfo fileInfo = new FileInfo(fullpath); return ((int)fileInfo.Length) / 1024; } return 0; } /// <summary> /// 返回文件扩展名,不含“.” /// </summary> /// <param name="_filepath">文件全名称</param> /// <returns>string</returns> public static string GetFileExt(string _filepath) { if (string.IsNullOrEmpty(_filepath)) { return ""; } if (_filepath.LastIndexOf(".") > 0) { return _filepath.Substring(_filepath.LastIndexOf(".") + 1); //文件扩展名,不含“.” } return ""; } /// <summary> /// 返回文件名,不含路径 /// </summary> /// <param name="_filepath">文件相对路径</param> /// <returns>string</returns> public static string GetFileName(string _filepath) { return _filepath.Substring(_filepath.LastIndexOf(@"/") + 1); } /// <summary> /// 文件是否存在 /// </summary> /// <param name="_filepath">文件相对路径</param> /// <returns>bool</returns> public static bool FileExists(string _filepath) { string fullpath = GetMapPath(_filepath); if (File.Exists(fullpath)) { return true; } return false; } /// <summary> /// 获得远程字符串 /// </summary> public static string GetDomainStr(string key, string uriPath) { string result = CacheHelper.Get(key) as string; if (result == null) { System.Net.WebClient client = new System.Net.WebClient(); try { client.Encoding = System.Text.Encoding.UTF8; result = client.DownloadString(uriPath); } catch { result = "暂时无法连接!"; } CacheHelper.Insert(key, result, 60); } return result; } #endregion #region 读取或写入cookie /// <summary> /// 写cookie值 /// </summary> /// <param name="strName">名称</param> /// <param name="strValue">值</param> public static void WriteCookie(string strName, string strValue) { HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; if (cookie == null) { cookie = new HttpCookie(strName); } cookie.Value = UrlEncode(strValue); HttpContext.Current.Response.AppendCookie(cookie); } /// <summary> /// 写cookie值 /// </summary> /// <param name="strName">名称</param> /// <param name="strValue">值</param> public static void WriteCookie(string strName, string key, string strValue) { HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; if (cookie == null) { cookie = new HttpCookie(strName); } cookie[key] = UrlEncode(strValue); HttpContext.Current.Response.AppendCookie(cookie); } /// <summary> /// 写cookie值 /// </summary> /// <param name="strName">名称</param> /// <param name="strValue">值</param> public static void WriteCookie(string strName, string key, string strValue, int expires) { HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; if (cookie == null) { cookie = new HttpCookie(strName); } cookie[key] = UrlEncode(strValue); cookie.Expires = DateTime.Now.AddMinutes(expires); HttpContext.Current.Response.AppendCookie(cookie); } /// <summary> /// 写cookie值 /// </summary> /// <param name="strName">名称</param> /// <param name="strValue">值</param> /// <param name="strValue">过期时间(分钟)</param> public static void WriteCookie(string strName, string strValue, int expires) { HttpCookie cookie = HttpContext.Current.Request.Cookies[strName]; if (cookie == null) { cookie = new HttpCookie(strName); } cookie.Value = UrlEncode(strValue); cookie.Expires = DateTime.Now.AddMinutes(expires); HttpContext.Current.Response.AppendCookie(cookie); } /// <summary> /// 读cookie值 /// </summary> /// <param name="strName">名称</param> /// <returns>cookie值</returns> public static string GetCookie(string strName) { if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null) return UrlDecode(HttpContext.Current.Request.Cookies[strName].Value.ToString()); return ""; } /// <summary> /// 读cookie值 /// </summary> /// <param name="strName">名称</param> /// <returns>cookie值</returns> public static string GetCookie(string strName, string key) { if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null && HttpContext.Current.Request.Cookies[strName][key] != null) return UrlDecode(HttpContext.Current.Request.Cookies[strName][key].ToString()); return ""; } /// <summary> /// 清除cookie /// </summary> /// <param name="strName">名称</param> /// <returns>cookie值</returns> public static void ClearCookie(string strName = "") { if (HttpContext.Current.Request.Cookies != null && string.IsNullOrWhiteSpace(strName)) HttpContext.Current.Request.Cookies.Clear(); if (HttpContext.Current.Request.Cookies[strName] != null) HttpContext.Current.Request.Cookies[strName].Expires = DateTime.Now.AddMilliseconds(-1); } #endregion #region 替换指定的字符串 /// <summary> /// 替换指定的字符串 /// </summary> /// <param name="originalStr">原字符串</param> /// <param name="oldStr">旧字符串</param> /// <param name="newStr">新字符串</param> /// <returns></returns> public static string ReplaceStr(string originalStr, string oldStr, string newStr) { if (string.IsNullOrEmpty(oldStr)) { return ""; } return originalStr.Replace(oldStr, newStr); } #endregion #region URL处理 /// <summary> /// URL字符编码 /// </summary> public static string UrlEncode(string str) { if (string.IsNullOrEmpty(str)) { return ""; } str = str.Replace("'", ""); return HttpContext.Current.Server.UrlEncode(str); } /// <summary> /// URL字符解码 /// </summary> public static string UrlDecode(string str) { if (string.IsNullOrEmpty(str)) { return ""; } return HttpContext.Current.Server.UrlDecode(str); } #endregion #region URL请求数据 /// <summary> /// HTTP POST方式请求数据 /// </summary> /// <param name="url">URL.</param> /// <param name="param">POST的数据</param> /// <returns></returns> public static string HttpPost(string url, string param) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; StreamWriter requestStream = null; WebResponse response = null; string responseStr = null; try { requestStream = new StreamWriter(request.GetRequestStream()); requestStream.Write(param); requestStream.Close(); response = request.GetResponse(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; requestStream = null; response = null; } return responseStr; } /// <summary> /// HTTP GET方式请求数据. /// </summary> /// <param name="url">URL.</param> /// <returns></returns> public static string HttpGet(string url) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; //request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; WebResponse response = null; string responseStr = null; try { response = request.GetResponse(); if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEnd(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; response = null; } return responseStr; } /// <summary> /// 执行URL获取页面内容 /// </summary> public static string UrlExecute(string urlPath) { if (string.IsNullOrEmpty(urlPath)) { return "error"; } StringWriter sw = new StringWriter(); try { HttpContext.Current.Server.Execute(urlPath, sw); return sw.ToString(); } catch (Exception) { return "error"; } finally { sw.Close(); sw.Dispose(); } } #endregion #region WebClient GET /// <summary> /// 异步请求 Get方式 /// </summary> /// <param name="url"></param> /// <returns></returns> public static string HttpGetAsync(string url) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; WebResponse response = null; Task<string> responseStr = null; try { response = request.GetResponseAsync().Result; if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEndAsync(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; response = null; } return responseStr.Result; } /// <summary> /// 异步请求 Post方式 /// </summary> /// <param name="url"></param> /// <returns></returns> public static string HttpPostAsync(string url,string param) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "*/*"; request.Timeout = 15000; request.AllowAutoRedirect = false; StreamWriter requestStream = null; WebResponse response = null; Task<string> responseStr = null; try { requestStream = new StreamWriter(request.GetRequestStreamAsync().Result); requestStream.Write(param); requestStream.Close(); response = request.GetResponseAsync().Result; if (response != null) { StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); responseStr = reader.ReadToEndAsync(); reader.Close(); } } catch (Exception) { throw; } finally { request = null; requestStream = null; response = null; } return responseStr.Result; } public static string HTTP_GET(string url) { return HTTP_GET(url, Encoding.UTF8); } public static string HTTP_GET(string url, Encoding Encode) { string result = string.Empty; try { var client = new WebClient(); client.Encoding = Encode; result = client.DownloadString(url); } catch (Exception ex) { result = "ERR:" + ex.Message; } return result; } #endregion #region WebClient POST public static string HTTP_POST(string url, string data) { return HTTP_POST(url, data, Encoding.UTF8); } /// <summary> /// post方式请求 /// </summary> /// <param name="url">请求路径</param> /// <param name="postString">请求数据</param> /// <param name="ContentType">默认application/x-www-form-urlencoded</param> /// <param name="Encode">编码:1 UTF8 2 ASCII 其他 Default 默认UTF8</param> /// <returns></returns> public static string HTTP_POST(string url, string data, Encoding Encode, string ContentType = "application/x-www-form-urlencoded") { string result = string.Empty; try { byte[] postData = Encode.GetBytes(data); WebClient webClient = new WebClient(); webClient.Headers.Add("Content-Type", ContentType);//采取POST方式必须加的header byte[] responseData = webClient.UploadData(url, "POST", postData);//得到返回字符流 result = Encode.GetString(responseData); ;//解码 } catch (Exception ex) { result = "ERR:" + ex.Message; } return result; } #endregion #region DataSet分页 public static DataSet SplitDataSet(DataSet ds, int pageSize, int pageIndex) { DataSet vds = new DataSet(); vds = ds.Clone(); if (pageIndex < 1) pageIndex = 1;//如果小于1,取第一页 if ((ds.Tables[0].Rows.Count + pageSize) <= (pageSize * pageIndex)) pageIndex = 1; int fromIndex = pageSize * (pageIndex - 1);//开始行 int toIndex = pageSize * pageIndex - 1; //结束行 for (int i = fromIndex; i <= toIndex; i++) { if (i >= (ds.Tables[0].Rows.Count)) //到达这一行,退出 break; vds.Tables[0].ImportRow(ds.Tables[0].Rows[i]); } ds.Dispose(); return vds; } #endregion #region JsonToDataTable public static DataTable JsonToDataTable(string strJson, string addColumnName = "") { DataTable tb = null; //获取数据 Regex rg = new Regex(@"(?<={)[^}]+(?=})"); MatchCollection mc = rg.Matches(strJson); for (int i = 0; i < mc.Count; i++) { string strRow = mc[i].Value; string[] strRows = strRow.Split(','); string json = "{" + mc[i].Value.Replace("\"", "\\\"") + "}"; //创建表 if (tb == null) { tb = new DataTable(); tb.TableName = ""; foreach (string str in strRows) { DataColumn dc = new DataColumn(); string[] strCell = str.Split(':'); dc.ColumnName = strCell[0].ToString().Replace("\"", "").Trim(); tb.Columns.Add(dc); } if (addColumnName != "") { DataColumn dc = new DataColumn(); dc.ColumnName = addColumnName; tb.Columns.Add(dc); } tb.AcceptChanges(); } //增加内容 DataRow dr = tb.NewRow(); for (int r = 0; r < strRows.Length; r++) { dr[r] = strRows[r].Split(':')[1].Trim().Replace(",", ",").Replace(":", ":").Replace("/", "").Replace("\"", "").Trim(); } if (addColumnName != "") { dr[strRows.Length] = json; } tb.Rows.Add(dr); tb.AcceptChanges(); } return tb; } #endregion #region 数据格式转换 /// <summary> /// 转换任意成SQL语句可以识别的日期格式字符串 /// </summary> /// <param name="data">用户输入时间或字符串</param> /// <returns></returns> public static string ToSQLDate(object date) { if (date != null && date.ToString() != DateTime.MinValue.ToString()) { try { return DateTime.Parse(date.ToString()).ToString("yyyy-MM-dd"); } catch { return date.ToString(); } } else { return String.Empty; } } /// <summary> /// 转换成系统计量数值格式 /// </summary> /// <param name="quantity"></param> /// <returns></returns> public static string ToQuantity(object quantity) { int quantityBit = 0; string result = ""; if (quantity != null && quantity.ToString().Length > 0) { try { result = String.Format("{0:" + quantityBit + "}", decimal.Parse(quantity.ToString())); } catch { result = String.Format("{0:" + quantityBit + "}", 0); } } else { result = String.Format("{0:" + quantityBit + "}", 0); } return result; } /// <summary> /// 转换成整数 /// </summary> /// <param name="value"></param> /// <returns></returns> public static int ToInt(object value) { int result = 0; try { result = Convert.ToInt32(value); } catch { result = 0; } return result; } /// <summary> /// 转换SQL特殊字符 /// </summary> /// <param name="value"></param> /// <returns></returns> public static string FormatSQL(string value) { return value.Trim().Replace("'", "''"); } #endregion #region 微信签名获取 public static int ConvertDateTimeInt(System.DateTime time) { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); return (int)(time - startTime).TotalSeconds; } public static string md5str16(string password) { MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider(); return BitConverter.ToString(hashmd5.ComputeHash(Encoding.Default.GetBytes(password))).Replace("-", "").ToLower().Substring(8, 16); } public static string GetSHA(string Pwd) { byte[] data = System.Text.Encoding.Default.GetBytes(Pwd);//以字节方式存储 System.Security.Cryptography.SHA1 sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider(); byte[] result = sha1.ComputeHash(data);//得到哈希值 return System.BitConverter.ToString(result).Replace("-", ""); //转换成为字符串的显示 } #endregion #region 获取当前日期 /// <summary> /// 获取系统当前日期字符串 /// </summary> /// <returns></returns> public static string NowStr(string format = "yyyy-MM-dd HH:mm:ss") { return Now().ToString(format); } /// <summary> /// 获取系统当前日期 /// </summary> /// <returns></returns> public static DateTime Now() { return DateTime.Now; } #endregion #region 获取当前IP地址 public static string GetLocalIP() { try { string HostName = Dns.GetHostName(); //得到主机名 IPHostEntry IpEntry = Dns.GetHostEntry(HostName); for (int i = 0; i < IpEntry.AddressList.Length; i++) { if (IpEntry.AddressList[i].AddressFamily == AddressFamily.InterNetwork) { return IpEntry.AddressList[i].ToString(); } } return ""; } catch (Exception ex) { return ""; } } #endregion #region 判断字符串是否为空 /// <summary> /// 字符串是否为空 /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool IsEmpty(string str) { return string.IsNullOrWhiteSpace(str); } #endregion #region 获取时间差 /// <summary> /// 获取当前时间与指定时间差 /// </summary> /// <param name="startTime">时间</param> /// <returns>***前</returns> public static string TimeDifference(DateTime startTime) { TimeSpan ts = TimeDifference(startTime, DateTime.Now); if (ts.TotalDays > 60) { return startTime.ToShortDateString(); } else if (ts.TotalDays > 30) { return "1个月前"; } else if (ts.TotalDays > 14) { return "2周前"; } else if (ts.TotalDays > 7) { return "1周前"; } else if (ts.TotalDays > 1) { return string.Format("{0}天前", (int)Math.Floor(ts.TotalDays)); } else if (ts.TotalHours > 1) { return string.Format("{0}小时前", (int)Math.Floor(ts.TotalHours)); } else if (ts.TotalMinutes > 1) { return string.Format("{0}分钟前", (int)Math.Floor(ts.TotalMinutes)); } else if (ts.TotalSeconds >= 1) { return string.Format("{0}秒前", (int)Math.Floor(ts.TotalSeconds)); } else { return "1秒前"; } } /// <summary> /// 获取两个时间差 /// </summary> /// <param name="startTime">开始时间</param> /// <param name="endTime">结束时间</param> /// <returns>TimeSpan</returns> public static TimeSpan TimeDifference(DateTime startTime, DateTime endTime) { TimeSpan ts = endTime - startTime; return ts; } #endregion }