mini_program_gizwits_sdk 3.6.3 → 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.
Files changed (135) hide show
  1. package/README.md +4 -0
  2. package/dist/index.js +3 -3
  3. package/package.json +1 -1
  4. package/yarn-error.log +6901 -0
  5. package/dist/src/GizLog.d.ts +0 -18
  6. package/dist/src/crc/calculators/crc16modbus.d.ts +0 -2
  7. package/dist/src/crc/calculators/crc32.d.ts +0 -2
  8. package/dist/src/crc/crc16modbus.d.ts +0 -7
  9. package/dist/src/crc/crc32.d.ts +0 -7
  10. package/dist/src/crc/create_buffer.d.ts +0 -3
  11. package/dist/src/crc/define_crc.d.ts +0 -7
  12. package/dist/src/crc/index.d.ts +0 -19
  13. package/dist/src/crc/types.d.ts +0 -11
  14. package/dist/src/errorCode.d.ts +0 -3
  15. package/dist/src/globalData.d.ts +0 -2
  16. package/dist/src/handler/EventListener.d.ts +0 -9
  17. package/dist/src/handler/ble.d.ts +0 -105
  18. package/dist/src/handler/lan.d.ts +0 -78
  19. package/dist/src/handler/socket.d.ts +0 -151
  20. package/dist/src/openApiRequest.d.ts +0 -3
  21. package/dist/src/productConfigFileManage.d.ts +0 -11
  22. package/dist/src/protocol/Bind.d.ts +0 -7
  23. package/dist/src/protocol/DeviceInfo.d.ts +0 -11
  24. package/dist/src/protocol/DiscoverUDP.d.ts +0 -17
  25. package/dist/src/protocol/GetDeviceStatus.d.ts +0 -5
  26. package/dist/src/protocol/Login.d.ts +0 -12
  27. package/dist/src/protocol/Ntp.d.ts +0 -5
  28. package/dist/src/protocol/OTA/AwaitNoti.d.ts +0 -7
  29. package/dist/src/protocol/OTA/CheckCanOTA.d.ts +0 -10
  30. package/dist/src/protocol/OTA/OTAPackPackage.d.ts +0 -8
  31. package/dist/src/protocol/OTA/OtaComplete.d.ts +0 -8
  32. package/dist/src/protocol/OTA/PreOTA.d.ts +0 -11
  33. package/dist/src/protocol/OTA/ResetPosition.d.ts +0 -6
  34. package/dist/src/protocol/OffLineData.d.ts +0 -23
  35. package/dist/src/protocol/ProtocolBase.d.ts +0 -11
  36. package/dist/src/protocol/Reset.d.ts +0 -8
  37. package/dist/src/protocol/SetReset.d.ts +0 -7
  38. package/dist/src/protocol/WifiConfig.d.ts +0 -6
  39. package/dist/src/protocol/dataPoint.d.ts +0 -34
  40. package/dist/src/protocol/tool.d.ts +0 -14
  41. package/dist/src/randomCode.d.ts +0 -3
  42. package/dist/src/request.d.ts +0 -1
  43. package/dist/src/sdk.d.ts +0 -136
  44. package/dist/src/sentry.d.ts +0 -2
  45. package/dist/src/services/devices.d.ts +0 -47
  46. package/dist/src/services/login.d.ts +0 -4
  47. package/dist/src/services/monitor.d.ts +0 -12
  48. package/dist/src/services/ota.d.ts +0 -7
  49. package/dist/src/services/tool.d.ts +0 -4
  50. package/dist/src/services/uploadP0.d.ts +0 -14
  51. package/dist/src/sleep.d.ts +0 -2
  52. package/dist/src/types/index.d.ts +0 -360
  53. package/dist/src/utils.d.ts +0 -46
  54. package/dist/src/wechatApi.d.ts +0 -19
  55. package/dist/src/wifiConfig/ConfigBase.d.ts +0 -27
  56. package/dist/src/wifiConfig/ap.d.ts +0 -11
  57. package/dist/src/wifiConfig/ble.d.ts +0 -41
  58. package/dist/src/wifiConfig/nfc/disposeData.d.ts +0 -2
  59. package/dist/src/wifiConfig/nfc/formatData.d.ts +0 -3
  60. package/dist/src/wifiConfig/nfc/formatSSID.d.ts +0 -6
  61. package/dist/src/wifiConfig/nfc/index.d.ts +0 -22
  62. package/dist/src/wifiConfig/nfc/isIncludedCH.d.ts +0 -1
  63. package/dist/src/wifiConfig/nfc/nfcAConnect.d.ts +0 -6
  64. package/dist/src/wifiConfig/nfc/nfcATransceive.d.ts +0 -5
  65. package/dist/src/wifiConfig/nfc/ssIDToASC.d.ts +0 -1
  66. package/dist/src/wifiConfig/nfc/stringToGbk.d.ts +0 -1
  67. package/dist/src/wifiConfig/nfc/transceive.wx.d.ts +0 -2
  68. package/dist/src/wifiConfig/nfc/types.d.ts +0 -15
  69. package/index.ts +0 -8
  70. package/src/GizLog.ts +0 -51
  71. package/src/crc/calculators/crc16modbus.ts +0 -36
  72. package/src/crc/calculators/crc32.ts +0 -47
  73. package/src/crc/crc16modbus.ts +0 -3
  74. package/src/crc/crc32.ts +0 -4
  75. package/src/crc/create_buffer.ts +0 -7
  76. package/src/crc/define_crc.ts +0 -9
  77. package/src/crc/index.ts +0 -10
  78. package/src/crc/package.json +0 -3
  79. package/src/crc/types.ts +0 -10
  80. package/src/errorCode.ts +0 -83
  81. package/src/globalData.ts +0 -9
  82. package/src/handler/EventListener.ts +0 -44
  83. package/src/handler/ble.ts +0 -1369
  84. package/src/handler/lan.ts +0 -388
  85. package/src/handler/socket.ts +0 -686
  86. package/src/openApiRequest.ts +0 -50
  87. package/src/productConfigFileManage.ts +0 -72
  88. package/src/protocol/Bind.ts +0 -22
  89. package/src/protocol/DeviceInfo.ts +0 -37
  90. package/src/protocol/DiscoverUDP.ts +0 -80
  91. package/src/protocol/GetDeviceStatus.ts +0 -61
  92. package/src/protocol/Login.ts +0 -43
  93. package/src/protocol/Ntp.ts +0 -13
  94. package/src/protocol/OTA/AwaitNoti.ts +0 -14
  95. package/src/protocol/OTA/CheckCanOTA.ts +0 -23
  96. package/src/protocol/OTA/OTAPackPackage.ts +0 -37
  97. package/src/protocol/OTA/OtaComplete.ts +0 -17
  98. package/src/protocol/OTA/PreOTA.ts +0 -48
  99. package/src/protocol/OTA/ResetPosition.ts +0 -14
  100. package/src/protocol/OffLineData.ts +0 -81
  101. package/src/protocol/ProtocolBase.ts +0 -54
  102. package/src/protocol/Reset.ts +0 -16
  103. package/src/protocol/SetReset.ts +0 -13
  104. package/src/protocol/WifiConfig.ts +0 -42
  105. package/src/protocol/dataPoint.ts +0 -687
  106. package/src/protocol/tool.ts +0 -140
  107. package/src/randomCode.ts +0 -25
  108. package/src/request.ts +0 -22
  109. package/src/sdk.ts +0 -1536
  110. package/src/sentry.ts +0 -55
  111. package/src/services/devices.ts +0 -312
  112. package/src/services/login.ts +0 -11
  113. package/src/services/monitor.ts +0 -117
  114. package/src/services/ota.ts +0 -17
  115. package/src/services/tool.ts +0 -10
  116. package/src/services/uploadP0.ts +0 -57
  117. package/src/sleep.ts +0 -2
  118. package/src/types/index.ts +0 -455
  119. package/src/utils.ts +0 -448
  120. package/src/wechatApi.ts +0 -211
  121. package/src/wifiConfig/ConfigBase.ts +0 -235
  122. package/src/wifiConfig/ap.ts +0 -184
  123. package/src/wifiConfig/ble.ts +0 -481
  124. package/src/wifiConfig/nfc/disposeData.ts +0 -63
  125. package/src/wifiConfig/nfc/formatData.ts +0 -46
  126. package/src/wifiConfig/nfc/formatSSID.ts +0 -59
  127. package/src/wifiConfig/nfc/index.ts +0 -133
  128. package/src/wifiConfig/nfc/isIncludedCH.ts +0 -8
  129. package/src/wifiConfig/nfc/nfcAConnect.ts +0 -30
  130. package/src/wifiConfig/nfc/nfcATransceive.ts +0 -29
  131. package/src/wifiConfig/nfc/ssIDToASC.ts +0 -12
  132. package/src/wifiConfig/nfc/stringToGbk.ts +0 -51
  133. package/src/wifiConfig/nfc/transceive.wx.ts +0 -124
  134. package/src/wifiConfig/nfc/types.ts +0 -18
  135. 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
- }
@@ -1,312 +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
- port_s: item.port_s,
79
- port: item.port,
80
- ws_port: item.ws_port,
81
- wss_port: item.wss_port,
82
- passcode: item.passcode,
83
- isBleOnline: false,
84
- isLanOnline: false,
85
- connectType: 'NONE',
86
- name: item.dev_alias,
87
- isBind: true,
88
- isOnline: item.is_online,
89
- };
90
- });
91
- return {
92
- success: true,
93
- data: newDevices,
94
- };
95
- }
96
- return {
97
- success: false,
98
- err: data.err,
99
- };
100
- };
101
-
102
- export interface IBindMacParams {
103
- mac: string;
104
- productKey: string;
105
- productSecret: string;
106
- alias?: string;
107
- beOwner?: boolean;
108
- }
109
- export async function bindMac({
110
- mac,
111
- productKey,
112
- productSecret,
113
- alias,
114
- beOwner,
115
- }: IBindMacParams): Promise<IServiceResult<IOpenApiDevice>> {
116
- const dataJson = {
117
- mac,
118
- product_key: productKey,
119
- dev_alias: alias,
120
- set_owner: beOwner,
121
- };
122
-
123
- const { Signature, timestamp } = psKeySign(productSecret);
124
-
125
- const data = await openApiRequest<IOpenApiDevice>('/app/bind_mac', {
126
- method: 'POST',
127
- data: dataJson,
128
- headers: {
129
- 'X-Gizwits-Signature': Signature,
130
- 'X-Gizwits-Timestamp': timestamp,
131
- },
132
- });
133
- return data;
134
- }
135
-
136
- export interface IUnbindReturn {
137
- failed: string[];
138
- success: string[];
139
- }
140
- export async function unbindDevice({
141
- devices,
142
- }: {
143
- devices: IDevice[];
144
- }): Promise<IServiceResult<IUnbindReturn>> {
145
- const data = await openApiRequest<IUnbindReturn>('/app/bindings', {
146
- method: 'DELETE',
147
- data: {
148
- devices: devices.map((device) => {
149
- return { did: device.did };
150
- }),
151
- },
152
- });
153
- return data;
154
- }
155
-
156
- interface ICheckDeviceRegisterParams {
157
- SSID: string;
158
- password: string;
159
- productKeys: string[];
160
- }
161
- export async function checkDeviceRegister({
162
- SSID,
163
- password,
164
- productKeys,
165
- }: ICheckDeviceRegisterParams): Promise<IServiceResult<IRandomCodesResult[]>> {
166
- const codes = getRandomCodes({
167
- SSID,
168
- password,
169
- pks: productKeys,
170
- });
171
- let codeStr = '';
172
- codes.map((item) => {
173
- codeStr += `${item},`;
174
- });
175
- codeStr = codeStr.substring(0, codeStr.length - 1);
176
- const data = await openApiRequest<IRandomCodesResult[]>(
177
- `/app/device_register?random_codes=${codeStr}`,
178
- { method: 'get' }
179
- );
180
- return data;
181
- }
182
-
183
- interface ISafeRegisterParams {
184
- productKey: string;
185
- productSecret: string;
186
- mac: string;
187
- passcode: string;
188
- gwDid?: string;
189
- isReset: boolean;
190
- }
191
-
192
- export interface ISafeRegisterReturn {
193
- successDevices: IDevice[];
194
- failedDevices: IDevice[];
195
- }
196
- export async function safeRegister({
197
- productKey,
198
- productSecret,
199
- mac,
200
- passcode,
201
- gwDid,
202
- isReset,
203
- }: ISafeRegisterParams): Promise<IServiceResult<ISafeRegisterReturn>> {
204
- let dataStr = `is_reset=${isReset ? 1 : 0}&mac=${mac}&passcode=${passcode}`;
205
- if (gwDid) {
206
- dataStr += `&gw_did=${gwDid}`;
207
- }
208
-
209
- const key = enc.Hex.parse(productSecret);
210
- const iv = enc.Hex.parse('');
211
- const srcs = enc.Utf8.parse(dataStr);
212
- const encrypted = AES.encrypt(srcs, key, {
213
- iv: iv,
214
- mode: mode.ECB,
215
- padding: pad.Pkcs7,
216
- });
217
- const hexStr = encrypted.ciphertext.toString().toUpperCase();
218
- const data = await openApiRequest<string>(
219
- `/dev/${productKey}/device`,
220
- {
221
- method: 'POST',
222
- data: {
223
- data: hexStr,
224
- },
225
- headers: {
226
- 'content-type': 'application/x-www-form-urlencoded',
227
- },
228
- },
229
- false
230
- );
231
- if (data.success) {
232
- const successDevices = unPackSafeRegisterRes({productSecret, iv, data: data.data});
233
- const failedDevices = [];
234
-
235
- const targetDevice = successDevices.find(item => item.mac === mac);
236
- if (!targetDevice) {
237
- // 不存在
238
- failedDevices.push({
239
- mac,
240
- })
241
- }
242
-
243
- // TODO 解码
244
- return {
245
- success: true,
246
- data: {
247
- successDevices,
248
- failedDevices,
249
- },
250
- };
251
- }
252
- return {
253
- success: false,
254
- err: data.err,
255
- };
256
- }
257
-
258
- const unPackSafeRegisterRes = ({productSecret, data, iv}: {productSecret: string, data: string, iv: any}) => {
259
- const aesKey = enc.Hex.parse(productSecret)
260
- const bodyHex = enc.Hex.parse(data)
261
- let resEncrypted = AES.decrypt(enc.Base64.stringify(bodyHex), aesKey, { iv: iv, mode: mode.ECB, padding: new Padding() });
262
- const resString = resEncrypted.toString(enc.Utf8);
263
- const newData = [];
264
- resString.split(',').map(item => {
265
- const tmp = item.split('&');
266
- const mac = tmp[0].replace('mac=', '');
267
- const did = tmp[1].replace('did=', '');
268
- newData.push({
269
- mac, did
270
- })
271
- })
272
- return newData;
273
- }
274
-
275
- // const unPackSafeRegister = unPackSafeRegisterRes({
276
- // productSecret: 'aaa0840301e04748adaf9fcd160e7508',
277
- // iv: enc.Hex.parse(''),
278
- // data: '56ab36690dcb1e42bc3e69dab30c2e670c2188dfb76cb5a2f12986d18eb069f0f63d3c89ab069f3573ef81ca02936ad4'
279
- // })
280
- // console.log('unPackSafeRegisterunPackSafeRegister', unPackSafeRegister)
281
-
282
- interface IRenameProps {
283
- name?: string;
284
- did: string;
285
- remark?: string;
286
- }
287
- export interface IRenamePropsReturn {
288
- remark: string;
289
- dev_alias: string;
290
- }
291
- export async function editBindInfo({
292
- name,
293
- remark,
294
- did,
295
- }: IRenameProps): Promise<IServiceResult<IRenamePropsReturn>> {
296
- const body: any = {};
297
- if (name) {
298
- body.dev_alias = name;
299
- }
300
- if (remark) {
301
- body.remark = remark;
302
- }
303
- const data = await openApiRequest<IRenamePropsReturn>(
304
- `/app/bindings/${did}`,
305
- {
306
- method: 'PUT',
307
- data: body,
308
- },
309
- true
310
- );
311
- return data;
312
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- }
@@ -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
@@ -1,2 +0,0 @@
1
- const sleep = (time: number) => new Promise<void>(resolve => setTimeout(() => resolve(), time));
2
- export default sleep;