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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
using System;
using Newtonsoft.Json.Linq;
using Shared.Common;
using System.Collections.Generic;
using Shared.Phone.Device.Logic;
 
namespace Shared.Phone.Device.VideoIntercom
{
    public class VideoMachine : FrameLayout
    {
        public VideoMachine()
        {
        }
 
        public static TempPassword tempPassword = null;
 
        public void Show(List<VideoCalss> videoInfosLists)
        {
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.TextID = R.MyInternationalizationString.videoIntercom;
            view.clickBtn.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); };
 
            var middle = new VerticalRefreshLayout
            {
                Y = view.topRowLayout.Bottom,
                Height = Application.GetRealHeight(Method.H - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
 
            for (int i = 0; i < videoInfosLists.Count; i++)
            {
                var videoInfos = videoInfosLists[i];
                var fLayout = new FrameLayout
                {
                    Height = Application.GetRealHeight(160),
                    BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
                };
                middle.AddChidren(fLayout);
                var iconBtn = new Button
                {
                    Width = Application.GetMinRealAverage(81),
                    Height = Application.GetMinRealAverage(81),
                    X = Application.GetRealWidth(58),
                    Y = Application.GetRealHeight(40),
                    UnSelectedImagePath = "Item/videoIntercom.png",
                };
                fLayout.AddChidren(iconBtn);
                var nameBtn = new Button
                {
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                    TextSize = 15,
                    Y = Application.GetRealHeight(30),
                    X = Application.GetRealWidth(176),
                    Height = Application.GetRealHeight(60),
                    Width = Application.GetRealWidth(400),
                    Text = videoInfos.DeviceName,
                };
                fLayout.AddChidren(nameBtn);
 
                var name1Btn = new Button
                {
                    Text = videoInfos.RoomName,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
                    TextSize = 12,
                    Y = nameBtn.Bottom + Application.GetRealHeight(3),
                    X = Application.GetRealWidth(176),
                    Height = Application.GetRealHeight(60),
                    Width = Application.GetRealWidth(400),
                };
                fLayout.AddChidren(name1Btn);
 
                var nextBtn = new Button
                {
                    Width = Application.GetMinRealAverage(104),
                    Height = Application.GetMinRealAverage(104),
                    UnSelectedImagePath = "Item/videoIntercomNext.png",
                    X = Application.GetRealWidth(743 + 176),
                    Y = Application.GetRealHeight(30),
                };
                fLayout.AddChidren(nextBtn);
 
                var lineBtn = new Button
                {
                    Width = Application.GetRealWidth(845),
                    Height = 1,
                    Y = fLayout.Height - 1,
                    X = Application.GetRealWidth(176),
                    BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
                };
                fLayout.AddChidren(lineBtn);
                var clickBtn = new Button
                {
                    Height = Application.GetRealHeight(160),
                };
                fLayout.AddChidren(clickBtn);
 
                clickBtn.MouseUpEventHandler += (sen, e) =>
                 {
#if iOS
                     GateWay.Ios.ESVideoInfo eSVideoInfo = new GateWay.Ios.ESVideoInfo();
                     eSVideoInfo.DeviceName = videoInfos.DeviceName;
                     eSVideoInfo.ESVideoUUID = videoInfos.ESVideoUUID;
                     eSVideoInfo.ESRoomID = videoInfos.ESRoomID;
                     eSVideoInfo.RoomName = videoInfos.RoomName;
                     GateWay.Ios.ESVideo.ShowESVideoMonitor(eSVideoInfo);
#elif Android
                     ((BaseActivity)Application.Activity).AudioRecord((result) =>
                     {
                         if (result == false) { return; }
                         Shared.Phone.VideoPhone.ESVideoInfo eSVideoInfo = new Shared.Phone.VideoPhone.ESVideoInfo();
                         eSVideoInfo.DeviceName = videoInfos.DeviceName;
                         eSVideoInfo.ESVideoUUID = videoInfos.ESVideoUUID;
                         eSVideoInfo.ESRoomID = videoInfos.ESRoomID;
                         eSVideoInfo.RoomName = videoInfos.RoomName;
                         Shared.Phone.VideoPhone.ESVideo.ShowESVideoMonitor(eSVideoInfo);
                     });
#endif
                 };
 
            }
 
            addQRCodeLayout(middle);
 
        }
 
        private void addQRCodeLayout(VerticalRefreshLayout middle)
        {
            //
            var fLayout = new FrameLayout
            {
                Height = Application.GetRealHeight(160),
                BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
            };
 
            //二维码icon
            var iconBtn = new Button
            {
                Width = Application.GetMinRealAverage(81),
                Height = Application.GetMinRealAverage(81),
                X = Application.GetRealWidth(58),
                Y = Application.GetRealHeight(40),
                UnSelectedImagePath = "Item/QRCode.png",
            };
            fLayout.AddChidren(iconBtn);
 
            // 名称
            var nameBtn = new Button
            {
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                TextSize = 15,
                Y = Application.GetRealHeight(50),
                X = Application.GetRealWidth(176),
                Height = Application.GetRealHeight(60),
                Width = Application.GetRealWidth(400),
                Text = "二维码/临时密码",
            };
            fLayout.AddChidren(nameBtn);
 
            //右箭头
            var nextBtn = new Button
            {
                Width = Application.GetMinRealAverage(104),
                Height = Application.GetMinRealAverage(104),
                UnSelectedImagePath = "Item/videoIntercomNext.png",
                X = Application.GetRealWidth(743 + 176),
                Y = Application.GetRealHeight(30),
            };
            fLayout.AddChidren(nextBtn);
 
            var clickBtn = new Button
            {
                Height = Application.GetRealHeight(160),
            };
            fLayout.AddChidren(clickBtn);
 
            clickBtn.MouseUpEventHandler += (sen, e) =>
            {
                var qrCode = new TempQRCode();
                UserView.HomePage.Instance.AddChidren(qrCode);
                UserView.HomePage.Instance.PageIndex += 1;
                qrCode.Show();
            };
 
 
            middle.AddChidren(fLayout);
        }
 
        /// <summary>
        /// 判断账号是否支持可视对讲
        /// </summary>
        /// <param name="topFrameLayout">可视对讲图标的父控件</param>
        public async static void AccountSupportVideo(FrameLayout topFrameLayout)
        {
            var jobject = new JObject();
            jobject.Add("RequestVersion", CommonPage.RequestVersion);
            jobject.Add("RequestSource", "0");
            jobject.Add("HomeID", Config.Instance.HomeId);
            var url = "https://developer.hdlcontrol.com/ProposedProductionApi/VideoIntercom/CheckBindRecord";
            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["StateCode"].ToString();
                        //可视对讲快捷方式
                        var videoIntercomBtn = new Button();
                        videoIntercomBtn.Gravity = Gravity.CenterVertical;
                        videoIntercomBtn.UnSelectedImagePath = "Item/videoIntercom.png";
                        videoIntercomBtn.Width = Application.GetMinRealAverage(69);
                        videoIntercomBtn.Height = Application.GetMinRealAverage(69);
                        List<VideoCalss> videoList= new List<VideoCalss>();
                        if (stateCode == "Success")
                        {//判断这个账号是否绑定;
                            topFrameLayout.AddChidren(videoIntercomBtn);
                            CloudsVideo cloudsVideo = Newtonsoft.Json.JsonConvert.DeserializeObject<CloudsVideo>(json["ResponseData"].ToString());
                            videoList = await GetVideoInfoList(cloudsVideo);
                        }
                        if (UserCenter.UserCenterResourse.ResidenceOption.SafetyShortcut)
                        {
                            videoIntercomBtn.X = Application.GetRealWidth(746 + 10);
                        }
                        else
                        {
                            videoIntercomBtn.X = Application.GetRealWidth(850 + 10);
                        }
                        videoIntercomBtn.MouseUpEventHandler += (sender, e) =>
                        {
 
                            var videoMachine = new Device.VideoIntercom.VideoMachine();
                            UserView.HomePage.Instance.AddChidren(videoMachine);
                            UserView.HomePage.Instance.PageIndex += 1;
                            videoMachine.Show(videoList);
                            
                        };
                    }
                }
                catch { }
            }
        }
 
        /// <summary>
        /// 获取可视对讲列表
        /// </summary>
        static async System.Threading.Tasks.Task<List<VideoCalss>> GetVideoInfoList(CloudsVideo clouds)
        {
            List<VideoCalss> eSVideoInfosList = new List<VideoCalss>();
            tempPassword = new TempPassword();
            var jobject = new JObject();
            jobject.Add("cmtID", clouds.FLCommunityID);
            jobject.Add("unitno", clouds.FLBuildingID);
            jobject.Add("method", "getUUIDList");
            var url = " http://112.74.164.111:180/api.php/Device/getmonitorUUID";
            var str = await Send.HttpWebRequest(url, jobject.ToString(), "POST");
            if (string.IsNullOrEmpty(str))
            {
                return eSVideoInfosList;
            }
            var json = JObject.Parse(str);
            if (json == null)
            {
                return eSVideoInfosList;
            }
            if (json["resCode"].ToString() != "0")
            {
                return eSVideoInfosList;
            }
            var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Dictionary<string, string>>>(json["list"].ToString());
            if (list.Count == 0)
            {
                return eSVideoInfosList;
            }
            foreach (var videoInfo in list)
            {
                VideoCalss eSVideoInfo = new VideoCalss();
                eSVideoInfo.ESRoomID = int.Parse(clouds.FLRoomID);
                string str1 = clouds.FLBuildingID.Substring(0, 2).TrimStart('0');
                string str2 = clouds.FLBuildingID.Substring(2, 2).TrimStart('0');
                eSVideoInfo.RoomName = str1 +Language.StringByID( R.MyInternationalizationString.dong) + str2 + Language.StringByID(R.MyInternationalizationString.unit);
                eSVideoInfo.DeviceName = videoInfo["aliasName"];
                if (videoInfo["uuid"].Contains(","))
                {
                    var uuid = videoInfo["uuid"].Split(',');
                    eSVideoInfo.ESVideoUUID = uuid[0];
                }
                else
                {
                    eSVideoInfo.ESVideoUUID = videoInfo["uuid"];
                }
                eSVideoInfosList.Add(eSVideoInfo);
            }
 
            // 初始化tempPassword对象
            tempPassword.CommunityID = clouds.FLCommunityID;
            tempPassword.FromTime = GetCurrentTimeStamp();
            tempPassword.ValidTime = GetTomorrowTimeStamp();
            tempPassword.Unitno = clouds.FLBuildingID;
            tempPassword.Roomno = clouds.FLRoomID;
            tempPassword.Code = getCode();
            tempPassword.NumTimes = "5";
            tempPassword.UserKey = clouds.UserKey;
            tempPassword.SecretKey= clouds.FLSecretKey;
            return eSVideoInfosList;
        }
 
        /// <summary>
        /// 获取当前时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentTimeStamp()
        {
            //TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            //return Convert.ToInt64(ts.TotalSeconds).ToString();
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            return ((long)(DateTime.Now - startTime).TotalSeconds).ToString(); // 相差秒数
        }
 
        /// <summary>
        /// 获取当前时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetTomorrowTimeStamp()
        {
            //TimeSpan ts = DateTime.Now.AddDays(1) - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            //return Convert.ToInt64(ts.TotalSeconds).ToString();
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            return ((long)(DateTime.Now.AddDays(1) - startTime).TotalSeconds).ToString(); // 相差秒数
        }
 
        private static string getCode()
        {
            Random rand = new Random();
            string code = "";
            for (int ctr = 0; ctr < 6; ctr++)
            {
                code += rand.Next(10).ToString();
            }
            return code;
        }
    }
 
   
    public class VideoCalss
    {
        /// <summary>
        /// 室外机的UUID
        /// 例:JJY000007FSEYX
        /// </summary>
        public string ESVideoUUID = string.Empty;
        /// <summary>
        /// 当前用户的房间ID
        /// 例:0801
        /// </summary>
        public int ESRoomID;
        /// <summary>
        /// 室外机的名称
        /// 例:室外机
        /// </summary>
        public string DeviceName = string.Empty;
        /// <summary>
        /// 房间命名
        /// 例:8栋1单元0801
        /// </summary>
        public string RoomName = string.Empty;
 
    }
 
    public class CloudsVideo
    {
        /// <summary>
        /// 栋楼单元号
        /// </summary>
        public string FLBuildingID = string.Empty;
        /// <summary>
        /// 那栋楼的名称
        /// </summary>
        public string FLBuildingName = string.Empty;
        /// <summary>
        /// 小区ID
        /// </summary>
        public string FLCommunityID = string.Empty;
        /// <summary>
        /// 房间ID
        /// </summary>
        public string FLRoomID = string.Empty;
        /// <summary>
        /// 住宅ID
        /// </summary>
        public string HomeID = string.Empty;
 
        public string FLSecretKey = string.Empty;
 
        /// <summary>
        /// 丰林可视对讲 UserKey
        /// </summary>
        public string UserKey = string.Empty;
 
    }
 
}