using System.Text.Json;
using JiDangJia.Contracts;
using JiDangJia.Services;
namespace JiDangJia.Views;
public sealed class PhonePage : PrivatePage
{
public PhonePage()
{
Title="绑定手机号";var phone=new Entry{Placeholder="11 位手机号",MaxLength=11,Keyboard=Keyboard.Telephone};var code=new Entry{Placeholder="短信验证码",MaxLength=6,Keyboard=Keyboard.Numeric};var state=Ui.Text("",12,Ui.Muted);
var body=Ui.Stack(Ui.Section("腾讯云短信验证"),Ui.Text("手机号仅用于此应用的账户验证。",11,Ui.Muted),phone,code,state,Ui.Button("获取验证码",async()=>{using var d=await AuthClient.Current.AccountRequest<JsonDocument>("/phone/code",new{phone=phone.Text??""});state.Text="验证码有效期 5 分钟,60 秒后可重发。";},false),Ui.Button("验证并绑定",async()=>{await AuthClient.Current.AccountRequest<OperationResult>("/phone/bind",new{phone=phone.Text??"",code=code.Text??""});await DisplayAlertAsync("已绑定","手机号已通过短信验证。","完成");await Navigation.PopAsync();}));body.Padding=18;Content=new ScrollView{Content=body};
Loaded+=async(_,_)=>{try{using var d=await AuthClient.Current.AccountRequest<JsonDocument>("/phone");state.Text=d.RootElement.GetProperty("configured").GetBoolean()?"验证码只发给填写的手机号。":"腾讯云短信暂未配置,试用可由管理员人工核验手机号。";}catch(Exception ex){state.Text=ex.Message;}};
}
}
using System.Text.Json;
using JiDangJia.Contracts;
using JiDangJia.Services;
namespace JiDangJia.Views;
public sealed class PhonePage : PrivatePage
{
public PhonePage()
{
Title="绑定手机号";var phone=new Entry{Placeholder="11 位手机号",MaxLength=11,Keyboard=Keyboard.Telephone};var code=new Entry{Placeholder="短信验证码",MaxLength=6,Keyboard=Keyboard.Numeric};var state=Ui.Text("",12,Ui.Muted);
var body=Ui.Stack(Ui.Section("腾讯云短信验证"),Ui.Text("手机号仅用于此应用的账户验证。",11,Ui.Muted),phone,code,state,Ui.Button("获取验证码",async()=>{using var d=await AuthClient.Current.AccountRequest<JsonDocument>("/phone/code",new{phone=phone.Text??""});state.Text="验证码有效期 5 分钟,60 秒后可重发。";},false),Ui.Button("验证并绑定",async()=>{await AuthClient.Current.AccountRequest<OperationResult>("/phone/bind",new{phone=phone.Text??"",code=code.Text??""});await DisplayAlertAsync("已绑定","手机号已通过短信验证。","完成");await Navigation.PopAsync();}));body.Padding=18;Content=new ScrollView{Content=body};
Loaded+=async(_,_)=>{try{using var d=await AuthClient.Current.AccountRequest<JsonDocument>("/phone");state.Text=d.RootElement.GetProperty("configured").GetBoolean()?"验证码只发给填写的手机号。":"腾讯云短信暂未配置,试用可由管理员人工核验手机号。";}catch(Exception ex){state.Text=ex.Message;}};
}
}