using System;
|
using Shared.Phone.UserCenter;
|
using Shared.Phone.Device.Logic;
|
using Shared.Common;
|
using Newtonsoft.Json.Linq;
|
|
namespace Shared.Phone.Device.VideoIntercom
|
{
|
public class TempQRCode : CommonFormBase
|
{
|
public TempQRCode()
|
{
|
}
|
|
private static string Password = "";
|
|
public void Show()
|
{
|
IniTempPassword();//获取临时密码
|
|
TopView topView = new TopView();
|
this.AddChidren(topView.TopRowView());
|
topView.toptitleNameBtn.Text = "二维码/临时密码";
|
topView.clickBtn.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); };
|
|
#region 临时密码
|
|
//临时密码 Layout
|
var tempPwdLayout = new FrameLayout
|
{
|
Radius = (uint)Application.GetRealHeight(37),
|
Y = Application.GetRealHeight(380),
|
Height = Application.GetRealWidth(481),
|
Width = Application.GetRealWidth(850),
|
Gravity = Gravity.CenterHorizontal,
|
|
};
|
this.AddChidren(tempPwdLayout);
|
|
// 背景
|
var tempImage = new ImageView
|
{
|
ImagePath = "Video/VideoTempPwdBackground.png",
|
};
|
tempPwdLayout.AddChidren(tempImage);
|
|
//title
|
var tempPwdTitleText = new TextView
|
{
|
Text = "临时密码",
|
Gravity = Gravity.CenterHorizontal,
|
TextSize = 15,
|
Height = Application.GetRealWidth(49),
|
Y = Application.GetRealHeight(161),
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
|
};
|
tempPwdLayout.AddChidren(tempPwdTitleText);
|
|
// password
|
var tempPwdText = new EditText
|
{
|
Text = Password,
|
TextSize = 23,
|
Height = Application.GetRealWidth(92),
|
TextColor = ZigbeeColor.Current.XMOrange,
|
Y = tempPwdTitleText.Bottom + Application.GetRealHeight(23),
|
//BackgroundColor=UserCenterColor.Current.Red,
|
Enable = false,
|
TextAlignment = TextAlignment.Center,
|
|
};
|
tempPwdLayout.AddChidren(tempPwdText);
|
|
var hideBtn = new Button
|
{
|
Height = Application.GetRealWidth(92),
|
Width = Application.GetRealWidth(92),
|
UnSelectedImagePath = "Account/UnhidePwd.png",
|
SelectedImagePath = "Account/HidePwd.png",
|
//BackgroundColor=UserCenterColor.Current.Red,
|
Y = tempPwdText.Y + Application.GetRealWidth(10),
|
X = Application.GetRealWidth(550),
|
IsSelected = true,
|
|
};
|
tempPwdLayout.AddChidren(hideBtn);
|
|
hideBtn.MouseUpEventHandler += (sender, e) =>
|
{
|
//
|
hideBtn.IsSelected = !hideBtn.IsSelected;
|
updateState(hideBtn, tempPwdText);
|
};
|
|
updateState(hideBtn, tempPwdText);
|
|
#endregion
|
|
#region 二维码
|
// FragmLayout
|
var qrCodeLayout = new FrameLayout
|
{
|
Width = Application.GetRealWidth(850),
|
Height = Application.GetRealWidth(657),
|
Y = tempPwdLayout.Bottom + Application.GetRealHeight(58),
|
Gravity = Gravity.CenterHorizontal,
|
};
|
|
this.AddChidren(qrCodeLayout);
|
// Image
|
var qrBackground = new ImageView
|
{
|
ImagePath = "Video/VideoQRCodeBackground.png",
|
|
};
|
qrCodeLayout.AddChidren(qrBackground);
|
|
//二维码
|
var btnQrCode = new PicViewControl(Application.GetRealWidth(358), Application.GetRealWidth(358), false);
|
btnQrCode.ImageBytes = QRCode.BytesFromText(Password, Application.GetRealWidth(358), Application.GetRealWidth(358));
|
btnQrCode.Gravity = Gravity.CenterHorizontal;
|
btnQrCode.Y = 0;
|
btnQrCode.Gravity = Gravity.Center;
|
qrCodeLayout.AddChidren(btnQrCode);
|
|
#endregion
|
}
|
|
private void updateState(Button btn, EditText editText)
|
{
|
editText.SecureTextEntry = btn.IsSelected;
|
}
|
|
/// <summary>
|
/// 获取门锁临时密码
|
/// </summary>
|
static async void IniTempPassword()
|
{
|
VideoMachine.tempPassword.Code = getCode();
|
string pwd = VideoMachine.tempPassword.Code;
|
var jobject = new JObject();
|
jobject.Add("communityID", VideoMachine.tempPassword.CommunityID);//社区 ID
|
jobject.Add("fromTime", VideoMachine.tempPassword.FromTime);//开始时间
|
jobject.Add("validTime", VideoMachine.tempPassword.ValidTime);//有效时间
|
jobject.Add("unitno", VideoMachine.tempPassword.Unitno);//单元号
|
jobject.Add("roomno", VideoMachine.tempPassword.Roomno);//房间号
|
jobject.Add("code", pwd);
|
jobject.Add("userKey", VideoMachine.tempPassword.UserKey);
|
jobject.Add("timestamp", VideoMachine.GetTomorrowTimeStamp());
|
jobject.Add("secretKey", VideoMachine.tempPassword.SecretKey);
|
jobject.Add("method", VideoMachine.tempPassword.Method);
|
jobject.Add("numTimes", VideoMachine.tempPassword.NumTimes);
|
|
|
var url = "http://112.74.164.111:180/api.php/Device/setdynamicpwd";
|
var str = await Send.HttpWebRequest(url, jobject.ToString(), "POST", 3, true);
|
if (!string.IsNullOrEmpty(str))
|
{
|
try
|
{
|
var json = JObject.Parse(str);
|
if (json != null)
|
{
|
var stateCode = json["resCode"].ToString();
|
if (stateCode != "0")
|
pwd = "创建失败";
|
}
|
}
|
catch { }
|
}
|
Password = pwd;
|
}
|
|
private static string getCode()
|
{
|
Random rand = new Random();
|
string code = "";
|
for (int ctr = 0; ctr < 6; ctr++)
|
{
|
code += rand.Next(10).ToString();
|
}
|
return code;
|
}
|
}
|
}
|