@fgz/wxmini-sdk 1.0.0
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/README.md +84 -0
- package/dist/index.cjs +1813 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +887 -0
- package/dist/index.d.ts +887 -0
- package/dist/index.js +1767 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1813 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('reflect-metadata');
|
|
4
|
+
var classTransformer = require('class-transformer');
|
|
5
|
+
var uuid = require('uuid');
|
|
6
|
+
var pako = require('pako');
|
|
7
|
+
|
|
8
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
|
|
10
|
+
var pako__default = /*#__PURE__*/_interopDefault(pako);
|
|
11
|
+
|
|
12
|
+
var __defProp = Object.defineProperty;
|
|
13
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
14
|
+
var result = void 0 ;
|
|
15
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
16
|
+
if (decorator = decorators[i])
|
|
17
|
+
result = (decorator(target, key, result) ) || result;
|
|
18
|
+
if (result) __defProp(target, key, result);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var Utils = class {
|
|
22
|
+
static allocUuid() {
|
|
23
|
+
const uuid$1 = uuid.v4();
|
|
24
|
+
return "" + uuid$1;
|
|
25
|
+
}
|
|
26
|
+
static now() {
|
|
27
|
+
return (/* @__PURE__ */ new Date()).getTime();
|
|
28
|
+
}
|
|
29
|
+
/* 浅拷贝, 克隆第一层引用 */
|
|
30
|
+
static cloneWithRef(obj) {
|
|
31
|
+
if (obj == null) return null;
|
|
32
|
+
return Object.assign(Object.create(Object.getPrototypeOf(obj)), obj);
|
|
33
|
+
}
|
|
34
|
+
static createNew(obj) {
|
|
35
|
+
if (obj == null) return null;
|
|
36
|
+
return Object.create(Object.getPrototypeOf(obj));
|
|
37
|
+
}
|
|
38
|
+
static isStringNotEmpty(str) {
|
|
39
|
+
return !this.isStringEmpty(str);
|
|
40
|
+
}
|
|
41
|
+
static isStringEmpty(str) {
|
|
42
|
+
return str == null || str === "";
|
|
43
|
+
}
|
|
44
|
+
static string2Utf8(str) {
|
|
45
|
+
if (str == null) return null;
|
|
46
|
+
return new TextEncoder().encode(str);
|
|
47
|
+
}
|
|
48
|
+
static utf8ToString(bytes) {
|
|
49
|
+
if (bytes == null) return null;
|
|
50
|
+
return new TextDecoder().decode(bytes);
|
|
51
|
+
}
|
|
52
|
+
static concatUint8Arrays(arrays) {
|
|
53
|
+
let totalLength = 0;
|
|
54
|
+
for (const array of arrays) {
|
|
55
|
+
totalLength += array.length;
|
|
56
|
+
}
|
|
57
|
+
const result = new Uint8Array(totalLength);
|
|
58
|
+
let offset = 0;
|
|
59
|
+
for (const array of arrays) {
|
|
60
|
+
result.set(array, offset);
|
|
61
|
+
offset += array.length;
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
static async sleep(ms) {
|
|
66
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
67
|
+
}
|
|
68
|
+
static async pollAsync(fn, timeout = 2e3, interval = 10) {
|
|
69
|
+
const endTime = Number(/* @__PURE__ */ new Date()) + timeout;
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const checkCondition = () => {
|
|
72
|
+
if (fn()) {
|
|
73
|
+
resolve();
|
|
74
|
+
} else if (Number(/* @__PURE__ */ new Date()) < endTime) {
|
|
75
|
+
setTimeout(checkCondition, interval);
|
|
76
|
+
} else {
|
|
77
|
+
reject(new Error("Timed out to wait for : " + fn.toString()));
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
checkCondition();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
static isNumber(value) {
|
|
84
|
+
return typeof value === "number" && !isNaN(value);
|
|
85
|
+
}
|
|
86
|
+
static isInteger(value) {
|
|
87
|
+
return Number.isInteger(value);
|
|
88
|
+
}
|
|
89
|
+
static isFloat(value) {
|
|
90
|
+
return this.isNumber(value) && !this.isInteger(value);
|
|
91
|
+
}
|
|
92
|
+
static async pollBlock(fn, timeout, interval, msg) {
|
|
93
|
+
const endTime = Number(/* @__PURE__ */ new Date()) + timeout;
|
|
94
|
+
while (Number(/* @__PURE__ */ new Date()) < endTime) {
|
|
95
|
+
const result = fn();
|
|
96
|
+
if (result) {
|
|
97
|
+
return Promise.resolve();
|
|
98
|
+
}
|
|
99
|
+
await this.sleep(interval);
|
|
100
|
+
}
|
|
101
|
+
if (msg == null) msg = "Timed out to wait for : " + fn.toString();
|
|
102
|
+
return Promise.reject(new Error(msg));
|
|
103
|
+
}
|
|
104
|
+
static error(message, ...optionalParams) {
|
|
105
|
+
console.error(message, optionalParams);
|
|
106
|
+
}
|
|
107
|
+
static log(message, ...optionalParams) {
|
|
108
|
+
console.log(message, optionalParams);
|
|
109
|
+
}
|
|
110
|
+
static debug(message, ...optionalParams) {
|
|
111
|
+
if (this._debug) console.debug(message, optionalParams);
|
|
112
|
+
}
|
|
113
|
+
static isInstance(obj, constructor) {
|
|
114
|
+
return obj instanceof constructor || constructor.name === "Boolean" && typeof obj === "boolean";
|
|
115
|
+
}
|
|
116
|
+
static assertNotNull(obj, msg) {
|
|
117
|
+
if (obj == null) throw new Error(msg ?? "Null value");
|
|
118
|
+
return obj;
|
|
119
|
+
}
|
|
120
|
+
static assertTrue(value, msg) {
|
|
121
|
+
if (!value) throw new Error(msg ?? "Not true");
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
Utils._debug = true;
|
|
125
|
+
var _Bytes = class _Bytes {
|
|
126
|
+
/**
|
|
127
|
+
* Flutter的setInt32,以及Netty等默认都是大端序存储int:[00,00,00,03]
|
|
128
|
+
*/
|
|
129
|
+
static readInt32(bytes, offset) {
|
|
130
|
+
if (offset < 0 || offset + 4 > bytes.length) {
|
|
131
|
+
throw new RangeError("Offset is out of bounds.");
|
|
132
|
+
}
|
|
133
|
+
const subArray = Array.from(bytes.slice(offset, offset + 4));
|
|
134
|
+
return new DataView(new Uint8Array(subArray).buffer).getInt32(0, _Bytes.LittleEndian);
|
|
135
|
+
}
|
|
136
|
+
static setInt32Bytes(bytes, offset, num) {
|
|
137
|
+
const dataView = new DataView(bytes.buffer);
|
|
138
|
+
dataView.setInt32(offset, num, _Bytes.LittleEndian);
|
|
139
|
+
}
|
|
140
|
+
static int32ToBytes(v) {
|
|
141
|
+
const b = new Uint8Array(4);
|
|
142
|
+
new DataView(b.buffer).setInt32(0, v);
|
|
143
|
+
return b;
|
|
144
|
+
}
|
|
145
|
+
static stringToBytes(s) {
|
|
146
|
+
const encoder = new TextEncoder();
|
|
147
|
+
return encoder.encode(s);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// JAVA端解析是大端序(低位靠前,高位靠后) : 0x00, 0x00, 0x01, 0x44 = 300
|
|
151
|
+
_Bytes.LittleEndian = false;
|
|
152
|
+
var Bytes = _Bytes;
|
|
153
|
+
|
|
154
|
+
// src/cson-core.ts
|
|
155
|
+
var CsonBean = class {
|
|
156
|
+
constructor() {
|
|
157
|
+
// 每个子类都会通过构造默认初始化此值(由自动代码生成器负责初始化)
|
|
158
|
+
this._OBJECT_TYPE_ = "";
|
|
159
|
+
this.setObjectType(this.getJavaType());
|
|
160
|
+
}
|
|
161
|
+
// 所有类都会重载此方法, 以获取子类真正对应的java类
|
|
162
|
+
getJavaType() {
|
|
163
|
+
return this._OBJECT_TYPE_;
|
|
164
|
+
}
|
|
165
|
+
getSimpleTypeName(removeDtoSuffix) {
|
|
166
|
+
const type = this.getJavaType();
|
|
167
|
+
const list = type.split(".");
|
|
168
|
+
if (list.length > 1) {
|
|
169
|
+
let last = list[list.length - 1];
|
|
170
|
+
if (last.endsWith("Dto") && removeDtoSuffix) {
|
|
171
|
+
return last.substring(0, last.length - 3);
|
|
172
|
+
}
|
|
173
|
+
return last;
|
|
174
|
+
}
|
|
175
|
+
return type;
|
|
176
|
+
}
|
|
177
|
+
getObjectType() {
|
|
178
|
+
return this._OBJECT_TYPE_;
|
|
179
|
+
}
|
|
180
|
+
setObjectType(type) {
|
|
181
|
+
this._OBJECT_TYPE_ = type;
|
|
182
|
+
return this;
|
|
183
|
+
}
|
|
184
|
+
getExtJsonMap() {
|
|
185
|
+
return this._extJsonMap;
|
|
186
|
+
}
|
|
187
|
+
setExtJsonMap(extMap) {
|
|
188
|
+
this._extJsonMap = extMap;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
CsonBean.OBJECT_TYPE_FIELD_NAME = "_OBJECT_TYPE_";
|
|
192
|
+
var CsonPojo = class extends CsonBean {
|
|
193
|
+
};
|
|
194
|
+
var _FeException = class _FeException extends CsonPojo {
|
|
195
|
+
getJavaType() {
|
|
196
|
+
return _FeException.JAVA_TYPE;
|
|
197
|
+
}
|
|
198
|
+
constructor(err, detail) {
|
|
199
|
+
super();
|
|
200
|
+
this.err = err;
|
|
201
|
+
this.detail = detail;
|
|
202
|
+
}
|
|
203
|
+
toString() {
|
|
204
|
+
let s = this.err;
|
|
205
|
+
if (Utils.isStringNotEmpty(this.detail)) s += "\n" + this.detail;
|
|
206
|
+
return `${this.getSimpleTypeName()}: ${s ?? ""}`;
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
_FeException.JAVA_TYPE = "flutter.rpc.FeException";
|
|
210
|
+
var FeException = _FeException;
|
|
211
|
+
var _FeJavaException = class _FeJavaException extends FeException {
|
|
212
|
+
getJavaType() {
|
|
213
|
+
return _FeJavaException.JAVA_TYPE;
|
|
214
|
+
}
|
|
215
|
+
constructor(err, detail) {
|
|
216
|
+
super();
|
|
217
|
+
this.err = err;
|
|
218
|
+
this.detail = detail;
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
_FeJavaException.JAVA_TYPE = "flutter.rpc.FeJavaException";
|
|
222
|
+
var FeJavaException = _FeJavaException;
|
|
223
|
+
var _CRpcFeCmd = class _CRpcFeCmd extends CsonPojo {
|
|
224
|
+
getJavaType() {
|
|
225
|
+
return _CRpcFeCmd.JAVA_TYPE;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
_CRpcFeCmd.JAVA_TYPE = "cson.rpc.CRpcFeCmd";
|
|
229
|
+
var CRpcFeCmd = _CRpcFeCmd;
|
|
230
|
+
var _CRpcFeRsp = class _CRpcFeRsp extends CsonPojo {
|
|
231
|
+
getJavaType() {
|
|
232
|
+
return _CRpcFeRsp.JAVA_TYPE;
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
_CRpcFeRsp.JAVA_TYPE = "cson.rpc.CRpcFeRsp";
|
|
236
|
+
var CRpcFeRsp = _CRpcFeRsp;
|
|
237
|
+
var _SystemCallback = class _SystemCallback extends CsonPojo {
|
|
238
|
+
getJavaType() {
|
|
239
|
+
return _SystemCallback.JAVA_TYPE;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
_SystemCallback.JAVA_TYPE = "fe.cmn.sys.SystemCallback";
|
|
243
|
+
_SystemCallback.FIELD_timeout = "timeout";
|
|
244
|
+
_SystemCallback.debugChannel = false;
|
|
245
|
+
_SystemCallback.DECLARED_FIELDS = [_SystemCallback.FIELD_timeout];
|
|
246
|
+
var SystemCallback = _SystemCallback;
|
|
247
|
+
var _FePojo = class _FePojo extends CsonPojo {
|
|
248
|
+
getJavaType() {
|
|
249
|
+
return _FePojo.JAVA_TYPE;
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
_FePojo.JAVA_TYPE = "fe.cmn.data.FePojo";
|
|
253
|
+
_FePojo.FIELD_userObject = "userObject";
|
|
254
|
+
_FePojo.FIELD_userPojo = "userPojo";
|
|
255
|
+
_FePojo.FIELD_binaryData = "binaryData";
|
|
256
|
+
_FePojo.DECLARED_FIELDS = [_FePojo.FIELD_userObject, _FePojo.FIELD_userPojo, _FePojo.FIELD_binaryData];
|
|
257
|
+
__decorateClass([
|
|
258
|
+
classTransformer.Transform(FUNC_decodeObject, { toClassOnly: true })
|
|
259
|
+
], _FePojo.prototype, "userPojo");
|
|
260
|
+
__decorateClass([
|
|
261
|
+
classTransformer.Transform(FUNC_encodeJsonUint8Array, { toPlainOnly: true }),
|
|
262
|
+
classTransformer.Transform(FUNC_decodeJsonUint8Array, { toClassOnly: true })
|
|
263
|
+
], _FePojo.prototype, "binaryData");
|
|
264
|
+
var FePojo = _FePojo;
|
|
265
|
+
var _NullPojo = class _NullPojo extends FePojo {
|
|
266
|
+
getJavaType() {
|
|
267
|
+
return _NullPojo.JAVA_TYPE;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
_NullPojo.JAVA_TYPE = "fe.cmn.data.NullPojo";
|
|
271
|
+
_NullPojo.DECLARED_FIELDS = [];
|
|
272
|
+
var NullPojo = _NullPojo;
|
|
273
|
+
var _ValuePojo = class _ValuePojo extends FePojo {
|
|
274
|
+
getJavaType() {
|
|
275
|
+
return _ValuePojo.JAVA_TYPE;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
_ValuePojo.JAVA_TYPE = "fe.cmn.data.ValuePojo";
|
|
279
|
+
_ValuePojo.FIELD_value = "value";
|
|
280
|
+
_ValuePojo.DECLARED_FIELDS = [_ValuePojo.FIELD_value];
|
|
281
|
+
var ValuePojo = _ValuePojo;
|
|
282
|
+
var _BinBlock = class _BinBlock extends CsonPojo {
|
|
283
|
+
getJavaType() {
|
|
284
|
+
return _BinBlock.JAVA_TYPE;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
_BinBlock.JAVA_TYPE = "cson.core.BinBlock";
|
|
288
|
+
_BinBlock.FIELD_id = "id";
|
|
289
|
+
_BinBlock.FIELD_start = "start";
|
|
290
|
+
_BinBlock.FIELD_end = "end";
|
|
291
|
+
_BinBlock.FIELD_extByteArray = "extByteArray";
|
|
292
|
+
_BinBlock.DECLARED_FIELDS = [_BinBlock.FIELD_id, _BinBlock.FIELD_start, _BinBlock.FIELD_end, _BinBlock.FIELD_extByteArray];
|
|
293
|
+
__decorateClass([
|
|
294
|
+
classTransformer.Transform(FUNC_encodeJsonUint8Array, { toPlainOnly: true }),
|
|
295
|
+
classTransformer.Transform(FUNC_decodeJsonUint8Array, { toClassOnly: true })
|
|
296
|
+
], _BinBlock.prototype, "extByteArray");
|
|
297
|
+
var BinBlock = _BinBlock;
|
|
298
|
+
var _PartitionTable = class _PartitionTable extends CsonPojo {
|
|
299
|
+
getJavaType() {
|
|
300
|
+
return _PartitionTable.JAVA_TYPE;
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
_PartitionTable.JAVA_TYPE = "cson.core.PartitionTable";
|
|
304
|
+
_PartitionTable.FIELD_callbackBridgeChannel = "callbackBridgeChannel";
|
|
305
|
+
_PartitionTable.FIELD_bodyLength = "bodyLength";
|
|
306
|
+
_PartitionTable.FIELD_lstBin = "lstBin";
|
|
307
|
+
_PartitionTable.DECLARED_FIELDS = [_PartitionTable.FIELD_callbackBridgeChannel, _PartitionTable.FIELD_bodyLength, _PartitionTable.FIELD_lstBin];
|
|
308
|
+
__decorateClass([
|
|
309
|
+
classTransformer.Transform(FUNC_decodeListJson, { toClassOnly: true })
|
|
310
|
+
], _PartitionTable.prototype, "lstBin");
|
|
311
|
+
var PartitionTable = _PartitionTable;
|
|
312
|
+
var _FeAbilityExecuteException = class _FeAbilityExecuteException extends FeException {
|
|
313
|
+
getJavaType() {
|
|
314
|
+
return _FeAbilityExecuteException.JAVA_TYPE;
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
_FeAbilityExecuteException.JAVA_TYPE = "fe.cmn.exception.FeAbilityExecuteException";
|
|
318
|
+
_FeAbilityExecuteException.FIELD_ability = "ability";
|
|
319
|
+
_FeAbilityExecuteException.DECLARED_FIELDS = [_FeAbilityExecuteException.FIELD_ability];
|
|
320
|
+
__decorateClass([
|
|
321
|
+
classTransformer.Transform(FUNC_decodeObject, { toClassOnly: true })
|
|
322
|
+
], _FeAbilityExecuteException.prototype, "ability");
|
|
323
|
+
var FeAbilityExecuteException = _FeAbilityExecuteException;
|
|
324
|
+
var _FeWxMiniCmdException = class _FeWxMiniCmdException extends FeAbilityExecuteException {
|
|
325
|
+
getJavaType() {
|
|
326
|
+
return _FeWxMiniCmdException.JAVA_TYPE;
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
_FeWxMiniCmdException.JAVA_TYPE = "fe.cmn.exception.FeWxMiniCmdException";
|
|
330
|
+
_FeWxMiniCmdException.FIELD_wxMiniServerUrl = "wxMiniServerUrl";
|
|
331
|
+
_FeWxMiniCmdException.FIELD_wxMiniAppUuid = "wxMiniAppUuid";
|
|
332
|
+
_FeWxMiniCmdException.DECLARED_FIELDS = [_FeWxMiniCmdException.FIELD_wxMiniServerUrl, _FeWxMiniCmdException.FIELD_wxMiniAppUuid];
|
|
333
|
+
var FeWxMiniCmdException = _FeWxMiniCmdException;
|
|
334
|
+
var _WxMiniBridgeCommand = class _WxMiniBridgeCommand extends CsonPojo {
|
|
335
|
+
getJavaType() {
|
|
336
|
+
return _WxMiniBridgeCommand.JAVA_TYPE;
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
_WxMiniBridgeCommand.JAVA_TYPE = "wx.mini.server.WxMiniBridgeCommand";
|
|
340
|
+
_WxMiniBridgeCommand.FIELD_debugAppUuid = "debugAppUuid";
|
|
341
|
+
_WxMiniBridgeCommand.FIELD_appId = "appId";
|
|
342
|
+
_WxMiniBridgeCommand.FIELD_cmd = "cmd";
|
|
343
|
+
_WxMiniBridgeCommand.FIELD_params = "params";
|
|
344
|
+
_WxMiniBridgeCommand.FIELD_extHeaders = "extHeaders";
|
|
345
|
+
_WxMiniBridgeCommand.FIELD_waitOnlineTimeoutS = "waitOnlineTimeoutS";
|
|
346
|
+
_WxMiniBridgeCommand.FIELD_timeoutS = "timeoutS";
|
|
347
|
+
_WxMiniBridgeCommand.DECLARED_FIELDS = [_WxMiniBridgeCommand.FIELD_debugAppUuid, _WxMiniBridgeCommand.FIELD_appId, _WxMiniBridgeCommand.FIELD_cmd, _WxMiniBridgeCommand.FIELD_params, _WxMiniBridgeCommand.FIELD_extHeaders, _WxMiniBridgeCommand.FIELD_waitOnlineTimeoutS, _WxMiniBridgeCommand.FIELD_timeoutS];
|
|
348
|
+
__decorateClass([
|
|
349
|
+
classTransformer.Transform(FUNC_decodeMapJson, { toClassOnly: true })
|
|
350
|
+
], _WxMiniBridgeCommand.prototype, "params");
|
|
351
|
+
__decorateClass([
|
|
352
|
+
classTransformer.Transform(FUNC_decodeMapJson, { toClassOnly: true })
|
|
353
|
+
], _WxMiniBridgeCommand.prototype, "extHeaders");
|
|
354
|
+
var WxMiniBridgeCommand = _WxMiniBridgeCommand;
|
|
355
|
+
var _WxMiniCommand = class _WxMiniCommand extends SystemCallback {
|
|
356
|
+
getJavaType() {
|
|
357
|
+
return _WxMiniCommand.JAVA_TYPE;
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
_WxMiniCommand.JAVA_TYPE = "fe.cmn.weixin.ability.WxMiniCommand";
|
|
361
|
+
_WxMiniCommand.FIELD_debugHttpUrl = "debugHttpUrl";
|
|
362
|
+
_WxMiniCommand.FIELD_debugAppUuid = "debugAppUuid";
|
|
363
|
+
_WxMiniCommand.FIELD_cmd = "cmd";
|
|
364
|
+
_WxMiniCommand.FIELD_params = "params";
|
|
365
|
+
_WxMiniCommand.FIELD_extHeaders = "extHeaders";
|
|
366
|
+
_WxMiniCommand.FIELD_waitOnlineTimeoutS = "waitOnlineTimeoutS";
|
|
367
|
+
_WxMiniCommand.PARAM_URL = "url";
|
|
368
|
+
_WxMiniCommand.PARAM_TITLE = "title";
|
|
369
|
+
_WxMiniCommand.PARAM_ICON_TYPE = "iconType";
|
|
370
|
+
_WxMiniCommand.PARAM_MESSAGE = "message";
|
|
371
|
+
_WxMiniCommand.PARAM_BUTTON = "button";
|
|
372
|
+
_WxMiniCommand.PARAM_REJECT_BUTTON = "rejectButton";
|
|
373
|
+
_WxMiniCommand.PARAM_FILE_PATH = "filePath";
|
|
374
|
+
_WxMiniCommand.DATA_FIELD_IN_MAP = "data";
|
|
375
|
+
_WxMiniCommand.getUserProfile_TITLE = "title";
|
|
376
|
+
_WxMiniCommand.getUserProfile_ICON_TYPE = "iconType";
|
|
377
|
+
_WxMiniCommand.getUserProfile_MESSAGE = "message";
|
|
378
|
+
_WxMiniCommand.getUserProfile_BUTTON = "button";
|
|
379
|
+
_WxMiniCommand.getUserProfile_QUERY_TYPE = "queryType";
|
|
380
|
+
_WxMiniCommand.getUserProfile_ORG_AVATAR_URL64 = "avatarUrl64";
|
|
381
|
+
_WxMiniCommand.getUserProfile_ORG_NICK = "nickName";
|
|
382
|
+
_WxMiniCommand.getPhoneNum_TITLE = "title";
|
|
383
|
+
_WxMiniCommand.getPhoneNum_ICON_TYPE = "iconType";
|
|
384
|
+
_WxMiniCommand.getPhoneNum_MESSAGE = "message";
|
|
385
|
+
_WxMiniCommand.getPhoneNum_BUTTON = "button";
|
|
386
|
+
_WxMiniCommand.getPhoneNum_REJECT_BUTTON = "rejectButton";
|
|
387
|
+
_WxMiniCommand.makePhoneCall_phoneNum = "phoneNum";
|
|
388
|
+
_WxMiniCommand.PARAM_count = "count";
|
|
389
|
+
_WxMiniCommand.PARAM_mediaType = "mediaType";
|
|
390
|
+
_WxMiniCommand.PARAM_sourceType = "sourceType";
|
|
391
|
+
_WxMiniCommand.PARAM_maxDuration = "maxDuration";
|
|
392
|
+
_WxMiniCommand.PARAM_sizeType = "sizeType";
|
|
393
|
+
_WxMiniCommand.PARAM_camera = "camera";
|
|
394
|
+
_WxMiniCommand.MEDIATYPE_image = "image";
|
|
395
|
+
_WxMiniCommand.MEDIATYPE_video = "video";
|
|
396
|
+
_WxMiniCommand.MEDIATYPE_mix = "mix";
|
|
397
|
+
_WxMiniCommand.SOURCETYPE_album = "album";
|
|
398
|
+
_WxMiniCommand.SOURCETYPE_camera = "camera";
|
|
399
|
+
_WxMiniCommand.SIZETYPE_original = "original";
|
|
400
|
+
_WxMiniCommand.SIZETYPE_compressed = "compressed";
|
|
401
|
+
_WxMiniCommand.CAMERA_back = "back";
|
|
402
|
+
_WxMiniCommand.CAMERA_front = "front";
|
|
403
|
+
_WxMiniCommand.PARAM_delta = "delta";
|
|
404
|
+
_WxMiniCommand.PARAM_UPLOAD_FILE_NAME = "fileName";
|
|
405
|
+
_WxMiniCommand.PARAM_UPLOAD_FORM_DATA = "formData";
|
|
406
|
+
_WxMiniCommand.PARAM_SHARE_FILE_NAME = "fileName";
|
|
407
|
+
_WxMiniCommand.PARAM_MAP_JSON = "mapJson";
|
|
408
|
+
_WxMiniCommand.PARAM_APPEND = "append";
|
|
409
|
+
_WxMiniCommand.PARAM_OPENIT = "openIt";
|
|
410
|
+
_WxMiniCommand.PARAM_LOCATION = "location";
|
|
411
|
+
_WxMiniCommand.PARAM_COUNT = "count";
|
|
412
|
+
_WxMiniCommand.PARAM_TYPE = "type";
|
|
413
|
+
_WxMiniCommand.PARAM_EXTENSION = "extension";
|
|
414
|
+
_WxMiniCommand.PARAM_sharePage = "sharePage";
|
|
415
|
+
_WxMiniCommand.PARAM_path = "path";
|
|
416
|
+
_WxMiniCommand.PARAM_style = "style";
|
|
417
|
+
_WxMiniCommand.PARAM_needShowEntrance = "needShowEntrance";
|
|
418
|
+
_WxMiniCommand.PARAM_entrancePath = "entrancePath";
|
|
419
|
+
_WxMiniCommand.CLIP_BOARD_DATA = "data";
|
|
420
|
+
_WxMiniCommand.DECLARED_FIELDS = [_WxMiniCommand.FIELD_debugHttpUrl, _WxMiniCommand.FIELD_debugAppUuid, _WxMiniCommand.FIELD_cmd, _WxMiniCommand.FIELD_params, _WxMiniCommand.FIELD_extHeaders, _WxMiniCommand.FIELD_waitOnlineTimeoutS];
|
|
421
|
+
__decorateClass([
|
|
422
|
+
classTransformer.Transform(FUNC_decodeMapJson, { toClassOnly: true })
|
|
423
|
+
], _WxMiniCommand.prototype, "params");
|
|
424
|
+
__decorateClass([
|
|
425
|
+
classTransformer.Transform(FUNC_decodeMapJson, { toClassOnly: true })
|
|
426
|
+
], _WxMiniCommand.prototype, "extHeaders");
|
|
427
|
+
var WxMiniCommand = _WxMiniCommand;
|
|
428
|
+
var _WxMiniConfigDto = class _WxMiniConfigDto extends CsonPojo {
|
|
429
|
+
getJavaType() {
|
|
430
|
+
return _WxMiniConfigDto.JAVA_TYPE;
|
|
431
|
+
}
|
|
432
|
+
};
|
|
433
|
+
_WxMiniConfigDto.JAVA_TYPE = "fe.cmn.weixin.WxMiniConfigDto";
|
|
434
|
+
_WxMiniConfigDto.FIELD_wxMiniServerUrl = "wxMiniServerUrl";
|
|
435
|
+
_WxMiniConfigDto.FIELD_wxMiniAppUuid = "wxMiniAppUuid";
|
|
436
|
+
_WxMiniConfigDto.FIELD_sceneFromWxMiniParams = "sceneFromWxMiniParams";
|
|
437
|
+
_WxMiniConfigDto.FIELD_initalQueryParameters = "initalQueryParameters";
|
|
438
|
+
_WxMiniConfigDto.DECLARED_FIELDS = [_WxMiniConfigDto.FIELD_wxMiniServerUrl, _WxMiniConfigDto.FIELD_wxMiniAppUuid, _WxMiniConfigDto.FIELD_sceneFromWxMiniParams, _WxMiniConfigDto.FIELD_initalQueryParameters];
|
|
439
|
+
__decorateClass([
|
|
440
|
+
classTransformer.Transform(FUNC_decodeMapJson, { toClassOnly: true })
|
|
441
|
+
], _WxMiniConfigDto.prototype, "initalQueryParameters");
|
|
442
|
+
var WxMiniConfigDto = _WxMiniConfigDto;
|
|
443
|
+
var _QueryWxMiniParam = class _QueryWxMiniParam extends SystemCallback {
|
|
444
|
+
getJavaType() {
|
|
445
|
+
return _QueryWxMiniParam.JAVA_TYPE;
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
_QueryWxMiniParam.JAVA_TYPE = "fe.cmn.weixin.ability.QueryWxMiniParam";
|
|
449
|
+
_QueryWxMiniParam.DECLARED_FIELDS = [];
|
|
450
|
+
var QueryWxMiniParam = _QueryWxMiniParam;
|
|
451
|
+
var _QuerySceneFromWxMiniParams = class _QuerySceneFromWxMiniParams extends SystemCallback {
|
|
452
|
+
getJavaType() {
|
|
453
|
+
return _QuerySceneFromWxMiniParams.JAVA_TYPE;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
_QuerySceneFromWxMiniParams.JAVA_TYPE = "fe.cmn.weixin.ability.QuerySceneFromWxMiniParams";
|
|
457
|
+
_QuerySceneFromWxMiniParams.DECLARED_FIELDS = [];
|
|
458
|
+
var QuerySceneFromWxMiniParams = _QuerySceneFromWxMiniParams;
|
|
459
|
+
var _CRpcCallbackCmd = class _CRpcCallbackCmd extends CsonPojo {
|
|
460
|
+
getJavaType() {
|
|
461
|
+
return _CRpcCallbackCmd.JAVA_TYPE;
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
_CRpcCallbackCmd.JAVA_TYPE = "flutter.rpc.CRpcCallbackCmd";
|
|
465
|
+
_CRpcCallbackCmd.FIELD_reqId = "reqId";
|
|
466
|
+
_CRpcCallbackCmd.FIELD_data = "data";
|
|
467
|
+
_CRpcCallbackCmd.DECLARED_FIELDS = [_CRpcCallbackCmd.FIELD_reqId, _CRpcCallbackCmd.FIELD_data];
|
|
468
|
+
__decorateClass([
|
|
469
|
+
classTransformer.Transform(FUNC_decodeObject, { toClassOnly: true })
|
|
470
|
+
], _CRpcCallbackCmd.prototype, "data");
|
|
471
|
+
var CRpcCallbackCmd = _CRpcCallbackCmd;
|
|
472
|
+
var _CRpcCallbackRsp = class _CRpcCallbackRsp extends CsonPojo {
|
|
473
|
+
getJavaType() {
|
|
474
|
+
return _CRpcCallbackRsp.JAVA_TYPE;
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
_CRpcCallbackRsp.JAVA_TYPE = "flutter.rpc.CRpcCallbackRsp";
|
|
478
|
+
_CRpcCallbackRsp.FIELD_reqId = "reqId";
|
|
479
|
+
_CRpcCallbackRsp.FIELD_result = "result";
|
|
480
|
+
_CRpcCallbackRsp.DECLARED_FIELDS = [_CRpcCallbackRsp.FIELD_reqId, _CRpcCallbackRsp.FIELD_result];
|
|
481
|
+
__decorateClass([
|
|
482
|
+
classTransformer.Transform(FUNC_decodeObject, { toClassOnly: true })
|
|
483
|
+
], _CRpcCallbackRsp.prototype, "result");
|
|
484
|
+
var CRpcCallbackRsp = _CRpcCallbackRsp;
|
|
485
|
+
|
|
486
|
+
// src/cson.ts
|
|
487
|
+
function FUNC_encodeJsonUint8Array({ value }) {
|
|
488
|
+
if (value instanceof Uint8Array) {
|
|
489
|
+
const u8 = Cson.putBytes(value);
|
|
490
|
+
if (u8 == null) return null;
|
|
491
|
+
return Array.from(u8);
|
|
492
|
+
}
|
|
493
|
+
return value;
|
|
494
|
+
}
|
|
495
|
+
function FUNC_decodeJsonUint8Array({ value }) {
|
|
496
|
+
if (value instanceof Uint8Array) {
|
|
497
|
+
return Cson.getBytes(value);
|
|
498
|
+
} else if (value instanceof Object) {
|
|
499
|
+
Object.values(value);
|
|
500
|
+
return Cson.getBytes(new Uint8Array(Object.values(value)));
|
|
501
|
+
}
|
|
502
|
+
return value;
|
|
503
|
+
}
|
|
504
|
+
function FUNC_decodeMapJson({ value }) {
|
|
505
|
+
if (value != null) {
|
|
506
|
+
if (value instanceof Map) {
|
|
507
|
+
const map = /* @__PURE__ */ new Map();
|
|
508
|
+
for (const [key, val] of value.entries()) {
|
|
509
|
+
const obj = Cson.decodeObject(val);
|
|
510
|
+
map.set(key, obj);
|
|
511
|
+
}
|
|
512
|
+
return map;
|
|
513
|
+
} else if (value instanceof Object) {
|
|
514
|
+
const map = /* @__PURE__ */ new Map();
|
|
515
|
+
for (const [key, val] of Object.entries(value)) {
|
|
516
|
+
const obj = Cson.decodeObject(val);
|
|
517
|
+
map.set(key, obj);
|
|
518
|
+
}
|
|
519
|
+
return map;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
return void 0;
|
|
523
|
+
}
|
|
524
|
+
function FUNC_decodeListJson({ value }) {
|
|
525
|
+
if (value != null) {
|
|
526
|
+
if (value instanceof Array) {
|
|
527
|
+
const lst = new Array();
|
|
528
|
+
for (const v of value) {
|
|
529
|
+
const obj = Cson.decodeObject(v);
|
|
530
|
+
lst.push(obj);
|
|
531
|
+
}
|
|
532
|
+
return lst;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
return void 0;
|
|
536
|
+
}
|
|
537
|
+
function FUNC_decodeObject({ value }) {
|
|
538
|
+
return Cson.decodeObject(value);
|
|
539
|
+
}
|
|
540
|
+
function int32ToBytes(value) {
|
|
541
|
+
const result = new Uint8Array(4);
|
|
542
|
+
for (let i = 0; i < 4; i++) {
|
|
543
|
+
result[i] = value >> 8 * (3 - i) & 255;
|
|
544
|
+
}
|
|
545
|
+
return result;
|
|
546
|
+
}
|
|
547
|
+
function bytesToInt32(bytes) {
|
|
548
|
+
if (bytes.length !== 4) {
|
|
549
|
+
throw new Error("Input must be a Uint8Array of length 4");
|
|
550
|
+
}
|
|
551
|
+
let value = 0;
|
|
552
|
+
for (let i = 0; i < 4; i++) {
|
|
553
|
+
value |= bytes[i] << 8 * (3 - i);
|
|
554
|
+
}
|
|
555
|
+
return value;
|
|
556
|
+
}
|
|
557
|
+
var _Cson = class _Cson {
|
|
558
|
+
static _setCache(mapBytes) {
|
|
559
|
+
this._serialNo = 0;
|
|
560
|
+
this._mapBytes = mapBytes == null ? /* @__PURE__ */ new Map() : mapBytes;
|
|
561
|
+
}
|
|
562
|
+
static putBytes(data) {
|
|
563
|
+
if (data === null || data.length === 0) return null;
|
|
564
|
+
const id = ++this._serialNo;
|
|
565
|
+
this._mapBytes.set(id, data);
|
|
566
|
+
return int32ToBytes(id);
|
|
567
|
+
}
|
|
568
|
+
static getBytes(o) {
|
|
569
|
+
if (o != null && o.length === 4) {
|
|
570
|
+
return this._mapBytes.get(bytesToInt32(o)) || null;
|
|
571
|
+
}
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
static _clearCache() {
|
|
575
|
+
this._setCache(null);
|
|
576
|
+
}
|
|
577
|
+
static encode(data, outputBytes) {
|
|
578
|
+
this._clearCache();
|
|
579
|
+
try {
|
|
580
|
+
const res = classTransformer.instanceToPlain(data);
|
|
581
|
+
if (outputBytes && this._mapBytes.size > 0) {
|
|
582
|
+
this._mapBytes.forEach((value, key) => {
|
|
583
|
+
outputBytes.set(key, value);
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
return JSON.stringify(res);
|
|
587
|
+
} finally {
|
|
588
|
+
this._clearCache();
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
static decode(targetClass, json, mapBytes) {
|
|
592
|
+
const normalJsonObj = JSON.parse(json);
|
|
593
|
+
this._setCache(mapBytes);
|
|
594
|
+
try {
|
|
595
|
+
const jO = classTransformer.plainToInstance(targetClass, normalJsonObj);
|
|
596
|
+
if (Array.isArray(jO)) {
|
|
597
|
+
throw new Error("Do not support JSON List");
|
|
598
|
+
}
|
|
599
|
+
return jO;
|
|
600
|
+
} finally {
|
|
601
|
+
this._clearCache();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
static decodeReturn(data, zip) {
|
|
605
|
+
const mapAttach = /* @__PURE__ */ new Map();
|
|
606
|
+
const rspJson = _Cson.decodeReturnPayload(data, zip, mapAttach);
|
|
607
|
+
if (Utils.isStringEmpty(rspJson)) return null;
|
|
608
|
+
const rspObj = _Cson.decodeJson(rspJson, mapAttach);
|
|
609
|
+
return rspObj;
|
|
610
|
+
}
|
|
611
|
+
static decodeJson(json, mapBytes) {
|
|
612
|
+
_Cson._setCache(mapBytes);
|
|
613
|
+
try {
|
|
614
|
+
let jO;
|
|
615
|
+
try {
|
|
616
|
+
jO = JSON.parse(json);
|
|
617
|
+
} catch (error) {
|
|
618
|
+
throw new Error("Invalid JSON");
|
|
619
|
+
}
|
|
620
|
+
return _Cson.decodeObject(jO);
|
|
621
|
+
} finally {
|
|
622
|
+
_Cson._clearCache();
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
static decodeObject(org) {
|
|
626
|
+
try {
|
|
627
|
+
if (org == null) {
|
|
628
|
+
return null;
|
|
629
|
+
} else if (Array.isArray(org)) {
|
|
630
|
+
const lstRet = [];
|
|
631
|
+
for (const o of org) {
|
|
632
|
+
lstRet.push(_Cson.decodeObject(o));
|
|
633
|
+
}
|
|
634
|
+
return lstRet;
|
|
635
|
+
} else if (!(org instanceof Object)) {
|
|
636
|
+
return org;
|
|
637
|
+
} else if (typeof org === "object" && org !== null) {
|
|
638
|
+
if (Utils.isStringNotEmpty(org[CsonBean.OBJECT_TYPE_FIELD_NAME])) {
|
|
639
|
+
const bean = JavaFactory.newBean(org[CsonBean.OBJECT_TYPE_FIELD_NAME], org);
|
|
640
|
+
return bean;
|
|
641
|
+
} else {
|
|
642
|
+
const type = org[CsonBean.OBJECT_TYPE_FIELD_NAME];
|
|
643
|
+
return JavaFactory.newBean(type, org);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return org;
|
|
647
|
+
} catch (error) {
|
|
648
|
+
throw new Error("Failed to decode : " + org.toString() + ", Cause:" + error);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
static decodeDynamicList(org) {
|
|
652
|
+
try {
|
|
653
|
+
if (org !== null && org.length > 0) {
|
|
654
|
+
const lstRet = [];
|
|
655
|
+
for (const o of org) {
|
|
656
|
+
lstRet.push(_Cson.decodeObject(o));
|
|
657
|
+
}
|
|
658
|
+
return lstRet;
|
|
659
|
+
}
|
|
660
|
+
return null;
|
|
661
|
+
} catch (error) {
|
|
662
|
+
throw new Error(`Failed to decode: ${JSON.stringify(org)}, Cause: ${error}`);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* 返回的是成功结果里的 result json
|
|
667
|
+
* 同时,参数 mapAttach 是附件二进制包(输出)
|
|
668
|
+
* 如果返回是异常对象, 则会抛出FeJavaException
|
|
669
|
+
*/
|
|
670
|
+
static decodeReturnPayload(data, zip, mapAttach) {
|
|
671
|
+
const sCmd = _Cson.decodeServerPackage(data, zip, mapAttach);
|
|
672
|
+
if (sCmd === null) return null;
|
|
673
|
+
const rsp = _Cson.decode(CRpcFeRsp, sCmd, mapAttach);
|
|
674
|
+
if (Utils.isStringNotEmpty(rsp.error)) {
|
|
675
|
+
const error = new FeJavaException();
|
|
676
|
+
error.err = rsp.error.error;
|
|
677
|
+
error.detail = rsp.error.errorStack;
|
|
678
|
+
throw error;
|
|
679
|
+
}
|
|
680
|
+
return rsp.resultJson;
|
|
681
|
+
}
|
|
682
|
+
static decodeServerPackage(data, zip, mapAttach) {
|
|
683
|
+
if (data === null || data.length === 0) return null;
|
|
684
|
+
const parLength = Bytes.readInt32(data, 0);
|
|
685
|
+
const btParTable = data.slice(4, 4 + parLength);
|
|
686
|
+
const parTable = _Cson.decode(
|
|
687
|
+
PartitionTable,
|
|
688
|
+
new TextDecoder().decode(btParTable),
|
|
689
|
+
null
|
|
690
|
+
);
|
|
691
|
+
const bodyStart = 4 + parLength;
|
|
692
|
+
const btBody = data.slice(bodyStart, bodyStart + (parTable.bodyLength || 0));
|
|
693
|
+
const attStart = bodyStart + (parTable.bodyLength || 0);
|
|
694
|
+
parTable.lstBin?.forEach((bk) => {
|
|
695
|
+
if (bk) {
|
|
696
|
+
const attBin = data.slice(
|
|
697
|
+
attStart + (bk.start || 0),
|
|
698
|
+
attStart + (bk.end !== void 0 ? bk.end + 1 : 0)
|
|
699
|
+
);
|
|
700
|
+
if (bk.id !== void 0) {
|
|
701
|
+
mapAttach.set(bk.id, attBin);
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
});
|
|
705
|
+
let sCmd;
|
|
706
|
+
if (zip) {
|
|
707
|
+
const unzipBtBody = pako__default.default.ungzip(btBody);
|
|
708
|
+
sCmd = new TextDecoder().decode(unzipBtBody);
|
|
709
|
+
} else {
|
|
710
|
+
sCmd = new TextDecoder().decode(btBody);
|
|
711
|
+
}
|
|
712
|
+
return sCmd;
|
|
713
|
+
}
|
|
714
|
+
static getPojoValue(pojo) {
|
|
715
|
+
if (pojo == null) return null;
|
|
716
|
+
if (pojo instanceof ValuePojo) return pojo.value;
|
|
717
|
+
if (pojo instanceof NullPojo) return null;
|
|
718
|
+
return pojo;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
_Cson._serialNo = 0;
|
|
722
|
+
_Cson._mapBytes = /* @__PURE__ */ new Map();
|
|
723
|
+
var Cson = _Cson;
|
|
724
|
+
var _JavaFactory = class _JavaFactory {
|
|
725
|
+
static registPojos(beans) {
|
|
726
|
+
beans.forEach((v, k) => {
|
|
727
|
+
_JavaFactory.registPojo(k, v);
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
static registPojo(javaType, pojo) {
|
|
731
|
+
_JavaFactory.CSON_BEANS.set(javaType, pojo);
|
|
732
|
+
}
|
|
733
|
+
static getPojoByName(javaType, create = true) {
|
|
734
|
+
if (javaType === null) return null;
|
|
735
|
+
const org = _JavaFactory.CSON_BEANS.get(javaType);
|
|
736
|
+
if (create ?? true) return Utils.cloneWithRef(org);
|
|
737
|
+
else return org;
|
|
738
|
+
}
|
|
739
|
+
static newBean(javaType, json) {
|
|
740
|
+
let bean = _JavaFactory.getPojoByName(javaType);
|
|
741
|
+
if (bean == null) {
|
|
742
|
+
bean = new CsonPojo().setObjectType(javaType);
|
|
743
|
+
if (json !== null) {
|
|
744
|
+
bean.setExtJsonMap(json);
|
|
745
|
+
}
|
|
746
|
+
return bean;
|
|
747
|
+
}
|
|
748
|
+
return classTransformer.plainToClassFromExist(bean, json);
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
_JavaFactory.CSON_BEANS = /* @__PURE__ */ new Map();
|
|
752
|
+
var JavaFactory = _JavaFactory;
|
|
753
|
+
|
|
754
|
+
// src/pojo-registry.ts
|
|
755
|
+
function registerAllPojos() {
|
|
756
|
+
const beans = /* @__PURE__ */ new Map([
|
|
757
|
+
// 基础 RPC 类型
|
|
758
|
+
[CRpcFeRsp.JAVA_TYPE, new CRpcFeRsp()],
|
|
759
|
+
[CRpcFeCmd.JAVA_TYPE, new CRpcFeCmd()],
|
|
760
|
+
[FeException.JAVA_TYPE, new FeException()],
|
|
761
|
+
[FeJavaException.JAVA_TYPE, new FeJavaException()],
|
|
762
|
+
// 基础 POJO
|
|
763
|
+
[SystemCallback.JAVA_TYPE, new SystemCallback()],
|
|
764
|
+
[FePojo.JAVA_TYPE, new FePojo()],
|
|
765
|
+
[NullPojo.JAVA_TYPE, new NullPojo()],
|
|
766
|
+
[ValuePojo.JAVA_TYPE, new ValuePojo()],
|
|
767
|
+
// 协议相关
|
|
768
|
+
[BinBlock.JAVA_TYPE, new BinBlock()],
|
|
769
|
+
[PartitionTable.JAVA_TYPE, new PartitionTable()],
|
|
770
|
+
[CRpcCallbackCmd.JAVA_TYPE, new CRpcCallbackCmd()],
|
|
771
|
+
[CRpcCallbackRsp.JAVA_TYPE, new CRpcCallbackRsp()],
|
|
772
|
+
// 异常类型
|
|
773
|
+
[FeAbilityExecuteException.JAVA_TYPE, new FeAbilityExecuteException()],
|
|
774
|
+
[FeWxMiniCmdException.JAVA_TYPE, new FeWxMiniCmdException()],
|
|
775
|
+
// WxMini 业务类型
|
|
776
|
+
[WxMiniBridgeCommand.JAVA_TYPE, new WxMiniBridgeCommand()],
|
|
777
|
+
[WxMiniCommand.JAVA_TYPE, new WxMiniCommand()],
|
|
778
|
+
[WxMiniConfigDto.JAVA_TYPE, new WxMiniConfigDto()],
|
|
779
|
+
[QueryWxMiniParam.JAVA_TYPE, new QueryWxMiniParam()],
|
|
780
|
+
[QuerySceneFromWxMiniParams.JAVA_TYPE, new QuerySceneFromWxMiniParams()]
|
|
781
|
+
]);
|
|
782
|
+
JavaFactory.registPojos(beans);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/device-info.ts
|
|
786
|
+
function isWxMiniprogram() {
|
|
787
|
+
if (typeof window === "undefined" || typeof navigator === "undefined") {
|
|
788
|
+
return false;
|
|
789
|
+
}
|
|
790
|
+
const userAgent = window.navigator.userAgent.toLowerCase();
|
|
791
|
+
return userAgent.includes("micromessenger") && userAgent.includes("miniprogram");
|
|
792
|
+
}
|
|
793
|
+
function isTouchDevice() {
|
|
794
|
+
if (typeof window === "undefined") return false;
|
|
795
|
+
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
796
|
+
}
|
|
797
|
+
function getPlatform() {
|
|
798
|
+
if (typeof navigator === "undefined") return "Unknown";
|
|
799
|
+
const ua = navigator.userAgent;
|
|
800
|
+
if (/Windows/.test(ua)) return "Windows";
|
|
801
|
+
if (/Macintosh|Mac OS X/.test(ua)) return "macOS";
|
|
802
|
+
if (/Linux/.test(ua)) return "Linux";
|
|
803
|
+
if (/Android/.test(ua)) return "Android";
|
|
804
|
+
if (/iPhone|iPad|iPod/.test(ua)) return "iOS";
|
|
805
|
+
return "Unknown";
|
|
806
|
+
}
|
|
807
|
+
function getBrowserName() {
|
|
808
|
+
if (typeof navigator === "undefined") return "Unknown";
|
|
809
|
+
const userAgent = navigator.userAgent.toLowerCase();
|
|
810
|
+
if (userAgent.includes("micromessenger")) return "WeChat";
|
|
811
|
+
if (userAgent.includes("firefox")) return "Firefox";
|
|
812
|
+
if (userAgent.includes("edg")) return "Edge (Chromium)";
|
|
813
|
+
if (userAgent.includes("edge")) return "Edge (Legacy)";
|
|
814
|
+
if (userAgent.includes("opr") || userAgent.includes("opera")) return "Opera";
|
|
815
|
+
if (userAgent.includes("trident") || userAgent.includes("msie")) return "Internet Explorer";
|
|
816
|
+
if (userAgent.includes("chrome")) return "Chrome";
|
|
817
|
+
if (userAgent.includes("safari")) return "Safari";
|
|
818
|
+
return "Unknown";
|
|
819
|
+
}
|
|
820
|
+
var PING_SERVICE = "[PING]";
|
|
821
|
+
var PingStatus = /* @__PURE__ */ ((PingStatus2) => {
|
|
822
|
+
PingStatus2[PingStatus2["success"] = 0] = "success";
|
|
823
|
+
PingStatus2[PingStatus2["failed"] = 1] = "failed";
|
|
824
|
+
PingStatus2[PingStatus2["timeout"] = 2] = "timeout";
|
|
825
|
+
PingStatus2[PingStatus2["none"] = 3] = "none";
|
|
826
|
+
return PingStatus2;
|
|
827
|
+
})(PingStatus || {});
|
|
828
|
+
var PingResult = class {
|
|
829
|
+
constructor(status = 3 /* none */, error) {
|
|
830
|
+
this.status = status;
|
|
831
|
+
this.error = error;
|
|
832
|
+
}
|
|
833
|
+
};
|
|
834
|
+
var WebSocketError = class extends Error {
|
|
835
|
+
constructor(msg) {
|
|
836
|
+
super(msg);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var WebSocketConnectError = class extends Error {
|
|
840
|
+
constructor(msg, options) {
|
|
841
|
+
super(msg);
|
|
842
|
+
this.name = "WebSocketConnectError";
|
|
843
|
+
this.cause = options?.cause;
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
var clients = /* @__PURE__ */ new Set();
|
|
847
|
+
var _WsClient = class _WsClient {
|
|
848
|
+
constructor(url) {
|
|
849
|
+
this.socket = null;
|
|
850
|
+
this.pingInterval = 5e3;
|
|
851
|
+
this._reqId = 300;
|
|
852
|
+
this._mapRpc = /* @__PURE__ */ new Map();
|
|
853
|
+
this._rpcCodec = new RpcCodec();
|
|
854
|
+
this.url = url;
|
|
855
|
+
clients.add(this);
|
|
856
|
+
}
|
|
857
|
+
getSocket() {
|
|
858
|
+
return this.socket;
|
|
859
|
+
}
|
|
860
|
+
getUrl() {
|
|
861
|
+
return this.url;
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* 设置服务端回调处理器
|
|
865
|
+
*/
|
|
866
|
+
setCallbackHandler(handler) {
|
|
867
|
+
this._callbackHandler = handler;
|
|
868
|
+
}
|
|
869
|
+
connect(options) {
|
|
870
|
+
if (!this.socket || !this.isSocketValid()) {
|
|
871
|
+
this.socket = new WebSocket(this.url);
|
|
872
|
+
this.socket.onopen = (event) => this.onSocketConnected(event);
|
|
873
|
+
this.socket.onmessage = (event) => this.onSocketMessage(event);
|
|
874
|
+
this.socket.onclose = (event) => this.onSocketClose(event);
|
|
875
|
+
this.socket.onerror = (event) => this.onSocketError(event);
|
|
876
|
+
if (options?.loopRetry != false) {
|
|
877
|
+
this.tryStartLoop();
|
|
878
|
+
}
|
|
879
|
+
} else {
|
|
880
|
+
Utils.log("WebSocket is already connected or connecting");
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
async blockConnect(options) {
|
|
884
|
+
this.connect(options);
|
|
885
|
+
try {
|
|
886
|
+
await Utils.pollBlock(
|
|
887
|
+
() => this.isSocketValid(),
|
|
888
|
+
3e3,
|
|
889
|
+
100,
|
|
890
|
+
"Timed out to connect server : " + this.url
|
|
891
|
+
);
|
|
892
|
+
} catch (err) {
|
|
893
|
+
this.close();
|
|
894
|
+
throw err;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
tryStartLoop() {
|
|
898
|
+
if (this.intervalId) return;
|
|
899
|
+
this.intervalId = setInterval(() => this.loopRetryConnect(), this.pingInterval);
|
|
900
|
+
}
|
|
901
|
+
close() {
|
|
902
|
+
clients.delete(this);
|
|
903
|
+
try {
|
|
904
|
+
if (this.socket) {
|
|
905
|
+
this.socket.close();
|
|
906
|
+
}
|
|
907
|
+
} catch (err) {
|
|
908
|
+
Utils.error(err);
|
|
909
|
+
}
|
|
910
|
+
if (this.intervalId != null) {
|
|
911
|
+
clearInterval(this.intervalId);
|
|
912
|
+
this.intervalId = void 0;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
loopRetryConnect() {
|
|
916
|
+
if (this.isSocketValid()) return;
|
|
917
|
+
Utils.log("Retry connecting : %s ... ", this.url);
|
|
918
|
+
this.connect();
|
|
919
|
+
}
|
|
920
|
+
onSocketConnected(event) {
|
|
921
|
+
Utils.log("WebSocket is connected : %s (%s)", this.url, event);
|
|
922
|
+
}
|
|
923
|
+
onSocketClose(event) {
|
|
924
|
+
Utils.log("WebSocket is closed : %s (%s)", this.url, event);
|
|
925
|
+
}
|
|
926
|
+
isSocketValid() {
|
|
927
|
+
return this.socket?.readyState === WebSocket.OPEN;
|
|
928
|
+
}
|
|
929
|
+
onSocketMessage(event) {
|
|
930
|
+
if (event.data instanceof Blob) {
|
|
931
|
+
event.data.arrayBuffer().then((bt) => {
|
|
932
|
+
this.handleReceivedData(bt);
|
|
933
|
+
});
|
|
934
|
+
} else throw new Error("Recieved illegal message : " + event);
|
|
935
|
+
}
|
|
936
|
+
static checkConnectionError(bytes) {
|
|
937
|
+
if (bytes == null) return;
|
|
938
|
+
const prefixLength = _WsClient.SIM_SERVER_CON_ERROR_HEADER.length;
|
|
939
|
+
const arrayLength = bytes.length;
|
|
940
|
+
if (arrayLength < prefixLength) {
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
for (let i = 0; i < prefixLength; i++) {
|
|
944
|
+
if (bytes[i] !== _WsClient.SIM_SERVER_CON_ERROR_HEADER[i]) {
|
|
945
|
+
return;
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
const body = bytes.subarray(prefixLength);
|
|
949
|
+
const msg = Utils.utf8ToString(body);
|
|
950
|
+
throw new WebSocketError(msg ?? "Unknown error message");
|
|
951
|
+
}
|
|
952
|
+
wrapSocketErrorBytes(error) {
|
|
953
|
+
const msg = error + "";
|
|
954
|
+
const msgBytes = Utils.string2Utf8(msg ?? "Unknown error");
|
|
955
|
+
return Utils.concatUint8Arrays([_WsClient.SIM_SERVER_CON_ERROR_HEADER, msgBytes]);
|
|
956
|
+
}
|
|
957
|
+
onSocketError(error) {
|
|
958
|
+
for (const req of Array.from(this._mapRpc.keys())) {
|
|
959
|
+
const func = this._mapRpc.get(req);
|
|
960
|
+
this._mapRpc.delete(req);
|
|
961
|
+
const msg = error.type + ":" + this.url + "(" + _WsClient.getWebSocketStateName(this.socket?.readyState) + ")";
|
|
962
|
+
func?.call(this, this.wrapSocketErrorBytes(msg), true);
|
|
963
|
+
}
|
|
964
|
+
Utils.error("WebSocket error : %s", error + "");
|
|
965
|
+
}
|
|
966
|
+
async ping(timeout = 5) {
|
|
967
|
+
return new Promise((resolve, reject) => {
|
|
968
|
+
const cmd = new CRpcFeCmd();
|
|
969
|
+
cmd.service = PING_SERVICE;
|
|
970
|
+
const result = new PingResult();
|
|
971
|
+
setTimeout(() => {
|
|
972
|
+
result.status = 2 /* timeout */;
|
|
973
|
+
resolve(result);
|
|
974
|
+
}, timeout * 1e3);
|
|
975
|
+
this.rpcAsync(cmd, null).then((_) => {
|
|
976
|
+
result.status = 0 /* success */;
|
|
977
|
+
resolve(result);
|
|
978
|
+
}).catch((error) => {
|
|
979
|
+
result.status = 1 /* failed */;
|
|
980
|
+
result.error = error;
|
|
981
|
+
resolve(result);
|
|
982
|
+
});
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
rpc(cmd, onAct) {
|
|
986
|
+
if (!this.isSocketValid())
|
|
987
|
+
throw new Error("Invalid connection status : " + _WsClient.getWebSocketStateName(this.socket?.readyState));
|
|
988
|
+
const req = this._reqId++;
|
|
989
|
+
cmd.reqId = req;
|
|
990
|
+
const cmdBytes = this._rpcCodec.toBytes(cmd);
|
|
991
|
+
this._mapRpc.set(req, onAct);
|
|
992
|
+
const header = _WsClient.buildRpcHeader(req, this._rpcCodec.zipOut);
|
|
993
|
+
try {
|
|
994
|
+
this.sendRpcBytes(header, cmdBytes);
|
|
995
|
+
} catch (err) {
|
|
996
|
+
if (err instanceof Error) {
|
|
997
|
+
console.error(err.message);
|
|
998
|
+
} else {
|
|
999
|
+
console.error(err);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
return req;
|
|
1003
|
+
}
|
|
1004
|
+
async rpcAsync(cmd, returnType) {
|
|
1005
|
+
return new Promise((resolve, reject) => {
|
|
1006
|
+
this.rpc(cmd, (data, isZip) => {
|
|
1007
|
+
try {
|
|
1008
|
+
const retData = Cson.decodeReturn(data, isZip);
|
|
1009
|
+
if (returnType != null) {
|
|
1010
|
+
if (Utils.isInstance(retData, returnType)) resolve(retData);
|
|
1011
|
+
else
|
|
1012
|
+
reject("Invalid return data type(Desired Type" + returnType + "). Value=" + retData);
|
|
1013
|
+
} else resolve(retData);
|
|
1014
|
+
} catch (error) {
|
|
1015
|
+
if (error instanceof FeException) reject(error);
|
|
1016
|
+
else reject("Failed to decode RPC return data:" + data);
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
});
|
|
1020
|
+
}
|
|
1021
|
+
async handleReceivedData(buffer) {
|
|
1022
|
+
const data = new Uint8Array(buffer);
|
|
1023
|
+
const bytes = new Uint8Array(data);
|
|
1024
|
+
const lowVer = new DataView(bytes.buffer, bytes.byteOffset).getInt8(_WsClient._rspZipFlagOffset);
|
|
1025
|
+
const zip = (lowVer & _WsClient._maskZipFlag) > 0;
|
|
1026
|
+
const pkgType = new DataView(bytes.buffer, bytes.byteOffset).getInt8(
|
|
1027
|
+
_WsClient._rspTypeFlagOffset
|
|
1028
|
+
);
|
|
1029
|
+
const req = Bytes.readInt32(bytes, _WsClient._rspReqIdOffset + 4);
|
|
1030
|
+
const body = bytes.slice(_WsClient._rspLength);
|
|
1031
|
+
if (pkgType === _WsClient._typeBinRpcRSP) {
|
|
1032
|
+
const func = this._mapRpc.get(req);
|
|
1033
|
+
if (func != null) {
|
|
1034
|
+
func(body, zip);
|
|
1035
|
+
this._mapRpc.delete(req);
|
|
1036
|
+
} else {
|
|
1037
|
+
Utils.error(`Recieved None Request Response (${req}) ${bytes.byteLength} byte`);
|
|
1038
|
+
}
|
|
1039
|
+
} else if (pkgType === _WsClient._typeBinRpcCallbackReq) {
|
|
1040
|
+
this.callbackFromServer(req, body);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
async callbackFromServer(reqId, cmdByte) {
|
|
1044
|
+
const rsp = new CRpcCallbackRsp();
|
|
1045
|
+
rsp.reqId = reqId;
|
|
1046
|
+
try {
|
|
1047
|
+
const mapAttach = /* @__PURE__ */ new Map();
|
|
1048
|
+
const rspJson = Cson.decodeServerPackage(cmdByte, true, mapAttach);
|
|
1049
|
+
if (Utils.isStringEmpty(rspJson)) return null;
|
|
1050
|
+
const cmd = Cson.decodeJson(rspJson, mapAttach);
|
|
1051
|
+
if (cmd.data != null) {
|
|
1052
|
+
if (this._callbackHandler) {
|
|
1053
|
+
const result = await this._callbackHandler.handleCallback(cmd.data);
|
|
1054
|
+
rsp.result = result == null ? void 0 : result;
|
|
1055
|
+
} else {
|
|
1056
|
+
Utils.log("No callback handler registered, ignoring server callback");
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
Utils.error("Callback error:", error);
|
|
1061
|
+
throw error;
|
|
1062
|
+
} finally {
|
|
1063
|
+
this.sendCallbackRsp(rsp);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
sendMessage(message) {
|
|
1067
|
+
if (this.socket && this.isSocketValid()) {
|
|
1068
|
+
this.socket.send(message);
|
|
1069
|
+
} else {
|
|
1070
|
+
Utils.error("WebSocket is invalid : %s", this.socket?.readyState);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
static getWebSocketStateName(state) {
|
|
1074
|
+
if (state == null) return "NULL";
|
|
1075
|
+
switch (state) {
|
|
1076
|
+
case WebSocket.OPEN:
|
|
1077
|
+
return "OPEN";
|
|
1078
|
+
case WebSocket.CONNECTING:
|
|
1079
|
+
return "CONNECTING";
|
|
1080
|
+
case WebSocket.CLOSING:
|
|
1081
|
+
return "CLOSING";
|
|
1082
|
+
default:
|
|
1083
|
+
case WebSocket.CLOSED:
|
|
1084
|
+
return "CLOSED";
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
async sendBinary(data) {
|
|
1088
|
+
await Utils.pollBlock(() => this.isSocketValid(), 5e3, 200);
|
|
1089
|
+
if (this.socket && this.socket.readyState === WebSocket.OPEN) {
|
|
1090
|
+
this.socket.send(data);
|
|
1091
|
+
} else {
|
|
1092
|
+
Utils.error("WebSocket is not open");
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
async sendRpcBytes(header, bytes) {
|
|
1096
|
+
if (!bytes || bytes.length === 0) return;
|
|
1097
|
+
if (bytes.length <= _WsClient._wsMaxFrame) {
|
|
1098
|
+
const lst = new Uint8Array([...header, _WsClient._wsFlagSingle, ...bytes]);
|
|
1099
|
+
this.sendBinary(lst.buffer);
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
const length = bytes.length;
|
|
1103
|
+
for (let i = 0; i < length; i += _WsClient._wsMaxFrame) {
|
|
1104
|
+
let end = i + _WsClient._wsMaxFrame;
|
|
1105
|
+
let flag = _WsClient._wsFlagEnd;
|
|
1106
|
+
if (i === 0) {
|
|
1107
|
+
flag = _WsClient._wsFlagStart;
|
|
1108
|
+
} else if (end >= length) {
|
|
1109
|
+
flag = _WsClient._wsFlagEnd;
|
|
1110
|
+
end = length;
|
|
1111
|
+
} else {
|
|
1112
|
+
flag = _WsClient._wsFlagContinue;
|
|
1113
|
+
}
|
|
1114
|
+
const lst = new Uint8Array([...header, flag, ...bytes.slice(i, end)]);
|
|
1115
|
+
await this.sendBinary(lst.buffer);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
static buildRpcHeader(reqID, zip) {
|
|
1119
|
+
const bytes = new Uint8Array(_WsClient._reqLength);
|
|
1120
|
+
const header = zip ? _WsClient._wsBinHeaderZip : _WsClient._wsBinHeader;
|
|
1121
|
+
bytes.set(header, 0);
|
|
1122
|
+
Bytes.setInt32Bytes(bytes, this._reqLength - 4, reqID);
|
|
1123
|
+
return bytes;
|
|
1124
|
+
}
|
|
1125
|
+
static buildCallbackRspHeader(reqID) {
|
|
1126
|
+
const bytes = new Uint8Array(_WsClient._reqLength);
|
|
1127
|
+
bytes.set(_WsClient._wsBinHeaderCallbackRSP, 0);
|
|
1128
|
+
Bytes.setInt32Bytes(bytes, this._reqLength - 4, reqID);
|
|
1129
|
+
return bytes;
|
|
1130
|
+
}
|
|
1131
|
+
buildCallbackRspHeader(reqID) {
|
|
1132
|
+
const bytes = new Uint8Array(_WsClient._reqLength);
|
|
1133
|
+
bytes.set(_WsClient._wsBinHeaderCallbackRSP, 0);
|
|
1134
|
+
const dataView = new DataView(bytes.buffer);
|
|
1135
|
+
dataView.setInt32(9, reqID, true);
|
|
1136
|
+
return bytes;
|
|
1137
|
+
}
|
|
1138
|
+
sendCallbackRsp(rsp) {
|
|
1139
|
+
const cmdBytes = this._rpcCodec.toBytes(rsp);
|
|
1140
|
+
const header = this.buildCallbackRspHeader(rsp.reqId);
|
|
1141
|
+
this.sendRpcBytes(header, cmdBytes);
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
// 小版本的0位,标识是否压缩
|
|
1145
|
+
_WsClient._maskZipFlag = 1;
|
|
1146
|
+
// 四号字节代表返回包类型
|
|
1147
|
+
_WsClient._typeBinRpcRSP = 101;
|
|
1148
|
+
_WsClient._typeBinRpcCallbackReq = 102;
|
|
1149
|
+
_WsClient._typeBinRpcCallbackRsp = 103;
|
|
1150
|
+
_WsClient._reqLength = 13;
|
|
1151
|
+
_WsClient._rspLength = 13;
|
|
1152
|
+
_WsClient._rspZipFlagOffset = 3;
|
|
1153
|
+
_WsClient._rspReqIdOffset = 5;
|
|
1154
|
+
_WsClient._rspTypeFlagOffset = 4;
|
|
1155
|
+
_WsClient._int32Length = 4;
|
|
1156
|
+
_WsClient._wsFlagSingle = 0;
|
|
1157
|
+
_WsClient._wsFlagStart = 2;
|
|
1158
|
+
_WsClient._wsFlagContinue = 3;
|
|
1159
|
+
_WsClient._wsFlagEnd = 4;
|
|
1160
|
+
_WsClient._wsMaxFrame = 65e3;
|
|
1161
|
+
_WsClient._wsBinHeader = new Uint8Array([
|
|
1162
|
+
"L".charCodeAt(0),
|
|
1163
|
+
1,
|
|
1164
|
+
0,
|
|
1165
|
+
0,
|
|
1166
|
+
100
|
|
1167
|
+
]);
|
|
1168
|
+
_WsClient._wsBinHeaderZip = new Uint8Array(["L".charCodeAt(0), 1, 0, 1, 100]);
|
|
1169
|
+
_WsClient._wsBinHeaderCallbackRSP = new Uint8Array([
|
|
1170
|
+
"L".charCodeAt(0),
|
|
1171
|
+
1,
|
|
1172
|
+
0,
|
|
1173
|
+
1,
|
|
1174
|
+
_WsClient._typeBinRpcCallbackRsp
|
|
1175
|
+
]);
|
|
1176
|
+
_WsClient.SIM_SERVER_CON_ERROR_HEADER = new Uint8Array([128, 0, 0, 128, 33, 77]);
|
|
1177
|
+
var WsClient = _WsClient;
|
|
1178
|
+
var RpcCodec = class {
|
|
1179
|
+
constructor() {
|
|
1180
|
+
this.zipOut = true;
|
|
1181
|
+
}
|
|
1182
|
+
toBytes(cmd) {
|
|
1183
|
+
const attach = /* @__PURE__ */ new Map();
|
|
1184
|
+
const json = Cson.encode(cmd, attach);
|
|
1185
|
+
let bodyBytes = new TextEncoder().encode(json);
|
|
1186
|
+
if (this.zipOut) {
|
|
1187
|
+
bodyBytes = pako__default.default.gzip(bodyBytes);
|
|
1188
|
+
}
|
|
1189
|
+
const pTable = new PartitionTable();
|
|
1190
|
+
pTable.bodyLength = bodyBytes.length;
|
|
1191
|
+
pTable.lstBin = [];
|
|
1192
|
+
let lstBin = [];
|
|
1193
|
+
let pos = 0;
|
|
1194
|
+
for (const [key, value] of attach) {
|
|
1195
|
+
lstBin = lstBin.concat(Array.from(value));
|
|
1196
|
+
const bk = new BinBlock();
|
|
1197
|
+
bk.id = key;
|
|
1198
|
+
bk.start = pos;
|
|
1199
|
+
const nowlength = lstBin.length;
|
|
1200
|
+
bk.end = nowlength - 1;
|
|
1201
|
+
pos = nowlength;
|
|
1202
|
+
pTable.lstBin.push(bk);
|
|
1203
|
+
}
|
|
1204
|
+
const parJson = Cson.encode(pTable, null);
|
|
1205
|
+
const parBytes = new TextEncoder().encode(parJson);
|
|
1206
|
+
let lstBytes = Array.from(int32ToBytes(parBytes.length));
|
|
1207
|
+
lstBytes = lstBytes.concat(Array.from(parBytes));
|
|
1208
|
+
lstBytes = lstBytes.concat(Array.from(bodyBytes));
|
|
1209
|
+
lstBytes = lstBytes.concat(lstBin);
|
|
1210
|
+
return new Uint8Array(lstBytes);
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
var ws_client_default = WsClient;
|
|
1214
|
+
|
|
1215
|
+
// src/rpc-core.ts
|
|
1216
|
+
var WsService = class {
|
|
1217
|
+
constructor(wsClient, service) {
|
|
1218
|
+
this.wsClient = wsClient;
|
|
1219
|
+
this.service = service;
|
|
1220
|
+
}
|
|
1221
|
+
getClient() {
|
|
1222
|
+
return this.wsClient;
|
|
1223
|
+
}
|
|
1224
|
+
getServiceName() {
|
|
1225
|
+
return this.service;
|
|
1226
|
+
}
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
// src/rpc-interface.ts
|
|
1230
|
+
var _IWxMiniBridgeService = class _IWxMiniBridgeService extends WsService {
|
|
1231
|
+
constructor(wsClient) {
|
|
1232
|
+
super(wsClient, _IWxMiniBridgeService.SERVICE);
|
|
1233
|
+
}
|
|
1234
|
+
async handleCommand(cmd) {
|
|
1235
|
+
const _cmd = new CRpcFeCmd();
|
|
1236
|
+
_cmd.service = this.getServiceName();
|
|
1237
|
+
_cmd.func = "handleCommand";
|
|
1238
|
+
_cmd.params = [cmd];
|
|
1239
|
+
return this.wsClient.rpcAsync(_cmd, null);
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
_IWxMiniBridgeService.SERVICE = "cell.wx.mini.server.IWxMiniBridgeService";
|
|
1243
|
+
_IWxMiniBridgeService.DEFAULT_TIMEOUTS = 30;
|
|
1244
|
+
_IWxMiniBridgeService.DEFAULT_WAIT_ONLINE_TIMEOUTS = 10;
|
|
1245
|
+
_IWxMiniBridgeService.DECLARED_FIELDS = [];
|
|
1246
|
+
var IWxMiniBridgeService = _IWxMiniBridgeService;
|
|
1247
|
+
|
|
1248
|
+
// src/wx-mini.ts
|
|
1249
|
+
function isWxMiniBridgeCommandResult(obj) {
|
|
1250
|
+
return typeof obj === "object" && obj !== null && "data" in obj && "startTime" in obj && "endTime" in obj && typeof obj.startTime === "number" && typeof obj.endTime === "number";
|
|
1251
|
+
}
|
|
1252
|
+
var _kBatchExecuteCommand = "PRECMD_BATCH_CMD_HEX";
|
|
1253
|
+
var WxMiniBridge = class {
|
|
1254
|
+
_processOneResult(result) {
|
|
1255
|
+
if (typeof result == "string") {
|
|
1256
|
+
try {
|
|
1257
|
+
const jsonMap = JSON.parse(result);
|
|
1258
|
+
if (isWxMiniBridgeCommandResult(jsonMap)) {
|
|
1259
|
+
return jsonMap.data;
|
|
1260
|
+
}
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
return result;
|
|
1265
|
+
}
|
|
1266
|
+
isBatchExecuting(command) {
|
|
1267
|
+
return command.cmd == _kBatchExecuteCommand;
|
|
1268
|
+
}
|
|
1269
|
+
async prepareBridgeClient() {
|
|
1270
|
+
if (!isWxMiniprogram()) {
|
|
1271
|
+
throw new Error("WxMiniCommand can't use out of wxMiniprogram.");
|
|
1272
|
+
}
|
|
1273
|
+
if (this._bridgeClient == void 0) {
|
|
1274
|
+
if (this.bridgeWebSocketUrl == void 0) {
|
|
1275
|
+
throw new Error("The wxMini bridge webSocket url is undefined.");
|
|
1276
|
+
}
|
|
1277
|
+
this._bridgeClient = new ws_client_default(this.bridgeWebSocketUrl);
|
|
1278
|
+
await this._bridgeClient.blockConnect();
|
|
1279
|
+
}
|
|
1280
|
+
return this._bridgeClient;
|
|
1281
|
+
}
|
|
1282
|
+
async handleBridgeCallback(command) {
|
|
1283
|
+
try {
|
|
1284
|
+
let bridgeCommand = new WxMiniBridgeCommand();
|
|
1285
|
+
bridgeCommand.appId = this.appUuid;
|
|
1286
|
+
bridgeCommand.cmd = command.cmd;
|
|
1287
|
+
bridgeCommand.params = command.params;
|
|
1288
|
+
bridgeCommand.timeoutS = command.timeout;
|
|
1289
|
+
bridgeCommand.waitOnlineTimeoutS = command.waitOnlineTimeoutS;
|
|
1290
|
+
let result = await this.handleBridgeCommand(bridgeCommand);
|
|
1291
|
+
if (typeof result == "string") {
|
|
1292
|
+
result = this._processOneResult(result);
|
|
1293
|
+
if (this.isBatchExecuting(command)) {
|
|
1294
|
+
if (typeof result == "string") {
|
|
1295
|
+
result = JSON.parse(result);
|
|
1296
|
+
}
|
|
1297
|
+
result = Object.fromEntries(Object.entries(result).map((value) => [value[0], this._processOneResult(value[1])]));
|
|
1298
|
+
result = JSON.stringify(result);
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
return result;
|
|
1302
|
+
} catch (error) {
|
|
1303
|
+
throw this._getWxMiniComdException(error, command);
|
|
1304
|
+
}
|
|
1305
|
+
}
|
|
1306
|
+
async handleBridgeCommand(command) {
|
|
1307
|
+
if (command.appId == void 0) {
|
|
1308
|
+
command.appId = this.appUuid;
|
|
1309
|
+
}
|
|
1310
|
+
let service = new IWxMiniBridgeService(await this.prepareBridgeClient());
|
|
1311
|
+
let result = await service.handleCommand(command);
|
|
1312
|
+
return result;
|
|
1313
|
+
}
|
|
1314
|
+
queryConfig() {
|
|
1315
|
+
const configDto = new WxMiniConfigDto();
|
|
1316
|
+
configDto.wxMiniAppUuid = this.appUuid;
|
|
1317
|
+
configDto.wxMiniServerUrl = this.serverUrl;
|
|
1318
|
+
configDto.sceneFromWxMiniParams = this.sceneFromWxMiniParams;
|
|
1319
|
+
configDto.initalQueryParameters = this.initalQueryParameters;
|
|
1320
|
+
return configDto;
|
|
1321
|
+
}
|
|
1322
|
+
querySceneFromWxMiniParams() {
|
|
1323
|
+
return this.sceneFromWxMiniParams;
|
|
1324
|
+
}
|
|
1325
|
+
/**
|
|
1326
|
+
* 关闭桥接连接
|
|
1327
|
+
*/
|
|
1328
|
+
close() {
|
|
1329
|
+
if (this._bridgeClient) {
|
|
1330
|
+
this._bridgeClient.close();
|
|
1331
|
+
this._bridgeClient = void 0;
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
_getWxMiniComdException(error, command) {
|
|
1335
|
+
const exception = new FeWxMiniCmdException();
|
|
1336
|
+
exception.ability = command;
|
|
1337
|
+
exception.wxMiniAppUuid = this.appUuid;
|
|
1338
|
+
exception.wxMiniServerUrl = this.serverUrl;
|
|
1339
|
+
if (error instanceof Error) {
|
|
1340
|
+
exception.err = error.message;
|
|
1341
|
+
exception.err = `${error}`;
|
|
1342
|
+
} else {
|
|
1343
|
+
exception.err = `${error}`;
|
|
1344
|
+
}
|
|
1345
|
+
return exception;
|
|
1346
|
+
}
|
|
1347
|
+
};
|
|
1348
|
+
|
|
1349
|
+
// src/wx-mini-api.ts
|
|
1350
|
+
var WxMiniCmd = /* @__PURE__ */ ((WxMiniCmd2) => {
|
|
1351
|
+
WxMiniCmd2["getUserProfile"] = "getUserProfile";
|
|
1352
|
+
WxMiniCmd2["makePhoneCall"] = "makePhoneCall";
|
|
1353
|
+
WxMiniCmd2["chooseMedia"] = "chooseMedia";
|
|
1354
|
+
WxMiniCmd2["readLocalFile"] = "readLocalFile";
|
|
1355
|
+
WxMiniCmd2["getPhoneNum"] = "getPhoneNum";
|
|
1356
|
+
WxMiniCmd2["scanCode"] = "scanCode";
|
|
1357
|
+
WxMiniCmd2["navigateTo"] = "navigateTo";
|
|
1358
|
+
WxMiniCmd2["redirectTo"] = "redirectTo";
|
|
1359
|
+
WxMiniCmd2["reLaunch"] = "reLaunch";
|
|
1360
|
+
WxMiniCmd2["navigateBack"] = "navigateBack";
|
|
1361
|
+
WxMiniCmd2["loginGetCode"] = "loginGetCode";
|
|
1362
|
+
WxMiniCmd2["saveProjectConfigParam"] = "saveProjectConfigParam";
|
|
1363
|
+
WxMiniCmd2["loadProjectConfigParam"] = "loadProjectConfigParam";
|
|
1364
|
+
WxMiniCmd2["downloadFile"] = "downloadFile";
|
|
1365
|
+
WxMiniCmd2["uploadFile"] = "uploadFile";
|
|
1366
|
+
WxMiniCmd2["saveFileToDisk"] = "saveFileToDisk";
|
|
1367
|
+
WxMiniCmd2["shareFileMessage"] = "shareFileMessage";
|
|
1368
|
+
WxMiniCmd2["openDocument"] = "openDocument";
|
|
1369
|
+
WxMiniCmd2["getLocation"] = "getLocation";
|
|
1370
|
+
WxMiniCmd2["openLocation"] = "openLocation";
|
|
1371
|
+
WxMiniCmd2["chooseLocation"] = "chooseLocation";
|
|
1372
|
+
WxMiniCmd2["queryAppGlobalData"] = "queryAppGlobalData";
|
|
1373
|
+
WxMiniCmd2["chooseMessageFile"] = "chooseMessageFile";
|
|
1374
|
+
WxMiniCmd2["setSharePageMessage"] = "setSharePageMessage";
|
|
1375
|
+
WxMiniCmd2["showShareImageMenu"] = "showShareImageMenu";
|
|
1376
|
+
WxMiniCmd2["saveImageToPhotosAlbum"] = "saveImageToPhotosAlbum";
|
|
1377
|
+
WxMiniCmd2["saveVideoToPhotosAlbum"] = "saveVideoToPhotosAlbum";
|
|
1378
|
+
WxMiniCmd2["getClipboardData"] = "getClipboardData";
|
|
1379
|
+
WxMiniCmd2["setClipboardData"] = "setClipboardData";
|
|
1380
|
+
WxMiniCmd2["startAudioRecord"] = "startAudioRecord";
|
|
1381
|
+
WxMiniCmd2["stopAudioRecord"] = "stopAudioRecord";
|
|
1382
|
+
WxMiniCmd2["pauseAudioRecord"] = "pauseAudioRecord";
|
|
1383
|
+
WxMiniCmd2["resumeAudioRecord"] = "resumeAudioRecord";
|
|
1384
|
+
return WxMiniCmd2;
|
|
1385
|
+
})(WxMiniCmd || {});
|
|
1386
|
+
var DEFAULT_TIMEOUT = 60 * 1e3;
|
|
1387
|
+
function buildCmd(cmd, opts, params) {
|
|
1388
|
+
const command = new WxMiniCommand();
|
|
1389
|
+
command.cmd = cmd;
|
|
1390
|
+
command.timeout = opts?.timeout ?? DEFAULT_TIMEOUT;
|
|
1391
|
+
if (params) {
|
|
1392
|
+
command.params = new Map(Object.entries(params));
|
|
1393
|
+
}
|
|
1394
|
+
return command;
|
|
1395
|
+
}
|
|
1396
|
+
function addParams(cmd, params) {
|
|
1397
|
+
if (!cmd.params) {
|
|
1398
|
+
cmd.params = /* @__PURE__ */ new Map();
|
|
1399
|
+
}
|
|
1400
|
+
for (const [k, v] of Object.entries(params)) {
|
|
1401
|
+
cmd.params.set(k, v ?? null);
|
|
1402
|
+
}
|
|
1403
|
+
return cmd;
|
|
1404
|
+
}
|
|
1405
|
+
var WxMiniApi = class {
|
|
1406
|
+
constructor(config) {
|
|
1407
|
+
this._bridge = new WxMiniBridge();
|
|
1408
|
+
if (config) {
|
|
1409
|
+
this.configure(config);
|
|
1410
|
+
}
|
|
1411
|
+
}
|
|
1412
|
+
/**
|
|
1413
|
+
* 设置或更新配置
|
|
1414
|
+
* @param config - appUuid 和 bridgeWebSocketUrl
|
|
1415
|
+
*/
|
|
1416
|
+
configure(config) {
|
|
1417
|
+
if (config.appUuid !== void 0) {
|
|
1418
|
+
this._bridge.appUuid = config.appUuid;
|
|
1419
|
+
}
|
|
1420
|
+
if (config.bridgeWebSocketUrl !== void 0) {
|
|
1421
|
+
this._bridge.bridgeWebSocketUrl = config.bridgeWebSocketUrl;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1424
|
+
/**
|
|
1425
|
+
* 关闭桥接连接,释放资源
|
|
1426
|
+
*/
|
|
1427
|
+
close() {
|
|
1428
|
+
this._bridge.close();
|
|
1429
|
+
}
|
|
1430
|
+
/** 执行一个命令并返回结果 */
|
|
1431
|
+
async execute(command) {
|
|
1432
|
+
return this._bridge.handleBridgeCallback(command);
|
|
1433
|
+
}
|
|
1434
|
+
/** 执行并将结果 JSON 解析为对象 */
|
|
1435
|
+
async executeAs(command) {
|
|
1436
|
+
const result = await this.execute(command);
|
|
1437
|
+
if (typeof result === "string") {
|
|
1438
|
+
return JSON.parse(result);
|
|
1439
|
+
}
|
|
1440
|
+
return result;
|
|
1441
|
+
}
|
|
1442
|
+
// ========================= 用户信息 =========================
|
|
1443
|
+
/**
|
|
1444
|
+
* 通过微信小程序接口, 获取用户信息(昵称/头像等)
|
|
1445
|
+
*/
|
|
1446
|
+
async getUserProfile(opts) {
|
|
1447
|
+
const command = buildCmd("getUserProfile" /* getUserProfile */, opts, {
|
|
1448
|
+
[WxMiniCommand.getUserProfile_MESSAGE]: opts.message,
|
|
1449
|
+
[WxMiniCommand.getUserProfile_BUTTON]: opts.buttonLabel,
|
|
1450
|
+
[WxMiniCommand.getUserProfile_QUERY_TYPE]: opts.type ?? "All"
|
|
1451
|
+
});
|
|
1452
|
+
return this.execute(command);
|
|
1453
|
+
}
|
|
1454
|
+
// ========================= 手机号 =========================
|
|
1455
|
+
/**
|
|
1456
|
+
* 通过微信小程序接口,获取用户手机号码
|
|
1457
|
+
*/
|
|
1458
|
+
async getPhoneNum(opts) {
|
|
1459
|
+
const command = buildCmd("getPhoneNum" /* getPhoneNum */, opts, {
|
|
1460
|
+
[WxMiniCommand.getPhoneNum_MESSAGE]: opts.message,
|
|
1461
|
+
[WxMiniCommand.getPhoneNum_BUTTON]: opts.buttonLabel,
|
|
1462
|
+
[WxMiniCommand.getPhoneNum_REJECT_BUTTON]: opts.rejectButtonLabel ?? null
|
|
1463
|
+
});
|
|
1464
|
+
return this.execute(command);
|
|
1465
|
+
}
|
|
1466
|
+
// ========================= 拨打电话 =========================
|
|
1467
|
+
/**
|
|
1468
|
+
* 拨打电话
|
|
1469
|
+
*/
|
|
1470
|
+
async makePhoneCall(opts) {
|
|
1471
|
+
const command = buildCmd("makePhoneCall" /* makePhoneCall */, opts, {
|
|
1472
|
+
[WxMiniCommand.makePhoneCall_phoneNum]: opts.phoneNum
|
|
1473
|
+
});
|
|
1474
|
+
await this.execute(command);
|
|
1475
|
+
}
|
|
1476
|
+
// ========================= 媒体选择 =========================
|
|
1477
|
+
/**
|
|
1478
|
+
* 调起相机并选取照片/视频
|
|
1479
|
+
*/
|
|
1480
|
+
async chooseMedia(opts = {}) {
|
|
1481
|
+
const {
|
|
1482
|
+
count = 2,
|
|
1483
|
+
mediaTypes = [WxMiniCommand.MEDIATYPE_mix],
|
|
1484
|
+
sourceTypes = [WxMiniCommand.SOURCETYPE_album, WxMiniCommand.SOURCETYPE_camera],
|
|
1485
|
+
maxDuration = 30,
|
|
1486
|
+
sizeTypes = [WxMiniCommand.SIZETYPE_compressed, WxMiniCommand.SIZETYPE_original],
|
|
1487
|
+
camera = WxMiniCommand.CAMERA_back
|
|
1488
|
+
} = opts;
|
|
1489
|
+
const command = buildCmd("chooseMedia" /* chooseMedia */, opts, {
|
|
1490
|
+
[WxMiniCommand.PARAM_count]: String(count),
|
|
1491
|
+
[WxMiniCommand.PARAM_mediaType]: JSON.stringify(mediaTypes),
|
|
1492
|
+
[WxMiniCommand.PARAM_sourceType]: JSON.stringify(sourceTypes),
|
|
1493
|
+
[WxMiniCommand.PARAM_maxDuration]: String(maxDuration),
|
|
1494
|
+
[WxMiniCommand.PARAM_sizeType]: JSON.stringify(sizeTypes),
|
|
1495
|
+
[WxMiniCommand.PARAM_camera]: camera
|
|
1496
|
+
});
|
|
1497
|
+
return this.executeAs(command);
|
|
1498
|
+
}
|
|
1499
|
+
// ========================= 扫码 =========================
|
|
1500
|
+
/**
|
|
1501
|
+
* 扫描二维码,返回二维码内容
|
|
1502
|
+
*/
|
|
1503
|
+
async scanCode(opts = {}) {
|
|
1504
|
+
const command = buildCmd("scanCode" /* scanCode */, opts);
|
|
1505
|
+
return this.execute(command);
|
|
1506
|
+
}
|
|
1507
|
+
// ========================= 文件操作 =========================
|
|
1508
|
+
/**
|
|
1509
|
+
* 读取本地文件内容
|
|
1510
|
+
* @warning 文件超过 60K 会导致链接中断,适合小文件
|
|
1511
|
+
*/
|
|
1512
|
+
async readLocalFile(opts) {
|
|
1513
|
+
const command = buildCmd("readLocalFile" /* readLocalFile */, opts, {
|
|
1514
|
+
[WxMiniCommand.PARAM_FILE_PATH]: opts.filePath
|
|
1515
|
+
});
|
|
1516
|
+
return this.execute(command);
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* 下载文件,返回临时文件路径
|
|
1520
|
+
*/
|
|
1521
|
+
async downloadFile(opts) {
|
|
1522
|
+
const command = buildCmd("downloadFile" /* downloadFile */, opts, {
|
|
1523
|
+
[WxMiniCommand.PARAM_URL]: opts.url
|
|
1524
|
+
});
|
|
1525
|
+
return this.execute(command);
|
|
1526
|
+
}
|
|
1527
|
+
/**
|
|
1528
|
+
* 上传文件到服务器
|
|
1529
|
+
*/
|
|
1530
|
+
async uploadFile(opts) {
|
|
1531
|
+
const command = buildCmd("uploadFile" /* uploadFile */, opts, {
|
|
1532
|
+
[WxMiniCommand.PARAM_URL]: opts.url,
|
|
1533
|
+
[WxMiniCommand.PARAM_FILE_PATH]: opts.filePath,
|
|
1534
|
+
[WxMiniCommand.PARAM_UPLOAD_FILE_NAME]: opts.fileName,
|
|
1535
|
+
[WxMiniCommand.PARAM_UPLOAD_FORM_DATA]: opts.formData ? JSON.stringify(opts.formData) : null
|
|
1536
|
+
});
|
|
1537
|
+
return this.execute(command);
|
|
1538
|
+
}
|
|
1539
|
+
/**
|
|
1540
|
+
* 打开预览文档(支持 txt/pdf/excel/word/ppt 等格式)
|
|
1541
|
+
*/
|
|
1542
|
+
async openDocument(opts) {
|
|
1543
|
+
const command = buildCmd("openDocument" /* openDocument */, opts, {
|
|
1544
|
+
[WxMiniCommand.PARAM_FILE_PATH]: opts.filePath
|
|
1545
|
+
});
|
|
1546
|
+
await this.execute(command);
|
|
1547
|
+
}
|
|
1548
|
+
/**
|
|
1549
|
+
* 保存图片到相册
|
|
1550
|
+
*/
|
|
1551
|
+
async saveImageToPhotosAlbum(opts) {
|
|
1552
|
+
const command = buildCmd("saveImageToPhotosAlbum" /* saveImageToPhotosAlbum */, opts, {
|
|
1553
|
+
[WxMiniCommand.PARAM_FILE_PATH]: opts.filePath
|
|
1554
|
+
});
|
|
1555
|
+
await this.execute(command);
|
|
1556
|
+
}
|
|
1557
|
+
/**
|
|
1558
|
+
* 保存视频到相册
|
|
1559
|
+
*/
|
|
1560
|
+
async saveVideoToPhotosAlbum(opts) {
|
|
1561
|
+
const command = buildCmd("saveVideoToPhotosAlbum" /* saveVideoToPhotosAlbum */, opts, {
|
|
1562
|
+
[WxMiniCommand.PARAM_FILE_PATH]: opts.filePath
|
|
1563
|
+
});
|
|
1564
|
+
await this.execute(command);
|
|
1565
|
+
}
|
|
1566
|
+
/**
|
|
1567
|
+
* 分享文件消息(将临时文件分享给他人)
|
|
1568
|
+
*/
|
|
1569
|
+
async shareFileMessage(opts) {
|
|
1570
|
+
const command = buildCmd("shareFileMessage" /* shareFileMessage */, opts, {
|
|
1571
|
+
[WxMiniCommand.PARAM_FILE_PATH]: opts.filePath,
|
|
1572
|
+
[WxMiniCommand.PARAM_SHARE_FILE_NAME]: opts.fileName
|
|
1573
|
+
});
|
|
1574
|
+
await this.execute(command);
|
|
1575
|
+
}
|
|
1576
|
+
/**
|
|
1577
|
+
* 从聊天记录中选择文件
|
|
1578
|
+
*/
|
|
1579
|
+
async chooseMessageFile(opts) {
|
|
1580
|
+
const command = buildCmd("chooseMessageFile" /* chooseMessageFile */, opts, {
|
|
1581
|
+
[WxMiniCommand.PARAM_COUNT]: String(opts.count),
|
|
1582
|
+
[WxMiniCommand.PARAM_TYPE]: opts.type ?? "all",
|
|
1583
|
+
[WxMiniCommand.PARAM_EXTENSION]: opts.extensions ? JSON.stringify(opts.extensions) : null
|
|
1584
|
+
});
|
|
1585
|
+
return this.executeAs(command);
|
|
1586
|
+
}
|
|
1587
|
+
// ========================= 页面导航 =========================
|
|
1588
|
+
/**
|
|
1589
|
+
* 跳转到小程序内部页面
|
|
1590
|
+
*/
|
|
1591
|
+
async navigateTo(opts) {
|
|
1592
|
+
const command = buildCmd("navigateTo" /* navigateTo */, opts, {
|
|
1593
|
+
[WxMiniCommand.PARAM_URL]: opts.path
|
|
1594
|
+
});
|
|
1595
|
+
await this.execute(command);
|
|
1596
|
+
}
|
|
1597
|
+
/**
|
|
1598
|
+
* 关闭当前页面后跳转
|
|
1599
|
+
*/
|
|
1600
|
+
async redirectTo(opts) {
|
|
1601
|
+
const command = buildCmd("redirectTo" /* redirectTo */, opts, {
|
|
1602
|
+
[WxMiniCommand.PARAM_URL]: opts.path
|
|
1603
|
+
});
|
|
1604
|
+
await this.execute(command);
|
|
1605
|
+
}
|
|
1606
|
+
/**
|
|
1607
|
+
* 关闭所有页面,打开应用内某页面(清空页面栈)
|
|
1608
|
+
*/
|
|
1609
|
+
async reLaunch(opts) {
|
|
1610
|
+
const command = buildCmd("reLaunch" /* reLaunch */, opts, {
|
|
1611
|
+
[WxMiniCommand.PARAM_URL]: opts.path
|
|
1612
|
+
});
|
|
1613
|
+
await this.execute(command);
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* 关闭当前页面,返回上一页面或多级页面
|
|
1617
|
+
*/
|
|
1618
|
+
async navigateBack(opts = {}) {
|
|
1619
|
+
const command = buildCmd("navigateBack" /* navigateBack */, opts, {
|
|
1620
|
+
[WxMiniCommand.PARAM_delta]: String(opts.delta ?? 1)
|
|
1621
|
+
});
|
|
1622
|
+
await this.execute(command);
|
|
1623
|
+
}
|
|
1624
|
+
// ========================= 登录 =========================
|
|
1625
|
+
/**
|
|
1626
|
+
* 调用微信登录,返回登录码 code
|
|
1627
|
+
*/
|
|
1628
|
+
async loginGetCode(opts = {}) {
|
|
1629
|
+
const command = buildCmd("loginGetCode" /* loginGetCode */, opts);
|
|
1630
|
+
return this.execute(command);
|
|
1631
|
+
}
|
|
1632
|
+
// ========================= 位置 =========================
|
|
1633
|
+
/**
|
|
1634
|
+
* 获取当前位置(经纬度)
|
|
1635
|
+
*/
|
|
1636
|
+
async getLocation(opts = {}) {
|
|
1637
|
+
const command = buildCmd("getLocation" /* getLocation */, opts, {
|
|
1638
|
+
[WxMiniCommand.PARAM_OPENIT]: String(opts.openIt ?? false)
|
|
1639
|
+
});
|
|
1640
|
+
return this.executeAs(command);
|
|
1641
|
+
}
|
|
1642
|
+
/**
|
|
1643
|
+
* 打开地图并定位到指定位置
|
|
1644
|
+
*/
|
|
1645
|
+
async openLocation(opts) {
|
|
1646
|
+
const command = buildCmd("openLocation" /* openLocation */, opts, {
|
|
1647
|
+
[WxMiniCommand.PARAM_LOCATION]: JSON.stringify(opts.location)
|
|
1648
|
+
});
|
|
1649
|
+
await this.execute(command);
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* 打开地图让用户选择位置,返回所选位置坐标
|
|
1653
|
+
*/
|
|
1654
|
+
async chooseLocation(opts = {}) {
|
|
1655
|
+
const command = buildCmd("chooseLocation" /* chooseLocation */, opts);
|
|
1656
|
+
addParams(command, {
|
|
1657
|
+
[WxMiniCommand.PARAM_LOCATION]: opts.initLocation ? JSON.stringify(opts.initLocation) : "{}"
|
|
1658
|
+
});
|
|
1659
|
+
return this.executeAs(command);
|
|
1660
|
+
}
|
|
1661
|
+
// ========================= 工程配置 =========================
|
|
1662
|
+
/**
|
|
1663
|
+
* 保存扩展的工程配置参数到小程序本地(页面启动时会自动合并传入)
|
|
1664
|
+
*/
|
|
1665
|
+
async saveExtProjectConfig(opts) {
|
|
1666
|
+
const command = buildCmd("saveProjectConfigParam" /* saveProjectConfigParam */, opts, {
|
|
1667
|
+
[WxMiniCommand.PARAM_MAP_JSON]: JSON.stringify(opts.params),
|
|
1668
|
+
[WxMiniCommand.PARAM_APPEND]: String(opts.append)
|
|
1669
|
+
});
|
|
1670
|
+
await this.execute(command);
|
|
1671
|
+
}
|
|
1672
|
+
/**
|
|
1673
|
+
* 读取保存在小程序本地的扩展工程配置参数
|
|
1674
|
+
*/
|
|
1675
|
+
async loadExtProjectConfig(opts = {}) {
|
|
1676
|
+
const command = buildCmd("loadProjectConfigParam" /* loadProjectConfigParam */, { timeout: opts.timeout ?? 5e3 });
|
|
1677
|
+
return this.executeAs(command);
|
|
1678
|
+
}
|
|
1679
|
+
// ========================= 应用数据 =========================
|
|
1680
|
+
/**
|
|
1681
|
+
* 查询小程序 App 的 GlobalData
|
|
1682
|
+
*/
|
|
1683
|
+
async queryAppGlobalData(opts = {}) {
|
|
1684
|
+
const command = buildCmd("queryAppGlobalData" /* queryAppGlobalData */, opts);
|
|
1685
|
+
return this.executeAs(command);
|
|
1686
|
+
}
|
|
1687
|
+
// ========================= 分享 =========================
|
|
1688
|
+
/**
|
|
1689
|
+
* 设置分享页信息(用于分享转发,全局一份)
|
|
1690
|
+
*/
|
|
1691
|
+
async setSharePageMessage(opts) {
|
|
1692
|
+
const command = buildCmd("setSharePageMessage" /* setSharePageMessage */, opts, {
|
|
1693
|
+
[WxMiniCommand.PARAM_sharePage]: JSON.stringify(opts.sharePage)
|
|
1694
|
+
});
|
|
1695
|
+
await this.execute(command);
|
|
1696
|
+
}
|
|
1697
|
+
/**
|
|
1698
|
+
* 显示图片分享菜单
|
|
1699
|
+
*/
|
|
1700
|
+
async showShareImageMenu(opts) {
|
|
1701
|
+
const command = buildCmd("showShareImageMenu" /* showShareImageMenu */, opts, {
|
|
1702
|
+
[WxMiniCommand.PARAM_path]: opts.path,
|
|
1703
|
+
[WxMiniCommand.PARAM_style]: opts.style,
|
|
1704
|
+
[WxMiniCommand.PARAM_needShowEntrance]: opts.needShowEntrance,
|
|
1705
|
+
[WxMiniCommand.PARAM_entrancePath]: opts.entrancePath
|
|
1706
|
+
});
|
|
1707
|
+
await this.execute(command);
|
|
1708
|
+
}
|
|
1709
|
+
// ========================= 剪贴板 =========================
|
|
1710
|
+
/**
|
|
1711
|
+
* 读取剪贴板内容
|
|
1712
|
+
*/
|
|
1713
|
+
async getClipboardData(opts = {}) {
|
|
1714
|
+
const command = buildCmd("getClipboardData" /* getClipboardData */, opts);
|
|
1715
|
+
return this.execute(command);
|
|
1716
|
+
}
|
|
1717
|
+
/**
|
|
1718
|
+
* 写入剪贴板
|
|
1719
|
+
*/
|
|
1720
|
+
async setClipboardData(opts) {
|
|
1721
|
+
const command = buildCmd("setClipboardData" /* setClipboardData */, opts, {
|
|
1722
|
+
[WxMiniCommand.CLIP_BOARD_DATA]: opts.data
|
|
1723
|
+
});
|
|
1724
|
+
await this.execute(command);
|
|
1725
|
+
}
|
|
1726
|
+
// ========================= 录音 =========================
|
|
1727
|
+
/**
|
|
1728
|
+
* 开始录音
|
|
1729
|
+
*/
|
|
1730
|
+
async startAudioRecord(opts = {}) {
|
|
1731
|
+
const command = buildCmd("startAudioRecord" /* startAudioRecord */, opts);
|
|
1732
|
+
const { duration, sampleRate, numberOfChannels, encodeBitRate, format, frameSize } = opts;
|
|
1733
|
+
const recOpts = {};
|
|
1734
|
+
if (duration !== void 0) recOpts.duration = duration;
|
|
1735
|
+
if (sampleRate !== void 0) recOpts.sampleRate = sampleRate;
|
|
1736
|
+
if (numberOfChannels !== void 0) recOpts.numberOfChannels = numberOfChannels;
|
|
1737
|
+
if (encodeBitRate !== void 0) recOpts.encodeBitRate = encodeBitRate;
|
|
1738
|
+
if (format !== void 0) recOpts.format = format;
|
|
1739
|
+
if (frameSize !== void 0) recOpts.frameSize = frameSize;
|
|
1740
|
+
if (Object.keys(recOpts).length > 0) {
|
|
1741
|
+
addParams(command, { options: JSON.stringify(recOpts) });
|
|
1742
|
+
}
|
|
1743
|
+
await this.execute(command);
|
|
1744
|
+
}
|
|
1745
|
+
/**
|
|
1746
|
+
* 停止录音,返回录音文件临时路径
|
|
1747
|
+
*/
|
|
1748
|
+
async stopAudioRecord(opts = {}) {
|
|
1749
|
+
const command = buildCmd("stopAudioRecord" /* stopAudioRecord */, opts);
|
|
1750
|
+
return this.execute(command);
|
|
1751
|
+
}
|
|
1752
|
+
/**
|
|
1753
|
+
* 暂停录音
|
|
1754
|
+
*/
|
|
1755
|
+
async pauseAudioRecord(opts = {}) {
|
|
1756
|
+
const command = buildCmd("pauseAudioRecord" /* pauseAudioRecord */, opts);
|
|
1757
|
+
await this.execute(command);
|
|
1758
|
+
}
|
|
1759
|
+
/**
|
|
1760
|
+
* 继续录音
|
|
1761
|
+
*/
|
|
1762
|
+
async resumeAudioRecord(opts = {}) {
|
|
1763
|
+
const command = buildCmd("resumeAudioRecord" /* resumeAudioRecord */, opts);
|
|
1764
|
+
await this.execute(command);
|
|
1765
|
+
}
|
|
1766
|
+
};
|
|
1767
|
+
|
|
1768
|
+
// src/index.ts
|
|
1769
|
+
registerAllPojos();
|
|
1770
|
+
|
|
1771
|
+
exports.BinBlock = BinBlock;
|
|
1772
|
+
exports.Bytes = Bytes;
|
|
1773
|
+
exports.CRpcCallbackCmd = CRpcCallbackCmd;
|
|
1774
|
+
exports.CRpcCallbackRsp = CRpcCallbackRsp;
|
|
1775
|
+
exports.CRpcFeCmd = CRpcFeCmd;
|
|
1776
|
+
exports.CRpcFeRsp = CRpcFeRsp;
|
|
1777
|
+
exports.Cson = Cson;
|
|
1778
|
+
exports.CsonBean = CsonBean;
|
|
1779
|
+
exports.CsonPojo = CsonPojo;
|
|
1780
|
+
exports.FeAbilityExecuteException = FeAbilityExecuteException;
|
|
1781
|
+
exports.FeException = FeException;
|
|
1782
|
+
exports.FeJavaException = FeJavaException;
|
|
1783
|
+
exports.FePojo = FePojo;
|
|
1784
|
+
exports.FeWxMiniCmdException = FeWxMiniCmdException;
|
|
1785
|
+
exports.IWxMiniBridgeService = IWxMiniBridgeService;
|
|
1786
|
+
exports.JavaFactory = JavaFactory;
|
|
1787
|
+
exports.NullPojo = NullPojo;
|
|
1788
|
+
exports.PartitionTable = PartitionTable;
|
|
1789
|
+
exports.PingResult = PingResult;
|
|
1790
|
+
exports.PingStatus = PingStatus;
|
|
1791
|
+
exports.QuerySceneFromWxMiniParams = QuerySceneFromWxMiniParams;
|
|
1792
|
+
exports.QueryWxMiniParam = QueryWxMiniParam;
|
|
1793
|
+
exports.RpcCodec = RpcCodec;
|
|
1794
|
+
exports.SystemCallback = SystemCallback;
|
|
1795
|
+
exports.Utils = Utils;
|
|
1796
|
+
exports.ValuePojo = ValuePojo;
|
|
1797
|
+
exports.WebSocketConnectError = WebSocketConnectError;
|
|
1798
|
+
exports.WebSocketError = WebSocketError;
|
|
1799
|
+
exports.WsClient = ws_client_default;
|
|
1800
|
+
exports.WsService = WsService;
|
|
1801
|
+
exports.WxMiniApi = WxMiniApi;
|
|
1802
|
+
exports.WxMiniBridge = WxMiniBridge;
|
|
1803
|
+
exports.WxMiniBridgeCommand = WxMiniBridgeCommand;
|
|
1804
|
+
exports.WxMiniCmd = WxMiniCmd;
|
|
1805
|
+
exports.WxMiniCommand = WxMiniCommand;
|
|
1806
|
+
exports.WxMiniConfigDto = WxMiniConfigDto;
|
|
1807
|
+
exports.clients = clients;
|
|
1808
|
+
exports.getBrowserName = getBrowserName;
|
|
1809
|
+
exports.getPlatform = getPlatform;
|
|
1810
|
+
exports.isTouchDevice = isTouchDevice;
|
|
1811
|
+
exports.isWxMiniprogram = isWxMiniprogram;
|
|
1812
|
+
//# sourceMappingURL=index.cjs.map
|
|
1813
|
+
//# sourceMappingURL=index.cjs.map
|