Example #1
0
        public string Create(ISimCaptchaOptions options)
        {
            var str = options.HZ;

            if (string.IsNullOrEmpty(str))
            {
                throw new Exception("没有设置随机汉字字符串");
            }

            char[]           str_char_arrary = str.ToArray();
            long             tick            = DateTime.Now.Ticks;
            Random           rand            = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
            HashSet <string> hs         = new HashSet <string>();
            bool             randomBool = true;

            while (randomBool)
            {
                if (hs.Count == options.WashCodeLength)
                {
                    break;
                }

                int rand_number = rand.Next(str_char_arrary.Length);
                hs.Add(str_char_arrary[rand_number].ToString());
            }
            string code = string.Join("", hs);

            return(code);
        }
Example #2
0
        public VCodeImgModel Create(string code, int width, int height, ISimCaptchaOptions options)
        {
            VCodeImgModel rtnResult = new VCodeImgModel {
                VCodePos = new List <PointPosModel>()
            };

            // TODO: 变化点: 答案: 4个字
            int rightCodeLength = options.CodeLength;

            Bitmap       Img = null;
            Graphics     g   = null;
            MemoryStream ms  = null;

            Color[] color_Array = { Color.Black, Color.DarkBlue, Color.Green, Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };

            if (options.Colors != null && options.Colors.Any())
            {
                List <Color> clrLst = new List <Color>();
                foreach (var c in options.Colors)
                {
                    if (c.StartsWith("#"))
                    {
                        try
                        {
                            clrLst.Add(Color.FromArgb(Convert.ToInt32($"FF{ c[1..]}", 16)));
Example #3
0
        public SimCaptchaService(ISimCaptchaOptions options, ICacheHelper cacheHelper, IVCodeImage vCodeImage, IJsonHelper jsonHelper, IAppChecker appChecker, IRandomCode randomCode)
        {
            this._options     = options;
            this._cacheHelper = cacheHelper;

            this.VCodeImage = vCodeImage;
            this.JsonHelper = jsonHelper;

            this.AppChecker     = appChecker;
            this.RandomCode     = randomCode;
            this._encryptHelper = new AesEncryptHelper();
        }
Example #4
0
        public SimCaptchaService(ISimCaptchaOptions options, ICache cache, IVCodeImage vCodeImage, IJsonHelper jsonHelper)
        {
            this._options     = options;
            this._cacheHelper = new CacheHelper(cache);

            this.VCodeImage = vCodeImage;
            this.JsonHelper = jsonHelper;

            this.AppChecker     = new DefaultAppChecker((SimCaptchaOptions)options);
            this.RandomCode     = new RandomCodeHanZi();
            this._encryptHelper = new AesEncryptHelper();
        }
Example #5
0
 public SimCaptchaService Set(ISimCaptchaOptions options)
 {
     this._options = options;
     return(this);
 }
 public DefaultAppChecker(SimCaptchaOptions options)
 {
     this.Options = options;
 }
Example #7
0
 public SimCaptchaClient Set(ISimCaptchaOptions options)
 {
     this._options = options;
     return(this);
 }
Example #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="appId"></param>
 /// <param name="appSecret"></param>
 /// <param name="verifyUrl">验证码服务端提供的验证ticket的url</param>
 public SimCaptchaClient(ISimCaptchaOptions options, IJsonHelper jsonHelper)
 {
     this._options   = options;
     this.JsonHelper = jsonHelper;
 }