private async Task LoadCaptcha() { var mth = new GetCaptcha(); var bytes = await ApiClient.Execute(mth); if (this.Stm != null) this.Stm.Dispose(); this.Stm = new MemoryStream(bytes); this.CaptchSource = StreamImageSource.FromStream(() => this.Stm); this.NotifyOfPropertyChange(() => this.CaptchSource); }
private static void RaiseOnTimerElapsed(object obj, ElapsedEventArgs e) { Task.Run(async() => { try { if (string.IsNullOrEmpty(Settings.Default.ApiKey)) { return; } CaptchaTimer.Elapsed -= RaiseOnTimerElapsed; await Utils.RemoveOldCaptcha(DateTime.Now.AddSeconds(-Utils.CaptchaLife)); if (Utils.CaptchaQueueCount < Utils.MaxCaptchaQueue) { while (Utils.CaptchaQueueCount < Utils.MaxCaptchaQueue) { if (!Utils.IsPermit) { return; } GetNoCaptcha(); var result = await GetCaptcha.GetNoCaptchaQueue(Settings.Default.ApiKey); if (result.Answer.StartsWith("Error message")) { if (result.Answer.Contains("Error message: Stopped")) { return; } //Informer.RaiseOnResultReceived(result.Answer); continue; } Utils.CaptchaQueue = result; await Utils.RemoveOldCaptcha( DateTime.Now.AddSeconds(-Utils.CaptchaLife)); } } } catch (Exception ex) { //Informer.RaiseOnResultReceived(ex.Message); } finally { CaptchaTimer.Elapsed += RaiseOnTimerElapsed; } }).Wait(); }
private static async void GetNoCaptcha(DriverStruct drStr) { drStr.IsEnabled = false; var result = await GetCaptcha.GetNoCaptcha(Settings.Default.AntigateKey, drStr); drStr.IsEnabled = true; if (!result.Answer.StartsWith("Error message") || result.Answer.Contains("Stopped") || result.Answer.Contains("Отменена задача")) { Utils.CaptchaQueue = result; } }
private async Task LoadCaptcha() { var mth = new GetCaptcha(); var bytes = await ApiClient.Execute(mth); if (this.Stm != null) this.Stm.Dispose(); this.Stm = new MemoryStream(bytes); //TODO var img = new BitmapImage(); await img.SetSourceAsync(this.Stm.AsRandomAccessStream()); this.CaptchaSource = img; this.NotifyOfPropertyChange(() => this.CaptchaSource); }
private async Task LoadCaptcha() { var mth = new GetCaptcha(); var bytes = await ApiClient.Execute(mth); if (this.Stm != null) { this.Stm.Dispose(); } this.Stm = new MemoryStream(bytes); this.CaptchSource = StreamImageSource.FromStream(() => this.Stm); this.NotifyOfPropertyChange(() => this.CaptchSource); }
private static async void GetNoCaptcha() { try { var result = await GetCaptcha.GetNoCaptcha(Settings.Default.ApiKey); if (result.Answer.StartsWith("Error message")) { if (result.Answer.Contains("Error message: Stopped")) { return; } //Informer.RaiseOnResultReceived(result.Answer); } Utils.CaptchaQueue = result; } catch (Exception) { } }
public IHttpActionResult PostSendRegisterCaptcha(GetCaptcha model) { //验证数据 if (model == null) { return(BadRequest("请输入手机号码")); } if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.First(s => s.Errors.Count > 0).Errors[0].ErrorMessage)); } Volunteer volunteer = db.Volunteers.FirstOrDefault(s => s.MobileNumber == model.MobileNumber && s.Status != EnumUserStatus.注销); //生成验证码 string code = new Random().Next(100000, 999999).ToString(); #if DEBUG code = "666666"; Thread.Sleep(2000); #endif //存储手机号码、验证码等信息到数据库 //1.新手机号码 if (volunteer == null) { DateTime now = DateTime.Now; volunteer = new Volunteer { Id = Guid.NewGuid(), MobileNumber = model.MobileNumber, SmsCaptcha = code, SmsCaptchaUsedFor = EnumCaptchaUsedFor.志愿者注册, SmsCaptchaExpiredTime = now.AddMinutes(30), RegisterTime = now }; try { db.Volunteers.Add(volunteer); db.SaveChanges(); } catch (Exception ex) { return(BadRequest("操作发生错误")); } } //2.已存在的手机号码 else { //排除已经提交手机号码但未进行验证的情况 if (volunteer.Status == EnumUserStatus.注册未验证手机) { return(BadRequest("该手机号码已注册")); } volunteer.SmsCaptcha = code; volunteer.SmsCaptchaUsedFor = EnumCaptchaUsedFor.志愿者注册; DateTime now = DateTime.Now; volunteer.SmsCaptchaExpiredTime = now.AddMinutes(30); db.Entry(volunteer).State = EntityState.Modified; try { db.SaveChanges(); } catch (Exception ex) { db.Entry(volunteer).State = EntityState.Unchanged; return(BadRequest("操作发生错误")); } } #if !DEBUG if (!Ali.SendWorkerRegisterSms(code, model.MobileNumber)) { //发送错误不处理 } #endif return(Ok()); }
public void CaptchaTest() { var mth = new GetCaptcha(); var stm = ApiClient.Execute(mth).Result; }