mini_program_gizwits_sdk 3.0.2-beta → 3.0.7
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.
- package/dist/index.js +3 -20
- package/dist/src/errorCode.d.ts +5 -0
- package/dist/src/globalData.d.ts +2 -0
- package/dist/src/openApiRequest.d.ts +9 -0
- package/dist/src/productConfigFileManage.d.ts +12 -0
- package/dist/src/protocol/Bind.d.ts +7 -0
- package/dist/src/protocol/DataPoint.d.ts +52 -0
- package/dist/src/protocol/GetDeviceStatus.d.ts +5 -0
- package/dist/src/protocol/Login.d.ts +12 -0
- package/dist/src/protocol/ProtocolBase.d.ts +11 -0
- package/dist/src/protocol/WifiConfig.d.ts +6 -0
- package/dist/src/protocol/tool.d.ts +9 -0
- package/dist/src/randomCode.d.ts +7 -0
- package/dist/src/request.d.ts +1 -0
- package/dist/src/services/devices.d.ts +53 -0
- package/dist/src/services/login.d.ts +8 -0
- package/dist/src/services/tool.d.ts +4 -0
- package/dist/src/sleep.d.ts +2 -0
- package/dist/src/socket.d.ts +107 -0
- package/dist/src/utils.d.ts +29 -0
- package/dist/src/wechatApi.d.ts +33 -0
- package/dist/src/wifiConfig/ConfigBase.d.ts +26 -0
- package/dist/src/wifiConfig/ap.d.ts +21 -0
- package/dist/src/wifiConfig/ble.d.ts +40 -0
- package/global.d.ts +28 -0
- package/index.ts +7 -0
- package/package.json +6 -3
- package/src/ble.ts +566 -0
- package/src/errorCode.ts +60 -0
- package/src/global.d.ts +42 -0
- package/src/globalData.ts +9 -0
- package/src/openApiRequest.ts +103 -0
- package/src/productConfigFileManage.ts +44 -0
- package/src/protocol/Bind.ts +22 -0
- package/src/protocol/GetDeviceStatus.ts +61 -0
- package/src/protocol/Login.ts +43 -0
- package/src/protocol/ProtocolBase.ts +53 -0
- package/src/protocol/WifiConfig.ts +41 -0
- package/src/protocol/dataPoint.ts +663 -0
- package/src/protocol/tool.ts +91 -0
- package/src/randomCode.ts +36 -0
- package/src/request.ts +22 -0
- package/src/sdk.ts +811 -0
- package/src/services/devices.ts +210 -0
- package/src/services/login.ts +15 -0
- package/src/services/tool.ts +10 -0
- package/src/sleep.ts +2 -0
- package/src/socket.ts +449 -0
- package/src/utils.ts +215 -0
- package/src/wechatApi.ts +179 -0
- package/src/wifiConfig/ConfigBase.ts +183 -0
- package/src/wifiConfig/ap.ts +193 -0
- package/src/wifiConfig/ble.ts +417 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// 检查头部 和可变长度字段,返回index
|
|
2
|
+
const checkHeader = (data) => {
|
|
3
|
+
let pointer = 0;
|
|
4
|
+
if (data[0] !== 0 || data[1] !== 0 || data[2] !== 0 || data[3] !== 3) {
|
|
5
|
+
// 数据不合法
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
pointer = 4;
|
|
9
|
+
return pointer;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const getProtocolLen = (data) => {
|
|
13
|
+
/**
|
|
14
|
+
* 插入len
|
|
15
|
+
* 计算方法,从第一位开始往下算,直到找到一个字节的最高位不为1
|
|
16
|
+
*/
|
|
17
|
+
let lengthIndex = 0;
|
|
18
|
+
for (; lengthIndex < data.length; lengthIndex++) {
|
|
19
|
+
if (fillString(data[lengthIndex].toString(2), 8)[0] !== '1') {
|
|
20
|
+
// 此时 lengthIndex 就是长度
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return lengthIndex + 1;
|
|
25
|
+
}
|
|
26
|
+
// 十进制数组转16进制字符串并补充
|
|
27
|
+
function arrayToString(arr: number[]) {
|
|
28
|
+
let string = '';
|
|
29
|
+
arr.map((item) => {
|
|
30
|
+
string += fillString(item.toString(16), 2);
|
|
31
|
+
return null;
|
|
32
|
+
});
|
|
33
|
+
return string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const fillString = (string: string, num: number, foot: boolean = false) => {
|
|
37
|
+
const len = num - string.length;
|
|
38
|
+
const paddingString = new Array(len).fill(0).join('');
|
|
39
|
+
if (foot) {
|
|
40
|
+
// 后面加
|
|
41
|
+
string += paddingString;
|
|
42
|
+
} else {
|
|
43
|
+
string = paddingString + string;
|
|
44
|
+
}
|
|
45
|
+
return string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const string2Bytes = (str: string) => {
|
|
49
|
+
const bytes: number[] = [];
|
|
50
|
+
for(let i = 0; i<str.length; i++) {
|
|
51
|
+
bytes.push(str.charCodeAt(i))
|
|
52
|
+
}
|
|
53
|
+
return bytes;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const hexStrint2byte = (str: string) => {
|
|
57
|
+
const length = Math.ceil(str.length / 2);
|
|
58
|
+
const bytes: number[] = [];
|
|
59
|
+
for (let i = 0; i < length; i++) {
|
|
60
|
+
const start = i * 2;
|
|
61
|
+
const end = start + 2;
|
|
62
|
+
const data = str.substring(start,end);
|
|
63
|
+
bytes.push(parseInt(data, 16))
|
|
64
|
+
}
|
|
65
|
+
return bytes
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const formatCode = (str) => {
|
|
69
|
+
const code = encodeURI(str);
|
|
70
|
+
if (code.indexOf('%') !== -1 && str !== '%') {
|
|
71
|
+
// utf8
|
|
72
|
+
return code
|
|
73
|
+
.split('%')
|
|
74
|
+
.filter((item) => item !== '')
|
|
75
|
+
.map((item) => parseInt(item, 16));
|
|
76
|
+
}
|
|
77
|
+
return [code.charCodeAt(0)];
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const formatCodesFromStr = (str: string) => {
|
|
81
|
+
const len = [0, 0];
|
|
82
|
+
let codes: number[] = [];
|
|
83
|
+
for (let i = 0; i < str.length; i++) {
|
|
84
|
+
const code = formatCode(str[i]);
|
|
85
|
+
len[1] += code.length;
|
|
86
|
+
codes = codes.concat(code);
|
|
87
|
+
}
|
|
88
|
+
return [codes, len];
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export { checkHeader, getProtocolLen, arrayToString, fillString, string2Bytes, hexStrint2byte, formatCodesFromStr, formatCode };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { MD5,enc,AES,mode,pad } from "crypto-js";
|
|
2
|
+
|
|
3
|
+
interface IGetRandomCodes {
|
|
4
|
+
SSID: string;
|
|
5
|
+
password: string;
|
|
6
|
+
pks: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface IGetRandomCode {
|
|
10
|
+
SSID: string;
|
|
11
|
+
password: string;
|
|
12
|
+
pk: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const getRandomCodes = ({ SSID, password, pks }: IGetRandomCodes): string[] => {
|
|
16
|
+
const randomCodes: string[] = [];
|
|
17
|
+
pks.map(item => {
|
|
18
|
+
const code = getRandomCode({
|
|
19
|
+
SSID,
|
|
20
|
+
password,
|
|
21
|
+
pk: item
|
|
22
|
+
});
|
|
23
|
+
randomCodes.push(code);
|
|
24
|
+
})
|
|
25
|
+
return randomCodes;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const getRandomCode = ({ SSID, password, pk }: IGetRandomCode): string => {
|
|
29
|
+
let aesKey:any = MD5(SSID + password).toString();
|
|
30
|
+
aesKey = enc.Hex.parse(aesKey)
|
|
31
|
+
let encryptedHexStr = enc.Utf8.parse(pk);
|
|
32
|
+
let encrypted = AES.encrypt(encryptedHexStr, aesKey, { iv: aesKey,mode: mode.ECB, padding: pad.ZeroPadding });
|
|
33
|
+
return MD5(encrypted.ciphertext).toString();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default getRandomCodes;
|
package/src/request.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requests a URL, returning a promise.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} url The URL we want to request
|
|
5
|
+
* @param {object} [options] The options we want to pass to "fetch"
|
|
6
|
+
* @return {object} An object containing either "data" or "err"
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export default function request<T>(url: string, options: any) {
|
|
11
|
+
return new Promise<T>((res, rej) => {
|
|
12
|
+
wx.request({
|
|
13
|
+
url, timeout: 3000, ...options,
|
|
14
|
+
success: (data: T) => {
|
|
15
|
+
res(data)
|
|
16
|
+
},
|
|
17
|
+
fail: (err: any) => {
|
|
18
|
+
rej(err);
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|