mini_program_gizwits_sdk 3.2.9 → 3.2.10-kuka

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.
@@ -1,4 +1,5 @@
1
1
  import openApiRequest from "../openApiRequest";
2
+ import { enc, AES, mode, pad } from 'crypto-js';
2
3
 
3
4
  export interface IUploadRes {
4
5
  }
@@ -11,9 +12,19 @@ interface IData {
11
12
  interface IProps {
12
13
  device: IDevice;
13
14
  data: IData[];
15
+ productSecret: string;
14
16
  }
15
- export async function uploadP0 ({device, data}: IProps) {
17
+ export async function uploadP0 ({device, data, productSecret}: IProps) {
16
18
  const path = `/v2/products/${device.productKey}/devices/offline-data`;
19
+
20
+ let passCode = device.passcode
21
+
22
+ const key = enc.Hex.parse(productSecret);
23
+ const iv = enc.Hex.parse('');
24
+ const srcs = enc.Utf8.parse(passCode);
25
+ const encrypted = AES.encrypt(srcs, key, { iv: iv, mode: mode.ECB, padding: pad.Pkcs7 });
26
+ passCode = encrypted.ciphertext.toString().toUpperCase();
27
+
17
28
  return openApiRequest<IUploadRes>(path, {
18
29
  data: {
19
30
  data,
@@ -22,7 +33,24 @@ export async function uploadP0 ({device, data}: IProps) {
22
33
  method: 'POST',
23
34
  headers: {
24
35
  'X-Gizwits-Device-Id': device.did,
25
- 'X-Gizwits-Device-passcode': device.passcode,
36
+ 'X-Gizwits-Device-passcode': passCode,
26
37
  },
27
38
  }, false)
28
- }
39
+ }
40
+
41
+ // setTimeout(() => {
42
+ // uploadP0({
43
+ // device: {
44
+ // productKey: "8da73e49a9c74d6e9321b4383b44e4e9",
45
+ // did: "SlJJzMGa0MDOmhUTt0PIul",
46
+ // passcode: "1234567890",
47
+ // },
48
+ // data: [
49
+ // {
50
+ // raw: "00000003",
51
+ // created_at: parseInt(`${Date.now() / 1000}`, 10)
52
+ // }
53
+ // ],
54
+ // productSecret: "bf5df28e904b455f85fa5be1805945ad"
55
+ // })
56
+ // }, 3000)
@@ -1,18 +0,0 @@
1
- export declare type TLogType = 'debug' | 'info' | 'warn' | 'error';
2
- declare class Log {
3
- logMap: {
4
- id: string;
5
- }[];
6
- console: any;
7
- debug: (...data: any[]) => void;
8
- info: (...data: any[]) => void;
9
- log: (...data: any[]) => void;
10
- warn: (...data: any[]) => void;
11
- error: (info: string, error: Error) => void;
12
- setLogLevel: (type: TLogType) => {
13
- success: boolean;
14
- err: IError;
15
- };
16
- }
17
- declare const _default: Log;
18
- export default _default;
@@ -1,9 +0,0 @@
1
- export default class EventListener<T> {
2
- listenerMap: any;
3
- addEventListener: <K extends keyof T>(type: K, func: T[K]) => Promise<{
4
- success: boolean;
5
- }>;
6
- removeEventListener: <K extends keyof T>(type: K, func: T[K]) => {
7
- success: boolean;
8
- };
9
- }
@@ -1,93 +0,0 @@
1
- import DiscoverUDP from "../protocol/DiscoverUdp";
2
- import { IResult } from "../sdk";
3
- import EventListener from "./EventListener";
4
- interface ConnectDevice {
5
- mac: string;
6
- productKey: string;
7
- socketHandle: TCPHandler;
8
- }
9
- interface ILanDevice extends IDevice {
10
- expandData: DiscoverUDP;
11
- ip: string;
12
- }
13
- declare type GizLanDeviceListNotifications = (devices: IDevice[]) => void;
14
- declare type GizLanDeviceDataNotifications = (mac: string, data: string) => void;
15
- export interface TLanHandleEvent {
16
- GizLanDeviceList: GizLanDeviceListNotifications;
17
- GizLanDeviceData: GizLanDeviceDataNotifications;
18
- }
19
- export declare class LanHandle extends EventListener<TLanHandleEvent> {
20
- connectedList: ConnectDevice[];
21
- private pks;
22
- scanList: ILanDevice[];
23
- private boradcastTimer;
24
- private UDPSocket;
25
- private deviceUDPPort;
26
- private appUDPPort;
27
- private offlineThreshold;
28
- private isActive;
29
- private listenDevOfflineTimer;
30
- constructor({ pks }: {
31
- pks: any;
32
- });
33
- init: () => void;
34
- private onAppShow;
35
- private onAppHide;
36
- private listenDevOffline;
37
- private notifyDevices;
38
- private notifyDeviceData;
39
- isSameDevice: (deviceA: IDevice, deviceB: IDevice) => boolean;
40
- disConnectDevice: (target: IDevice) => {
41
- success: boolean;
42
- err?: undefined;
43
- } | {
44
- success: boolean;
45
- err: any;
46
- };
47
- onData: (mac: string, hexString: string) => void;
48
- connectDevice: (device: any) => Promise<IResult<any>>;
49
- onError: (err: any) => void;
50
- isMatchPk: (pk: any) => boolean;
51
- onMessage: (res: WechatMiniprogram.UDPSocketOnMessageCallbackResult) => void;
52
- onDeviceClose: ({ productKey, mac }: {
53
- productKey: any;
54
- mac: any;
55
- }) => void;
56
- write: (device: IDevice, value: ArrayBuffer) => Promise<{
57
- success: boolean;
58
- } | {
59
- success: boolean;
60
- message: string;
61
- }>;
62
- updateDevice: (updateDevice: DiscoverUDP, ip: string) => void;
63
- sendBoradCast: () => void;
64
- private startDiscover;
65
- destory: () => void;
66
- }
67
- interface ITCPHandlerProps {
68
- ip: string;
69
- mac: string;
70
- productKey: string;
71
- onClose: (ip: any) => void;
72
- onData: (mac: string, data: string) => void;
73
- }
74
- declare class TCPHandler {
75
- private deviceTCPPort;
76
- private ip;
77
- private productKey;
78
- private mac;
79
- private tcpHandler;
80
- private onData;
81
- private onCloseListener;
82
- constructor({ ip, onClose, mac, productKey, onData }: ITCPHandlerProps);
83
- connect: () => Promise<IResult<any>>;
84
- write: (data: ArrayBuffer) => {
85
- success: boolean;
86
- };
87
- onMessage: (message: any) => void;
88
- onError: () => void;
89
- onClose: () => void;
90
- initListener: () => void;
91
- destory: () => void;
92
- }
93
- export {};
@@ -1,17 +0,0 @@
1
- import ProtocolBase from "./ProtocolBase";
2
- declare type TDecodeType = 'ASCII' | 'HEX';
3
- declare class DiscoverUDP extends ProtocolBase {
4
- did: string;
5
- mac: string;
6
- productKey: string;
7
- deviceType: number;
8
- apiUrl: string;
9
- protocolVersion: string;
10
- mcuVersion: string;
11
- moduleVersion: string;
12
- constructor(data: number[]);
13
- parseEndChat: (index: any, key: any) => any;
14
- baseParse: (index: any, key: any, type?: TDecodeType) => any;
15
- static pack: () => Uint8Array;
16
- }
17
- export default DiscoverUDP;
@@ -1,5 +0,0 @@
1
- import ProtocolBase from "./ProtocolBase";
2
- declare class Ntp extends ProtocolBase {
3
- static pack: () => number[];
4
- }
5
- export default Ntp;
@@ -1,23 +0,0 @@
1
- import ProtocolBase from "./ProtocolBase";
2
- export declare class RequestSync extends ProtocolBase {
3
- state: number;
4
- len: number;
5
- constructor(data: number[]);
6
- static pack: () => number[];
7
- }
8
- export declare class SyncPackage extends ProtocolBase {
9
- id: number;
10
- timestemp: number;
11
- payloadLen: number;
12
- payload: number[];
13
- constructor(data: number[]);
14
- static pack: (id: number) => number[];
15
- }
16
- export declare class DeletePackage extends ProtocolBase {
17
- static pack: (id: number) => number[];
18
- }
19
- export declare class CancelSync extends ProtocolBase {
20
- state: number;
21
- constructor(data: number[]);
22
- static pack: () => number[];
23
- }
@@ -1,2 +0,0 @@
1
- declare const _default: (err: any) => void;
2
- export default _default;
@@ -1,12 +0,0 @@
1
- export interface IUploadRes {
2
- }
3
- interface IData {
4
- raw: string;
5
- created_at: number;
6
- }
7
- interface IProps {
8
- device: IDevice;
9
- data: IData[];
10
- }
11
- export declare function uploadP0({ device, data }: IProps): Promise<import("../openApiRequest").IServiceResult<IUploadRes>>;
12
- export {};