mini_program_gizwits_sdk 3.2.30 → 3.2.32-FeiSiMan

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.js +3 -3
  2. package/dist/src/aepApi/aepApiRequest.d.ts +7 -0
  3. package/dist/src/handler/ble.d.ts +5 -10
  4. package/dist/src/protocol/Reset.d.ts +8 -0
  5. package/dist/src/protocol/SetReset.d.ts +7 -0
  6. package/dist/src/sdk.d.ts +204 -0
  7. package/dist/src/wifiConfig/ConfigBase.d.ts +2 -1
  8. package/dist/src/wifiConfig/ble.d.ts +16 -3
  9. package/dist/src/wifiConfig/nfc/disposeData.d.ts +2 -0
  10. package/dist/src/wifiConfig/nfc/formatData.d.ts +3 -0
  11. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +6 -0
  12. package/dist/src/wifiConfig/nfc/index.d.ts +22 -0
  13. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +1 -0
  14. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +6 -0
  15. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +5 -0
  16. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +1 -0
  17. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +1 -0
  18. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +2 -0
  19. package/dist/src/wifiConfig/nfc/types.d.ts +15 -0
  20. package/package.json +1 -1
  21. package/src/aepApi/aepApiRequest.ts +62 -0
  22. package/src/handler/ble.ts +32 -17
  23. package/src/protocol/Reset.ts +16 -0
  24. package/src/protocol/SetReset.ts +13 -0
  25. package/src/protocol/dataPoint.ts +18 -18
  26. package/src/sdk.ts +129 -36
  27. package/src/services/devices.ts +92 -4
  28. package/src/utils.ts +15 -5
  29. package/src/wifiConfig/ConfigBase.ts +3 -1
  30. package/src/wifiConfig/ble.ts +86 -26
  31. package/src/wifiConfig/nfc/disposeData.ts +63 -0
  32. package/src/wifiConfig/nfc/formatData.ts +46 -0
  33. package/src/wifiConfig/nfc/formatSSID.ts +59 -0
  34. package/src/wifiConfig/nfc/index.ts +136 -0
  35. package/src/wifiConfig/nfc/isIncludedCH.ts +8 -0
  36. package/src/wifiConfig/nfc/nfcAConnect.ts +30 -0
  37. package/src/wifiConfig/nfc/nfcATransceive.ts +29 -0
  38. package/src/wifiConfig/nfc/ssIDToASC.ts +12 -0
  39. package/src/wifiConfig/nfc/stringToGbk.ts +51 -0
  40. package/src/wifiConfig/nfc/transceive.wx.ts +124 -0
  41. package/src/wifiConfig/nfc/types.ts +18 -0
@@ -1,5 +1,5 @@
1
1
  import productConfigFileManage from "../productConfigFileManage";
2
- import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte, completeBlock} from "./tool";
2
+ import { arrayToString, checkHeader, fillString, getProtocolLen, hexStrint2byte, completeBlock } from "./tool";
3
3
 
4
4
  export interface IDataPointConfig {
5
5
  name: string;
@@ -35,7 +35,7 @@ type TDataOptionType = 'status_writable' | 'status_readonly' | 'alert' | 'fault'
35
35
  export interface IDataPointAttr {
36
36
  display_name: string;
37
37
  uint_spec: IUnitSpec;
38
- name:string;
38
+ name: string;
39
39
  data_type: TDataType;
40
40
  position: IDataPointPosition;
41
41
  type: TDataOptionType;
@@ -181,7 +181,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
181
181
  */
182
182
  const flag = [0];
183
183
  const headerCmd = [0, 147]; // cmd
184
- const sn = [0,0,0,0];
184
+ const sn = [0, 0, 0, 0];
185
185
 
186
186
  // 业务指令命令字 定长上报是4,变长上报是14
187
187
  let cmd = [0x1];
@@ -194,7 +194,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
194
194
 
195
195
  // 找到可写
196
196
  if (!isAdaptiveDatapoint) {
197
- attrsConfig = attrsConfig.filter(item => item.type ==='status_writable')
197
+ attrsConfig = attrsConfig.filter(item => item.type === 'status_writable')
198
198
  }
199
199
 
200
200
  attrsConfig.map((item) => {
@@ -265,7 +265,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
265
265
  return {
266
266
  data: packageData,
267
267
  raw: {
268
- header: [0,0,0,3],
268
+ header: [0, 0, 0, 3],
269
269
  flag,
270
270
  len: lengthArr,
271
271
  headerCmd,
@@ -274,7 +274,7 @@ const DataPointToP = ({ config, data, isAdaptiveDatapoint }: IDataPointToP0Param
274
274
  }
275
275
  };
276
276
  };
277
-
277
+
278
278
  interface IPToDataPointParams {
279
279
  config: IDataPointAttr[];
280
280
  data: number[];
@@ -316,7 +316,7 @@ function PToDataPoint({ config = [], data }: IPToDataPointParams) {
316
316
  let action: number;
317
317
  let message = '';
318
318
  let messageType: messageType;
319
- const rawData: IRawData = { header: arrayToString(data.slice(0, 4)), flag: '', len: '', cmd: '', sn: '',action: '', payload: '' };
319
+ const rawData: IRawData = { header: arrayToString(data.slice(0, 4)), flag: '', len: '', cmd: '', sn: '', action: '', payload: '' };
320
320
  // 获取数据长度 0,0,0,3 到 0 这一段都是长度 校验长度可以忽略
321
321
  const attrs = config;
322
322
 
@@ -662,7 +662,7 @@ function calculationCmdData({ attrs, flagString, boolEnumLength, cmdData, accumu
662
662
  const unpack = async (data: number[], pk: string) => {
663
663
  const productConfig = await productConfigFileManage.getConfigFile(pk);
664
664
  if (productConfig) {
665
- const resData = PToDataPoint({config: (await productConfig).entities[0].attrs, data})
665
+ const resData = PToDataPoint({ config: (await productConfig).entities[0].attrs, data })
666
666
  if (resData.kvData) {
667
667
  // 格式化binary
668
668
  resData.kvData = await formatBinary(resData?.kvData, pk, 'object');
@@ -675,16 +675,16 @@ const pack = async (data: object, pk: string) => {
675
675
  const productConfig = await productConfigFileManage.getConfigFile(pk);
676
676
  if (productConfig) {
677
677
  const isAdaptiveDatapoint = productConfig.protocolType === 'var_len';
678
- return DataPointToP({data, config: (await productConfig).entities[0].attrs, isAdaptiveDatapoint});
678
+ return DataPointToP({ data, config: (await productConfig).entities[0].attrs, isAdaptiveDatapoint });
679
679
  }
680
680
  return null;
681
681
  }
682
682
 
683
683
  const padBoradcastData = (data: number[]) => {
684
- const head = [0,0,0,3];
684
+ const head = [0, 0, 0, 3];
685
685
  const flag = [0];
686
686
  const headerCmd = [0, 0x93]; // cmd
687
- const sn = [0, 0, 0 ,0];
687
+ const sn = [0, 0, 0, 0];
688
688
  const flagToEnd = flag.concat(headerCmd).concat(sn).concat(data);
689
689
  const lengthArr: number[] = getVariableLength(flagToEnd);
690
690
  return arrayToString(head.concat(lengthArr).concat(flagToEnd));
@@ -692,10 +692,10 @@ const padBoradcastData = (data: number[]) => {
692
692
 
693
693
  type TargetType = 'int' | 'string';
694
694
  // 格式化enum 兼容sdk 和 socket 之间的差异
695
- const formatEnum = async (attrs: any, pk: string, targetType: TargetType ) => {
696
- for(let key in attrs) {
695
+ const formatEnum = async (attrs: any, pk: string, targetType: TargetType) => {
696
+ for (let key in attrs) {
697
697
  const itemData = await productConfigFileManage.getAttrItem(pk, key);
698
- if (itemData && itemData.data_type ==='enum') {
698
+ if (itemData && itemData.data_type === 'enum') {
699
699
  if (targetType === 'int' && typeof attrs[key] === 'string') {
700
700
  // 转成int
701
701
  const enumIndex = itemData.enum.findIndex(item => item === attrs[key]);
@@ -710,10 +710,10 @@ const formatEnum = async (attrs: any, pk: string, targetType: TargetType ) => {
710
710
  }
711
711
 
712
712
  type BTargetType = 'string' | 'object';
713
- const formatBinary = async (attrs: any, pk: string, targetType: BTargetType ) => {
714
- for(let key in attrs) {
713
+ const formatBinary = async (attrs: any, pk: string, targetType: BTargetType) => {
714
+ for (let key in attrs) {
715
715
  const itemData = await productConfigFileManage.getAttrItem(pk, key);
716
- if (itemData && itemData.data_type ==='binary') {
716
+ if (itemData && itemData.data_type === 'binary') {
717
717
  if (targetType === 'object' && typeof attrs[key] === 'string') {
718
718
  attrs[key] = hexStrint2byte(attrs[key])
719
719
  }
@@ -725,4 +725,4 @@ const formatBinary = async (attrs: any, pk: string, targetType: BTargetType ) =>
725
725
  return attrs
726
726
  }
727
727
 
728
- export {pack, unpack, padBoradcastData, formatEnum, formatBinary};
728
+ export { pack, unpack, padBoradcastData, formatEnum, formatBinary };
package/src/sdk.ts CHANGED
@@ -9,6 +9,8 @@ import { LanHandle } from './handler/lan';
9
9
  import productConfigFileManage from './productConfigFileManage';
10
10
  import { formatEnum, IDataPointConfig, pack, unpack } from './protocol/DataPoint';
11
11
  import Ntp from './protocol/Ntp';
12
+ import Reset from './protocol/Reset';
13
+ import SetReset from './protocol/SetReset';
12
14
  import { CancelSync, DeletePackage, RequestSync, SyncPackage } from './protocol/OffLineData';
13
15
  import ProtocolBase from './protocol/ProtocolBase';
14
16
  import { arrayToString, hexStrint2byte } from './protocol/tool';
@@ -35,6 +37,7 @@ import {
35
37
  } from './utils';
36
38
  import ApConfig from './wifiConfig/ap';
37
39
  import BLEConfig from './wifiConfig/ble';
40
+ import NFCConfig from './wifiConfig/nfc';
38
41
 
39
42
  const version = sdkConfig.version;
40
43
  interface SyncCallBackParams {
@@ -56,10 +59,11 @@ export interface ISDKResult<T> {
56
59
  }
57
60
  export interface ISetCommonDeviceOnboardingDeployProps {
58
61
  ssid: string;
62
+ bssid?: string;
59
63
  password: string;
60
64
  timeout: number;
61
65
  isBind?: boolean;
62
- mode?: 0 | 3; // 0 AP 3 BLE
66
+ mode?: 0 | 3 | 5; // 0 AP 3 BLE 5 NFC
63
67
  softAPSSIDPrefix?: string;
64
68
  }
65
69
 
@@ -68,6 +72,12 @@ export interface ISetDeviceOnboardingDeployProps
68
72
  softAPSSIDPrefix: string;
69
73
  }
70
74
 
75
+ export interface IConfigResult {
76
+ mac: string;
77
+ productKey: string;
78
+ }
79
+
80
+
71
81
  export interface IRandomCodesResult {
72
82
  random_code: string;
73
83
  product_key: string;
@@ -126,6 +136,7 @@ export interface IResult<T> {
126
136
 
127
137
  interface ICloudServiceInfo {
128
138
  openAPIInfo: string;
139
+ aepAPIInfo: string;
129
140
  }
130
141
 
131
142
  export type TimeoutHandle = ReturnType<typeof setTimeout> | null;
@@ -142,6 +153,8 @@ interface GizwitsSdkOption {
142
153
  token?: string;
143
154
  uid?: string;
144
155
  offlineThreshold?: number;
156
+ accessKey?: string; // 京东平台接口请求参数
157
+ secretKey?: string;// 京东平台接口请求参数
145
158
  }
146
159
 
147
160
  class GizwitsMiniSDK {
@@ -205,7 +218,8 @@ class GizwitsMiniSDK {
205
218
  }
206
219
  });
207
220
 
208
- const connectionMap = this.socketHandle._connections;
221
+ // const connectionMap = this.socketHandle._connections;
222
+ const connectionMap = {};
209
223
 
210
224
  Object.keys(connectionMap).forEach((wsInfo) => {
211
225
  const conn = connectionMap[wsInfo];
@@ -292,16 +306,16 @@ class GizwitsMiniSDK {
292
306
  }
293
307
 
294
308
  private get socketHandle() {
295
- if (!this._gizSocket) {
296
- this._gizSocket = new GizwitsWS({
297
- appID: getGlobalData('appID'),
298
- token: getGlobalData('token'),
299
- uid: getGlobalData('uid'),
300
- });
301
- this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData);
302
- this._gizSocket.subscribeBindingChanged(this.getBindingList);
303
- this._gizSocket.subscribeSocketStatus(this.handleSocketStatus);
304
- }
309
+ // if (!this._gizSocket) {
310
+ // this._gizSocket = new GizwitsWS({
311
+ // appID: getGlobalData('appID'),
312
+ // token: getGlobalData('token'),
313
+ // uid: getGlobalData('uid'),
314
+ // });
315
+ // this._gizSocket.subscribeDeviceStatus(this.handleSocketDeviceData);
316
+ // this._gizSocket.subscribeBindingChanged(this.getBindingList);
317
+ // this._gizSocket.subscribeSocketStatus(this.handleSocketStatus);
318
+ // }
305
319
  return this._gizSocket;
306
320
  }
307
321
 
@@ -314,6 +328,8 @@ class GizwitsMiniSDK {
314
328
  token,
315
329
  uid,
316
330
  offlineThreshold,
331
+ accessKey,
332
+ secretKey
317
333
  }: GizwitsSdkOption) => {
318
334
  this.productInfo = productInfo;
319
335
  // 保存相关信息
@@ -321,7 +337,10 @@ class GizwitsMiniSDK {
321
337
  setGlobalData('appSecret', appSecret);
322
338
  setGlobalData('productInfo', productInfo);
323
339
  setGlobalData('token', token);
340
+ console.log('SDK init', token);
324
341
  setGlobalData('uid', uid);
342
+ setGlobalData('accessKey', accessKey);
343
+ setGlobalData('secretKey', secretKey);
325
344
 
326
345
  /**
327
346
  * 同时也设置域名信息
@@ -336,7 +355,7 @@ class GizwitsMiniSDK {
336
355
  * lan 比较特殊
337
356
  * 初始化sdk的时候就要开始扫描设备
338
357
  */
339
- this.initLan();
358
+ // this.initLan();
340
359
  }
341
360
  public reInit(props: GizwitsSdkOption) {
342
361
  this.init(props);
@@ -353,7 +372,7 @@ class GizwitsMiniSDK {
353
372
  openAPIInfo !== getGlobalData('cloudServiceInfo').openAPIInfo
354
373
  ) {
355
374
  // 需要重启
356
- this.socketHandle.destory();
375
+ // this.socketHandle.destory();
357
376
  this._gizSocket = null;
358
377
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
359
378
  this.socketHandle;
@@ -452,6 +471,32 @@ class GizwitsMiniSDK {
452
471
  }
453
472
  break
454
473
  }
474
+ case '0062': {
475
+ // 蓝牙重置命令,app代理设备进行重置
476
+ const resetInfo = new Reset(bleBytesData)
477
+ GizLog.debug("收到代理重置事件", resetInfo)
478
+
479
+ if (resetInfo.status === 1) {
480
+ // 需要重置
481
+ this.deviceSafetyApi({
482
+ mac: target.mac,
483
+ productKey: target.productKey,
484
+ isReset: true
485
+ }).then(async data => {
486
+ GizLog.debug("代理重置结果", data)
487
+ if (data.success && data.data.successDevices.length > 0) {
488
+ // 回写数据
489
+ GizLog.debug("重置成功,回写数据")
490
+ await this.bleHandle.write(curDevice.deviceId, numberArray2Uint8Array(SetReset.pack(0)).buffer)
491
+ }
492
+ })
493
+ }
494
+ break;
495
+ }
496
+ case '0064': {
497
+ // 回写重置结果ack,暂时先忽略
498
+ break;
499
+ }
455
500
  case '0052': {
456
501
  // 设备回复是否允许同步数据
457
502
  const requestSyncData = new RequestSync(bleBytesData)
@@ -762,7 +807,7 @@ class GizwitsMiniSDK {
762
807
  case 'WAN': {
763
808
  // 枚举要转换成枚举值
764
809
  const newAttrs = await formatEnum(attrs, target.productKey, 'string')
765
-
810
+ return;
766
811
  return this.socketHandle.writeData(target, newAttrs);
767
812
  }
768
813
  case 'LAN': {
@@ -803,6 +848,7 @@ class GizwitsMiniSDK {
803
848
  }
804
849
  }
805
850
  case 'WAN': {
851
+ return { success: false };
806
852
  return this.socketHandle.send(target.did, data);
807
853
  }
808
854
  case 'LAN': {
@@ -954,7 +1000,7 @@ class GizwitsMiniSDK {
954
1000
  if (data.success) {
955
1001
  setGlobalData('token', data.data?.token);
956
1002
  setGlobalData('uid', data.data?.uid);
957
- this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
1003
+ // this.socketHandle.updateToken({token: data.data.token, uid: data.data.uid})
958
1004
  }
959
1005
  return data;
960
1006
  };
@@ -975,6 +1021,7 @@ class GizwitsMiniSDK {
975
1021
  );
976
1022
  }
977
1023
  case 'WAN':
1024
+ return { success: false, }
978
1025
  return this.socketHandle.readStatus(target, attrNames);
979
1026
  default: {
980
1027
  return {
@@ -1010,6 +1057,7 @@ class GizwitsMiniSDK {
1010
1057
  // 广播不需要连接
1011
1058
  return {
1012
1059
  success: true,
1060
+ message: '',
1013
1061
  };
1014
1062
  }
1015
1063
 
@@ -1022,7 +1070,7 @@ class GizwitsMiniSDK {
1022
1070
  switch (type) {
1023
1071
  case 'BLE': {
1024
1072
  // 连接BLE
1025
- const data = await this.bleHandle.connectDevice(target);
1073
+ const data = await this.bleHandle.connectDevice(target) as IResult<any>;
1026
1074
  if (data.success) {
1027
1075
 
1028
1076
  // 蓝牙设备比较特殊,在get 里面从bleHandle里找到连接的设备,再把connectType 设置成BLE,所以这里更新metaData 要强制更新并推送
@@ -1042,11 +1090,12 @@ class GizwitsMiniSDK {
1042
1090
  // const target = this.deviceList.find((item) =>
1043
1091
  // isSameDevice(item, device)
1044
1092
  // );
1045
- const data = this.socketHandle.connectDevice(target);
1046
- if (data.success) {
1047
- this.setDeviceMeta(device, 'connectType', 'WAN', true);
1048
- }
1049
- return data;
1093
+ // const data = this.socketHandle.connectDevice(target);
1094
+ // if (data.success) {
1095
+ // this.setDeviceMeta(device, 'connectType', 'WAN', true);
1096
+ // }
1097
+ // return data;
1098
+ return { success: false, }
1050
1099
  }
1051
1100
  case 'LAN': {
1052
1101
  const data = await this.lanHandle.connectDevice(target);
@@ -1058,6 +1107,7 @@ class GizwitsMiniSDK {
1058
1107
  }
1059
1108
  return {
1060
1109
  success: false,
1110
+ message: '',
1061
1111
  };
1062
1112
  };
1063
1113
 
@@ -1081,11 +1131,14 @@ class GizwitsMiniSDK {
1081
1131
  return disconnectRes;
1082
1132
  }
1083
1133
  case 'WAN': {
1084
- const res = this.socketHandle.disConnectDevice(target);
1085
- if (res.success) {
1086
- this.setDeviceMeta(target, 'connectType', 'NONE', true);
1087
- }
1088
- return res;
1134
+ // const res = this.socketHandle.disConnectDevice(target);
1135
+ // if (res.success) {
1136
+ // this.setDeviceMeta(target, 'connectType', 'NONE', true);
1137
+ // }
1138
+ // return res;
1139
+ return {
1140
+ success: false,
1141
+ };
1089
1142
  }
1090
1143
  case 'LAN': {
1091
1144
  const res = this.lanHandle.disConnectDevice(target);
@@ -1161,6 +1214,7 @@ class GizwitsMiniSDK {
1161
1214
  */
1162
1215
  setDeviceOnboardingDeploy = async ({
1163
1216
  ssid,
1217
+ bssid = '',
1164
1218
  password,
1165
1219
  mode = 0,
1166
1220
  timeout,
@@ -1174,12 +1228,13 @@ class GizwitsMiniSDK {
1174
1228
  };
1175
1229
  }
1176
1230
  const sTime = new Date().getTime();
1177
- GizLog.debug('GIZ_SDK: 配网开始时间:' + sTime);
1231
+ GizLog.debug('GIZ_SDK: 配网开始时间:' + sTime, mode);
1178
1232
  try {
1179
1233
  switch (mode) {
1180
1234
  case 0: {
1181
1235
  this.currentWifiConfigHandle = new ApConfig(
1182
1236
  ssid,
1237
+ bssid,
1183
1238
  password,
1184
1239
  this.specialProductKeys,
1185
1240
  this.specialProductKeySecrets
@@ -1199,6 +1254,7 @@ class GizwitsMiniSDK {
1199
1254
  case 3: {
1200
1255
  this.currentWifiConfigHandle = new BLEConfig(
1201
1256
  ssid,
1257
+ bssid,
1202
1258
  password,
1203
1259
  this.specialProductKeys,
1204
1260
  this.specialProductKeySecrets,
@@ -1216,9 +1272,43 @@ class GizwitsMiniSDK {
1216
1272
  GizLog.debug('GIZ_SDK: 配网用时:' + (eTime - sTime));
1217
1273
  return data;
1218
1274
  }
1275
+ case 5: {
1276
+ // 只有安卓支持
1277
+ const sysInfo = await wx.getSystemInfoSync();
1278
+ console.log('sysInfosysInfo', sysInfo)
1279
+ if (sysInfo.platform !== 'android') {
1280
+ return {
1281
+ success: false,
1282
+ message: '只支持安卓'
1283
+ }
1284
+ }
1285
+ const cloudServiceInfo = getGlobalData('cloudServiceInfo');
1286
+
1287
+ console.log('cloudServiceInfo', cloudServiceInfo)
1288
+
1289
+ this.currentWifiConfigHandle = new NFCConfig(
1290
+ ssid,
1291
+ bssid,
1292
+ password,
1293
+ this.specialProductKeys,
1294
+ this.specialProductKeySecrets,
1295
+ cloudServiceInfo?.openAPIInfo || 'api.gizwits.com',
1296
+ );
1297
+ const data =
1298
+ await this.currentWifiConfigHandle.setDeviceOnboardingDeploy({
1299
+ timeout,
1300
+ isBind,
1301
+ softAPSSIDPrefix,
1302
+ });
1303
+ this.currentWifiConfigHandle = null;
1304
+ const eTime = new Date().getTime();
1305
+ GizLog.debug('GIZ_SDK: 配网结束时间:' + eTime);
1306
+ GizLog.debug('GIZ_SDK: 配网用时:' + (eTime - sTime));
1307
+ return data;
1308
+ }
1219
1309
  }
1220
1310
  } catch (error) {
1221
- GizLog.error("GIZ_SDK: setDeviceOnboardingDeploy", new Error(JSON.stringify(error)));
1311
+ GizLog.error("GIZ_SDK: setDeviceOnboardingDeploy", error);
1222
1312
  if (
1223
1313
  (error as ISDKResult<IDevice[]>).err &&
1224
1314
  (error as ISDKResult<IDevice[]>).err!.errorCode
@@ -1240,8 +1330,10 @@ class GizwitsMiniSDK {
1240
1330
  private setDomain = (cloudServiceInfo: ICloudServiceInfo) => {
1241
1331
  const openAPIInfo =
1242
1332
  (cloudServiceInfo && cloudServiceInfo.openAPIInfo) || 'api.gizwits.com';
1333
+ const aepAPIInfo =
1334
+ (cloudServiceInfo && cloudServiceInfo.aepAPIInfo) || 'https://mini-dev.viessmann.cn/';
1243
1335
 
1244
- const newData = { ...(cloudServiceInfo || {}), openAPIInfo };
1336
+ const newData = { ...(cloudServiceInfo || {}), openAPIInfo, aepAPIInfo };
1245
1337
  setGlobalData('cloudServiceInfo', newData);
1246
1338
  };
1247
1339
 
@@ -1268,11 +1360,12 @@ class GizwitsMiniSDK {
1268
1360
 
1269
1361
  // 内部刷新设备列表的方法
1270
1362
  public getBindingList = async () => {
1271
- const data = await getBindingList();
1272
- this.deviceList = data.data || [];
1273
- // 推送
1274
- this.notiDeviceList();
1275
- return data;
1363
+ // const data = await getBindingList();
1364
+ // this.deviceList = data.data || [];
1365
+ // // 推送
1366
+ // this.notiDeviceList();
1367
+ // return data;
1368
+ return {}
1276
1369
  };
1277
1370
 
1278
1371
  /**
@@ -1371,7 +1464,7 @@ class GizwitsMiniSDK {
1371
1464
  public destory = () => {
1372
1465
  this.bleHandle.destory();
1373
1466
  this.lanHandle.destory();
1374
- this.socketHandle.destory();
1467
+ // this.socketHandle.destory();
1375
1468
  this.keepScanTimer && clearInterval(this.keepScanTimer);
1376
1469
  };
1377
1470
  }
@@ -1,10 +1,10 @@
1
+ import { enc, AES, mode, pad } from 'crypto-js';
1
2
  import openApiRequest, { IServiceResult } from '../openApiRequest';
2
3
  import getRandomCodes from '../randomCode';
3
4
  import { IRandomCodesResult } from '../sdk';
4
5
  import { psKeySign } from './tool';
5
6
  // eslint-disable-next-line import/no-commonjs
6
7
  // const CryptoJS = require('crypto-js');
7
- import { enc, AES, mode, pad } from 'crypto-js';
8
8
 
9
9
  export interface IOpenApiDevice {
10
10
  product_key: string;
@@ -26,6 +26,58 @@ interface IDeviceRes {
26
26
  devices: IOpenApiDevice[];
27
27
  }
28
28
 
29
+ // 云端aes 特殊解码
30
+ class Padding {
31
+ /**
32
+ * Pads data using the algorithm defined in PKCS #5/7.
33
+ *
34
+ * @param data The data to pad.
35
+ * @param blockSize The multiple that the data should be padded to.
36
+ *
37
+ * @example
38
+ *
39
+ * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
40
+ */
41
+ pad = (data, blockSize) => {
42
+ }
43
+
44
+
45
+ /**
46
+ * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
47
+ *
48
+ * @param data The data to unpad.
49
+ *
50
+ * @example
51
+ *
52
+ * CryptoJS.pad.Pkcs7.unpad(wordArray);
53
+ */
54
+ unpad = (data) => {
55
+ const AES_BLOCK_LEN = 16;
56
+ const len = data.sigBytes;
57
+ let readed = 0;
58
+ let repeat = 1;
59
+ const stringData = data.toString(enc.Utf8);
60
+ while (readed + AES_BLOCK_LEN <= len) {
61
+ readed += AES_BLOCK_LEN;
62
+ }
63
+ for(let i = 0; i < (AES_BLOCK_LEN - 2) / 2; i++)
64
+ {
65
+ const start = readed - i * 2;
66
+ if(stringData.substring(start, start - 2) == stringData.substring(start - 2, start - 4))
67
+ {
68
+ repeat++;
69
+ }
70
+ else
71
+ {
72
+ readed -= repeat * 2;
73
+
74
+ break;
75
+ }
76
+ }
77
+ data.sigBytes = readed;
78
+ }
79
+ }
80
+
29
81
  export const getBindingList = async (): Promise<IServiceResult<IDevice[]>> => {
30
82
  const data = await openApiRequest<IDeviceRes>(
31
83
  '/app/bindings?show_disabled=0&limit=1000&skip=0',
@@ -37,6 +89,7 @@ export const getBindingList = async (): Promise<IServiceResult<IDevice[]>> => {
37
89
  if (data.success) {
38
90
  const newDevices: IDevice[] = data.data!.devices.map((item) => {
39
91
  return {
92
+ ...item,
40
93
  productKey: item.product_key,
41
94
  mac: item.mac,
42
95
  did: item.did,
@@ -195,12 +248,23 @@ export async function safeRegister({
195
248
  false
196
249
  );
197
250
  if (data.success) {
198
- // 解码
251
+ const successDevices = unPackSafeRegisterRes({ productSecret, iv, data: data.data });
252
+ const failedDevices = [];
253
+
254
+ const targetDevice = successDevices.find(item => item.mac === mac);
255
+ if (!targetDevice) {
256
+ // 不存在
257
+ failedDevices.push({
258
+ mac,
259
+ })
260
+ }
261
+
262
+ // TODO 解码
199
263
  return {
200
264
  success: true,
201
265
  data: {
202
- successDevices: [],
203
- failedDevices: [],
266
+ successDevices,
267
+ failedDevices,
204
268
  },
205
269
  };
206
270
  }
@@ -210,6 +274,30 @@ export async function safeRegister({
210
274
  };
211
275
  }
212
276
 
277
+ const unPackSafeRegisterRes = ({ productSecret, data, iv }: { productSecret: string, data: string, iv: any }) => {
278
+ const aesKey = enc.Hex.parse(productSecret)
279
+ const bodyHex = enc.Hex.parse(data)
280
+ let resEncrypted = AES.decrypt(enc.Base64.stringify(bodyHex), aesKey, { iv: iv, mode: mode.ECB, padding: new Padding() });
281
+ const resString = resEncrypted.toString(enc.Utf8);
282
+ const newData = [];
283
+ resString.split(',').map(item => {
284
+ const tmp = item.split('&');
285
+ const mac = tmp[0].replace('mac=', '');
286
+ const did = tmp[1].replace('did=', '');
287
+ newData.push({
288
+ mac, did
289
+ })
290
+ })
291
+ return newData;
292
+ }
293
+
294
+ // const unPackSafeRegister = unPackSafeRegisterRes({
295
+ // productSecret: 'aaa0840301e04748adaf9fcd160e7508',
296
+ // iv: enc.Hex.parse(''),
297
+ // data: '56ab36690dcb1e42bc3e69dab30c2e670c2188dfb76cb5a2f12986d18eb069f0f63d3c89ab069f3573ef81ca02936ad4'
298
+ // })
299
+ // console.log('unPackSafeRegisterunPackSafeRegister', unPackSafeRegister)
300
+
213
301
  interface IRenameProps {
214
302
  name?: string;
215
303
  did: string;
package/src/utils.ts CHANGED
@@ -134,11 +134,12 @@ const parseAdv = (advertisData: ArrayBuffer, pks: string[]) => {
134
134
  }
135
135
 
136
136
  const tmpBytes = advertisData.slice(index + 1, index + len + 1);
137
- if (len >= 6 && len <= 8) {
138
- mac = ab2hex(tmpBytes);
139
- if (mac.length == 16) {
140
- mac = mac.substring(0, 15);
141
- }
137
+ if (len >= 6 && len <= 15) {
138
+ // 菲斯曼的mac需要转化下
139
+ const nums = Array.prototype.map.call(new Uint8Array(tmpBytes), function (bit) {
140
+ return bit;
141
+ });
142
+ mac = numberArrToASCIIString(nums);
142
143
  }
143
144
 
144
145
  if (len == 16) {
@@ -155,6 +156,15 @@ const parseAdv = (advertisData: ArrayBuffer, pks: string[]) => {
155
156
  return {bleWorkStatus, mac, productKey}
156
157
  }
157
158
 
159
+ // 数值数组转字符串(按AscII码转化)
160
+ function numberArrToASCIIString(nums: number[]) {
161
+ // 数值数组转字符串(按AscII码转化)
162
+ let str = '';
163
+ for (let i = 0; i < nums.length; i++) {
164
+ str += String.fromCharCode(nums[i]);
165
+ }
166
+ return str;
167
+ }
158
168
 
159
169
  export const advertisData2PkAndMac = (
160
170
  advertisData: ArrayBuffer,
@@ -9,6 +9,7 @@ interface IRejectCallback {
9
9
  }
10
10
  class ConfigBase {
11
11
  ssid = '';
12
+ bssid = '';
12
13
  password = '';
13
14
  specialProductKeys: string[] = [];
14
15
  disableSearchDevice = false;
@@ -17,8 +18,9 @@ class ConfigBase {
17
18
  private setDeviceOnboardingDeployRej?: (value: unknown) => void = () => {}; // 保存promise的rej,用于临时中断
18
19
  // private setDeviceOnboardingDeployRes?: (value: unknown) => void = () => {}; // 保存promise的res,用于临时中断
19
20
 
20
- constructor(ssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]) {
21
+ constructor(ssid: string, bssid: string, password: string, specialProductKeys: string[], specialProductKeySecrets: string[]) {
21
22
  this.ssid = ssid;
23
+ this.bssid = bssid;
22
24
  this.password = password;
23
25
  this.specialProductKeys = specialProductKeys;
24
26
  this.specialProductKeySecrets = specialProductKeySecrets;