HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2020-12-31 fe3b2466c68b5db70d38e78039703add3b8b1dfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
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;
        }
    }
}