Exemplo n.º 1
0
        public void CreateVerifyCodeTask(WebLib.RandCodeType type, Action <Image, HttpContext> callback, Action <HttpContext> failCallback)
        {
            var url      = "";
            var referUrl = "";

            switch (type)
            {
            case RandCodeType.SjRand:
                if (Session.HttpConf.IsUamLogin)
                {
                    CreateVerifyCodeTask64(type, callback, failCallback);
                    return;
                }
                url      = string.Format("passcodeNew/getPassCodeNew?module=login&rand=sjrand&{0}", _random.NextDouble());
                referUrl = "leftTicket/init";
                break;

            case RandCodeType.Randp:
                url      = $"passcodeNew/getPassCodeNew?module=passenger&rand=randp&{_random.NextDouble()}";
                referUrl = "confirmPassenger/initDc";
                break;

            case RandCodeType.RandpResign:
                url      = $"passcodeNew/getPassCodeNew?module=passenger&rand=randp&{_random.NextDouble()}";
                referUrl = "confirmPassenger/initGc";
                break;

            default:
                break;
            }

            var netctx = Create <Image>(HttpMethod.Get, url, referUrl);

            if (ApiConfiguration.Instance.EnableVerifycodeLoadDelay && Session.LastCheckRandCodeTime.HasValue)
            {
                var timespan = DateTime.Now - Session.LastCheckRandCodeTime.Value;
                if (timespan.TotalMilliseconds < NetworkConfiguration.Current.ReloadVcCodeDelay)
                {
                    netctx.SendDelay(new TimeSpan(0, 0, 0, 0, (int)(NetworkConfiguration.Current.ReloadVcCodeDelay - timespan.TotalMilliseconds)));
                }
            }
            netctx.SendAsPromise().Done((x, y) =>
            {
                var ctx = y.Result;
                //刷新过快?
                if ((ctx.ResponseContent as ResponseBinaryContent).Result.Length == 1492)
                {
                    failCallback(y.Result);
                }
                else
                {
                    LastVcLoadTime = DateTime.Now;
                    ctx.Result.Tag = (ctx.ResponseContent as ResponseImageContent).ResultStream;
                    callback(ctx.Result, ctx);
                }
            }).Fail((x, y) =>
            {
                failCallback(y.Result);
            });
        }
Exemplo n.º 2
0
        void CreateVerifyCodeTask64(WebLib.RandCodeType type, Action <Image, HttpContext> callback, Action <HttpContext> failCallback)
        {
            var netctx = Create(HttpMethod.Get, "/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand&1546670759129&callback=jQuery19109564546343775517_1546669788561&_=1546669788578", "resources/login.html", result: new { image = "", result_code = 0, result_message = "" });

            if (ApiConfiguration.Instance.EnableVerifycodeLoadDelay && Session.LastCheckRandCodeTime.HasValue)
            {
                var timespan = DateTime.Now - Session.LastCheckRandCodeTime.Value;
                if (timespan.TotalMilliseconds < NetworkConfiguration.Current.ReloadVcCodeDelay)
                {
                    netctx.SendDelay(new TimeSpan(0, 0, 0, 0, (int)(NetworkConfiguration.Current.ReloadVcCodeDelay - timespan.TotalMilliseconds)));
                }
            }
            netctx.SendAsPromise().Done((x, y) =>
            {
                var ctx   = y.Result;
                Image img = null;
                if (!ctx.Result.image.IsNullOrEmpty())
                {
                    try
                    {
                        var ms  = new MemoryStream(Convert.FromBase64String(ctx.Result.image));
                        img     = Image.FromStream(ms);
                        img.Tag = ms;
                    }
                    catch (Exception e)
                    {
                        failCallback(y.Result);
                        return;
                    }
                }
                //0-正常,3-过于频繁
                if (ctx.Result.result_code != 0)
                {
                    failCallback(y.Result);
                }
                else
                {
                    LastVcLoadTime = DateTime.Now;
                    callback(img, ctx);
                }
            }).Fail((x, y) =>
            {
                failCallback(y.Result);
            });
        }