随笔 - 8  文章 - 1 评论 - 4 trackbacks - 0

using WL.Infrastructure.Http;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;

namespace WL.Infrastructure.Common
{
    public class Common
    {
        private static int seed = 1;
        private static int key_seed = 1;
        private static int noseed = 1;
        private static int domseed = 1;
        private static int geseed = 1;
        /// <summary> 
        /// 取得客户端真实IP。如果有代理则取第一个非内网地址 
        /// </summary> 
        public static string IPAddress
        {
            get
            {
                string result = String.Empty;

                result = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (result != null && result != String.Empty)
                {
                    //可能有代理; 
                    if (result.IndexOf(".") == -1)    //没有“.”肯定是非IPv4格式; 
                        result = null;
                    else
                    {
                        if (result.IndexOf(",") != -1)
                        {
                            //有“,”,估计多个代理。取第一个不是内网的IP。; 
                            result = result.Replace(" ", "").Replace("'", "");
                            string[] temparyip = result.Split(",;".ToCharArray());
                            for (int i = 0; i < temparyip.Length; i++)
                            {
                                if (IsIPAddress(temparyip[i])
                                    && temparyip[i].Substring(0, 3) != "10."
                                    && temparyip[i].Substring(0, 7) != "192.168"
                                    && temparyip[i].Substring(0, 7) != "172.16.")
                                {
                                    return temparyip[i];    //找到不是内网的地址 ;
                                }
                            }
                        }
                        else if (IsIPAddress(result)) //代理即是IP格式; 
                            return result;
                        else
                            result = null;    //代理中的内容 非IP,取IP ;
                    }

                }

                string IpAddress = (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null && HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != String.Empty) ? HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];



                if (null == result || result == String.Empty)
                    result = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

                if (result == null || result == String.Empty)
                    result = HttpContext.Current.Request.UserHostAddress;
                if (result == "::1")
                {
                    result = "127.0.0.1";
                }
                return result;
            }
        }
        /// <summary>
        /// 绕过cnd获取真实ip
        /// </summary>
        /// <returns></returns>
        public static string GetUserIp()
        {
            string userIP = "未获取用户IP";

            try
            {
                if (HttpContext.Current == null
            || HttpContext.Current.Request == null
            || HttpContext.Current.Request.ServerVariables == null)
                    return "";

                string CustomerIP = "";

                //CDN加速后取到的IP  
                CustomerIP = HttpContext.Current.Request.Headers["Cdn-Src-Ip"];
                if (!string.IsNullOrEmpty(CustomerIP))
                {
                    return CustomerIP;
                }

                CustomerIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

                if (!String.IsNullOrEmpty(CustomerIP))
                    return CustomerIP;

                if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
                {
                    CustomerIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                    if (CustomerIP == null)
                        CustomerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                }
                else
                {
                    CustomerIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

                }

                if (string.Compare(CustomerIP, "unknown", true) == 0)
                    return HttpContext.Current.Request.UserHostAddress;
                return CustomerIP;
            }
            catch { }

            return userIP;
        }
        /**/
        /// <summary>
        /// 判断是否是IP地址格式 0.0.0.0
        /// </summary>
        /// <param name="str1">待判断的IP地址</param>
        /// <returns>true or false</returns>
        public static bool IsIPAddress(string str1)
        {
            if (str1 == null || str1 == string.Empty || str1.Length < 7 || str1.Length > 15) return false;

            string regformat = @"^/d{1,3}[/.]/d{1,3}[/.]/d{1,3}[/.]/d{1,3}$";

            Regex regex = new Regex(regformat, RegexOptions.IgnoreCase);
            return regex.IsMatch(str1);
        }
        /// <summary>
        /// 时间转换时间戳
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string ConvertDateTimeInt(string time)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            DateTime dtNow = DateTime.Parse(time);
            TimeSpan toNow = dtNow.Subtract(dtStart);
            string timeStamp = toNow.Ticks.ToString();
            timeStamp = timeStamp.Substring(0, timeStamp.Length - 7);
            return timeStamp;
        }
        /// <summary>
        /// 时间戳转换时间
        /// </summary>
        /// <param name="datestr"></param>
        /// <returns></returns>
        public static DateTime ConvertDate(string datestr)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long lTime = long.Parse(datestr + "0000000");
            TimeSpan toNow = new TimeSpan(lTime);
            DateTime dtResult = dtStart.Add(toNow);
            return dtResult;
        }
        /// <summary>
        /// 转换时间
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static string ConvertDateTimeInt_flot(string time)
        {
            DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            DateTime dtNow = DateTime.Parse(time);
            TimeSpan toNow = dtNow.Subtract(dtStart);
            string timeStamp = toNow.Ticks.ToString();
            timeStamp = timeStamp.Substring(0, timeStamp.Length - 4);
            return timeStamp;
        }
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="_rootPath"></param>
        /// <param name="_file"></param>
        /// <param name="_filename"></param>
        /// <param name="type_s"></param>
        /// <returns></returns>
        public static string FileUploader(string _rootPath, HttpPostedFileBase _file, string _filename = null, string type_s = "")
        {
            string sFileName = _filename;
            if (_file != null)
            {
                string _filePath = _file.FileName;
                if (_filePath != string.Empty)
                {
                    string _fileType = _filePath.Substring(_filePath.LastIndexOf("."));
                    string sFileRoot = _rootPath;
                    if (!System.IO.Directory.Exists(sFileRoot))
                        System.IO.Directory.CreateDirectory(sFileRoot);
                    if (sFileName == null)
                    {
                        if (type_s != "")
                        {
                            sFileName = DateTime.Now.ToString("yyyyMMddHHmmssms") + type_s;
                        }
                        else
                        {
                            sFileName = DateTime.Now.ToString("yyyyMMddHHmmssms") + _fileType;
                        }
                    }
                    else
                    {
                        if (type_s != "")
                        {
                            sFileName = sFileName + type_s;
                        }
                        else
                        {
                            sFileName = sFileName + _fileType;
                        }
                    }
                    string sFilePath = sFileRoot + "\\" + sFileName;
                    _file.SaveAs(sFilePath);
                }
            }
            return sFileName;
        }
        /// <summary>
        /// 根据路径把文件转换成数据流
        /// </summary>
        /// <param name="strpath"></param>
        /// <returns></returns>
        public static byte[] Returnbyte(string strpath)
        {
            // 以二进制方式读文件
            FileStream fsMyfile = new FileStream(strpath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            // 创建一个二进制数据流读入器,和打开的文件关联
            BinaryReader brMyfile = new BinaryReader(fsMyfile);
            // 把文件指针重新定位到文件的开始
            brMyfile.BaseStream.Seek(0, SeekOrigin.Begin);
            byte[] bytes = brMyfile.ReadBytes(Convert.ToInt32(fsMyfile.Length.ToString()));
            // 关闭以上new的各个对象
            brMyfile.Close();
            return bytes;
        }
        public static void DeleteFile(string filepatch)
        {
            FileInfo file = new FileInfo(filepatch);//指定文件路径
            if (file.Exists)//判断文件是否存在
            {
                file.Attributes = FileAttributes.Normal;//将文件属性设置为普通,比方说只读文件设置为普通
                file.Delete();//删除文件
            }
        }
        /// 取得某月的第一天
        /// </summary>
        /// <param name="datetime">要取得月份第一天的时间</param>
        /// <returns></returns>
        private DateTime FirstDayOfMonth(DateTime datetime)
        {
            return datetime.AddDays(1 - datetime.Day);
        }
        /// <summary>
        /// 取得某月的最后一天
        /// </summary>
        /// <param name="datetime">要取得月份最后一天的时间</param>
        /// <returns></returns>
        private DateTime LastDayOfMonth(DateTime datetime)
        {
            return datetime.AddDays(1 - datetime.Day).AddMonths(1).AddDays(-1);
        }

        /// <summary>
        /// 取得上个月第一天
        /// </summary>
        /// <param name="datetime">要取得上个月第一天的当前时间</param>
        /// <returns></returns>
        public DateTime FirstDayOfPreviousMonth(DateTime datetime)
        {
            return datetime.AddDays(1 - datetime.Day).AddMonths(-1);
        }

        /// <summary>
        /// 取得上个月的最后一天
        /// </summary>
        /// <param name="datetime">要取得上个月最后一天的当前时间</param>
        /// <returns></returns>
        public DateTime LastDayOfPrdviousMonth(DateTime datetime)
        {
            return datetime.AddDays(1 - datetime.Day).AddDays(-1);
        }

        /// <summary>
        /// 取得上周的第一天
        /// </summary>
        /// <param name="datetime">要取得上周最后一天的当前时间</param>
        /// <returns></returns>
        public static DateTime FirstDayOfPrdviousWeek(DateTime datetime)
        {
            //星期一为第一天  
            int weeknow = Convert.ToInt32(datetime.DayOfWeek);
 
            //因为是以星期一为第一天,所以要判断weeknow等于0时,要向前推6天。  
            weeknow = (weeknow == 0 ? (7 - 1) : (weeknow - 1));
            int daydiff = (-1) * weeknow;
 
            //本周第一天  
            string FirstDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd");
            return Convert.ToDateTime(FirstDay);
        }

        /// <summary>
        /// 取得上周的最后一天
        /// </summary>
        /// <param name="datetime">要取得上周最后一天的当前时间</param>
        /// <returns></returns>
        public static DateTime LastDayOfPrdviousWeek(DateTime datetime)
        {
            //星期天为最后一天  
            int weeknow = Convert.ToInt32(datetime.DayOfWeek);
            weeknow = (weeknow == 0 ? 7 : weeknow);
            int daydiff = (7 - weeknow);

            //本周最后一天  
            string LastDay = datetime.AddDays(daydiff).ToString("yyyy-MM-dd");
            return Convert.ToDateTime(LastDay);
        }

        /// <summary>
        /// 判断字符串是否为正整数
        /// </summary>
        /// <param name="str">要判断的字符串对象</param>
        /// <returns></returns>
        public static bool IsInt(string str)
        {
            bool isInt = false;
            if (!string.IsNullOrEmpty(str))
            {
                isInt = Regex.IsMatch(str, @"^(0|([1-9]\d*))$");
            }
            return isInt;
        }

        /// <summary>
        /// 判断是否为DateTime
        /// </summary>
        /// <param name="strDate"></param>
        /// <returns></returns>
        public static bool IsDateTime(string strDate)
        {
            try
            {
                DateTime.Parse(strDate);
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 生成单号
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        public static string GetOrderNo()
        {
            if (seed == int.MaxValue)
            {
                seed = 1;
            }
            seed++;
            string tbout_trade_no = "";
            string guid = Guid.NewGuid().ToString();
            string last = guid.Replace("-", "");
            char[] cc = last.ToCharArray();
            StringBuilder sb = new StringBuilder(4);
            Random rd = new Random((unchecked((int)DateTime.Now.Ticks + seed)));
            for (int i = 0; i < 6; i++)
            {
                sb.Append(cc[rd.Next(cc.Length)]);
            }

            tbout_trade_no = sb + "-" + DateTime.Now.ToString("yyyyMMddHHmmssff");
            return tbout_trade_no;
        }
        /// <summary>
        /// 生成密匙
        /// </summary>
        /// <param name="mch_id"></param>
        /// <returns></returns>
        public static string GetGGAPIKey(string num_id)
        {
            if (key_seed == int.MaxValue)
            {
                key_seed = 1;
            }
            key_seed++;
            string key = "";
            char[] constant = {'0','1','2','3','4','5','6','7','8','9',
                               'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                               'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
            StringBuilder sb = new StringBuilder(4);
            for (int i = 0; i < 5; i++)
            {
                Random rd = new Random((unchecked((int)DateTime.Now.Ticks + i)));
                sb.Append(constant[rd.Next(62)]);
            }
            key = MD5.Md5UTF8(num_id + sb).ToLower();
            return key;
        }
        /// <summary>
        /// PostUTF8格式的JSON
        /// </summary>
        /// <param name="json"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string PostUtf8Json(string json, string url, int timeout = 1000000)
        {
            byte[] encodebytes = System.Text.Encoding.UTF8.GetBytes(json);
            HttpHelper helper = new HttpHelper();
            HttpItem item = new HttpItem();
            item.URL = url;
            item.Timeout = timeout;
            item.Method = "POST";
            item.PostdataByte = encodebytes;
            item.PostEncoding = Encoding.UTF8;
            item.PostDataType = PostDataType.Byte;
            HttpResult result = helper.GetHtml(item);
            string msg = "";
            if ((int)result.StatusCode < 400)
            {
                msg = result.Html;
                if (msg == "操作超时")
                {
                    //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
                    msg = "";
                }
            }
            else
            {
                //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
            }
            return msg;
        }
        /// <summary>
        /// PostUTF8格式的Form
        /// </summary>
        /// <param name="json"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string PostUtf8Form(string json, string url, int timeout = 1000000)
        {
            byte[] encodebytes = System.Text.Encoding.UTF8.GetBytes(json);
            HttpHelper helper = new HttpHelper();
            HttpItem item = new HttpItem();
            item.URL = url;
            item.Timeout = timeout;
            item.Method = "POST";
            item.Allowautoredirect = true;
            item.ContentType = "application/x-www-form-urlencoded";
            item.PostdataByte = encodebytes;
            item.PostEncoding = Encoding.UTF8;
            item.PostDataType = PostDataType.Byte;
            HttpResult result = helper.GetHtml(item);
            string msg = "";
            if ((int)result.StatusCode < 400)
            {
                msg = result.Html;
                if (msg == "操作超时")
                {
                    //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
                    msg = "";
                }
            }
            else
            {
                //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
            }
            return msg;
        }
        /// <summary>
        /// PostGB2312格式的表单
        /// </summary>
        /// <param name="json"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string PostGB2312Form(string json, string url, int timeout = 5000)
        {
            byte[] encodebytes = System.Text.Encoding.GetEncoding("GB2312").GetBytes(json);
            HttpHelper helper = new HttpHelper();
            HttpItem item = new HttpItem();
            item.URL = url;
            item.Timeout = timeout;
            item.Method = "POST";
            item.Allowautoredirect = true;
            item.ContentType = "application/x-www-form-urlencoded";
            item.PostdataByte = encodebytes;
            item.PostEncoding = Encoding.GetEncoding("GB2312");
            item.PostDataType = PostDataType.Byte;
            HttpResult result = helper.GetHtml(item);
            string msg = "";
            if ((int)result.StatusCode < 400)
            {
                msg = result.Html;
                if (msg == "操作超时")
                {
                    //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
                    msg = "";
                }
            }
            else
            {
                //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
            }
            return msg;
        }
        /// <summary>
        /// PostUTF8格式的JSON
        /// </summary>
        /// <param name="json"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string PostUtf8File(byte[] encodebytes, string url, int timeout = 1000000)
        {
            //byte[] encodebytes = System.Text.Encoding.UTF8.GetBytes(json);
            HttpHelper helper = new HttpHelper();
            HttpItem item = new HttpItem();
            item.URL = url;
            item.Timeout = timeout;
            item.Method = "POST";
            item.ContentType = "multipart/form-data";
            item.PostdataByte = encodebytes;
            item.PostEncoding = Encoding.UTF8;
            item.PostDataType = PostDataType.Byte;
            HttpResult result = helper.GetHtml(item);
            string msg = "";
            if ((int)result.StatusCode < 400)
            {
                msg = result.Html;
                if (msg == "操作超时")
                {
                    //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
                    msg = "";
                }
            }
            else
            {
                //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
            }
            return msg;
        }
        /// <summary>
        /// Get格式
        /// </summary>
        /// <param name="json"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetUrl(string url, int timeout = 1000000)
        {
            HttpHelper helper = new HttpHelper();
            HttpItem item = new HttpItem();
            item.Timeout = timeout;
            item.URL = url;
            HttpResult result = helper.GetHtml(item);
            string msg = "";
            if ((int)result.StatusCode < 400)
            {
                msg = result.Html;
                if (msg == "操作超时")
                {
                    //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
                    msg = "";
                }
            }
            else
            {
                //LoggerFactory.Current.Create().LogError("请求错误,状态码为" + (int)result.StatusCode + ",url为" + url);
            }
            return msg;
        }
        /// <summary>
        /// 生成随机字符串
        /// </summary>
        /// <returns></returns>
        public static string get_noce_str()
        {
            if (noseed == int.MaxValue)
            {
                noseed = 1;
            }
            noseed++;
            char[] constant = {'0','1','2','3','4','5','6','7','8','9',
                               'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                               'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
            StringBuilder sb = new StringBuilder(16);
            Random rd = new Random((unchecked((int)DateTime.Now.Ticks + noseed)));
            for (int i = 0; i < 16; i++)
            {
                sb.Append(constant[rd.Next(62)]);
            }
            return sb.ToString();
        }
        /// <summary>
        /// 生成6位邀请码
        /// </summary>
        /// <returns></returns>
        public static string get_generate_str()
        {
            if (geseed == int.MaxValue)
            {
                geseed = 1;
            }
            geseed++;
            char[] constant = {'0','1','2','3','4','5','6','7','8','9',
                               'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
                               'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
            StringBuilder sb = new StringBuilder(6);
            Random rd = new Random((unchecked((int)DateTime.Now.Ticks + geseed)));
            for (int i = 0; i < 6; i++)
            {
                sb.Append(constant[rd.Next(62)]);
            }
            return sb.ToString();
        }
        /// <summary>
        /// 生成6位订单号
        /// </summary>
        /// <returns></returns>
        public static string Nrandom()
        {
            if (domseed == int.MaxValue)
            {
                domseed = 1;
            }
            domseed++;
            string rm = "";
            Random rd = new Random((unchecked((int)DateTime.Now.Ticks + domseed)));
            for (int i = 0; i < 6; i++)
            {
                rm += rd.Next(0, 9).ToString();
            }
            return rm;
        }
        /// <summary>
        /// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
        /// </summary>
        /// <param name="sArray">需要拼接的数组</param>
        /// <param name="code">字符编码</param>
        /// <returns>拼接完成以后的字符串</returns>
        public static string CreateLinkStringA(SortedDictionary<string, string> dicArray)
        {
            StringBuilder prestr = new StringBuilder();
            foreach (KeyValuePair<string, string> temp in dicArray)
            {
                prestr.Append(temp.Key + "=" + temp.Value + "&");
            }

            //去掉最後一個&字符
            int nLen = prestr.Length;
            prestr.Remove(nLen - 1, 1);

            return prestr.ToString();
        }
        /// <summary>
        /// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
        /// </summary>
        /// <param name="sArray">需要拼接的数组</param>
        /// <param name="code">字符编码</param>
        /// <returns>拼接完成以后的字符串</returns>
        public static string CreateLinkStringB(Dictionary<string, string> dicArray)
        {
            StringBuilder prestr = new StringBuilder();
            foreach (KeyValuePair<string, string> temp in dicArray)
            {
                prestr.Append(temp.Key + "=" + temp.Value + "&");
            }

            //去掉最後一個&字符
            int nLen = prestr.Length;
            prestr.Remove(nLen - 1, 1);

            return prestr.ToString();
        }
        /// <summary>
        /// 把数组所有元素,按照“参数值”的模式用“&”字符拼接成字符串,并对参数值做urlencode
        /// </summary>
        /// <param name="sArray">需要拼接的数组</param>
        /// <param name="code">字符编码</param>
        /// <returns>拼接完成以后的字符串</returns>
        public static string CreateLinkStringC(Dictionary<string, string> dicArray)
        {
            StringBuilder prestr = new StringBuilder();
            foreach (KeyValuePair<string, string> temp in dicArray)
            {
                prestr.Append(temp.Value);
            }
            return prestr.ToString();
        }
        /// <summary>
        /// 多余字段用指定字符串代替
        /// </summary>
        /// <param name="MaxLength">字符串最大长度</param>
        /// <param name="ReplaceRemark">超出时代替的符号</param>
        /// <param name="value">要转换的字符串</param>
        /// <returns></returns>
        public static string Overflow(int MaxLength, string ReplaceRemark, string value)
        {
            if (value.Length > MaxLength)
            {
                return value = value.Remove(MaxLength) + ReplaceRemark;
            }
            return value;
        }

        /// <summary>  
        /// 每隔n个字符插入n个字符  
        /// </summary>  
        /// <param name="input">源字符串</param>  
        /// <param name="interval">间隔字符数</param>  
        /// <param name="value">待插入值</param>  
        /// <returns>返回新生成字符串</returns>  
        public static string InsertFormat(string input, int interval, string value)
        {
            for (int i = interval; i < input.Length; i += interval + value.Length)
                input = input.Insert(i, value);
            return input;
        }

        /// <summary>
        /// 手机号码隐藏中间4位
        /// </summary>
        /// <param name="phone"></param>
        /// <returns></returns>
        public static string HidePhone(string phone)
        {
            return Regex.Replace(phone, "(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        }
        /// <summary>
        /// 判断是否带http,flase=有,ture=没有
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static bool IsHttp(string url)
        {
            string reg = @"^(http(s)?:\/\/)?(www\.)?[\w-]+(\.\w{2,4})?\.\w{2,4}?(\/)?$";
            Regex r = new Regex(reg);
            //给网址去所有空格
            string urlStr = url.Trim();
            Match m = r.Match(urlStr);

            //判断是否带http://
            if (!m.Success)
                return false;
            return true;
        }
        #region 得到一周的周一和周日的日期
        /// <summary> 
        /// 计算本周的周一日期 
        /// </summary> 
        /// <returns></returns> 
        public static DateTime GetMondayDate()
        {
            return GetMondayDate(DateTime.Now);
        }
        /// <summary> 
        /// 计算本周周日的日期 
        /// </summary> 
        /// <returns></returns> 
        public static DateTime GetSundayDate()
        {
            return GetSundayDate(DateTime.Now);
        }
        /// <summary> 
        /// 计算某日起始日期(礼拜一的日期) 
        /// </summary> 
        /// <param name="someDate">该周中任意一天</param> 
        /// <returns>返回礼拜一日期,后面的具体时、分、秒和传入值相等</returns> 
        public static DateTime GetMondayDate(DateTime someDate)
        {
            int i = someDate.DayOfWeek - DayOfWeek.Monday;
            if (i == -1) i = 6;// i值 > = 0 ,因为枚举原因,Sunday排在最前,此时Sunday-Monday=-1,必须+7=6。 
            TimeSpan ts = new TimeSpan(i, 0, 0, 0);
            return someDate.Subtract(ts);
        }
        /// <summary> 
        /// 计算某日结       rPing urlStr = url.数&= url.数&s在/     =cVa}t     /// g)   Sn       rPing u=mmary>mn(vaxLeng    7(v;returns>返回礼拜一日期,后面的具体时、分、秒和传入值相等&am>s> 
        public #end = @"^
       pubeturn scs Valit;&lCValue + {        return sValit;&lCVal/summary> 
       input;
        }

        /// <summary&验    0时ilder();        /// </summary>
        /eturn s符串代summary> 
        //get {传入10;result = HttpContext.Current.Request.ServerVariables[验    0时ﰏder();        /// </summary>
        /eturn s符in代summary> 
        //get {传入1;result = HttpContext.Current.Request.ServerVariables[" + (            /// </summary>
        /// <param name="plr prestr =ringC(验    0der();
            foreach (KeyValueP;returns></returns>
        public s照“参Valit;&lCVal/lm name="intervat; 
        /// [] nt)DMember日期/ [lm namreturn Customer/ [] valit;&lNum日期/ [lm namreturn Customer;/summary⁢&lNumber   ///    return sb.To斺" +     re序列Tim; 
        /// sStr///    /// <summary>
        /0','1','2','3','4','5'sStr'4',
        }
   sStrt;param name="datetb    ///t;sumsStr'4',        p /// r (int i  =clm nam *tusCodt;param name="date[] sStr日期/ [lm namreturn Customer    /// </summary>lram>       /// <returns></retub    /+atusCod;urns></retusStr[i]t;/b    诏</param>
        ///斺" + (int)ry + turn Customer    /// </summary>lram>       /// <returns></retuString()4',
        }
   sStr[i]ttpResult result = // &pownu<1 *tt;sumMng _Pow(1  plm nametpResult result = nt)DMember[i]t;/r4',      pownu& p /// r (int i >
        /// <returns&//抽取(int)ry + turn Customer    /// </summary>lram>       /// <returns></retu             ///nt)DMember[i]lic static string Nrandomt = // &   gt;字=       StringB(Dictionary<retuString()4',
        }
    string Nrandomt = // &   Posit;/r4',        p   gt;字- 1 string Nrandomt = valit;&lNum[i]t;/ /// r
           SileUploade   Posi dtResult;
        t;
        ///斺" + (            /omer    /// </summary>lram>       /// <returns></retury⁢&lNumber   /+= valit;&lNum[i]lic static string Nrandom()
        {
        ry⁢&lNumber      return input;
        }

        /// <summary>流验    0图片        /// </summary>
        /// <param name="pc               出      pageint daydiff = (7 - weeknow);

       alue = value.Reit;&lNumgt; Ma    ydiff = (7 - weeknow);
 publiceader参Valit;&lGraphic(;/summary⁢&lCVal,             c      e="intervat; 
        //Bitmap image / <retmap(t;sumMng _Ceilaticry⁢&lCVal>字*tu2.0), 22 string NrandomGraphics eturGraphics.FromImage(image// <returns&g= Regex.IsMatch(str, @"^(0|([1-9]斺" + (int)r
      Dictionary<retuString()4',om
        }
    string Nrandomt = //清空图片背景色tring Nrandomt = g.Clear(Color.Wh把文件转换成1-9]斺图片0干扰线件转换成1-9]    /// </summary>2,
                  atch(str, @"^(0|([1-9]]]]]// &x1t;/r4',om      image.WidametpResult result = ]]]]// &x2t;/r4',om      image.WidametpResult result = ]]]]// &y1t;/r4',om      image.Heigh_filePath = _file.FileNam/ &y2t;/r4',om      image.Heigh_filePath = _file.FileNag.DrawLinw);
  Pen(Color.Silver), x1,&y1, x2,&y2 string Nrandommmmm                  F   ]  urn s始 ur("Arial" dt2,&( urSty   /old |  urSty   Ity&ic,'r','s','t','u','v'LinwarGradientBrush brush  sLinwarGradientBrush(t;summctangle(体image.Widamimage.Heigh_fic string get_generColor.B i ,rColor.DarkRed dt.2f       r','s','t','u','v'g.Draw staticry⁢&lCVal,   ur, brush, 3, 2文件转换成1-9]斺图片0前景干扰点件转换成1-9]    /// </summary>usC
                  atch(str, @"^(0|([1-9]]]]]// &xt;/r4',om      image.WidametpResult result = ]]]]// &yt;/r4',om      image.Heigh_filePath = _file.FileNammage.SetPixel(x,&y,rColor.FromArgb(r4',om      ','r','s','t','u','v'                  斺图片0边框线件转换成1-9]g.Drawmmctangle(;
  Pen(Color.Silver), 体image.Widam; dicAimage.Heigh_- 1 string Nrandomt = //保rMyf片t;/sumtring Nrandomt = Memory二u   u sMemory二  string Nrandomt = /mage.Sav; inp p mage插.Jpt;
        /// t = // 出 片t       /// t = c      .Response.Clear(
        /// t = c      .Response.CstUtf8File(byt/mage/jpt;tml(item);
        c      .Response.return把 inplics>&l string Nrandom()
        {
 fetull Regex.IsMatch(str, @"^(0|([1-9]g.Dispo的文件关联
 t = /mage.Dispo的文件关联
 esult = HttpContext.Current.Request.ServerVariables[http(sa    图片0der();        /// </summary>
        /
       alue = value.Reit;&lNumer prestr =验    0der();
            foreach (KeyValueP;returns></returns>
        public seDate// &Get mageWidam/// &.Reit;&lNumer presummary> 
        /// <ret;sum(.Reit;&lNumer pre*tu2.0)   return input;
        }

        /// <summary>tp(sa    0d();        /// </summary>
        /
       ;returns></returns>
        public seDatedopube&Get mageHeigh_/summary> 
        /// <re22.5="value">;待插入C# MVC 升级版nput;
        }

        /// <summary>流验    0图片        /// </summary>
        /// <param name="pc   ainsPage         出      pageint daydiff = (7 - weeknow);

       alue = value.Reit;&lNumgt; Ma    ydiff = (7 - weeknow);
 public  }
   参Valit;&lGraphic(;/summary⁢&lCVale="intervat; 
        //Bitmap image / <retmap(t;sumMng _Ceilaticry⁢&lCVal>字*tu2.0), 22 string NrandomGraphics eturGraphics.FromImage(image// <returns&g= Regex.IsMatch(str, @"^(0|([1-9]斺" + (int)r
      Dictionary<retuString()4',om
        }
    string Nrandomt = //清空图片背景色tring Nrandomt = g.Clear(Color.Wh把文件转换成1-9]斺图片0干扰线件转换成1-9]    /// </summary>2,
                  atch(str, @"^(0|([1-9]]]]]// &x1t;/r4',om      image.WidametpResult (0|([1-9]]]]]// &x2t;/r4',om      image.WidametpResult result = ]]]]// &y1t;/r4',om      image.Heigh_filePath = _file.FileNam/ &y2t;/r4',om      image.Heigh_filePath = _file.FileNag.DrawLinw);
  Pen(Color.Silver), x1,&y1, x2,&y2 string Nrandommmmm                  F   ]  urn s始 ur("Arial" dt2,&( urSty   /old |  urSty   Ity&ic,'r','s','t','u','v'LinwarGradientBrush brush  sLinwarGradientBrush(t;summctangle(体image.Widamimage.Heigh_fic string get_generColor.B i ,rColor.DarkRed dt.2f       r','s','t','u','v'g.Draw staticry⁢&lCVal,   ur, brush, 3, 2文件转换成1-9]斺图片0前景干扰点件转换成1-9]    /// </summary>usC
                  atch(str, @"^(0|([1-9]]]]]// &xt;/r4',om      image.WidametpResult result = ]]]]// &yt;/r4',om      image.Heigh_filePath = _file.FileNammage.SetPixel(x,&y,rColor.FromArgb(r4',om      ','r','s','t','u','v'                  斺图片0边框线件转换成1-9]g.Drawmmctangle(;
  Pen(Color.Silver), 体image.Widam; dicAimage.Heigh_- 1 string Nrandomt = //保rMyf片t;/sumtring Nrandomt = Memory二u   u sMemory二  string Nrandomt = /mage.Sav; inp p mage插.Jpt;
        /// t = // 出 片t       /// t = 传入nplics>&lstring Nrandom()
        {
 fetull Regex.IsMatch(str, @"^(0|([1-9]g.Dispo的文件关联
 t = /mage.Dispo的文件关联
 esult = HttpCont}
}

  

poted on 2018-05-15 22:09 韦俊宇 阅读(...) 评论(...) 编辑 收藏
ult
ult tu
Cont
Copyrigh_©2019 韦俊宇 PL','ed by: 博客园 模板提供:沪江博客