public static IQueryable <TSource> OrderExp <TSource>(this IQueryable <TSource> source, string sortName, int sortway)
        {
            if (Regexs.IsNull(sortName))
            {
                return(source);
            }

            //sortName 首字母大小写转换
            #region 首字母大小写转换
            char[] sortNameChar = sortName.ToCharArray();
            char   firstLetter  = sortNameChar[0];
            if ('a' <= firstLetter && firstLetter <= 'z')
            {
                firstLetter     = (char)(firstLetter & ~0x20);
                sortNameChar[0] = firstLetter;
                sortName        = new string(sortNameChar);
            }
            #endregion

            var  orderWay = sortway == 0 ? "OrderBy" : "OrderByDescending";
            Type type     = typeof(TSource);
            var  property = type.GetProperty(sortName);
            if (property == null)
            {
                return(source);
            }
            var parmarer          = Expression.Parameter(type);
            var propertyAccess    = Expression.MakeMemberAccess(parmarer, property);
            var orderByExpression = Expression.Lambda(propertyAccess, parmarer);
            var resultExpression  = Expression.Call(typeof(Queryable), orderWay, new Type[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExpression));

            return(source.Provider.CreateQuery <TSource>(resultExpression));
        }
Beispiel #2
0
        /// <summary>
        /// 校验身份证
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static async Task <IDCardIdentificationResponse> CheckIDCard(IDCardIdentificationBaseRequest dto)
        {
            /**
             * //https://cloud.tencent.com/document/product/866/33524
             * 身份证识别 接口文档
             **/
            var baseUrl    = "https://ocr.tencentcloudapi.com/";
            var action     = "IDCardOCR";                    //公共参数,本接口取值:IDCardOCR。 必选:是
            var version    = "2018-11-19";                   //公共参数,本接口取值:2018-11-19。 必选:是
            var region     = CosConfig.REGION;               //公共参数,详见产品支持的 地域列表 必选:是
            var _imageUrl  = Format.UrlEncode(dto.ImageUrl); //图片的 Url 地址。要求图片经Base64编码后不超过 7M,建议图片存储于腾讯云,可保障更高的下载速度和稳定性
            var _cardSide  = dto.CardSide;                   //FRONT:身份证有照片的一面(人像面),BACK:身份证有国徽的一面(国徽面),该参数如果不填,将为您自动判断身份证正反面。
            var coinfigDto = new IDCardIdentificationConfig()
            {
                CropIdCard      = true,
                CropPortrait    = true,
                CopyWarn        = true,
                BorderCheckWarn = true,
                ReshootWarn     = true,
                DetectPsWarn    = true,
                TempIdWarn      = true,
                InvalidDateWarn = true,
                Quality         = true
            };
            var config = JsonConvert.SerializeObject(coinfigDto);

            //请求接口
            var api = new StringBuilder()
                      .Append($"{baseUrl}?")
                      .Append($"ImageUrl={_imageUrl}")
                      .Append($"{(Regexs.IsNull(_cardSide) ? "" : $"&CardSide={_cardSide}")}")
Beispiel #3
0
        public static async Task <CIReponseDto.ImageInfoResponse> GetImageInfo(string url, bool isJoin = false, int againCount = 4)
        {
            var c = isJoin ? "|" : "?";

            if (Regexs.IsNull(url))
            {
                return(null);
            }
            var           api      = $"{url}{c}imageInfo";
            var           client   = new RestClient(api);
            var           request  = new RestRequest(method: Method.GET);
            IRestResponse response = await client.ExecuteAsync(request);

            try
            {
                var responseData = JsonConvert.DeserializeObject <CIReponseDto.ImageInfoResponse>(response.Content);

                return(responseData);
            }
            catch (System.Exception ex)
            {
                if (againCount > 0)
                {
                    System.Threading.Thread.Sleep(2000);
                    againCount--;
                    return(await GetImageInfo(url, isJoin, againCount));
                }
                throw ex;
            }
        }
Beispiel #4
0
        public void Test_GetJson()
        {
            string jsonp  = @"jsonp({""a"":""1234"",""b"":9999})";
            var    json   = "{\"a\":\"1234\",\"b\":9999}";
            var    result = Regexs.GetValue(jsonp, @"^\w+\((\{[^()]+\})\)$", "$1");

            Output.WriteLine(result);
            Assert.Equal(json, result);
        }
Beispiel #5
0
 private void btn_RunTest2_Click(object sender, EventArgs e)
 {
     try
     {
         UC_Info uc = new UC_Info();
         uc.Dock = DockStyle.Fill;
         Frm_TemplateDefault frm = new Frm_TemplateDefault(uc);
         frm.titleCustom.Text = "Test map";
         DateTime timeStart = DateTime.Now;
         if (fctxt_Pattern.Text.Trim() == string.Empty || fctxt_Test.Text.Trim() == string.Empty)
         {
             MessageBox.Show("Please, input data Pattern string and Test string", "Run test", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             return;
         }
         else
         {
             Style  fontTitle = new TextStyle(Brushes.Wheat, null, FontStyle.Bold);
             Style  fontBody  = new TextStyle(Brushes.Green, null, FontStyle.Bold);
             string sReg      = fctxt_Pattern.SelectedText;
             string sString   = fctxt_Test.Text;
             if (string.IsNullOrEmpty(sReg))
             {
                 sReg = fctxt_Pattern.Text;
             }
             Dictionary <int, RegesValueWithPatternOfGroup> listResult2 = new Dictionary <int, RegesValueWithPatternOfGroup>();
             uc.TextCustom.AppendText("Pattern: ", fontTitle);
             uc.TextCustom.AppendText(sReg + Environment.NewLine, new TextStyle(Brushes.White, null, FontStyle.Bold));
             if (Regexs.RunPatternRegular(sString, sReg, out listResult2))
             {
                 uc.TextCustom.AppendText("Time: " + (DateTime.Now - timeStart).TotalMilliseconds + " milliseconds ~ " + (DateTime.Now - timeStart).TotalSeconds + " seconds\n", fontTitle);
                 int k = 0;
                 foreach (KeyValuePair <int, RegesValueWithPatternOfGroup> group in listResult2)
                 {
                     k++;
                     uc.TextCustom.AppendText(Environment.NewLine + "Found map: " + k.ToString() + "/" + listResult2.Count.ToString() + Environment.NewLine + "-----------Group var map-----------" + Environment.NewLine, fontTitle);
                     foreach (KeyValuePair <string, Dictionary <int, string> > var in group.Value.value)
                     {
                         uc.TextCustom.AppendText(var.Key + " : " + string.Join(" | ", var.Value.Values.ToArray()) + Environment.NewLine, fontTitle);
                     }
                     uc.TextCustom.AppendText("-----------Map string--------------" + Environment.NewLine, fontTitle);
                     uc.TextCustom.AppendText(group.Value.stringfind + Environment.NewLine, fontBody);
                 }
             }
             else
             {
                 uc.TextCustom.AppendText("Time: " + (DateTime.Now - timeStart).TotalMilliseconds + " milliseconds ~ " + (DateTime.Now - timeStart).TotalSeconds + " seconds\n", fontTitle);
                 uc.TextCustom.AppendText("Not math :(", new TextStyle(Brushes.Red, null, FontStyle.Italic));
             }
             frm.Show();
         }
     }
     catch (Exception ex)
     {
         InitParametar.Send_Error(ex.ToString(), MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name);
     }
 }
Beispiel #6
0
        /// <summary>
        /// 加密手机号码信息
        /// </summary>
        /// <param name="value"></param>
        /// <param name="specialChar"></param>
        /// <returns></returns>
        public static string EncryptPhone(string value, char specialChar = '*')
        {
            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }

            if (Regexs.IsMatch(value, RegexPatterns.MobilePhone))
            {
                return(EncryptString(value, 3, 4, specialChar));
            }

            return(EncryptSensitiveInfo(value, specialChar));
        }
 /// <summary>
 /// 是否验证通过
 /// </summary>
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value.SafeString().IsEmpty())
     {
         return(ValidationResult.Success);
     }
     if (Regexs.IsMatch(value.SafeString(), ValidatePattern.IdCardPattern))
     {
         return(ValidationResult.Success);
     }
     return(new ValidationResult(FormatErrorMessage(string.IsNullOrWhiteSpace(validationContext.DisplayName)
         ? validationContext.MemberName
         : validationContext.DisplayName)));
 }
        /// <summary>
        /// 是否验证通过
        /// </summary>
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (value.SafeString().IsEmpty())
            {
                return(ValidationResult.Success);
            }

            if (Regexs.IsMatch(value.SafeString(), ValidatePattern.IdCardPattern))
            {
                return(ValidationResult.Success);
            }

            return(new ValidationResult(FormatErrorMessage(string.Empty)));
        }
Beispiel #9
0
        /// <summary>
        /// 加密邮箱信息
        /// </summary>
        /// <param name="value"></param>
        /// <param name="specialChar"></param>
        /// <returns></returns>
        public static string EncryptEmail(string value, char specialChar = '*')
        {
            if (string.IsNullOrEmpty(value))
            {
                return(value);
            }

            if (Regexs.IsMatch(value, RegexPatterns.Email))
            {
                int suffixLen = value.LastIndexOf('@');
                return($"{EncryptSensitiveInfo(value.Substring(0, suffixLen), specialChar)}{value.Substring(suffixLen)}");
            }

            return(EncryptSensitiveInfo(value, specialChar));
        }
Beispiel #10
0
        /// <summary>
        /// 获取文件基本信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static CIReponseDto.ImageInfoResponse GetUrlVideoInfo(string url)
        {
            if (Regexs.IsNull(url))
            {
                return(null);
            }
            var request = WebRequest.Create(url) as HttpWebRequest;

            using (var response = request.GetResponse() as HttpWebResponse)
            {
                return(new CIReponseDto.ImageInfoResponse()
                {
                    Format = Path.GetExtension(url).TrimStart('.'),
                    Size = response.ContentLength.ToString()
                });
            }
        }
Beispiel #11
0
        ///   <summary>
        ///   获取验证码剩余配置
        ///   </summary>
        ///  <param name="qq">QQ账号</param>
        ///  <param name="sid">sid</param>
        ///  <param name="sess">sess</param>
        ///  <param name="cap_cd">cap_cd</param>
        ///  <param name="vsig">vsig</param>
        ///  <param name="rand_par">rand_par</param>
        ///  <param name="websig">websig</param>
        ///  <param name="y">Y坐标</param>
        /// <returns>Image</returns>
        public void LoadSlider(string qq, string sid, string sess, string cap_cd, ref string vsig, ref string rand_par, ref string websig, ref int y)
        {
            string temp = string.Empty, url = string.Empty, data = string.Empty;
            Regexs a = new Regexs();

            url  = "https://ssl.captcha.qq.com/cap_union_new_show?aid=" + Resources.aid + "&captype=&protocol=https&clientype=1&disturblevel=&apptype=2&noheader=0&color=&showtype=&fb=1&theme=&lang=2052&ua=" + Resources.ua + "&sess=" + sess + "&fwidth=0&sid=" + sid + "&uid=" + qq + "&cap_cd=" + cap_cd + "&rnd=" + GetText.GetRandom(111111, 999999) + "&forcestyle=undefined&wxLang=";
            data = WEB.GetWebData(url, ref temp, ref temp, ref temp);
            a.Matches(data, "class=13&vsig=\"\\+(.*?)\\+");
            temp = a.GetText(0, 1);
            a.Matches(data, "," + "Q" + "=\"(.*?)\"");
            vsig = a.GetText(0, 1);
            a.Matches(data, "Number\\(\"(.*?)\"");
            y = Convert.ToInt16(a.GetText(0, 1));
            a.Matches(data, "ans=\"(.*?)\"&(.*?)=");
            rand_par = a.GetText(0, 2);
            a.Matches(data, "websig=(.*?)&");
            websig = a.GetText(0, 1);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public override bool IsValid(object value)
 {
     if (value == null)
     {
         return(false);
     }
     return(Regexs.IsIdCard(value.ToString()));
     //if (value == null)
     //    return false;
     //var v = value.ToString();
     //if (Regexs.IdCardRegex.IsMatch(v) == false) {
     //    return false;
     //}
     //if (v.Length == 18) {
     //    return Check18(v);
     //} else if (v.Length == 15) {
     //    return true;
     //}
     //return false;
 }
Beispiel #13
0
        /// <summary>
        /// 设置别名,返回前缀和名称
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="isSplit">是否用句点分割名称</param>
        private void Resolve(string name, bool isSplit)
        {
            var pattern = @"\s+[aA][sS]\s+";
            var list    = Regexs.Split(name, pattern);

            if (list == null || list.Length == 0)
            {
                return;
            }
            if (list.Length == 2)
            {
                _alias = list[1];
            }
            if (isSplit)
            {
                SplitName(list[0]);
                return;
            }
            _name = name;
        }
Beispiel #14
0
        /// <summary>
        /// 加载数据
        /// </summary>
        /// <param name="data">数据</param>
        public override void LoadData(string data)
        {
            if (data.IsEmpty())
            {
                return;
            }
            data = data.Trim().TrimEnd(';');
            var json = Regexs.GetValue(data, @"^\w+\((\s+\{[^()]+\}\s+)\)$", "$1");

            if (json.IsEmpty())
            {
                return;
            }
            var jObject = JObject.Parse(json);

            foreach (var token in jObject.Children())
            {
                AddNodes(token);
            }
        }
Beispiel #15
0
        public static Match ReturnMatch(Regexs regexToMatch, string stringToMatch)
        {
            switch (regexToMatch)
            {
            case Regexs.SkypeRealAddress:
                Regex regex = new Regex(@"(?<=https://).*?([^/]*)");
                Match match = regex.Match(stringToMatch);
                return(match);

            case Regexs.NTLMResponse:
                Regex regex2 = new Regex(@"(?<=NTLM ).*?(?=\r|,)");
                Match match2 = regex2.Match(stringToMatch);
                return(match2);

            case Regexs.NTLMResponseADFS:
                Regex regex3 = new Regex(@"(?<=Negotiate ).*?(?=\r|,)");
                Match match3 = regex3.Match(stringToMatch);
                return(match3);

            case Regexs.ADFSAuthURL:
                Regex regex4 = new Regex(@"(?<=https://).*?([^/]*)");
                Match match4 = regex4.Match(stringToMatch);
                return(match4);

            case Regexs.cwtToken:
                Regex regex5 = new Regex(@"cwt=.*?(?="")");
                Match match5 = regex5.Match(stringToMatch);
                return(match5);

            case Regexs.applicationsURL:
                Regex regex6 = new Regex(@"(?<=\""applications\"":{\""href\"":\"")(.*?"")");
                Match match6 = regex6.Match(stringToMatch);
                return(match6);

            case Regexs.sipUsername:
                Regex regex7 = new Regex(@"(?<=sip:).*?([^/]*)");
                Match match7 = regex7.Match(stringToMatch);
                return(match7);
            }
            return(null);
        }
        public string GetRegexPattern()
        {
            if (Regexs.TryGetValue(".", out var path))
            {
                return(path);
            }
            if (!IsRegex)
            {
                return(GetNicePath());
            }
            var sb     = new StringBuilder();
            var slices = m_path.Text.Split('/');

            foreach (var x in slices)
            {
                if (x == "")
                {
                    continue;
                }
                sb.Append(@"\/");
                if (x.StartsWith("{"))
                {
                    var name    = x[1..^ 1];
Beispiel #17
0
        /// <summary>
        /// 企业付款到银行卡
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public static async Task <PayToUserResult> PayToBank(WxPayToBankRequest dto)
        {
            const string api = "https://api.mch.weixin.qq.com/mmpaysptrans/pay_bank";

            /*1.生成签名*/
            var dictionary = new SortedDictionary <string, object>
            {
                { "mch_id", WxPayConfig.mchId },
                { "partner_trade_no", dto.PartnerTradeNo },
                { "nonce_str", WeChatUtil.getNoncestr() },
                { "enc_bank_no", await WeChatUtil.RSAEncrypt(dto.EncBankNo) },
                { "enc_true_name", await WeChatUtil.RSAEncrypt(dto.EncTrueName) },
                { "bank_code", dto.BankCode },
                { "amount", dto.Amount }
            };

            dictionary.Add("sign", WeChatUtil.CreateSign(dictionary, WxPayConfig.key));
            /*2.生成xml数据*/
            var xml = WeChatUtil.WeChatSignXml(dictionary);

            /*开始请求接口*/
            try
            {
                var xmlStr = WeChatUtil.WxCerHttpPost(api, xml, WxPayConfig.cerPath, WxPayConfig.mchId);
                if (!Regexs.IsNull(xmlStr))
                {
                    var returnXml = WePayXmlUtil.XmlToObect <PayToUserResult>(xmlStr);
                    return(returnXml);
                }
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(null);
        }
Beispiel #18
0
        /// <summary>
        /// 外部Url获取图片基本信息
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <CIReponseDto.ImageInfoResponse> GetUrlImageInfo(string url)
        {
            if (Regexs.IsNull(url))
            {
                return(null);
            }
            var           client   = new RestClient(url);
            var           request  = new RestRequest(method: Method.GET);
            IRestResponse response = await client.ExecuteAsync(request);

            using (var ms = new System.IO.MemoryStream(response.RawBytes))
            {
                using (var _image = System.Drawing.Bitmap.FromStream(ms, true))
                {
                    return(new CIReponseDto.ImageInfoResponse()
                    {
                        Format = _image.RawFormat.ToString(),
                        Width = _image.Width.ToString(),
                        Height = _image.Height.ToString(),
                        Size = ms.Length.ToString()
                    });
                }
            }
        }