using System; using Shared.Common; using System.Collections.Generic; using System.Timers; using System.Text.RegularExpressions; namespace Shared.Phone.UserCenter.User { /// /// 根据手机找回密码 /// public class ForgotPasswordByPhoneForm : UserCenterCommonForm { #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { //设定标题 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.ForgotPassword)); //初始化中部控件 this.InitMiddleFrame(); } /// /// 初始化中部控件 /// private void InitMiddleFrame() { this.Show(); } #endregion #region ■ 以下为复制郭雪城的代码_____________ public string phoneStr = ""; /// /// 手机号输入是否符合规则 /// public bool IsRightAccount = false; /// /// 下来选择手机区号 默认中国大陆为86 ///发送国际 / 港澳台消息时,接收号码格式为00 + 国际区号 + 号码,如“008615899998888” 调用API时,Company字段请传入整型值:4。 。 ///国内 调用API时,Company字段请传入整型值:0。 /// public List areaCodeList = new List(); private async void Show() { ShowForgotPWD(); CommonPage.Loading.Start(); try { var requestOBJ = new SendDataToServer.GetAreaCodeOBJ() { RequestVersion = CommonPage.RequestVersion }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(requestOBJ); var revertOBJ = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/GetAreaCode", System.Text.Encoding.UTF8.GetBytes(requestJson)); if (revertOBJ == null) { return; } if (revertOBJ.StateCode.ToUpper() == "SUCCESS") { var responseData = revertOBJ.ResponseData; areaCodeList = Newtonsoft.Json.JsonConvert.DeserializeObject>(responseData.ToString()); } } catch { } finally { CommonPage.Loading.Hide(); } } void ShowForgotPWD() { var t = new Timer(); var dateBegin = new DateTime(); #region --midFL-- var accountTIPS = new Button() { Width = Application.GetRealWidth(1080 - CommonPage.XLeft * 2), Height = Application.GetRealHeight(100), TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterHorizontal, TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor, TextID = R.MyInternationalizationString.PleaseInputThePhoneAndYouWillHaveVerificationCode }; bodyFrameLayout.AddChidren(accountTIPS); var accountFL = new FrameLayout() { Y = accountTIPS.Bottom + Application.GetRealHeight(100), Height = Application.GetRealHeight(100) }; bodyFrameLayout.AddChidren(accountFL); var accountZoneBtn = new Button() { Height = Application.GetRealHeight(100) - 1, Width = Application.GetRealWidth(200), X = Application.GetRealWidth(CommonPage.XLeft), Text = "+" + CommonPage.PhoneZoneStr, TextAlignment = TextAlignment.Center, TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor }; accountFL.AddChidren(accountZoneBtn); var accountZoneLine = new Button() { X = Application.GetRealWidth(10) + accountZoneBtn.Right, Width = 1, Height = Application.GetRealHeight(50), Gravity = Gravity.CenterVertical, BackgroundColor = ZigbeeColor.Current.GXCTextBlackColor }; accountFL.AddChidren(accountZoneLine); var accountET = new EditText() { X = Application.GetRealWidth(50) + accountZoneLine.Right, Width = Application.GetRealWidth(1080 - 100) - accountZoneLine.X, Height = Application.GetRealHeight(100) - 1, TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputPhoneNum), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor }; accountFL.AddChidren(accountET); var accountLine = new FrameLayout() { Y = Application.GetRealHeight(100) - 1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; accountFL.AddChidren(accountLine); var verificationCodeFL = new FrameLayout() { Y = accountFL.Bottom + Application.GetRealHeight(100), Height = Application.GetRealHeight(100) }; bodyFrameLayout.AddChidren(verificationCodeFL); var verificationCodeET = new EditText() { X = Application.GetRealWidth(CommonPage.XLeft), Width = Application.GetRealWidth(500), Height = Application.GetRealHeight(100) - 1, TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.GXCTextBlackColor, PlaceholderText = Language.StringByID(R.MyInternationalizationString.PleaseInputVerificationCode), PlaceholderTextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor }; verificationCodeFL.AddChidren(verificationCodeET); var verificationCodeLine = new FrameLayout() { Y = Application.GetRealHeight(100) - 1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor }; verificationCodeFL.AddChidren(verificationCodeLine); var sendCodeBtn = new Button() { X = Application.GetRealWidth(1080 - 400 - CommonPage.XLeft), Width = Application.GetRealWidth(400), Y = Application.GetRealHeight(100) + verificationCodeFL.Bottom, Height = Application.GetRealHeight(100), TextID = R.MyInternationalizationString.SendVerificationCode, TextColor = ZigbeeColor.Current.GXCButtonUnselectedColor, SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor, TextAlignment = TextAlignment.CenterRight, Enable = false, IsSelected = false, }; bodyFrameLayout.AddChidren(sendCodeBtn); var resetPWDBtn = new Button() { Width = Application.GetRealWidth(700), Y = Application.GetRealHeight(1920 - 220 - 400), Height = Application.GetRealHeight(110), Radius = (uint)Application.GetRealHeight(55), TextID = R.MyInternationalizationString.ResetPWD, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, TextAlignment = TextAlignment.Center, TextSize = 15, BackgroundColor = ZigbeeColor.Current.GXCButtonUnselectedColor, SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, Gravity = Gravity.CenterHorizontal, Enable = false, IsSelected = false }; bodyFrameLayout.AddChidren(resetPWDBtn); //错误提示Btn var loginErrorBtn = new Button() { Y = resetPWDBtn.Bottom + Application.GetRealHeight(50), Width = Application.GetRealWidth(1080 - 100), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCRedColor, Gravity = Gravity.CenterHorizontal }; bodyFrameLayout.AddChidren(loginErrorBtn); #endregion #region --event-- accountET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; //校验手机号 if (CommonPage.PhoneZoneStr != "86") { var reg = new Regex(CommonPage.PhoneForForeignRegexStr); var mFalg = reg.Match(accountET.Text.Trim()); if (!mFalg.Success) { var aler = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.PleaseInputTheCorrectCellPhoneNumber), Language.StringByID(R.MyInternationalizationString.Confrim)); aler.Show(); sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; IsRightAccount = false; accountET.Text = ""; } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = true; IsRightAccount = true; } } else { if (accountET.Text.Trim().Length == 11) { var reg = new Regex(CommonPage.PhoneRegexStr); var mFalg = reg.Match(accountET.Text.Trim()); if (!mFalg.Success) { sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; var aler = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.PleaseInputTheCorrectCellPhoneNumber), Language.StringByID(R.MyInternationalizationString.OK)); aler.Show(); accountET.Text = ""; IsRightAccount = false; } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = true; IsRightAccount = true; } } else if (accountET.Text.Trim().Length > 11) { accountET.Text = e.Remove(11); } else { sendCodeBtn.Enable = sendCodeBtn.IsSelected = false; IsRightAccount = false; //正则表达式判断是否数字 var reg = new Regex("^[0-9]*$"); if (!reg.IsMatch(accountET.Text)) { var aler = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.PleaseInputTheCorrectCellPhoneNumber), Language.StringByID(R.MyInternationalizationString.Confrim)); aler.Show(); accountET.Text = ""; } } } }; verificationCodeET.TextChangeEventHandler += (sender, e) => { loginErrorBtn.Text = ""; if (verificationCodeET.Text.Trim().Length > 0 && IsRightAccount) { resetPWDBtn.Enable = resetPWDBtn.IsSelected = true; } else { resetPWDBtn.Enable = resetPWDBtn.IsSelected = false; } }; Button tempClickZoneImgBtn = new Button(); Button tempClickZoneNameBtn = new Button(); EventHandler phoneZoneHandler = (senderZone, eZone) => { //ZoneListView var phoneZoneSelectedShowView = new Dialog() { Height = Application.GetRealHeight(1000), Width = Application.GetRealWidth(700), BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, Radius = (uint)Application.GetRealHeight(30) }; phoneZoneSelectedShowView.Show(); var phoneZoneTitle = new Button() { Height = Application.GetRealHeight(110), TextID = R.MyInternationalizationString.PleaseSelectAreaCode, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, TextSize = 15, BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor }; phoneZoneSelectedShowView.AddChidren(phoneZoneTitle); var phoneZoneSelectedListView = new VerticalScrolViewLayout() { Y = phoneZoneTitle.Bottom, Height = Application.GetRealHeight(1000 - 110 * 2), BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor }; phoneZoneSelectedShowView.AddChidren(phoneZoneSelectedListView); for (int i = 0; i < areaCodeList.Count; i++) { var zoneItemLName = areaCodeList[i].Name; var zoneItemLCode = areaCodeList[i].Code; var zoneItemFL = new FrameLayout() { Width = phoneZoneSelectedListView.Width, Height = Application.GetRealHeight(110), Tag = i + 10086 }; phoneZoneSelectedListView.AddChidren(zoneItemFL); var zoneIsSelectedBtn = new Button() { Width = Application.GetMinReal(80), Height = Application.GetMinReal(80), UnSelectedImagePath = "Account/Check.png", SelectedImagePath = "Account/CheckSelected.png", Tag = i + 10086, Gravity = Gravity.CenterVertical }; zoneItemFL.AddChidren(zoneIsSelectedBtn); var zoneItemNameBtn = new Button() { X = Application.GetRealWidth(20) + zoneIsSelectedBtn.Right, Width = zoneItemFL.Width - Application.GetRealWidth(100), Height = Application.GetRealHeight(110) - 1, Text = zoneItemLName, TextColor = ZigbeeColor.Current.GXCTextBlackColor, SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor, TextAlignment = TextAlignment.CenterLeft, Tag = i + 10000 }; zoneItemFL.AddChidren(zoneItemNameBtn); var zoneLine = new Button() { Y = zoneItemFL.Height - 1, Width = zoneItemFL.Width, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCPlaceHolderTextColor }; zoneItemFL.AddChidren(zoneLine); EventHandler selectedZone = (sender, e) => { tempClickZoneImgBtn.IsSelected = false; tempClickZoneNameBtn.IsSelected = false; zoneItemNameBtn.IsSelected = true; zoneIsSelectedBtn.IsSelected = true; tempClickZoneImgBtn = zoneIsSelectedBtn; tempClickZoneNameBtn = zoneItemNameBtn; CommonPage.PhoneZoneStr = zoneItemLCode; }; zoneIsSelectedBtn.MouseUpEventHandler += selectedZone; zoneItemNameBtn.MouseUpEventHandler += selectedZone; //默认 if (zoneItemLCode == CommonPage.PhoneZoneStr) { zoneItemNameBtn.IsSelected = true; zoneIsSelectedBtn.IsSelected = true; tempClickZoneImgBtn = zoneIsSelectedBtn; tempClickZoneNameBtn = zoneItemNameBtn; } } var cancleBtn = new Button() { Y = phoneZoneSelectedListView.Bottom, Height = Application.GetRealHeight(110), Width = Application.GetRealWidth(700 / 2), BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, TextID = R.MyInternationalizationString.Cancel, TextSize = 15 }; phoneZoneSelectedShowView.AddChidren(cancleBtn); cancleBtn.MouseUpEventHandler += (sender, e) => { phoneZoneSelectedShowView.Close(); }; cancleBtn.MouseDownEventHandler += (sender, e) => { cancleBtn.IsSelected = true; }; var lineCancleOK = new Button() { X = cancleBtn.Right, Y = phoneZoneSelectedListView.Bottom, Height = Application.GetRealHeight(110), Width = 1, BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor }; phoneZoneSelectedShowView.AddChidren(lineCancleOK); var okBtn = new Button() { X = lineCancleOK.Right + 1, Y = phoneZoneSelectedListView.Bottom, Height = Application.GetRealHeight(110), Width = Application.GetRealWidth(700 / 2) - 1, BackgroundColor = ZigbeeColor.Current.GXCButtonBlueColor, TextID = R.MyInternationalizationString.Confrim, TextSize = 15 }; phoneZoneSelectedShowView.AddChidren(okBtn); okBtn.MouseUpEventHandler += (sender, e) => { accountZoneBtn.Text = "+" + CommonPage.PhoneZoneStr; phoneZoneSelectedShowView.Close(); }; okBtn.MouseDownEventHandler += (sender, e) => { okBtn.IsSelected = true; }; }; accountZoneBtn.MouseUpEventHandler += phoneZoneHandler; sendCodeBtn.MouseUpEventHandler += async (sender, e) => { string phoneNum = accountET.Text.Trim(); CommonPage.Loading.Start(); try { int companyInt = 0; if (CommonPage.PhoneZoneStr == "86") { companyInt = CommonPage.Company; phoneStr = phoneNum; } else { companyInt = CommonPage.CompanyForINTERNETION; phoneStr = phoneNum; } var reqDtoSignPhone = new SendDataToServer.LoginSendVerCodeObj() { Account = phoneStr, Company = companyInt, AreaCode = int.Parse(CommonPage.PhoneZoneStr), Language = CommonPage.ZigBeeLanguage }; var requesetJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDtoSignPhone); var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/LoginSendVerCode", System.Text.Encoding.UTF8.GetBytes(requesetJson)); if (requestRevertObj == null) { CommonPage.Instance.FailureToServer(); return; } var stateCodeStr = requestRevertObj.StateCode.ToUpper(); if (stateCodeStr == "SUCCESS") { TimeBegin(); var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.SendVerificationCodeSuccess), Language.StringByID(R.MyInternationalizationString.Confrim)); alert.Show(); } else if (stateCodeStr == "PARAMETEROREMPTY") { //提供的参数错误 loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY); } else if (stateCodeStr == "ACCOUNTNOEXISTS") { //账号不存在 loginErrorBtn.TextID = R.MyInternationalizationString.ACCOUNTNOEXISTS; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.ACCOUNTNOEXISTS); } else if (stateCodeStr == "SENDFAIL") { //验证码发送失败 loginErrorBtn.TextID = R.MyInternationalizationString.SENDFAIL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.SENDFAIL); } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } }; resetPWDBtn.MouseUpEventHandler += async (sender, e) => { var vCode = verificationCodeET.Text.Trim(); var vPhone = accountET.Text.Trim(); CommonPage.Loading.Start(); try { var reqDto = new SendDataToServer.ValidatorCodeObj() { Account = vPhone, Code = int.Parse(vCode), AreaCode = int.Parse(CommonPage.PhoneZoneStr), Language = CommonPage.ZigBeeLanguage }; var requestJson = Newtonsoft.Json.JsonConvert.SerializeObject(reqDto); //验证验证码 var requestRevertObj = await CommonPage.Instance.RequestHttpsZigbeeAsync("ZigbeeUsers/ValidatorCode", System.Text.Encoding.UTF8.GetBytes(requestJson)); if (requestRevertObj == null) { CommonPage.Instance.FailureToServer(); return; } var stateCodeStr = requestRevertObj.StateCode.ToUpper(); if (stateCodeStr == "SUCCESS") { ModifyPWD(vPhone); } else if (stateCodeStr == "PARAMETEROREMPTY") { //提供的参数错误 loginErrorBtn.TextID = R.MyInternationalizationString.PARAMETEROREMPTY; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.PARAMETEROREMPTY); } else if (stateCodeStr == "VALIDCODEANDPHONENOEQUAL") { //验证码错误 loginErrorBtn.TextID = R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.VALIDCODEANDPHONENOEQUAL); } else { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.RequestServerFailed); } } catch { loginErrorBtn.TextID = R.MyInternationalizationString.RequestServerFailed; } finally { CommonPage.Loading.Hide(); } }; void ModifyPWD(string account) { var newPWD = new ForgotPasswordSetNewPasswordForm(); this.AddForm(newPWD, account, "phone", CommonPage.PhoneZoneStr); } void TimeBegin() { t.Interval = 1000; t.AutoReset = true; t.Enabled = true; t.Elapsed += new ElapsedEventHandler(TimeOut); //启动计时器倒计时-60s t.Start(); dateBegin = DateTime.Now; } void TimeOut(object source, System.Timers.ElapsedEventArgs e) { var span = DateTime.Now - dateBegin; if (span.TotalSeconds <= 61) { Application.RunOnMainThread(() => { sendCodeBtn.Text = Convert.ToInt16((60 - span.TotalSeconds)) + "s" + Language.StringByID(R.MyInternationalizationString.SendVerificationCode); sendCodeBtn.Enable = false; }); } else { Application.RunOnMainThread(() => { sendCodeBtn.Enable = true; sendCodeBtn.TextID = R.MyInternationalizationString.SendVerificationCode; t.Stop(); t.Close(); }); } } #endregion } #endregion } }