黄学彪
2019-11-20 5174e95a428876018ce3372f3dbc24b2861ea472
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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Shared;
using Shared.Common;
using Shared.Common.ResponseEntity;
using Shared.Phone.UserCenter;
 
namespace ZigBee.Device
{
    public class DoorLock : Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo
    {
        public DoorLock()
        {
            this.Type = DeviceType.DoorLock;
        }
 
        #region 门锁本地变量
        /// <summary>
        /// 本地门锁用户和账户列表
        /// key:门锁用户ID
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, LocaDoorLockObj> localDoorLockUserList = new Dictionary<int, LocaDoorLockObj>();
        /// <summary>
        /// 本地门账户列表
        /// key:账户ID(主账户是GUID,子账户是分享过来的账户ID)
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, LocaDoorLockObj> localDoorLockAccountList = new Dictionary<string, LocaDoorLockObj>();
 
        public string currentUserDisplayMethod = string.Empty;//当前用户显示方式
        //本地所有账户列表
        public List<Shared.Phone.UserCenter.MemberInfoRes> localAllAccountList = new List<Shared.Phone.UserCenter.MemberInfoRes> { };
        public string LocalTempPassword = string.Empty;//本地生成的临时密码
        public Dictionary<string, bool> IsFreezeAccount = new Dictionary<string, bool> { };//是否冻结子账户
        public Dictionary<string, bool> HasRemoteUnlockAccess = new Dictionary<string, bool> { };//是否给子账户拥有远程开锁的条件
        public Dictionary<string, bool> IsFailedToGetDoorLockInfo = new Dictionary<string, bool> { };//是否获取门锁数据失败
        public string RemoteUnlockPassword = string.Empty;//远程开锁密码
 
        public static int RemoteUnlockCount = 5;//远程开锁次数限制
        public static DateTime maxValue = DateTime.MaxValue;
        public static DateTime minValue = DateTime.MinValue;
 
        #region 临时密码信息
        /// <summary>
        /// 用户管理发送数据回复
        /// </summary>
        public TempPasswordObject tempPasswordObject;
        /// <summary>
        /// 临时密码本地对象
        /// </summary>
        [System.Serializable]
        public class TempPasswordObject
        {
            /// <summary>
            ///  临时密码ID
            /// </summary>
            public int UserId;
            /// <summary>
            /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null
            /// </summary>
            //public string PrimaryId;
            /// <summary>
            ///  6位有动态临时密码
            /// </summary>
            public string TempPassword;
            /// <summary>
            /// 门锁有效时间
            /// </summary>
            public DateTime ValidTime;
            /// <summary>
            /// 门锁失效时间
            /// </summary>
            public DateTime InValidTime;
        }
        #endregion
 
        #endregion
 
        #region 与云端通讯接口
        #region 门锁服务器发送基本信息
        /// <summary>
        ///  添加门锁
        /// </summary>
        public class BaseDoorLockServerData
        {
            /// <summary>
            /// RequestVersion
            /// </summary>
            public string RequestVersion = Shared.Common.CommonPage.RequestVersion;
            /// <summary>
            /// LoginAccessToken
            /// </summary>
            public string LoginAccessToken = Shared.Common.Config.Instance.Token;
            /// <summary>
            /// 住宅Id -->键名 : HomeId
            /// </summary>
            public string HomeId = Shared.Common.Config.Instance.HomeId;
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId
            /// </summary>
            public string DoorLockId = "";
            /// <summary>
            /// 门锁本地用户Id -->键名 : DoorLockLocalUserId
            /// </summary>
            public string DoorLockLocalUserId = "";
 
            /// <summary>
            /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl
            /// </summary>
            public bool IsOtherAccountCtrl = false;
        }
        #endregion
 
        #region 添加门锁
        /// <summary>
        ///  添加门锁
        /// </summary>
        public class AddDoorLockData : BaseDoorLockServerData
        {
            /// <summary>
            /// 云端帐号Id -->键名 : CloudAccountId
            /// </summary>
            public string CloudAccountId = "";
            /// <summary>
            /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选)
            /// </summary>
            public int OpenLockMode = 0;
            /// <summary>
            /// Data 相关内容(如:密码、指纹、IC卡 的二进制) -->键名 : Data (可选)
            public byte[] Data = null;
            /// <summary>
            /// 用户Id备注 -->键名 : UserIdRemarks
            /// </summary>
            public string UserIdRemarks = "";
            /// <summary>
            /// IsFreezeUser 是否冻结用户 -->键名 : IsFreezeUser (可选)
            /// </summary>
            public bool IsFreezeUser = false;
            /// <summary>
            /// IsTempUnlockAuthority 是否临时开锁权限 -->键名 : IsTempUnlockAuthority(可选)
            /// </summary>
            public bool IsTempUnlockAuthority = false;
            /// <summary>
            /// EntryTime 录入时间 -->键名 : EntryTime(可选)
            /// </summary>
            public DateTime EntryTime = System.DateTime.Now;
        }
 
        /// <summary>
        /// 添加门锁结果
        /// </summary>
        public class AddDoorLockDataRes
        {
            /// <summary>
            /// 响应的版本号,一般请求什么版本号,这里与之请求相同
            /// </summary>
            public string ResponseVersion = string.Empty;
            /// <summary>
            /// 响应状态码:
            ///<para>(1)Success 则[调用此接口操作成功], ResponseData则为null</para>
            ///<para>(2)ParameterOrEmpty,则响应字段中[ErrorInfo] 为错误信息, ResponseData则为null</para>
            ///(<para>3)NoLogin,则响应字段中[ErrorInfo] 为错误信息为[无效登录Token!]</para>
            ///<para>(4)NoRecord,则响应字段中[ErrorInfo] 为错误信息为[当前提交DoorLockId值在云端不存在,请确认值是否正确!]</para>
            ///<para>(5)DoorLockIdNoIsYou,则响应字段中[ErrorInfo] 为错误信息为[当前提交DoorLockId并不属于你当前帐号的,请确认值是否正确!]</para>
            /// </summary>
            public string StateCode = string.Empty;
        }
        #endregion
 
        #region 更新门锁
        /// <summary>
        ///   更新门锁
        /// </summary>
        public class RefreshDoorLockData : BaseDoorLockServerData
        {
            /// <summary>
            /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null
            /// </summary>
            public string PrimaryId = "";
            /// <summary>
            /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选)
            /// </summary>
            public int OpenLockMode = 0;
 
            /// <summary>
            /// 住宅Id (可选)
            /// </summary>
            public byte[] Data;
            /// <summary>
            /// 用户Id备注
            /// </summary>
            public string UserIdRemarks = "";
            /// <summary>
            /// 是否为管理员门锁
            /// </summary>
            public bool IsFreezeUser;
            /// <summary>
            /// 是否为管理员门锁
            /// </summary>
            public bool IsTempUnlockAuthority;
        }
        #endregion
 
        #region 删除门锁
        /// <summary>
        /// 删除门锁
        /// </summary>
        public class DeleteDoorLockData : BaseDoorLockServerData
        {
            /// <summary>
            /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null
            /// </summary>
            public string PrimaryId = "";
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId (可选)
            /// DelDoorLockDelType 门锁删除类型(0: 根椐门锁主键(云端主键)删除(单条删除)、1:根椐门锁Id批量删除(凡是与门锁Id相同都会删除)、2:根椐门锁Id及门锁本地用户Id批量删除(这个门锁Id这个门锁本地用户Id均会被删除)) -->键名 : DelDoorLockDelType 默认值: 0
            /// </summary>
            public int DelDoorLockDelType;
        }
        #endregion
 
        #region 添加门锁临时密码
        /// <summary>
        ///  添加门锁
        /// </summary>
        public class AddDoorLockTempPasswordData
        {
            /// <summary>
            /// RequestVersion
            /// </summary>
            public string RequestVersion = Shared.Common.CommonPage.RequestVersion;
            /// <summary>
            /// LoginAccessToken
            /// </summary>
            public string LoginAccessToken = Shared.Common.Config.Instance.Token;
            /// <summary>
            /// 住宅Id -->键名 : HomeId
            /// </summary>
            public string HomeId = Shared.Common.Config.Instance.HomeId;
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId
            /// </summary>
            public string LocalDoorLockId = "";
            /// <summary>
            /// 临时密码Id -->键名 : TempPwdId
            /// </summary>
            public string TempPwdId = "";
            /// <summary>
            /// 临时密码 -->键名 : TempPwd
            /// </summary>
            public string TempPwd = "";
            /// <summary>
            /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime  默认值: 0001/1/1
            /// </summary>
            public DateTime ValidBeginTime;
            /// <summary>
            /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime
            /// </summary>
            public DateTime ValidEndTime;
            /// <summary>
            /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl
            /// </summary>
            public bool IsOtherAccountCtrl = false;
        }
 
        /// <summary>
        /// 添加门锁结果
        /// </summary>
        public class AddDoorLockTempPasswordDataRes : AddDoorLockDataRes
        {
        }
        #endregion
 
        #region 删除门锁临时密码
        /// <summary>
        ///  删除门锁
        /// </summary>
        public class DelDoorLockTempPasswordData
        {
            /// <summary>
            /// RequestVersion
            /// </summary>
            public string RequestVersion = Shared.Common.CommonPage.RequestVersion;
            /// <summary>
            /// LoginAccessToken
            /// </summary>
            public string LoginAccessToken = Shared.Common.Config.Instance.Token;
            /// <summary>
            /// 住宅Id -->键名 : HomeId
            /// </summary>
            public string HomeId = Shared.Common.Config.Instance.HomeId;
            /// <summary>
            /// LocalDoorLockId 搜索本地门锁Id -->键名 : LocalDoorLockId  默认值: null
            /// </summary>
            public string LocalDoorLockId = "";
            /// <summary>
            /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl
            /// </summary>
            public bool IsOtherAccountCtrl = false;
        }
 
        /// <summary>
        /// 删除门锁结果
        /// </summary>
        public class DelDoorLockTempPasswordDataRes : AddDoorLockDataRes
        {
        }
        #endregion
 
        #region 更新门锁临时密码
        /// <summary>
        ///  更新门锁
        /// </summary>
        public class ModifyDoorLockTempPasswordData
        {
            /// <summary>
            /// RequestVersion
            /// </summary>
            public string RequestVersion = Shared.Common.CommonPage.RequestVersion;
            /// <summary>
            /// LoginAccessToken
            /// </summary>
            public string LoginAccessToken = Shared.Common.Config.Instance.Token;
            /// <summary>
            /// 住宅Id -->键名 : HomeId
            /// </summary>
            public string HomeId = Shared.Common.Config.Instance.HomeId;
            /// <summary>
            /// 门锁密码主键(获取门锁密码分页中的Id) -->键名 : DoorLockPwdId
            /// </summary>
            public string DoorLockPwdId = "";
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId
            /// </summary>
            public string LocalDoorLockId = "";
            /// <summary>
            /// 临时密码Id -->键名 : TempPwdId
            /// </summary>
            public string TempPwdId = "";
            /// <summary>
            /// 临时密码 -->键名 : TempPwd
            /// </summary>
            public string TempPwd = "";
            /// <summary>
            /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime  默认值: 0001/1/1
            /// </summary>
            public DateTime ValidBeginTime;
            /// <summary>
            /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime
            /// </summary>
            public DateTime ValidEndTime;
            /// <summary>
            /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl
            /// </summary>
            public bool IsOtherAccountCtrl = false;
        }
 
        /// <summary>
        /// 添加门锁结果
        /// </summary>
        public class ModigDoorLockTempPasswordDataRes : AddDoorLockDataRes
        {
        }
        #endregion
 
        #region 获取门锁临时密码
        /// <summary>
        ///  获取门锁
        /// </summary>
        public class GetDoorLockTempPasswordData
        {
            /// <summary>
            /// RequestVersion
            /// </summary>
            public string RequestVersion = Shared.Common.CommonPage.RequestVersion;
            /// <summary>
            /// LoginAccessToken
            /// </summary>
            public string LoginAccessToken = Shared.Common.Config.Instance.Token;
            /// <summary>
            /// 住宅Id -->键名 : HomeId
            /// </summary>
            public string HomeId = Shared.Common.Config.Instance.HomeId;
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId
            /// </summary>
            public string LocalDoorLockId = "";
            /// <summary>
            /// 临时密码Id -->键名 : TempPwdId
            /// </summary>
            public string TempPwdId = "";
            /// <summary>
            /// 临时密码 -->键名 : TempPwd
            /// </summary>
            public string TempPwd = "";
            /// <summary>
            /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime  默认值: 0001/1/1
            /// </summary>
            public DateTime? ValidBeginTime;
            /// <summary>
            /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime
            /// </summary>
            public DateTime? ValidEndTime;
            /// <summary>
            /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl
            /// </summary>
            public bool IsOtherAccountCtrl = false;
        }
 
        /// <summary>
        /// 获取门锁临时密码结果
        /// </summary>
        [Serializable]
        public class GetDoorLockTempPasswordDataRes
        {
            public List<CloudDoorLockTempPasswordObj> PageData = new List<CloudDoorLockTempPasswordObj>();
            public int PageIndex;
            public int PageSize;
            public int TotalCount;
            public int TotalPages;
            public bool HasPreviousPage;
            public bool HasNextPage;
        }
        [Serializable]
        public class CloudDoorLockTempPasswordObj
        {
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId
            /// </summary>
            public string LocalDoorLockId = "";
            /// <summary>
            /// 临时密码Id -->键名 : TempPwdId
            /// </summary>
            public string TempPwdId = "";
            /// <summary>
            /// 临时密码 -->键名 : TempPwd
            /// </summary>
            public string TempPwd = "";
            /// <summary>
            /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime  默认值: 0001/1/1
            /// </summary>
            public DateTime ValidBeginTime;
            /// <summary>
            /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime
            /// </summary>
            public DateTime ValidEndTime;
            /// <summary>
            /// 【门锁云端主键】,用于【添加门锁历史】接口中的DoorLockId参数及【删除门锁】接口中的PrimaryId参数,注意不是网关中的【门锁Id
            /// </summary>
            public string Id;
            /// <summary>
            /// 创建时间
            /// </summary>
            public DateTime CreatedOnUtc;
        }
 
        /// <summary>
        /// 从云服务器中获取门锁临时密码
        /// </summary>
        public static async System.Threading.Tasks.Task<GetDoorLockTempPasswordDataRes> GetDoorLockTempPasswordFromServer(string RequestName, GetDoorLockTempPasswordData getDoorLockTempPasswordData)
        {
            return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<GetDoorLockTempPasswordDataRes>>)(async () =>
            {
                GetDoorLockTempPasswordDataRes listInfo = null;
                var revertObj = await SendDoorLockToServer(RequestName, getDoorLockTempPasswordData);
                if (revertObj != null && revertObj.ResponseData != null)
                {
                    var result = revertObj.ResponseData.ToString();
                    if (result != null)
                    {
                        listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDoorLockTempPasswordDataRes>(result);
                    }
                }
                return listInfo;
            }));
        }
        #endregion
 
        #region 获取门锁
        /// <summary>
        ///  获取门锁
        /// </summary>
        public class GetDoorLockData : BaseDoorLockServerData
        {
            /// <summary>
            /// 云端帐号Id -->键名 : CloudAccountId (可选)
            /// </summary>
            public string CloudAccountId = "";
        }
 
        [Serializable]
        public class GetDoorLockDataRes
        {
            public List<CloudDoorLockObj> PageData = new List<CloudDoorLockObj>();
            public int PageIndex;
            public int PageSize;
            public int TotalCount;
            public int TotalPages;
            public bool HasPreviousPage;
            public bool HasNextPage;
        }
        [Serializable]
        public class CloudDoorLockObj
        {
            /// <summary>
            /// 门锁Id
            /// </summary>
            public string DoorLockId;
            /// <summary>
            /// 云端帐号Id
            /// </summary>
            public string CloudAccountId;
            /// <summary>
            /// OpenLockMode 开锁方式(密码、指纹、IC卡)
            /// </summary>
            public int OpenLockMode;
            /// <summary>
            /// 门锁本地用户Id
            /// </summary>
            public string DoorLockLocalUserId;
            /// <summary>
            /// 住宅Id
            /// </summary>
            public byte[] Data;
            /// <summary>
            /// 用户Id备注
            /// </summary>
            public string UserIdRemarks;
            /// <summary>
            /// 是否为管理员门锁
            /// </summary>
            public bool IsAdminDoorLock;
            /// <summary>
            /// 是否为管理员门锁
            /// </summary>
            public bool IsFreezeUser;
            /// <summary>
            /// 是否为管理员门锁
            /// </summary>
            public bool IsTempUnlockAuthority;
            /// <summary>
            /// 录入时间
            /// </summary>
            public DateTime EntryTime;
            /// <summary>
            /// 最后更新时间
            /// </summary>
            public string LastChangeTime;
            /// <summary>
            /// 【门锁云端主键】,用于【添加门锁历史】接口中的DoorLockId参数及【删除门锁】接口中的PrimaryId参数,注意不是网关中的【门锁Id
            /// </summary>
            public string Id;
            /// <summary>
            /// 创建时间
            /// </summary>
            public DateTime CreatedOnUtc;
        }
 
        /// <summary>
        /// 获取门锁云服务器
        /// </summary>
        public static async System.Threading.Tasks.Task<GetDoorLockDataRes> GetDoorLockInfoFromServer(string RequestName, GetDoorLockData getDoorLockData)
        {
            return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<GetDoorLockDataRes>>)(async () =>
            {
                GetDoorLockDataRes listInfo = null;
                var revertObj = await SendDoorLockToServer(RequestName, getDoorLockData);
                if (revertObj != null && revertObj.ResponseData != null)
                {
                    var result = revertObj.ResponseData.ToString();
                    if (result != null)
                    {
                        listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDoorLockDataRes>(result);
                    }
                }
                return listInfo;
            }));
        }
        #endregion
 
        /// <summary>
        /// 发送门锁数据到服务器,只回复状态,没有数据处理
        /// </summary>
        /// <returns>获取从接口那里取到的ResponsePack</returns>
        /// <param name="RequestName">访问地址</param>
        /// <param name="obj">一个类</param>
        public static async Task<ResponsePack> SendDoorLockToServer(string RequestName, object obj)
        {
            try
            {
                //序列化对象
                var requestJson = JsonConvert.SerializeObject(obj);
                var byteData = System.Text.Encoding.UTF8.GetBytes(requestJson);
                byte[] result1 = null;
                //访问接口
                if (UserCenterResourse.UserInfo.AuthorityNo == 1)
                {
                    result1 = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, byteData);
                }
                else
                {
                    result1 = await CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, byteData);
                }
                if (result1 != null)
                {
                    var result2 = Encoding.UTF8.GetString(result1);
                    if (result2 != null)
                    {
                        var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResponsePack>(result2);
                        return result;
                    }
                }
                return null;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }
 
        /// <summary>
        /// 获取子账户信息
        /// </summary>
        static List<Shared.Phone.UserCenter.MemberInfoRes> DoorLockAccountList = new List<Shared.Phone.UserCenter.MemberInfoRes> { };
        public static async System.Threading.Tasks.Task<List<Shared.Phone.UserCenter.MemberInfoRes>> GetSubAccountByDistributedMark()
        {
            DoorLockAccountList.Clear();
            return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<List<Shared.Phone.UserCenter.MemberInfoRes>>>)(async () =>
           {
               var pra = new Shared.Phone.UserCenter.MemberListInfoPra();
               string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra);
               var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result);
               return listInfo;
           }));
        }
 
        /// <summary>
        /// 服务器获取数据失败提示
        /// </summary>
        public void FailureToServer()
        {
            Application.RunOnMainThread(() =>
            {
                var alert = new Alert(Language.StringByID(Shared.R.MyInternationalizationString.TIP), Language.StringByID(Shared.R.MyInternationalizationString.RequestServerFailed), Language.StringByID(Shared.R.MyInternationalizationString.Confrim));
                alert.Show();
            });
        }
        #endregion
 
        #region  与网关通讯接口
        #region 门锁操作事件通知
        /// <summary>
        /// 门锁操作事件通知
        /// </summary>
        public DoorLockOperatingEventNotificationCommand doorLockOperatingEventNotificationCommand;
        /// <summary>
        /// 门锁操作事件通知
        /// </summary>
        [System.Serializable]
        public class DoorLockOperatingEventNotificationCommand
        {
            /// <summary>
            /// 用户id
            ///门锁本地录入的密码、指纹、感应卡都有唯一对应的用户Id
            /// </summary>
            public int UserID;
            /// <summary>
            /// 事件触发源
            /// 常用:
            /// 0:Keypad(键盘/密码);3:RFID(射频卡);15:指纹
            ///不常用:
            /// 1:RF(Zigbee无线);2:Manual(手动);255:Indeterminate(不确定)
            /// </summary>
            public int OperationEventSoure;
            /// <summary>
            /// 事件码
            /// 常用:
            /// 键盘/密码,指纹、感应卡:1:Lock命令成功事件;2:Unlock命令成功事件
            ///不常用:
            /// 请查看枚举
            /// </summary>
            public int OperationEventCode;
            /// <summary>
            /// 保留,默认0
            /// </summary>
            public int PIN;
            /// <summary>
            /// 门锁本地当前时间的时间戳
            /// </summary>
            public int ZigbeeLocalTime;
        }
 
        public class AccountsObj
        {
            /// <summary>
            /// 关联app账号
            /// </summary>
            public string Account;
            /// <summary>
            /// 保留
            /// </summary>
            public int Type;
            /// <summary>
            ///  保留
            /// </summary>
            public int Status;
        }
 
        /// <summary>
        /// “OperationEventSoure”列表
        /// </summary>
        public enum OperationEventSoure
        {
            /// <summary>
            /// 键盘/密码
            /// </summary>
            Keypad = 0,
            /// <summary>
            /// Zigbee无线
            /// </summary>
            RF = 1,
            /// <summary>
            /// 手动
            /// </summary>
            Manual = 2,
            /// <summary>
            /// 射频卡
            /// </summary>
            RFID = 3,
            /// <summary>
            /// 指纹
            /// </summary>
            Fingerprint = 15,
            /// <summary>
            /// Indeterminate(不确定)
            /// </summary>
            Indeterminate = 255,
        }
 
        /// <summary>
        /// “OperationEventSoure”类型为“Keypad”即密码 的“OperationEventCode”事件
        /// </summary>
        public enum KeypadEventDescription
        {
            /// <summary>
            /// 未知事件
            /// </summary>
            UnknownEvent = 0,
            /// <summary>
            /// Lock命令成功事件
            /// </summary>
            LockSuccessEvent = 1,
            /// <summary>
            /// Unlock命令成功事件
            /// </summary>
            UnlockSuccessEvent = 2,
            /// <summary>
            /// Lock命令:error,invalid PIN事件
            /// </summary>
            LockInvalidPinEvent = 3,
            /// <summary>
            /// Lock命令:error,invalid schedule事件
            /// </summary>
            LockInvalidScheduleEvent = 4,
            /// <summary>
            /// Unlock命令:error,invalid PIN事件
            /// </summary>
            UnlockInvalidPinEvent = 5,
            /// <summary>
            /// Unlock命令:error,invalid schedule事件Unlock命令:error,invalid schedule事件
            /// </summary>
            UnlockInvalidScheduleEvent = 6,
            /// <summary>
            /// 非访问用户操作事件
            /// </summary>
            NonAccess = 15,
        }
 
        /// <summary>
        /// “OperationEventSoure”类型为“RF” 的“OperationEventCode”事件
        /// </summary>
        public enum RfEventDescription
        {
            /// <summary>
            /// 未知事件
            /// </summary>
            UnknownEvent = 0,
            /// <summary>
            /// Lock命令成功事件
            /// </summary>
            LockSuccessEvent = 1,
            /// <summary>
            /// Unlock命令成功事件
            /// </summary>
            UnlockSuccessEvent = 2,
            /// <summary>
            /// Lock命令:error,invalid code事件
            /// </summary>
            LockInvalidPinEvent = 3,
            /// <summary>
            /// Lock命令:error,invalid schedule事件
            /// </summary>
            LockInvalidScheduleEvent = 4,
            /// <summary>
            /// Unlock命令:error,invalid code事件
            /// </summary>
            UnlockInvalidPinEvent = 5,
            /// <summary>
            /// Unlock命令:error,invalid schedule事件
            /// </summary>
            UnlockInvalidScheduleEvent = 6,
        }
 
        /// <summary>
        /// “OperationEventSoure”类型为“Manual” 的“OperationEventCode”事件
        /// </summary>
        public enum ManualEventDescription
        {
            /// <summary>
            /// 未知事件
            /// </summary>
            UnknownEvent = 0,
            /// <summary>
            /// Thumbturn Lock;手动转动上锁
            /// </summary>
            ThumbturnLockEvent = 1,
            /// <summary>
            /// Thumbturn Unlock;手动转动解锁
            /// </summary>
            UnlockSuccessEvent = 2,
            /// <summary>
            /// One touch Lock;一键上锁
            /// </summary>
            LockInvalidPinEvent = 7,
            /// <summary>
            ///Key Lock;按键上锁
            /// </summary>
            LockInvalidScheduleEvent = 8,
            /// <summary>
            /// Key Unlock;按键解锁
            /// </summary>
            UnlockInvalidPinEvent = 9,
            /// <summary>
            /// Auto lock;自动上锁
            /// </summary>
            UnlockInvalidScheduleEvent = 10,
            /// <summary>
            /// Schedule Lock;时间表上锁
            /// </summary>
            ScheduleLockEvent = 11,
            /// <summary>
            /// Schedule Unlock;时间表解锁
            /// </summary>
            ScheduleUnlockEvent = 12,
            /// <summary>
            /// Manual Lock(Key or Thumbturn);手动上锁
            /// </summary>
            ManualLockEvent = 13,
            /// <summary>
            ///anual Unlock(Key or Thumbturn);手动解锁
            /// </summary>
            ManualUnlockEvent = 14,
        }
 
        /// <summary>
        /// “OperationEventSoure”类型为“RFID” 的“OperationEventCode”事件
        /// </summary>
        public enum RfidEventDescription
        {
            /// <summary>
            /// 未知事件
            /// </summary>
            UnknownEvent = 0,
            /// <summary>
            /// Lock命令成功事件
            /// </summary>
            LockSuccessEvent = 1,
            /// <summary>
            /// Unlock命令成功事件
            /// </summary>
            UnlockSuccessEvent = 2,
            /// <summary>
            /// Lock命令:error,invalid RFID ID事件
            /// </summary>
            LockInvalidRfidIdEvent = 3,
            /// <summary>
            /// Lock命令:error,invalid schedule事件
            /// </summary>
            LockInvalidScheduleEvent = 4,
            /// <summary>
            /// Unlock命令:error,invalid RFID ID事件
            /// </summary>
            UnlockInvalidRfidIdEvent = 5,
            /// <summary>
            /// Unlock命令:error,invalid schedule事件
            /// </summary>
            UnlockInvalidScheduleEvent = 6,
        }
        #endregion
 
        #region 门锁编程事件通知
        /// <summary>
        /// 门锁编程事件通知
        /// </summary>
        public DoorLockProgrammingEventNotificationCommand doorLockProgrammingEventNotificationCommand;
        /// <summary>
        /// 门锁编程事件通知
        /// </summary>
        [System.Serializable]
        public class DoorLockProgrammingEventNotificationCommand
        {
            /// <summary>
            /// 用户id
            ///门锁本地录入的密码、指纹、感应卡都有唯一对应的用户Id
            /// </summary>
            public int UserID;
            /// <summary>
            /// 保留
            /// </summary>
            public int UserType;
            /// <summary>
            ///  保留
            /// </summary>
            public int UserStatus;
            /// <summary>
            /// 编程事件触发源
            /// 常用:
            /// 0:Keypad(键盘/密码);3:RFID(射频卡);15:指纹
            ///不常用:
            /// 1:RF(Zigbee无线);2:Manual(手动);255:Indeterminate(不确定)
            /// </summary>
            public int ProgramEventSoure;
            /// <summary>
            /// 编程事件码
            /// 常用:
            /// 键盘/密码,指纹、感应卡:1:Lock命令成功事件;2:Unlock命令成功事件
            ///不常用:
            /// 请查看枚举
            /// </summary>
            public int ProgramEventCode;
            /// <summary>
            /// 保留,默认0
            /// </summary>
            public int PIN;
            /// <summary>
            /// 门锁本地当前时间的时间戳
            /// </summary>
            public int ZigbeeLocalTime;
        }
        #endregion
 
        #region 矫正门锁时间
        /// <summary>
        /// 矫正门锁时间
        /// </summary>
        /// <returns>The writable value async.</returns>
        /// <param name="timestamp">矫正门锁的时间</param>
        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> RectifyDoorLockTimeAsync(int timestamp)
        {
            if (Gateway == null)
            {
                return null;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                SetWritableValueResponAllData d = null;
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
 
                        if (temp == null)
                        {
                            d = new SetWritableValueResponAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
 
                    if (topic == gatewayID + "/" + "SetWritableValue_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
 
                        if (tempData == null)
                        {
                            d = new SetWritableValueResponAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
                            DebugPrintLog($"UI收到通知后的主题_{ topic}");
                        }
                    }
                };
                Gateway.Actions += action;
                DebugPrintLog("SetWritableValue_Actions 启动" + "_" + System.DateTime.Now.ToString());
 
                try
                {
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 10 }, { "Command", 120 } };
                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0 }, { "AttributeDataType", 226 }, { "AttributeData", timestamp } };
                    jObject.Add("Data", data);
                    Gateway.Send("SetWritableValue", jObject.ToString());
                }
                catch { }
 
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (d != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    d = new SetWritableValueResponAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("SetWritableValue_Actions 退出" + System.DateTime.Now.ToString());
 
                return d;
            });
        }
 
        /// <summary>
        /// 网关版本信息,网关反馈信息
        /// </summary>
        public SetWritableValueResponAllData setWritableValueResponAllData;
        /// <summary>
        /// 网关版本信息,网关反馈信息
        /// </summary>
        [System.Serializable]
        public class SetWritableValueResponAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 网关版本信息
            /// </summary>
            public SetWritableValueResponData setWritableValueResponData;
        }
 
        /// <summary>
        /// 设置可写属性的值的数据
        /// </summary>
        [System.Serializable]
        public class SetWritableValueResponData
        {
            /// <summary>
            /// 配置属性所在的cluster
            /// </summary>
            public int Cluster;
            /// <summary>
            /// 0:配置成功(若配置成功,下面的AttributeId字段不存在)
            ///<para>134:不支持该属性</para>
            ///<para>135:无效的属性值</para>
            ///<para>141:无效的数据类型</para>
            /// </summary>
            public int Status;
 
        }
        #endregion
        #endregion
 
        #region 与设备通讯接口(私有命令)
 
        #region 用户管理控制
        ///<summary >
        ///用户管理控制
        /// <para>passData:透传数据</para>
        /// </summary>
        public async System.Threading.Tasks.Task<DefaultControlResponseAllData> DefaultControlAsync(string passData)
        {
            DefaultControlResponseAllData result = null;
            if (Gateway == null)
            {
                result = new DefaultControlResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
 
                        if (temp == null)
                        {
                            result = new DefaultControlResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
 
                        else
                        {
                            result = new DefaultControlResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        {
                            result = new DefaultControlResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 16)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0002")
                                    {
                                        var tempD = new DefaultControlResponseData();
                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        result = new DefaultControlResponseAllData { defaultControlResponseData = tempD };
                                        DebugPrintLog($"UI收到通知后的主题_command:0450_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
 
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
 
                try
                {
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
 
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > 9000)
                {
                    result = new DefaultControlResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
 
                return result;
            });
        }
 
        /// <summary>
        /// 用户管理发送数据
        /// </summary>
        public string SetUserAccessData(int userId, AccessType accessType)
        {
            string data = "";
            string dataLength = "07";
            string dataComand1 = "50";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "03";
            string delUserTypeStr = "";
            string userIdStr = "";
            try
            {
                switch ((int)accessType)
                {
                    case 0:
                        delUserTypeStr = "00";
                        break;
                    case 1:
                        delUserTypeStr = "01";
                        break;
                    case 2:
                        delUserTypeStr = "20";
                        break;
                    case 3:
                        delUserTypeStr = "21";
                        break;
                }
                var sbString = new System.Text.StringBuilder();
                string temp = Convert.ToString(userId, 16);
 
                switch (temp.Length)
                {
                    case 1:
                        userIdStr = "0" + temp + "00";
                        break;
                    case 2:
                        userIdStr = temp + "00";
                        break;
                    case 3:
                        var thirdBit = temp.Substring(temp.Length - 2, 1);
                        userIdStr = temp + "0" + thirdBit;
                        break;
                    case 4:
                        userIdStr = temp;
                        break;
                }
                sbString.Append(userIdStr.ToString().ToUpper());
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                   delUserTypeStr + sbString;
            }
            catch { };
 
            return data;
        }
 
        /// <summary>
        /// 用户管理发送数据回复
        /// </summary>
        public DefaultControlResponseAllData defaultControlResponseAllData;
        [System.Serializable]
        public class DefaultControlResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 用户管理数据回复
            /// </summary>
            public DefaultControlResponseData defaultControlResponseData;
        }
 
        /// <summary>
        /// 用户管理数据回复
        /// </summary>
        [System.Serializable]
        public class DefaultControlResponseData
        {
            /// <summary>
            ///响应操作码(0-ffff)
            /// </summary>
            public string command = "";
            /// <summary>
            /// 状态值
            /// <para>默认响应结果:
            ///<para>0 删除成功</para>
            ///<para>1 删除失败</para>
            ///<para>2 用户不存在</para>
            ///<para>32 冻结成功</para>
            ///<para>34 冻结失败</para>
            ///<para>33 解冻成功</para>
            ///<para>35 解冻失败</para>
            /// </summary>
            public int status = -1;
        }
 
        public enum AccessType
        {
            /// <summary>
            /// 0x00 删除全部单次用户
            /// </summary>
            DelAllUsers = 0,
            /// <summary>
            /// 0x01 删除指定用户(按编号)
            /// </summary>
            DelCurrentUser = 1,
            /// <summary>
            /// 0x20 冻结指定用户
            /// </summary>
            DisEnable = 2,
            /// <summary>
            /// 0x21 解冻指定用户
            /// </summary>
            Enable = 3,
        }
        #endregion
 
        #region 验证门锁密码
        ///<summary >
        ///验证门锁密码
        ///<para>inputPassword:输入的门锁密码</para>
        /// </summary>
        public async System.Threading.Tasks.Task<VerifyPasswordResponseAllData> VerifyPasswordAsync(string inputPassword)
        {
            VerifyPasswordResponseAllData result = null;
            if (Gateway == null)
            {
                result = new VerifyPasswordResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
 
                        if (temp == null)
                        {
                            result = new VerifyPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
 
                        else
                        {
                            result = new VerifyPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        {
                            result = new VerifyPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 12)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0454")
                                    {
                                        var result1 = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
                                        result = new VerifyPasswordResponseAllData { result = result1 };
                                        DebugPrintLog($"UI收到通知后的主题_command:0454_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
 
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
 
                try
                {
                    var getPw = await GetkeyPassword();
                    var passData = VerifyPasswordData(inputPassword, getPw);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
 
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null && result.result == 0)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new VerifyPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
 
                return result;
            });
        }
        /// <summary>
        /// 验证门锁密码
        /// </summary>
        public string VerifyPasswordData(string keyPassword, int password, int fixedPassword = 0x190605)
        {
            string data = "";
            string dataLength = "08";
            string dataComand1 = "53";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "04";
            string passwordStr = "";
            try
            {
                int keyPasswordInt = System.Convert.ToInt32(keyPassword, 16);
                var pawStr = System.Convert.ToString((keyPasswordInt ^ password) + fixedPassword, 16);
                pawStr = pawStr.PadLeft(8, '0');
                for (int i = 6; i >= 0; i = i - 2)
                {
                    passwordStr += pawStr.Substring(i, 2);
                }
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                 passwordStr;
            }
            catch { };
            return data;
        }
 
        /// <summary>
        /// 用户管理发送数据回复
        /// </summary>
        public VerifyPasswordResponseAllData verifyPasswordResponseAllData;
        [System.Serializable]
        public class VerifyPasswordResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 用户管理数据回复
            /// <para>0:成功</para>
            ///<para>1:失败</para>
            /// </summary>
            public int result = -1;
        }
        #endregion
 
        #region 远程开锁
        ///<summary >
        ///远程开锁
        ///<para>inputPassword: 输入密码/para>
        /// </summary>
        public async System.Threading.Tasks.Task<RemoteResponseAllData> RemoteControlAsync(string inputPassword)
        {
            RemoteResponseAllData result = null;
            if (Gateway == null)
            {
                result = new RemoteResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
 
                        if (temp == null)
                        {
                            result = new RemoteResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
 
                        else
                        {
                            result = new RemoteResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    else if (topic == $"{gatewayID}/DoorLock/DoorLockOperatingEventNotificationCommand")
                    {
                        var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString());
                        if (OperatingEventNotificationDatad != null)
                        {
                            if (OperatingEventNotificationDatad.OperationEventSoure == 1 && OperatingEventNotificationDatad.OperationEventCode == 5)
                            {
                                result = new RemoteResponseAllData { IsPawDispear = true };
                            }
                        }
                    }
                    else if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        {
                            result = new RemoteResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 16)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0002")
                                    {
                                        var tempD = new RemoteResponseData();
                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        result = new RemoteResponseAllData { responseData = tempD };
                                        DebugPrintLog($"UI收到通知后的主题_command:0462_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
 
                try
                {
                    var getPw = await GetkeyPassword();
                    var passData = RemoteData(inputPassword, getPw);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
 
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 5000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result == null)
                    {
                        continue;
                    }
                    if (result.responseData != null && result.responseData.command == "0462")
                    {
                        break;
                    }
                    if (result.IsPawDispear == true)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new RemoteResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
 
                return result;
            });
        }
        /// <summary>
        /// 远程发送数据
        /// </summary>
        string RemoteData(string keyPassword, int password, int fixedPassword = 0x190605)
        {
            string data = "";
            string dataLength = "08";
            string dataComand1 = "62";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "04";
            string passwordStr = "";
            try
            {
                int keyPasswordInt = System.Convert.ToInt32(keyPassword, 16);
                var pawStr = System.Convert.ToString((keyPasswordInt ^ password) + fixedPassword, 16);
                pawStr = pawStr.PadLeft(8, '0');
                for (int i = 6; i >= 0; i = i - 2)
                {
                    passwordStr += pawStr.Substring(i, 2);
                }
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                 passwordStr;
            }
            catch { };
 
            return data;
        }
 
        /// <summary>
        ///  远程回复数据
        /// </summary>
        public RemoteResponseAllData remoteResponseAllData;
        [System.Serializable]
        public class RemoteResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary> 
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 临时密码回复数据
            /// </summary>
            public RemoteResponseData responseData;
            /// <summary>
            /// 是否密码被删除
            /// </summary>
            public bool IsPawDispear = false;
        }
 
        /// <summary>
        /// 用户管理数据回复
        /// </summary>
        [System.Serializable]
        public class RemoteResponseData
        {
            /// <summary>
            ///响应操作码(0-ffff)
            /// </summary>
            public string command = "";
            /// <summary>
            /// 状态值
            /// <para>默认响应结果:
            ///<para>0 成功</para>
            ///<para>1 失败</para> 
            /// </summary>
            public int status = -1;
        }
        #endregion
 
        #region 临时密码发送数据
        ///<summary >
        ///远程开锁
        ///<para>inputPassword: 输入密码/para>
        /// </summary>
        public async System.Threading.Tasks.Task<TempPasswordResponseAllData> TempPasswordAsync(string inputPassword, System.DateTime startTime, System.DateTime endTime, string fixedPassword = "190605")
        {
            TempPasswordResponseAllData result = null;
            if (Gateway == null)
            {
                result = new TempPasswordResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
 
                        if (temp == null)
                        {
                            result = new TempPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
 
                        else
                        {
                            result = new TempPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        {
                            result = new TempPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 16)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0002")
                                    {
                                        var tempD = new TempPasswordResponseData();
                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        result = new TempPasswordResponseAllData { responseData = tempD };
                                        DebugPrintLog($"UI收到通知后的主题_command:0463_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
 
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
 
                try
                {
                    var getPw = await GetkeyPassword();
                    var passData = TempPasswordData(inputPassword, getPw, startTime, endTime);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
 
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null && result.responseData != null && result.responseData.command == "0463")
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > 9000)
                {
                    result = new TempPasswordResponseAllData
                    { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
 
                return result;
            });
        }
        /// <summary>
        /// 临时密码发送数据
        /// </summary>
        public string TempPasswordData(string keyPassword, int password, System.DateTime startTime, System.DateTime endTime)
        {
            string data = "";
            string dataLength = "10";
            string dataComand1 = "63";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "0c";
            string passwordStr = "";
            string vaildTimeStr = "";
            string invalidTimeStr = "";
            try
            {
                int keyPasswordInt = System.Convert.ToInt32(keyPassword, 16);
                var pawStr = System.Convert.ToString((keyPasswordInt ^ password) + 0x190605, 16);
                pawStr = pawStr.PadLeft(8, '0');
                for (int i = 6; i >= 0; i = i - 2)
                {
                    passwordStr += pawStr.Substring(i, 2);
                }
 
                var startTimeStr = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(startTime);
                var endTimeStr = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(endTime);
                startTimeStr = string.Format("{0:X}", System.Convert.ToInt64(startTimeStr));
                endTimeStr = string.Format("{0:X}", System.Convert.ToInt64(endTimeStr));
                for (int i = 6; i >= 0; i = i - 2)
                {
                    vaildTimeStr += startTimeStr.Substring(i, 2);
                    invalidTimeStr += endTimeStr.Substring(i, 2);
                }
 
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                   passwordStr + vaildTimeStr + invalidTimeStr;
            }
            catch (Exception ex)
            {
                var mess = ex.Message;
            };
            return data;
        }
 
        /// <summary>
        /// 临时密码回复数据
        /// </summary>
        public TempPasswordResponseAllData tempPasswordResponseAllData;
        [System.Serializable]
        public class TempPasswordResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary> 
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 临时密码回复数据
            /// </summary>
            public TempPasswordResponseData responseData;
        }
 
        /// <summary>
        /// 临时密码回复数据
        /// </summary>
        [System.Serializable]
        public class TempPasswordResponseData
        {
            /// <summary>
            ///响应操作码(0-ffff)
            /// </summary>
            public string command = "";
            /// <summary>
            /// 状态值
            /// <para>0--注册成功</para>
            /// <para>1--注册失败</para>
            /// <para>2--用户已存在(重复密码)</para>
            /// <para>3-- 用户已满(+已满类型回复)</para>
            /// <para>4--有效时间重叠</para>
            /// </summary>
            public int status = -1;
        }
        #endregion
 
        #region 获取门锁密钥
        /// <summary>
        /// 门锁随机密码
        /// <para>获取加密的随机密钥,返回的密钥经过一个简单的加法加密加上0x190605,因此获取的密钥需要减上0x190605</para>
        /// </summary>
        /// <returns></returns>
        async System.Threading.Tasks.Task<int> GetkeyPassword()
        {
            string passwordStr = "";
            var result = await GetKeyPassworAsync();
            //返回小端
            if (result == null || result.keyPassword == null)
            {
                return 0;
            }
 
            for (int i = 6; i >= 0; i = i - 2)
            {
                passwordStr += result.keyPassword.Substring(i, 2);
            }
            var keyPasswordInt = System.Convert.ToInt32(passwordStr, 16);
            return keyPasswordInt - 0x190605;
        }
 
        ///<summary >
        ///获取门锁密钥
        /// </summary>
        async System.Threading.Tasks.Task<KeyPasswordInfo> GetKeyPassworAsync(int keyType = 0)
        {
            KeyPasswordInfo result = null;
            if (Gateway == null)
            {
                result = new KeyPasswordInfo { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "Error_Respon")
                    {
                        var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
                        var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
 
                        if (temp == null)
                        {
                            result = new KeyPasswordInfo { errorMessageBase = "网关错误回复,且数据是空" };
                        }
 
                        else
                        {
                            result = new KeyPasswordInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
 
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        {
                            result = new KeyPasswordInfo { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
                                if (data.Length == 20)
                                {
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
 
                                    if (command == "0461")
                                    {
                                        var kType = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
                                        var keyPassword = data[12].ToString() + data[13].ToString() + data[14].ToString() + data[15].ToString() + data[16].ToString() + data[17].ToString() + data[18].ToString() + data[19].ToString();
                                        result = new KeyPasswordInfo { keyType = kType, keyPassword = keyPassword };
                                        DebugPrintLog($"UI收到通知后的主题_command:0460_{ topic}");
                                    }
                                }
                            }
                        }
                    }
                };
 
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
 
                try
                {
                    var passData = KeyPasswordData(keyType);
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
                }
                catch { }
 
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)//WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new KeyPasswordInfo { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
 
                return result;
            });
        }
 
        /// <summary>
        /// 获取门锁密钥
        /// </summary>
        string KeyPasswordData(int keyType)
        {
            string data = "";
            string dataLength = "05";
            string dataComand1 = "60";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "01";
            string keyTypeData = "";
 
            try
            {
                var tempTypeString = new System.Text.StringBuilder();
                var temp = Convert.ToString(keyType, 16);
                switch (temp.Length)
                {
                    case 1:
                        keyTypeData = "0" + temp;
                        break;
                    case 2:
                        keyTypeData = temp;
                        break;
                }
                tempTypeString.Append(keyTypeData.ToString().ToUpper());
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
            tempTypeString;
            }
            catch { };
 
            return data;
        }
 
        /// <summary>
        /// 获取门锁密钥回复
        /// </summary>
        [System.Serializable]
        public class KeyPasswordInfo
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            ///密钥类型
            ///<apra></apra>
            /// </summary>
            public int keyType = -1;
 
            /// <summary>
            /// 密钥
            /// </summary>
            public string keyPassword;
        }
        #endregion
 
        #region 读取锁上信息
        ///<summary >
        ///读取锁上信息
        /// </summary>
        public async System.Threading.Tasks.Task<DoorlockUserInfo> GetDoorlockUserInfoAsync()
        {
            DoorlockUserInfo result = null;
            int totalNum = 0;
            int currentNum = -1;
            DoorLockUserDetailData doorLockUserDetailData = new DoorLockUserDetailData { };
            if (Gateway == null)
            {
                result = new DoorlockUserInfo { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                var dateTime = DateTime.Now;
                Action<string, string> action = (topic, message) =>
                {
                    var gatewayID = topic.Split('/')[0];
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
 
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
 
                        if (clientDataPassthroughResponseData != null)
                        {
                            if (clientDataPassthroughResponseData.PassData != null)
                            {
                                var data = clientDataPassthroughResponseData.PassData;
                                var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                if (command == "0452")
                                {
                                    dateTime = DateTime.Now;
                                    int returnAllLength = 2 + 2 * Convert.ToInt32(data[0].ToString() + data[1].ToString(), 16);
                                    int usefulLength = (returnAllLength - 16);
                                    int tempCount = 0;
                                    var listData = new List<string>();
                                    while (tempCount < usefulLength)
                                    {
                                        listData.Add(data[16 + tempCount].ToString());
                                        tempCount++;
                                    }
                                    for (int j = 0; j < listData.Count / 4; j++)
                                    {
                                        int curIndex = 4 * j;
                                        var userInfo = new UserObj();
                                        userInfo.UserType = Convert.ToInt32(listData[curIndex + 2].ToString(), 16);
                                        userInfo.UserId = Convert.ToInt32(listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16);
                                        doorLockUserDetailData.UserObjList.Add(userInfo);
                                    }
                                    doorLockUserDetailData.userType = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
                                    doorLockUserDetailData.totalNum = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16);
                                    doorLockUserDetailData.currentNum = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                    result = new DoorlockUserInfo { doorLockUserDetailData = doorLockUserDetailData };
                                    DebugPrintLog($"UI收到通知后的主题_command:0451_{ topic}");
                                }
                            }
                        }
                    }
                };
 
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
 
                try
                {
                    var passData = DoorlockUserData();
                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } };
                    var data = new JObject { { "PassData", passData } };
                    jObject.Add("Data", data);
                    Gateway.Send(("ClientDataPassthrough"), jObject.ToString());
 
                }
                catch { }
 
                //接收一个包最多等3秒,没有收到就退出
                while ((DateTime.Now - dateTime).TotalMilliseconds < 3000)
                {
                    await System.Threading.Tasks.Task.Delay(100);
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
 
                return result;
            });
        }
 
        /// <summary>
        /// 读取锁上信息
        /// </summary>
        string DoorlockUserData()
        {
            string data = "";
            string dataLength = "05";
            string dataComand1 = "51";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "01";
            string keyTypeData = "01";
 
            try
            {
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + keyTypeData;
            }
            catch { };
 
            return data;
        }
 
        /// <summary>
        /// 读取锁上信息回复
        /// </summary>
        [System.Serializable]
        public class DoorlockUserInfo
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 门锁设备返回信息
            /// </summary>
            public DoorLockUserDetailData doorLockUserDetailData;
        }
 
        /// <summary>
        /// 门锁设备返回信息
        /// </summary>
        public class DoorLockUserDetailData
        {
            /// <summary>
            /// 类型(读取锁上已有用户)
            /// </summary>
            public int userType;
            /// <summary>
            /// 数据包总数
            /// </summary>
            public int totalNum;
            /// <summary>
            /// 数据包序号
            /// </summary>
            public int currentNum;
 
            /// <summary>
            /// 虚拟驱动信息
            /// </summary>
            public List<UserObj> UserObjList = new List<UserObj>();
        }
 
        public class UserObj
        {
            /// <summary>
            /// 门锁用户类型
            /// </summary>
            public int UserType;
 
            /// <summary>
            /// 门锁用户Id号
            /// </summary>
            public int UserId;
        }
        #endregion
 
        #endregion
    }
}