mini_program_gizwits_sdk 3.6.4 → 3.6.5
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 -3
- package/package.json +1 -1
- package/yarn-error.log +6901 -0
- package/dist/src/GizLog.d.ts +0 -18
- package/dist/src/crc/calculators/crc16modbus.d.ts +0 -2
- package/dist/src/crc/calculators/crc32.d.ts +0 -2
- package/dist/src/crc/crc16modbus.d.ts +0 -7
- package/dist/src/crc/crc32.d.ts +0 -7
- package/dist/src/crc/create_buffer.d.ts +0 -3
- package/dist/src/crc/define_crc.d.ts +0 -7
- package/dist/src/crc/index.d.ts +0 -19
- package/dist/src/crc/types.d.ts +0 -11
- package/dist/src/errorCode.d.ts +0 -3
- package/dist/src/globalData.d.ts +0 -2
- package/dist/src/handler/EventListener.d.ts +0 -9
- package/dist/src/handler/ble.d.ts +0 -105
- package/dist/src/handler/lan.d.ts +0 -78
- package/dist/src/handler/socket.d.ts +0 -151
- package/dist/src/openApiRequest.d.ts +0 -3
- package/dist/src/productConfigFileManage.d.ts +0 -11
- package/dist/src/protocol/Bind.d.ts +0 -7
- package/dist/src/protocol/DeviceInfo.d.ts +0 -11
- package/dist/src/protocol/DiscoverUDP.d.ts +0 -17
- package/dist/src/protocol/GetDeviceStatus.d.ts +0 -5
- package/dist/src/protocol/Login.d.ts +0 -12
- package/dist/src/protocol/Ntp.d.ts +0 -5
- package/dist/src/protocol/OTA/AwaitNoti.d.ts +0 -7
- package/dist/src/protocol/OTA/CheckCanOTA.d.ts +0 -10
- package/dist/src/protocol/OTA/OTAPackPackage.d.ts +0 -8
- package/dist/src/protocol/OTA/OtaComplete.d.ts +0 -8
- package/dist/src/protocol/OTA/PreOTA.d.ts +0 -11
- package/dist/src/protocol/OTA/ResetPosition.d.ts +0 -6
- package/dist/src/protocol/OffLineData.d.ts +0 -23
- package/dist/src/protocol/ProtocolBase.d.ts +0 -11
- package/dist/src/protocol/Reset.d.ts +0 -8
- package/dist/src/protocol/SetReset.d.ts +0 -7
- package/dist/src/protocol/WifiConfig.d.ts +0 -6
- package/dist/src/protocol/dataPoint.d.ts +0 -34
- package/dist/src/protocol/tool.d.ts +0 -14
- package/dist/src/randomCode.d.ts +0 -3
- package/dist/src/request.d.ts +0 -1
- package/dist/src/sdk.d.ts +0 -136
- package/dist/src/sentry.d.ts +0 -2
- package/dist/src/services/devices.d.ts +0 -47
- package/dist/src/services/login.d.ts +0 -4
- package/dist/src/services/monitor.d.ts +0 -12
- package/dist/src/services/ota.d.ts +0 -7
- package/dist/src/services/tool.d.ts +0 -4
- package/dist/src/services/uploadP0.d.ts +0 -14
- package/dist/src/sleep.d.ts +0 -2
- package/dist/src/types/index.d.ts +0 -361
- package/dist/src/utils.d.ts +0 -46
- package/dist/src/wechatApi.d.ts +0 -19
- package/dist/src/wifiConfig/ConfigBase.d.ts +0 -27
- package/dist/src/wifiConfig/ap.d.ts +0 -11
- package/dist/src/wifiConfig/ble.d.ts +0 -41
- package/dist/src/wifiConfig/nfc/disposeData.d.ts +0 -2
- package/dist/src/wifiConfig/nfc/formatData.d.ts +0 -3
- package/dist/src/wifiConfig/nfc/formatSSID.d.ts +0 -6
- package/dist/src/wifiConfig/nfc/index.d.ts +0 -22
- package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +0 -6
- package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +0 -5
- package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +0 -1
- package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +0 -2
- package/dist/src/wifiConfig/nfc/types.d.ts +0 -15
- package/index.ts +0 -8
- package/src/GizLog.ts +0 -51
- package/src/crc/calculators/crc16modbus.ts +0 -36
- package/src/crc/calculators/crc32.ts +0 -47
- package/src/crc/crc16modbus.ts +0 -3
- package/src/crc/crc32.ts +0 -4
- package/src/crc/create_buffer.ts +0 -7
- package/src/crc/define_crc.ts +0 -9
- package/src/crc/index.ts +0 -10
- package/src/crc/package.json +0 -3
- package/src/crc/types.ts +0 -10
- package/src/errorCode.ts +0 -83
- package/src/globalData.ts +0 -9
- package/src/handler/EventListener.ts +0 -44
- package/src/handler/ble.ts +0 -1369
- package/src/handler/lan.ts +0 -389
- package/src/handler/socket.ts +0 -686
- package/src/openApiRequest.ts +0 -50
- package/src/productConfigFileManage.ts +0 -72
- package/src/protocol/Bind.ts +0 -22
- package/src/protocol/DeviceInfo.ts +0 -37
- package/src/protocol/DiscoverUDP.ts +0 -80
- package/src/protocol/GetDeviceStatus.ts +0 -61
- package/src/protocol/Login.ts +0 -43
- package/src/protocol/Ntp.ts +0 -13
- package/src/protocol/OTA/AwaitNoti.ts +0 -14
- package/src/protocol/OTA/CheckCanOTA.ts +0 -23
- package/src/protocol/OTA/OTAPackPackage.ts +0 -37
- package/src/protocol/OTA/OtaComplete.ts +0 -17
- package/src/protocol/OTA/PreOTA.ts +0 -48
- package/src/protocol/OTA/ResetPosition.ts +0 -14
- package/src/protocol/OffLineData.ts +0 -81
- package/src/protocol/ProtocolBase.ts +0 -54
- package/src/protocol/Reset.ts +0 -16
- package/src/protocol/SetReset.ts +0 -13
- package/src/protocol/WifiConfig.ts +0 -42
- package/src/protocol/dataPoint.ts +0 -687
- package/src/protocol/tool.ts +0 -140
- package/src/randomCode.ts +0 -25
- package/src/request.ts +0 -22
- package/src/sdk.ts +0 -1536
- package/src/sentry.ts +0 -55
- package/src/services/devices.ts +0 -313
- package/src/services/login.ts +0 -11
- package/src/services/monitor.ts +0 -117
- package/src/services/ota.ts +0 -17
- package/src/services/tool.ts +0 -10
- package/src/services/uploadP0.ts +0 -57
- package/src/sleep.ts +0 -2
- package/src/types/index.ts +0 -456
- package/src/utils.ts +0 -449
- package/src/wechatApi.ts +0 -211
- package/src/wifiConfig/ConfigBase.ts +0 -235
- package/src/wifiConfig/ap.ts +0 -185
- package/src/wifiConfig/ble.ts +0 -460
- package/src/wifiConfig/nfc/disposeData.ts +0 -63
- package/src/wifiConfig/nfc/formatData.ts +0 -46
- package/src/wifiConfig/nfc/formatSSID.ts +0 -59
- package/src/wifiConfig/nfc/index.ts +0 -134
- package/src/wifiConfig/nfc/isIncludedCH.ts +0 -8
- package/src/wifiConfig/nfc/nfcAConnect.ts +0 -30
- package/src/wifiConfig/nfc/nfcATransceive.ts +0 -29
- package/src/wifiConfig/nfc/ssIDToASC.ts +0 -12
- package/src/wifiConfig/nfc/stringToGbk.ts +0 -51
- package/src/wifiConfig/nfc/transceive.wx.ts +0 -124
- package/src/wifiConfig/nfc/types.ts +0 -18
- package/src/wifiConfig/timeZoneName.json +0 -1
package/src/sentry.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {MD5} from "crypto-js";
|
|
2
|
-
import request from "./request";
|
|
3
|
-
|
|
4
|
-
export default (err) => {
|
|
5
|
-
const platformInfo = wx.getSystemInfoSync();
|
|
6
|
-
const baseData = {
|
|
7
|
-
"exception": {
|
|
8
|
-
"values": [{
|
|
9
|
-
"type": "Error",
|
|
10
|
-
"value": err.stack,
|
|
11
|
-
"stacktrace": {
|
|
12
|
-
},
|
|
13
|
-
"mechanism": {
|
|
14
|
-
"type": "generic",
|
|
15
|
-
"handled": true
|
|
16
|
-
}
|
|
17
|
-
}]
|
|
18
|
-
},
|
|
19
|
-
"level": "error",
|
|
20
|
-
"event_id": MD5(`${new Date().getTime()}`).toString(),
|
|
21
|
-
"platform": "javascript",
|
|
22
|
-
"sdk": {
|
|
23
|
-
},
|
|
24
|
-
"timestamp": new Date().getTime() / 1000,
|
|
25
|
-
"environment": "production",
|
|
26
|
-
"contexts": {
|
|
27
|
-
"device": {
|
|
28
|
-
},
|
|
29
|
-
"os": {
|
|
30
|
-
"name": platformInfo.platform,
|
|
31
|
-
"version": platformInfo.version
|
|
32
|
-
},
|
|
33
|
-
"extra": {}
|
|
34
|
-
},
|
|
35
|
-
"extra": {
|
|
36
|
-
"message": err.message
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
var options = {
|
|
40
|
-
'method': 'POST',
|
|
41
|
-
'headers': {
|
|
42
|
-
'Connection': 'keep-alive',
|
|
43
|
-
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1 wechatdevtools/1.06.2206090 MicroMessenger/8.0.5 Language/zh_CN webview/',
|
|
44
|
-
'content-type': 'application/json',
|
|
45
|
-
'Accept': '*/*',
|
|
46
|
-
'Sec-Fetch-Site': 'cross-site',
|
|
47
|
-
'Sec-Fetch-Mode': 'cors',
|
|
48
|
-
'Sec-Fetch-Dest': 'empty',
|
|
49
|
-
'Referer': 'https://servicewechat.com/wx6dc8e50cb68bc121/devtools/page-frame.html',
|
|
50
|
-
'Cookie': '__org='
|
|
51
|
-
},
|
|
52
|
-
data: JSON.stringify(baseData)
|
|
53
|
-
};
|
|
54
|
-
request('https://appmonitor.gizwits.com/api/21/store/?sentry_key=0b2de791abf548a1bedf0b0ebdd8ecc7&sentry_version=7', options)
|
|
55
|
-
}
|
package/src/services/devices.ts
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
import { enc, AES, mode, pad } from 'crypto-js';
|
|
2
|
-
import openApiRequest from '../openApiRequest';
|
|
3
|
-
import getRandomCodes from '../randomCode';
|
|
4
|
-
import { psKeySign } from './tool';
|
|
5
|
-
import { IDevice, IDeviceRes, IOpenApiDevice, IRandomCodesResult, IServiceResult } from '../types';
|
|
6
|
-
// eslint-disable-next-line import/no-commonjs
|
|
7
|
-
// const CryptoJS = require('crypto-js');
|
|
8
|
-
|
|
9
|
-
// 云端aes 特殊解码
|
|
10
|
-
class Padding {
|
|
11
|
-
/**
|
|
12
|
-
* Pads data using the algorithm defined in PKCS #5/7.
|
|
13
|
-
*
|
|
14
|
-
* @param data The data to pad.
|
|
15
|
-
* @param blockSize The multiple that the data should be padded to.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
*
|
|
19
|
-
* CryptoJS.pad.Pkcs7.pad(wordArray, 4);
|
|
20
|
-
*/
|
|
21
|
-
pad = (data, blockSize) => {
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Unpads data that had been padded using the algorithm defined in PKCS #5/7.
|
|
27
|
-
*
|
|
28
|
-
* @param data The data to unpad.
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
*
|
|
32
|
-
* CryptoJS.pad.Pkcs7.unpad(wordArray);
|
|
33
|
-
*/
|
|
34
|
-
unpad = (data) => {
|
|
35
|
-
const AES_BLOCK_LEN = 16;
|
|
36
|
-
const len = data.sigBytes;
|
|
37
|
-
let readed = 0;
|
|
38
|
-
let repeat = 1;
|
|
39
|
-
const stringData= data.toString(enc.Utf8);
|
|
40
|
-
while(readed + AES_BLOCK_LEN <= len)
|
|
41
|
-
{
|
|
42
|
-
readed += AES_BLOCK_LEN;
|
|
43
|
-
}
|
|
44
|
-
for(let i = 0; i < (AES_BLOCK_LEN - 2) / 2; i++)
|
|
45
|
-
{
|
|
46
|
-
const start = readed - i * 2;
|
|
47
|
-
if(stringData.substring(start, start - 2) == stringData.substring(start - 2, start - 4))
|
|
48
|
-
{
|
|
49
|
-
repeat++;
|
|
50
|
-
}
|
|
51
|
-
else
|
|
52
|
-
{
|
|
53
|
-
readed -= repeat * 2;
|
|
54
|
-
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
data.sigBytes = readed;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const getBindingList = async (): Promise<IServiceResult<IDevice[]>> => {
|
|
63
|
-
const data = await openApiRequest<IDeviceRes>(
|
|
64
|
-
'/app/bindings?show_disabled=0&limit=1000&skip=0',
|
|
65
|
-
{
|
|
66
|
-
method: 'GET',
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
if (data.success) {
|
|
71
|
-
const newDevices: IDevice[] = data.data!.devices.map((item) => {
|
|
72
|
-
return {
|
|
73
|
-
...item,
|
|
74
|
-
productKey: item.product_key,
|
|
75
|
-
mac: item.mac,
|
|
76
|
-
did: item.did,
|
|
77
|
-
host: item.host,
|
|
78
|
-
localName: '',
|
|
79
|
-
port_s: item.port_s,
|
|
80
|
-
port: item.port,
|
|
81
|
-
ws_port: item.ws_port,
|
|
82
|
-
wss_port: item.wss_port,
|
|
83
|
-
passcode: item.passcode,
|
|
84
|
-
isBleOnline: false,
|
|
85
|
-
isLanOnline: false,
|
|
86
|
-
connectType: 'NONE',
|
|
87
|
-
name: item.dev_alias,
|
|
88
|
-
isBind: true,
|
|
89
|
-
isOnline: item.is_online,
|
|
90
|
-
};
|
|
91
|
-
});
|
|
92
|
-
return {
|
|
93
|
-
success: true,
|
|
94
|
-
data: newDevices,
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
success: false,
|
|
99
|
-
err: data.err,
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export interface IBindMacParams {
|
|
104
|
-
mac: string;
|
|
105
|
-
productKey: string;
|
|
106
|
-
productSecret: string;
|
|
107
|
-
alias?: string;
|
|
108
|
-
beOwner?: boolean;
|
|
109
|
-
}
|
|
110
|
-
export async function bindMac({
|
|
111
|
-
mac,
|
|
112
|
-
productKey,
|
|
113
|
-
productSecret,
|
|
114
|
-
alias,
|
|
115
|
-
beOwner,
|
|
116
|
-
}: IBindMacParams): Promise<IServiceResult<IOpenApiDevice>> {
|
|
117
|
-
const dataJson = {
|
|
118
|
-
mac,
|
|
119
|
-
product_key: productKey,
|
|
120
|
-
dev_alias: alias,
|
|
121
|
-
set_owner: beOwner,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const { Signature, timestamp } = psKeySign(productSecret);
|
|
125
|
-
|
|
126
|
-
const data = await openApiRequest<IOpenApiDevice>('/app/bind_mac', {
|
|
127
|
-
method: 'POST',
|
|
128
|
-
data: dataJson,
|
|
129
|
-
headers: {
|
|
130
|
-
'X-Gizwits-Signature': Signature,
|
|
131
|
-
'X-Gizwits-Timestamp': timestamp,
|
|
132
|
-
},
|
|
133
|
-
});
|
|
134
|
-
return data;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export interface IUnbindReturn {
|
|
138
|
-
failed: string[];
|
|
139
|
-
success: string[];
|
|
140
|
-
}
|
|
141
|
-
export async function unbindDevice({
|
|
142
|
-
devices,
|
|
143
|
-
}: {
|
|
144
|
-
devices: IDevice[];
|
|
145
|
-
}): Promise<IServiceResult<IUnbindReturn>> {
|
|
146
|
-
const data = await openApiRequest<IUnbindReturn>('/app/bindings', {
|
|
147
|
-
method: 'DELETE',
|
|
148
|
-
data: {
|
|
149
|
-
devices: devices.map((device) => {
|
|
150
|
-
return { did: device.did };
|
|
151
|
-
}),
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
return data;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
interface ICheckDeviceRegisterParams {
|
|
158
|
-
SSID: string;
|
|
159
|
-
password: string;
|
|
160
|
-
productKeys: string[];
|
|
161
|
-
}
|
|
162
|
-
export async function checkDeviceRegister({
|
|
163
|
-
SSID,
|
|
164
|
-
password,
|
|
165
|
-
productKeys,
|
|
166
|
-
}: ICheckDeviceRegisterParams): Promise<IServiceResult<IRandomCodesResult[]>> {
|
|
167
|
-
const codes = getRandomCodes({
|
|
168
|
-
SSID,
|
|
169
|
-
password,
|
|
170
|
-
pks: productKeys,
|
|
171
|
-
});
|
|
172
|
-
let codeStr = '';
|
|
173
|
-
codes.map((item) => {
|
|
174
|
-
codeStr += `${item},`;
|
|
175
|
-
});
|
|
176
|
-
codeStr = codeStr.substring(0, codeStr.length - 1);
|
|
177
|
-
const data = await openApiRequest<IRandomCodesResult[]>(
|
|
178
|
-
`/app/device_register?random_codes=${codeStr}`,
|
|
179
|
-
{ method: 'get' }
|
|
180
|
-
);
|
|
181
|
-
return data;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
interface ISafeRegisterParams {
|
|
185
|
-
productKey: string;
|
|
186
|
-
productSecret: string;
|
|
187
|
-
mac: string;
|
|
188
|
-
passcode: string;
|
|
189
|
-
gwDid?: string;
|
|
190
|
-
isReset: boolean;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
export interface ISafeRegisterReturn {
|
|
194
|
-
successDevices: IDevice[];
|
|
195
|
-
failedDevices: IDevice[];
|
|
196
|
-
}
|
|
197
|
-
export async function safeRegister({
|
|
198
|
-
productKey,
|
|
199
|
-
productSecret,
|
|
200
|
-
mac,
|
|
201
|
-
passcode,
|
|
202
|
-
gwDid,
|
|
203
|
-
isReset,
|
|
204
|
-
}: ISafeRegisterParams): Promise<IServiceResult<ISafeRegisterReturn>> {
|
|
205
|
-
let dataStr = `is_reset=${isReset ? 1 : 0}&mac=${mac}&passcode=${passcode}`;
|
|
206
|
-
if (gwDid) {
|
|
207
|
-
dataStr += `&gw_did=${gwDid}`;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
const key = enc.Hex.parse(productSecret);
|
|
211
|
-
const iv = enc.Hex.parse('');
|
|
212
|
-
const srcs = enc.Utf8.parse(dataStr);
|
|
213
|
-
const encrypted = AES.encrypt(srcs, key, {
|
|
214
|
-
iv: iv,
|
|
215
|
-
mode: mode.ECB,
|
|
216
|
-
padding: pad.Pkcs7,
|
|
217
|
-
});
|
|
218
|
-
const hexStr = encrypted.ciphertext.toString().toUpperCase();
|
|
219
|
-
const data = await openApiRequest<string>(
|
|
220
|
-
`/dev/${productKey}/device`,
|
|
221
|
-
{
|
|
222
|
-
method: 'POST',
|
|
223
|
-
data: {
|
|
224
|
-
data: hexStr,
|
|
225
|
-
},
|
|
226
|
-
headers: {
|
|
227
|
-
'content-type': 'application/x-www-form-urlencoded',
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
false
|
|
231
|
-
);
|
|
232
|
-
if (data.success) {
|
|
233
|
-
const successDevices = unPackSafeRegisterRes({productSecret, iv, data: data.data});
|
|
234
|
-
const failedDevices = [];
|
|
235
|
-
|
|
236
|
-
const targetDevice = successDevices.find(item => item.mac === mac);
|
|
237
|
-
if (!targetDevice) {
|
|
238
|
-
// 不存在
|
|
239
|
-
failedDevices.push({
|
|
240
|
-
mac,
|
|
241
|
-
})
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// TODO 解码
|
|
245
|
-
return {
|
|
246
|
-
success: true,
|
|
247
|
-
data: {
|
|
248
|
-
successDevices,
|
|
249
|
-
failedDevices,
|
|
250
|
-
},
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
success: false,
|
|
255
|
-
err: data.err,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const unPackSafeRegisterRes = ({productSecret, data, iv}: {productSecret: string, data: string, iv: any}) => {
|
|
260
|
-
const aesKey = enc.Hex.parse(productSecret)
|
|
261
|
-
const bodyHex = enc.Hex.parse(data)
|
|
262
|
-
let resEncrypted = AES.decrypt(enc.Base64.stringify(bodyHex), aesKey, { iv: iv, mode: mode.ECB, padding: new Padding() });
|
|
263
|
-
const resString = resEncrypted.toString(enc.Utf8);
|
|
264
|
-
const newData = [];
|
|
265
|
-
resString.split(',').map(item => {
|
|
266
|
-
const tmp = item.split('&');
|
|
267
|
-
const mac = tmp[0].replace('mac=', '');
|
|
268
|
-
const did = tmp[1].replace('did=', '');
|
|
269
|
-
newData.push({
|
|
270
|
-
mac, did
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
|
-
return newData;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// const unPackSafeRegister = unPackSafeRegisterRes({
|
|
277
|
-
// productSecret: 'aaa0840301e04748adaf9fcd160e7508',
|
|
278
|
-
// iv: enc.Hex.parse(''),
|
|
279
|
-
// data: '56ab36690dcb1e42bc3e69dab30c2e670c2188dfb76cb5a2f12986d18eb069f0f63d3c89ab069f3573ef81ca02936ad4'
|
|
280
|
-
// })
|
|
281
|
-
// console.log('unPackSafeRegisterunPackSafeRegister', unPackSafeRegister)
|
|
282
|
-
|
|
283
|
-
interface IRenameProps {
|
|
284
|
-
name?: string;
|
|
285
|
-
did: string;
|
|
286
|
-
remark?: string;
|
|
287
|
-
}
|
|
288
|
-
export interface IRenamePropsReturn {
|
|
289
|
-
remark: string;
|
|
290
|
-
dev_alias: string;
|
|
291
|
-
}
|
|
292
|
-
export async function editBindInfo({
|
|
293
|
-
name,
|
|
294
|
-
remark,
|
|
295
|
-
did,
|
|
296
|
-
}: IRenameProps): Promise<IServiceResult<IRenamePropsReturn>> {
|
|
297
|
-
const body: any = {};
|
|
298
|
-
if (name) {
|
|
299
|
-
body.dev_alias = name;
|
|
300
|
-
}
|
|
301
|
-
if (remark) {
|
|
302
|
-
body.remark = remark;
|
|
303
|
-
}
|
|
304
|
-
const data = await openApiRequest<IRenamePropsReturn>(
|
|
305
|
-
`/app/bindings/${did}`,
|
|
306
|
-
{
|
|
307
|
-
method: 'PUT',
|
|
308
|
-
data: body,
|
|
309
|
-
},
|
|
310
|
-
true
|
|
311
|
-
);
|
|
312
|
-
return data;
|
|
313
|
-
}
|
package/src/services/login.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import openApiRequest from "../openApiRequest";
|
|
2
|
-
import { ILoginRes } from "../types";
|
|
3
|
-
|
|
4
|
-
export async function AnonymousLogin ({uid}: {uid: string}) {
|
|
5
|
-
return openApiRequest<ILoginRes>('/app/users', {
|
|
6
|
-
data: {
|
|
7
|
-
phone_id: uid,
|
|
8
|
-
},
|
|
9
|
-
method: 'POST',
|
|
10
|
-
}, false)
|
|
11
|
-
}
|
package/src/services/monitor.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { version } from '../../package.json';
|
|
2
|
-
import { getGlobalData } from "../globalData";
|
|
3
|
-
import openApiRequest from '../openApiRequest';
|
|
4
|
-
import { IDevice } from '../types';
|
|
5
|
-
|
|
6
|
-
interface MobileInfo {
|
|
7
|
-
brand: string;
|
|
8
|
-
model: string; // 设备型号。新机型刚推出一段时间会显示unknown,微信会尽快进行适配。
|
|
9
|
-
pixelRatio: number;
|
|
10
|
-
systemVersion: string; // 操作系统版本
|
|
11
|
-
platform: string; // 客户端平台
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
interface AppInfo {
|
|
15
|
-
wxSdkVersion: string; // 客户端基础库版本
|
|
16
|
-
gizwitsSdkVersion: string; // Gizwits SDK 版本
|
|
17
|
-
appID: string; // gizwitsAppID
|
|
18
|
-
bluetoothEnabled?: boolean; // 蓝牙是否可用
|
|
19
|
-
locationEnabled?: boolean; // 定位是否可用
|
|
20
|
-
wifiEnabled?: boolean; // wifi是否可用
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// 统计每天设备活跃数
|
|
24
|
-
// 统计设备失败原因
|
|
25
|
-
// 统计设备连接时长
|
|
26
|
-
// 统计连接每个阶段时长
|
|
27
|
-
|
|
28
|
-
type EventType = "BleDeviceConnectStart" | "BleDeviceConnectEnd" | "BleDeviceConnectBind" | "BleDeviceConnectLogin" | "BleDeviceConnectFinish";
|
|
29
|
-
type FailureType = Omit<EventType, 'BleDeviceConnectStart' | 'BleDeviceConnectFinish'>
|
|
30
|
-
|
|
31
|
-
interface Event {
|
|
32
|
-
origin: "MINI-WX",
|
|
33
|
-
mobileInfo: MobileInfo,
|
|
34
|
-
userInfo: null,
|
|
35
|
-
appInfo: AppInfo,
|
|
36
|
-
eventID: string,
|
|
37
|
-
eventType: EventType,
|
|
38
|
-
monitorTarget: {
|
|
39
|
-
device: {
|
|
40
|
-
mac: string;
|
|
41
|
-
did: string;
|
|
42
|
-
productKey: string;
|
|
43
|
-
},
|
|
44
|
-
success: boolean;
|
|
45
|
-
failureType?: FailureType
|
|
46
|
-
},
|
|
47
|
-
time: Date,
|
|
48
|
-
timeStamp: Number,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
class BaseInfo {
|
|
52
|
-
mobile: MobileInfo;
|
|
53
|
-
app: AppInfo;
|
|
54
|
-
constructor() {
|
|
55
|
-
wx.getSystemInfoAsync({
|
|
56
|
-
success: (res) => {
|
|
57
|
-
this.app = {
|
|
58
|
-
wxSdkVersion: res.SDKVersion,
|
|
59
|
-
gizwitsSdkVersion: version,
|
|
60
|
-
appID: 'unknown',
|
|
61
|
-
bluetoothEnabled: res.bluetoothEnabled,
|
|
62
|
-
locationEnabled: res.locationEnabled,
|
|
63
|
-
wifiEnabled: res.wifiEnabled,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
this.mobile = {
|
|
67
|
-
brand: res.brand,
|
|
68
|
-
model: res.model,
|
|
69
|
-
pixelRatio: res.pixelRatio,
|
|
70
|
-
systemVersion: res.system,
|
|
71
|
-
platform: res.platform,
|
|
72
|
-
};
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
updateAppId(appId: string) {
|
|
78
|
-
this.app.appID = appId;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const baseInfo = new BaseInfo();
|
|
83
|
-
|
|
84
|
-
interface IProps {
|
|
85
|
-
device: IDevice;
|
|
86
|
-
eventID: string;
|
|
87
|
-
eventType: EventType,
|
|
88
|
-
success: boolean;
|
|
89
|
-
failureType?: FailureType
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function reportEvent({ device, eventID, eventType, success, failureType }: IProps) {
|
|
93
|
-
baseInfo.updateAppId(getGlobalData('appID') || 'unknown');
|
|
94
|
-
const path = `/v2/products/${device.productKey}/devices/bluetooth-connect-data`;
|
|
95
|
-
const curDate = new Date();
|
|
96
|
-
|
|
97
|
-
const eventData: Event = {
|
|
98
|
-
origin: "MINI-WX",
|
|
99
|
-
mobileInfo: baseInfo.mobile,
|
|
100
|
-
userInfo: null,
|
|
101
|
-
appInfo: baseInfo.app,
|
|
102
|
-
eventID,
|
|
103
|
-
eventType,
|
|
104
|
-
monitorTarget: {
|
|
105
|
-
device,
|
|
106
|
-
success,
|
|
107
|
-
failureType,
|
|
108
|
-
},
|
|
109
|
-
time: curDate,
|
|
110
|
-
timeStamp: Math.floor(curDate.getTime() / 1000),
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return openApiRequest<any>(path, {
|
|
114
|
-
data: eventData,
|
|
115
|
-
method: 'POST',
|
|
116
|
-
}, true);
|
|
117
|
-
}
|
package/src/services/ota.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import openApiRequest from "../openApiRequest";
|
|
2
|
-
import { IOTAType, OTARes } from "../types";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
//type 指定固件类型,1代表WiFi模组,2代表MCU
|
|
6
|
-
export async function checkUpdate ({did, type, hardVersion, softVersion}: {did: string, type: IOTAType, hardVersion: string, softVersion: string}) {
|
|
7
|
-
const realType = type == 'MCU' ? '2': '1';
|
|
8
|
-
return openApiRequest<OTARes>(`/app/ota/v4.1/update_and_check/${did}`, {
|
|
9
|
-
data: {
|
|
10
|
-
type: realType,
|
|
11
|
-
hard_version: hardVersion,
|
|
12
|
-
soft_version: softVersion,
|
|
13
|
-
https: '1',
|
|
14
|
-
},
|
|
15
|
-
method: 'POST',
|
|
16
|
-
}, true)
|
|
17
|
-
}
|
package/src/services/tool.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-commonjs
|
|
2
|
-
import { MD5 } from "crypto-js";
|
|
3
|
-
|
|
4
|
-
export const psKeySign = (productSecret: string) => {
|
|
5
|
-
const timestamp = Math.round(new Date().getTime()/1000);
|
|
6
|
-
|
|
7
|
-
const str = productSecret + timestamp;
|
|
8
|
-
const Signature = MD5(str).toString();
|
|
9
|
-
return {Signature, timestamp};
|
|
10
|
-
}
|
package/src/services/uploadP0.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import openApiRequest from "../openApiRequest";
|
|
2
|
-
import { enc, AES, mode, pad } from 'crypto-js';
|
|
3
|
-
import { IDevice } from "../types";
|
|
4
|
-
|
|
5
|
-
export interface IUploadRes {
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
interface IData {
|
|
9
|
-
raw: string;
|
|
10
|
-
created_at: number;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface IProps {
|
|
14
|
-
device: IDevice;
|
|
15
|
-
data: IData[];
|
|
16
|
-
productSecret: string;
|
|
17
|
-
}
|
|
18
|
-
export async function uploadP0 ({device, data, productSecret}: IProps) {
|
|
19
|
-
const path = `/v2/products/${device.productKey}/devices/offline-data`;
|
|
20
|
-
|
|
21
|
-
let passCode = device.passcode
|
|
22
|
-
|
|
23
|
-
const key = enc.Hex.parse(productSecret);
|
|
24
|
-
const iv = enc.Hex.parse('');
|
|
25
|
-
const srcs = enc.Utf8.parse(passCode);
|
|
26
|
-
const encrypted = AES.encrypt(srcs, key, { iv: iv, mode: mode.ECB, padding: pad.Pkcs7 });
|
|
27
|
-
passCode = encrypted.ciphertext.toString().toUpperCase();
|
|
28
|
-
|
|
29
|
-
return openApiRequest<IUploadRes>(path, {
|
|
30
|
-
data: {
|
|
31
|
-
data,
|
|
32
|
-
encoding: 'hex',
|
|
33
|
-
},
|
|
34
|
-
method: 'POST',
|
|
35
|
-
headers: {
|
|
36
|
-
'X-Gizwits-Device-Id': device.did,
|
|
37
|
-
'X-Gizwits-Device-passcode': passCode,
|
|
38
|
-
},
|
|
39
|
-
}, false)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// setTimeout(() => {
|
|
43
|
-
// uploadP0({
|
|
44
|
-
// device: {
|
|
45
|
-
// productKey: "8da73e49a9c74d6e9321b4383b44e4e9",
|
|
46
|
-
// did: "SlJJzMGa0MDOmhUTt0PIul",
|
|
47
|
-
// passcode: "1234567890",
|
|
48
|
-
// },
|
|
49
|
-
// data: [
|
|
50
|
-
// {
|
|
51
|
-
// raw: "00000003",
|
|
52
|
-
// created_at: parseInt(`${Date.now() / 1000}`, 10)
|
|
53
|
-
// }
|
|
54
|
-
// ],
|
|
55
|
-
// productSecret: "bf5df28e904b455f85fa5be1805945ad"
|
|
56
|
-
// })
|
|
57
|
-
// }, 3000)
|
package/src/sleep.ts
DELETED