@qqbrowser/qbot-claw-launcher 0.9.78 → 0.9.79

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.
@@ -0,0 +1,1317 @@
1
+ /* @tencent/qb-auth-send-h5@2.5.0 */
2
+ function _arrayLikeToArray(r, a) {
3
+ (null == a || a > r.length) && (a = r.length);
4
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
5
+ return n;
6
+ }
7
+ function _arrayWithHoles(r) {
8
+ if (Array.isArray(r)) return r;
9
+ }
10
+ function _arrayWithoutHoles(r) {
11
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
12
+ }
13
+ function _iterableToArray(r) {
14
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
15
+ }
16
+ function _iterableToArrayLimit(r, l) {
17
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
18
+ if (null != t) {
19
+ var e,
20
+ n,
21
+ i,
22
+ u,
23
+ a = [],
24
+ f = !0,
25
+ o = !1;
26
+ try {
27
+ if (i = (t = t.call(r)).next, 0 === l) {
28
+ if (Object(t) !== t) return;
29
+ f = !1;
30
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
31
+ } catch (r) {
32
+ o = !0, n = r;
33
+ } finally {
34
+ try {
35
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
36
+ } finally {
37
+ if (o) throw n;
38
+ }
39
+ }
40
+ return a;
41
+ }
42
+ }
43
+ function _nonIterableRest() {
44
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
45
+ }
46
+ function _nonIterableSpread() {
47
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
48
+ }
49
+ function _regeneratorRuntime() {
50
+ _regeneratorRuntime = function () {
51
+ return e;
52
+ };
53
+ var t,
54
+ e = {},
55
+ r = Object.prototype,
56
+ n = r.hasOwnProperty,
57
+ o = Object.defineProperty || function (t, e, r) {
58
+ t[e] = r.value;
59
+ },
60
+ i = "function" == typeof Symbol ? Symbol : {},
61
+ a = i.iterator || "@@iterator",
62
+ c = i.asyncIterator || "@@asyncIterator",
63
+ u = i.toStringTag || "@@toStringTag";
64
+ function define(t, e, r) {
65
+ return Object.defineProperty(t, e, {
66
+ value: r,
67
+ enumerable: !0,
68
+ configurable: !0,
69
+ writable: !0
70
+ }), t[e];
71
+ }
72
+ try {
73
+ define({}, "");
74
+ } catch (t) {
75
+ define = function (t, e, r) {
76
+ return t[e] = r;
77
+ };
78
+ }
79
+ function wrap(t, e, r, n) {
80
+ var i = e && e.prototype instanceof Generator ? e : Generator,
81
+ a = Object.create(i.prototype),
82
+ c = new Context(n || []);
83
+ return o(a, "_invoke", {
84
+ value: makeInvokeMethod(t, r, c)
85
+ }), a;
86
+ }
87
+ function tryCatch(t, e, r) {
88
+ try {
89
+ return {
90
+ type: "normal",
91
+ arg: t.call(e, r)
92
+ };
93
+ } catch (t) {
94
+ return {
95
+ type: "throw",
96
+ arg: t
97
+ };
98
+ }
99
+ }
100
+ e.wrap = wrap;
101
+ var h = "suspendedStart",
102
+ l = "suspendedYield",
103
+ f = "executing",
104
+ s = "completed",
105
+ y = {};
106
+ function Generator() {}
107
+ function GeneratorFunction() {}
108
+ function GeneratorFunctionPrototype() {}
109
+ var p = {};
110
+ define(p, a, function () {
111
+ return this;
112
+ });
113
+ var d = Object.getPrototypeOf,
114
+ v = d && d(d(values([])));
115
+ v && v !== r && n.call(v, a) && (p = v);
116
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
117
+ function defineIteratorMethods(t) {
118
+ ["next", "throw", "return"].forEach(function (e) {
119
+ define(t, e, function (t) {
120
+ return this._invoke(e, t);
121
+ });
122
+ });
123
+ }
124
+ function AsyncIterator(t, e) {
125
+ function invoke(r, o, i, a) {
126
+ var c = tryCatch(t[r], t, o);
127
+ if ("throw" !== c.type) {
128
+ var u = c.arg,
129
+ h = u.value;
130
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
131
+ invoke("next", t, i, a);
132
+ }, function (t) {
133
+ invoke("throw", t, i, a);
134
+ }) : e.resolve(h).then(function (t) {
135
+ u.value = t, i(u);
136
+ }, function (t) {
137
+ return invoke("throw", t, i, a);
138
+ });
139
+ }
140
+ a(c.arg);
141
+ }
142
+ var r;
143
+ o(this, "_invoke", {
144
+ value: function (t, n) {
145
+ function callInvokeWithMethodAndArg() {
146
+ return new e(function (e, r) {
147
+ invoke(t, n, e, r);
148
+ });
149
+ }
150
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
151
+ }
152
+ });
153
+ }
154
+ function makeInvokeMethod(e, r, n) {
155
+ var o = h;
156
+ return function (i, a) {
157
+ if (o === f) throw Error("Generator is already running");
158
+ if (o === s) {
159
+ if ("throw" === i) throw a;
160
+ return {
161
+ value: t,
162
+ done: !0
163
+ };
164
+ }
165
+ for (n.method = i, n.arg = a;;) {
166
+ var c = n.delegate;
167
+ if (c) {
168
+ var u = maybeInvokeDelegate(c, n);
169
+ if (u) {
170
+ if (u === y) continue;
171
+ return u;
172
+ }
173
+ }
174
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
175
+ if (o === h) throw o = s, n.arg;
176
+ n.dispatchException(n.arg);
177
+ } else "return" === n.method && n.abrupt("return", n.arg);
178
+ o = f;
179
+ var p = tryCatch(e, r, n);
180
+ if ("normal" === p.type) {
181
+ if (o = n.done ? s : l, p.arg === y) continue;
182
+ return {
183
+ value: p.arg,
184
+ done: n.done
185
+ };
186
+ }
187
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
188
+ }
189
+ };
190
+ }
191
+ function maybeInvokeDelegate(e, r) {
192
+ var n = r.method,
193
+ o = e.iterator[n];
194
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
195
+ var i = tryCatch(o, e.iterator, r.arg);
196
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
197
+ var a = i.arg;
198
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
199
+ }
200
+ function pushTryEntry(t) {
201
+ var e = {
202
+ tryLoc: t[0]
203
+ };
204
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
205
+ }
206
+ function resetTryEntry(t) {
207
+ var e = t.completion || {};
208
+ e.type = "normal", delete e.arg, t.completion = e;
209
+ }
210
+ function Context(t) {
211
+ this.tryEntries = [{
212
+ tryLoc: "root"
213
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
214
+ }
215
+ function values(e) {
216
+ if (e || "" === e) {
217
+ var r = e[a];
218
+ if (r) return r.call(e);
219
+ if ("function" == typeof e.next) return e;
220
+ if (!isNaN(e.length)) {
221
+ var o = -1,
222
+ i = function next() {
223
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
224
+ return next.value = t, next.done = !0, next;
225
+ };
226
+ return i.next = i;
227
+ }
228
+ }
229
+ throw new TypeError(typeof e + " is not iterable");
230
+ }
231
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
232
+ value: GeneratorFunctionPrototype,
233
+ configurable: !0
234
+ }), o(GeneratorFunctionPrototype, "constructor", {
235
+ value: GeneratorFunction,
236
+ configurable: !0
237
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
238
+ var e = "function" == typeof t && t.constructor;
239
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
240
+ }, e.mark = function (t) {
241
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
242
+ }, e.awrap = function (t) {
243
+ return {
244
+ __await: t
245
+ };
246
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
247
+ return this;
248
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
249
+ void 0 === i && (i = Promise);
250
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
251
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
252
+ return t.done ? t.value : a.next();
253
+ });
254
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
255
+ return this;
256
+ }), define(g, "toString", function () {
257
+ return "[object Generator]";
258
+ }), e.keys = function (t) {
259
+ var e = Object(t),
260
+ r = [];
261
+ for (var n in e) r.push(n);
262
+ return r.reverse(), function next() {
263
+ for (; r.length;) {
264
+ var t = r.pop();
265
+ if (t in e) return next.value = t, next.done = !1, next;
266
+ }
267
+ return next.done = !0, next;
268
+ };
269
+ }, e.values = values, Context.prototype = {
270
+ constructor: Context,
271
+ reset: function (e) {
272
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
273
+ },
274
+ stop: function () {
275
+ this.done = !0;
276
+ var t = this.tryEntries[0].completion;
277
+ if ("throw" === t.type) throw t.arg;
278
+ return this.rval;
279
+ },
280
+ dispatchException: function (e) {
281
+ if (this.done) throw e;
282
+ var r = this;
283
+ function handle(n, o) {
284
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
285
+ }
286
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
287
+ var i = this.tryEntries[o],
288
+ a = i.completion;
289
+ if ("root" === i.tryLoc) return handle("end");
290
+ if (i.tryLoc <= this.prev) {
291
+ var c = n.call(i, "catchLoc"),
292
+ u = n.call(i, "finallyLoc");
293
+ if (c && u) {
294
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
295
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
296
+ } else if (c) {
297
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
298
+ } else {
299
+ if (!u) throw Error("try statement without catch or finally");
300
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
301
+ }
302
+ }
303
+ }
304
+ },
305
+ abrupt: function (t, e) {
306
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
307
+ var o = this.tryEntries[r];
308
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
309
+ var i = o;
310
+ break;
311
+ }
312
+ }
313
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
314
+ var a = i ? i.completion : {};
315
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
316
+ },
317
+ complete: function (t, e) {
318
+ if ("throw" === t.type) throw t.arg;
319
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
320
+ },
321
+ finish: function (t) {
322
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
323
+ var r = this.tryEntries[e];
324
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
325
+ }
326
+ },
327
+ catch: function (t) {
328
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
329
+ var r = this.tryEntries[e];
330
+ if (r.tryLoc === t) {
331
+ var n = r.completion;
332
+ if ("throw" === n.type) {
333
+ var o = n.arg;
334
+ resetTryEntry(r);
335
+ }
336
+ return o;
337
+ }
338
+ }
339
+ throw Error("illegal catch attempt");
340
+ },
341
+ delegateYield: function (e, r, n) {
342
+ return this.delegate = {
343
+ iterator: values(e),
344
+ resultName: r,
345
+ nextLoc: n
346
+ }, "next" === this.method && (this.arg = t), y;
347
+ }
348
+ }, e;
349
+ }
350
+ function _slicedToArray(r, e) {
351
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
352
+ }
353
+ function _toConsumableArray(r) {
354
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
355
+ }
356
+ function _unsupportedIterableToArray(r, a) {
357
+ if (r) {
358
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
359
+ var t = {}.toString.call(r).slice(8, -1);
360
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
361
+ }
362
+ }
363
+
364
+ /******************************************************************************
365
+ Copyright (c) Microsoft Corporation.
366
+
367
+ Permission to use, copy, modify, and/or distribute this software for any
368
+ purpose with or without fee is hereby granted.
369
+
370
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
371
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
372
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
373
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
374
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
375
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
376
+ PERFORMANCE OF THIS SOFTWARE.
377
+ ***************************************************************************** */
378
+
379
+ function __awaiter(thisArg, _arguments, P, generator) {
380
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
381
+ return new (P || (P = Promise))(function (resolve, reject) {
382
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
383
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
384
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
385
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
386
+ });
387
+ }
388
+
389
+ var Scene;
390
+ (function (Scene) {
391
+ Scene["h5"] = "h5";
392
+ Scene["windows"] = "windows";
393
+ Scene["mac"] = "mac";
394
+ Scene["external"] = "external";
395
+ Scene["wxminiprogram"] = "wxminiprogram";
396
+ })(Scene || (Scene = {}));
397
+
398
+ // 对比版本号大小
399
+ var compareVersionStrings = function compareVersionStrings(version1, version2) {
400
+ try {
401
+ // 将字符串按 '.' 分割成数组
402
+ var parts1 = version1.split('.').map(Number);
403
+ var parts2 = version2.split('.').map(Number);
404
+ // 获取最大长度
405
+ var maxLength = Math.max(parts1.length, parts2.length);
406
+ // 比较每个部分
407
+ for (var i = 0; i < maxLength; i++) {
408
+ var num1 = parts1[i] || 0; // 如果没有该部分,默认为 0
409
+ var num2 = parts2[i] || 0; // 如果没有该部分,默认为 0
410
+ if (num1 > num2) {
411
+ return 1; // version1 大于 version2
412
+ } else if (num1 < num2) {
413
+ return -1; // version1 小于 version2
414
+ }
415
+ }
416
+ return 0; // 两个版本相等
417
+ } catch (error) {
418
+ console.error('compareVersionStrings error: ', error);
419
+ return -1;
420
+ }
421
+ };
422
+ var parseJsonIfString = function parseJsonIfString(input) {
423
+ // 检查输入是否为字符串
424
+ if (typeof input === 'string') {
425
+ try {
426
+ // 尝试解析 JSON 字符串
427
+ return JSON.parse(input);
428
+ } catch (e) {
429
+ // 如果解析失败,返回原始字符串或处理错误
430
+ console.error('Invalid JSON string:', e);
431
+ return input; // 或者根据需要返回 null 或其他值
432
+ }
433
+ }
434
+ // 如果输入不是字符串,直接返回
435
+ return input;
436
+ };
437
+ // 生成uuid
438
+ var getUuid = function getUuid() {
439
+ if (crypto.randomUUID) {
440
+ return crypto.randomUUID();
441
+ }
442
+ var time = performance.now().toString(36); // 高精度时间戳
443
+ var random = Math.random().toString(36).slice(2); // 随机字符串
444
+ return "".concat(time, "-").concat(random);
445
+ };
446
+
447
+ // 星爵SDK的appkey
448
+ var QIMEISDKAPPKEY = '7800236';
449
+
450
+ var getAccountInfo = function getAccountInfo(scene) {
451
+ return new Promise(function (resolve) {
452
+ var _a, _b, _c, _d;
453
+ try {
454
+ if (scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.login) === null || _b === void 0 ? void 0 : _b.getAccountInfo)) {
455
+ // 移动端内
456
+ window.browser.login.getAccountInfo(function (rsp) {
457
+ var res = parseJsonIfString(rsp);
458
+ if (res === null || res === void 0 ? void 0 : res.qb_access_token) {
459
+ // 适配鸿蒙
460
+ res.qbtoken = res.qb_access_token;
461
+ }
462
+ resolve(res);
463
+ });
464
+ } else if (scene === Scene.windows && ((_c = chrome === null || chrome === void 0 ? void 0 : chrome.account) === null || _c === void 0 ? void 0 : _c.getLoginInfo)) {
465
+ // windows pc
466
+ chrome.account.getLoginInfo(function (res) {
467
+ if (res === null || res === void 0 ? void 0 : res.qbLoginInfo) {
468
+ res.qbLoginInfo = parseJsonIfString(res.qbLoginInfo);
469
+ }
470
+ resolve(res);
471
+ });
472
+ } else if (scene === Scene.mac && ((_d = chrome === null || chrome === void 0 ? void 0 : chrome.qbAccount) === null || _d === void 0 ? void 0 : _d.getLoginInfo)) {
473
+ // mac pc
474
+ chrome.qbAccount.getLoginInfo(function (res) {
475
+ if (res === null || res === void 0 ? void 0 : res.qbLoginInfo) {
476
+ res.qbLoginInfo = parseJsonIfString(res.qbLoginInfo);
477
+ }
478
+ resolve(res);
479
+ });
480
+ } else {
481
+ // 端外
482
+ resolve({});
483
+ }
484
+ } catch (error) {
485
+ console.error('getAccountInfo error: ', error);
486
+ resolve({});
487
+ }
488
+ });
489
+ };
490
+ var getDeviceInfo = function getDeviceInfo(scene) {
491
+ return new Promise(function (resolve) {
492
+ var _a, _b;
493
+ try {
494
+ if (scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.getBrowserParam)) {
495
+ // 移动端内
496
+ window.browser.app.getBrowserParam(function (rsp) {
497
+ var res = parseJsonIfString(rsp);
498
+ resolve(res);
499
+ });
500
+ } else if (scene === Scene.windows || scene === Scene.mac) {
501
+ // pc
502
+ getPcDeviceInfo(scene).then(function (res) {
503
+ resolve(res);
504
+ });
505
+ } else {
506
+ // 端外
507
+ resolve({});
508
+ }
509
+ } catch (error) {
510
+ console.error('getDeviceInfo error: ', error);
511
+ resolve({});
512
+ }
513
+ });
514
+ };
515
+ // 获取全局对象,兼容不同环境
516
+ var getGlobal = function getGlobal() {
517
+ if (typeof window !== 'undefined') {
518
+ return window;
519
+ }
520
+ if (typeof self !== 'undefined') {
521
+ return self;
522
+ }
523
+ if (typeof globalThis !== 'undefined') {
524
+ return globalThis;
525
+ }
526
+ return {};
527
+ };
528
+ // 获取pc端guid,qua2,qimei36
529
+ var getPcDeviceInfo = function getPcDeviceInfo(scene) {
530
+ return new Promise(function (resolve) {
531
+ var _a, _b, _c, _d, _e, _f;
532
+ try {
533
+ if (scene === Scene.windows) {
534
+ // window端,因为老版本qb用的是window.qb_external.getxxxx,新版本用window.chrome.qbExternal.getxxxx,需要做一层判断兼容
535
+ var globalObj = getGlobal();
536
+ // eslint-disable-next-line @typescript-eslint/naming-convention
537
+ var qb_external = globalObj.qb_external;
538
+ if (((_a = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _a === void 0 ? void 0 : _a.getFavSyncGuid) || ((_b = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _b === void 0 ? void 0 : _b.getQUA) || ((_c = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _c === void 0 ? void 0 : _c.getQ36)) {
539
+ // 支持新版本获取方法
540
+ Promise.all([getQbExternalFavSyncGuid(), getQbExternalQUA(), getQbExternalQ36()]).then(function (info) {
541
+ var _info = _slicedToArray(info, 3),
542
+ guid = _info[0],
543
+ qua2 = _info[1],
544
+ qimei36 = _info[2];
545
+ resolve({
546
+ guid: guid,
547
+ qua2: qua2,
548
+ qimei36: qimei36
549
+ });
550
+ });
551
+ } else if (((_d = qb_external === null || qb_external === void 0 ? void 0 : qb_external.getFavSyncGuid) === null || _d === void 0 ? void 0 : _d.call(qb_external)) || ((_e = qb_external === null || qb_external === void 0 ? void 0 : qb_external.getQUA) === null || _e === void 0 ? void 0 : _e.call(qb_external)) || ((_f = qb_external === null || qb_external === void 0 ? void 0 : qb_external.getQ36) === null || _f === void 0 ? void 0 : _f.call(qb_external))) {
552
+ // 走老版本的获取方法
553
+ var guid = qb_external.getFavSyncGuid() || '';
554
+ var qua2 = qb_external.getQUA() || '';
555
+ var qimei36 = qb_external.getQ36() || '';
556
+ resolve({
557
+ guid: guid,
558
+ qua2: qua2,
559
+ qimei36: qimei36
560
+ });
561
+ } else {
562
+ console.error('getPcDeviceInfo error: ', 'The Windows client does not have permission to getPcDeviceInfo');
563
+ resolve({
564
+ guid: '',
565
+ qua2: '',
566
+ qimei36: ''
567
+ });
568
+ }
569
+ } else if (scene === Scene.mac) {
570
+ Promise.all([getQbExternalGuid(), getQbExternalQUA(), getQbExternalQ36()]).then(function (info) {
571
+ var _info2 = _slicedToArray(info, 3),
572
+ guid = _info2[0],
573
+ qua2 = _info2[1],
574
+ qimei36 = _info2[2];
575
+ resolve({
576
+ guid: guid,
577
+ qua2: qua2,
578
+ qimei36: qimei36
579
+ });
580
+ });
581
+ }
582
+ } catch (error) {
583
+ console.error('getPcDeviceInfo error: ', error);
584
+ resolve({
585
+ guid: '',
586
+ qua2: '',
587
+ qimei36: ''
588
+ });
589
+ }
590
+ });
591
+ };
592
+ // pc获取favSyncGuid
593
+ var getQbExternalFavSyncGuid = function getQbExternalFavSyncGuid() {
594
+ return new Promise(function (resolve) {
595
+ var _a;
596
+ try {
597
+ if ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _a === void 0 ? void 0 : _a.getFavSyncGuid) {
598
+ chrome.qbExternal.getFavSyncGuid(function (guid) {
599
+ resolve(guid);
600
+ });
601
+ } else {
602
+ resolve('');
603
+ }
604
+ } catch (error) {
605
+ console.error('getQbExternalFavSyncGuid error: ', error);
606
+ resolve('');
607
+ }
608
+ });
609
+ };
610
+ // pc获取guid
611
+ var getQbExternalGuid = function getQbExternalGuid() {
612
+ return new Promise(function (resolve) {
613
+ var _a;
614
+ try {
615
+ if ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _a === void 0 ? void 0 : _a.getGuid) {
616
+ chrome.qbExternal.getGuid(function (guid) {
617
+ resolve(guid);
618
+ });
619
+ } else {
620
+ resolve('');
621
+ }
622
+ } catch (error) {
623
+ console.error('getQbExternalGuid error: ', error);
624
+ resolve('');
625
+ }
626
+ });
627
+ };
628
+ // pc获取qua2
629
+ var getQbExternalQUA = function getQbExternalQUA() {
630
+ return new Promise(function (resolve) {
631
+ var _a;
632
+ try {
633
+ if ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _a === void 0 ? void 0 : _a.getQUA) {
634
+ chrome.qbExternal.getQUA(function (qua) {
635
+ resolve(qua);
636
+ });
637
+ } else {
638
+ resolve('');
639
+ }
640
+ } catch (error) {
641
+ console.error('getQbExternalQUA error: ', error);
642
+ resolve('');
643
+ }
644
+ });
645
+ };
646
+ // pc获取qimei36
647
+ var getQbExternalQ36 = function getQbExternalQ36() {
648
+ return new Promise(function (resolve) {
649
+ var _a;
650
+ try {
651
+ if ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _a === void 0 ? void 0 : _a.getQ36) {
652
+ chrome.qbExternal.getQ36(function (qimei36) {
653
+ resolve(qimei36);
654
+ });
655
+ } else {
656
+ resolve('');
657
+ }
658
+ } catch (error) {
659
+ console.error('getQbExternalQ36 error: ', error);
660
+ resolve('');
661
+ }
662
+ });
663
+ };
664
+ // 刷新票据
665
+ var refreshToken = function refreshToken(scene, accountInfo, type) {
666
+ return new Promise(function (resolve, reject) {
667
+ var _a, _b, _c, _d;
668
+ try {
669
+ if (scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.login) === null || _b === void 0 ? void 0 : _b.refreshToken)) {
670
+ // 移动端内
671
+ window.browser.login.refreshToken({
672
+ uin: accountInfo.uin,
673
+ type: type === 'token' ? 4 : 3
674
+ }, function (rsp) {
675
+ var res = parseJsonIfString(rsp);
676
+ if ((res === null || res === void 0 ? void 0 : res.token) || (res === null || res === void 0 ? void 0 : res.qbtoken) || (res === null || res === void 0 ? void 0 : res.qb_access_token)) {
677
+ // 刷票成功
678
+ var newAccountInfo = Object.assign(Object.assign({}, accountInfo), res);
679
+ if (res === null || res === void 0 ? void 0 : res.qb_access_token) {
680
+ // 适配鸿蒙
681
+ newAccountInfo.qbtoken = res.qb_access_token;
682
+ }
683
+ resolve(newAccountInfo);
684
+ } else {
685
+ // 刷票失败
686
+ reject({
687
+ error: 'refreshToken failed',
688
+ scene: scene,
689
+ accountInfo: accountInfo,
690
+ res: res,
691
+ type: type
692
+ });
693
+ }
694
+ });
695
+ } else if (scene === Scene.windows) {
696
+ // windows pc
697
+ var qbid = accountInfo.qbid;
698
+ var openid = accountInfo.openid;
699
+ if (type === 'qbtoken') {
700
+ qbid = ((_c = accountInfo.qbLoginInfo) === null || _c === void 0 ? void 0 : _c.qbid) || accountInfo.qbid;
701
+ openid = ((_d = accountInfo.qbLoginInfo) === null || _d === void 0 ? void 0 : _d.openid) || accountInfo.openid;
702
+ }
703
+ refreshWindowsToken({
704
+ qbid: qbid,
705
+ openid: openid,
706
+ type: type
707
+ }, function (res) {
708
+ if ((res === null || res === void 0 ? void 0 : res.ret) === 0) {
709
+ // 刷票成功
710
+ if (res === null || res === void 0 ? void 0 : res.qbLoginInfo) {
711
+ res.qbLoginInfo = parseJsonIfString(res.qbLoginInfo);
712
+ }
713
+ var newAccountInfo = Object.assign(Object.assign({}, accountInfo), res);
714
+ resolve(newAccountInfo);
715
+ } else {
716
+ // 刷票失败
717
+ reject({
718
+ error: 'refreshToken failed',
719
+ scene: scene,
720
+ accountInfo: accountInfo,
721
+ res: res,
722
+ type: type
723
+ });
724
+ }
725
+ });
726
+ } else if (scene === Scene.mac) {
727
+ // mac pc
728
+ refreshMacToken(type, function (res) {
729
+ if ((res === null || res === void 0 ? void 0 : res.ret) === 0) {
730
+ // 刷票成功
731
+ if (res === null || res === void 0 ? void 0 : res.qbLoginInfo) {
732
+ res.qbLoginInfo = parseJsonIfString(res.qbLoginInfo);
733
+ }
734
+ var newAccountInfo = Object.assign(Object.assign({}, accountInfo), res);
735
+ resolve(newAccountInfo);
736
+ } else {
737
+ // 刷票失败
738
+ reject({
739
+ error: 'refreshToken failed',
740
+ scene: scene,
741
+ accountInfo: accountInfo,
742
+ res: res,
743
+ type: type
744
+ });
745
+ }
746
+ });
747
+ } else {
748
+ // 端外
749
+ reject({
750
+ error: 'external scene need to refresh token',
751
+ scene: scene,
752
+ type: type
753
+ });
754
+ }
755
+ } catch (error) {
756
+ console.error('refreshToken error: ', error);
757
+ reject({
758
+ error: error,
759
+ scene: scene,
760
+ type: type
761
+ });
762
+ }
763
+ });
764
+ };
765
+ /**
766
+ * 刷新登录token。只有能取到QB票据的QB版本,才能刷新QB票据
767
+ *
768
+ * @param param 刷新token需要传入的信息
769
+ * @param param.qbid 用户的qbid
770
+ * @param param.openid 用户的openid
771
+ * @param param.type 传入qbtoken,表示刷新QB票据。不传入,则刷新社交票据
772
+ * @param callback 刷新完成后的回调函数
773
+ */
774
+ var refreshWindowsToken = function refreshWindowsToken(param, callback) {
775
+ var _a, _b, _c;
776
+ if ((param === null || param === void 0 ? void 0 : param.type) === 'qbtoken') {
777
+ if ((_a = chrome === null || chrome === void 0 ? void 0 : chrome.account) === null || _a === void 0 ? void 0 : _a.refreshTokenEx) {
778
+ chrome.account.refreshTokenEx(JSON.stringify({
779
+ qbid: param.qbid,
780
+ openid: param.openid,
781
+ type: 'qbtoken'
782
+ }), callback);
783
+ } else if ((_b = chrome === null || chrome === void 0 ? void 0 : chrome.account) === null || _b === void 0 ? void 0 : _b.refreshQbToken) {
784
+ chrome.account.refreshQbToken({
785
+ qbid: param.qbid,
786
+ openid: param.openid
787
+ }, callback);
788
+ } else {
789
+ // qbtoken刷新不支持
790
+ console.error('not support qbtoken refresh!');
791
+ callback({});
792
+ }
793
+ return;
794
+ }
795
+ (_c = chrome === null || chrome === void 0 ? void 0 : chrome.account) === null || _c === void 0 ? void 0 : _c.refreshToken({
796
+ qbid: param.qbid,
797
+ openid: param.openid
798
+ }, callback);
799
+ };
800
+ /**
801
+ * 刷新登录token。只有能取到QB票据的QB版本,才能刷新QB票据
802
+ *
803
+ * @param param 刷新token需要传入的信息
804
+ * @param param.qbid 用户的qbid
805
+ * @param param.openid 用户的openid
806
+ * @param param.type 传入qbtoken,表示刷新QB票据。不传入,则刷新社交票据
807
+ * @param callback 刷新完成后的回调函数
808
+ */
809
+ var refreshMacToken = function refreshMacToken(type, callback) {
810
+ var _a, _b;
811
+ if ((_b = (_a = window === null || window === void 0 ? void 0 : window.chrome) === null || _a === void 0 ? void 0 : _a.qbAccount) === null || _b === void 0 ? void 0 : _b.refreshTokenEx) {
812
+ window.chrome.qbAccount.refreshTokenEx(JSON.stringify({
813
+ type: type
814
+ }), callback);
815
+ } else {
816
+ window.chrome.qbAccount.refreshToken(callback);
817
+ }
818
+ };
819
+ /**
820
+ * 根据客户端返回的mode,判断当前登录类型。wx: 微信登录。qq: qq登录。qqsdk: 老的qqsdk登录
821
+ *
822
+ * @param mode 客户端返回的登录mode
823
+ * @returns 登录类型
824
+ * mac 2是qq 3是微信
825
+ * win 2是qq 3是微信 5是qq
826
+ */
827
+ var getLoginTypeByMode = function getLoginTypeByMode(scene, mode) {
828
+ if (!mode) {
829
+ return 4;
830
+ }
831
+ if (mode === 3) {
832
+ // wx登录
833
+ return 2;
834
+ } else if (mode === 2 || mode === 5) {
835
+ // qq登录
836
+ return 4;
837
+ }
838
+ return mode;
839
+ };
840
+ // 获取终端版本号
841
+ var getVersion = function getVersion(scene) {
842
+ return new Promise(function (resolve) {
843
+ var _a, _b;
844
+ try {
845
+ if (scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.getQua2)) {
846
+ // 移动端内
847
+ window.browser.app.getQua2(function (qua2) {
848
+ if (qua2) {
849
+ var match = qua2.match(/PPVN=([^&]*)/);
850
+ var version = match ? match[1] : null;
851
+ resolve(version);
852
+ } else {
853
+ resolve('0.0.0.0');
854
+ }
855
+ });
856
+ } else {
857
+ // pc & 端外
858
+ resolve('0.0.0.0');
859
+ }
860
+ } catch (error) {
861
+ console.error('getVersion error: ', error);
862
+ resolve('0.0.0.0');
863
+ }
864
+ });
865
+ };
866
+ // 移动端内,手机账号登录时,用于获取其绑定的社交账号的票据
867
+ var getSocialMediaTokenInfoOfPhone = function getSocialMediaTokenInfoOfPhone(scene) {
868
+ return new Promise(function (resolve, reject) {
869
+ var _a, _b;
870
+ if (scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.login) === null || _b === void 0 ? void 0 : _b.getSocialMediaTokenInfoOfPhone)) {
871
+ // 移动端内
872
+ window.browser.login.getSocialMediaTokenInfoOfPhone(function (rsp) {
873
+ var res = parseJsonIfString(rsp);
874
+ if (res.code === 0) {
875
+ resolve(res);
876
+ } else {
877
+ reject(new Error("getSocialMediaTokenInfoOfPhone error: ".concat(JSON.stringify(res))));
878
+ }
879
+ });
880
+ } else {
881
+ // 非移动端内
882
+ reject(new Error("getSocialMediaTokenInfoOfPhone not support, scene: ".concat(scene)));
883
+ }
884
+ });
885
+ };
886
+ // 获取uskey
887
+ var getUsKey = function getUsKey(scene, busInfo) {
888
+ return new Promise(function (resolve) {
889
+ var _a, _b, _c;
890
+ try {
891
+ if (scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.getUsKey)) {
892
+ // 移动端内
893
+ window.browser.app.getUsKey({
894
+ busId: QIMEISDKAPPKEY,
895
+ busInfo: busInfo
896
+ }, function (res) {
897
+ if ((res === null || res === void 0 ? void 0 : res.ret) === 0) {
898
+ resolve(res === null || res === void 0 ? void 0 : res.result);
899
+ } else {
900
+ // jsapi调用失败
901
+ console.error('window.browser.app.getUsKey error: ', res);
902
+ resolve('');
903
+ }
904
+ });
905
+ } else if ((scene === Scene.windows || scene === Scene.mac) && ((_c = chrome === null || chrome === void 0 ? void 0 : chrome.qbExternal) === null || _c === void 0 ? void 0 : _c.getUskey)) {
906
+ chrome.qbExternal.getUskey(busInfo, function (usKey) {
907
+ resolve(usKey);
908
+ });
909
+ } else {
910
+ // 端外,或者端内低版本没有jsapi
911
+ resolve('');
912
+ }
913
+ } catch (error) {
914
+ console.error('getUsKey error: ', error);
915
+ resolve('');
916
+ }
917
+ });
918
+ };
919
+
920
+ var REALHOST = 'https://qbh5.qq.com/h5/v2';
921
+ var TESTHOST = 'https://pbtest.imtt.qq.com/h5/v2';
922
+ var RETCODEMAP = {
923
+ wrongParam: '-20',
924
+ failed: '-23',
925
+ needLogout: '-27',
926
+ tokenRefresh: '-28',
927
+ qbtokenRefresh: '-34' // qb票据刷新
928
+ };
929
+ var authSend = function authSend(options, body, extInfo) {
930
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
931
+ var sendPbVaild, accountInfo, deviceInfo, url, headers, res, refreshType;
932
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
933
+ while (1) switch (_context.prev = _context.next) {
934
+ case 0:
935
+ if (checkOptionsVaild(options)) {
936
+ _context.next = 2;
937
+ break;
938
+ }
939
+ return _context.abrupt("return", Promise.reject({
940
+ position: 'Options parameter exception',
941
+ options: options
942
+ }));
943
+ case 2:
944
+ _context.next = 4;
945
+ return checkSendPbVaild(options.scene);
946
+ case 4:
947
+ sendPbVaild = _context.sent;
948
+ if (!sendPbVaild) {
949
+ _context.next = 7;
950
+ break;
951
+ }
952
+ return _context.abrupt("return", sendPb(options, body));
953
+ case 7:
954
+ if (!(options.authType === '1')) {
955
+ _context.next = 13;
956
+ break;
957
+ }
958
+ _context.next = 10;
959
+ return getSocialMediaTokenInfoOfPhone(options.scene);
960
+ case 10:
961
+ accountInfo = _context.sent;
962
+ _context.next = 16;
963
+ break;
964
+ case 13:
965
+ _context.next = 15;
966
+ return getAccountInfo(options.scene);
967
+ case 15:
968
+ accountInfo = _context.sent;
969
+ case 16:
970
+ _context.next = 18;
971
+ return getDeviceInfo(options.scene);
972
+ case 18:
973
+ deviceInfo = _context.sent;
974
+ if (!(options.isAuth && !checkLogin(options.scene, accountInfo, extInfo))) {
975
+ _context.next = 21;
976
+ break;
977
+ }
978
+ return _context.abrupt("return", Promise.reject({
979
+ position: 'Authentication is required, please log in first',
980
+ options: options,
981
+ accountInfo: accountInfo,
982
+ extInfo: extInfo
983
+ }));
984
+ case 21:
985
+ url = getUrl(options);
986
+ _context.next = 24;
987
+ return getHeaders(options, extInfo, accountInfo, deviceInfo);
988
+ case 24:
989
+ headers = _context.sent;
990
+ _context.prev = 25;
991
+ _context.next = 28;
992
+ return post(options.scene, url, headers, body);
993
+ case 28:
994
+ res = _context.sent;
995
+ if (!(options.scene !== Scene.external && ((res === null || res === void 0 ? void 0 : res.code) === RETCODEMAP.tokenRefresh || (res === null || res === void 0 ? void 0 : res.code) === RETCODEMAP.qbtokenRefresh))) {
996
+ _context.next = 40;
997
+ break;
998
+ }
999
+ // 非端外业务场景,根据后台返回的错误码进行刷新票据重新请求
1000
+ refreshType = res.code === RETCODEMAP.tokenRefresh ? 'token' : 'qbtoken';
1001
+ _context.next = 33;
1002
+ return refreshToken(options.scene, accountInfo, refreshType);
1003
+ case 33:
1004
+ accountInfo = _context.sent;
1005
+ _context.next = 36;
1006
+ return getHeaders(options, extInfo, accountInfo, deviceInfo);
1007
+ case 36:
1008
+ headers = _context.sent;
1009
+ _context.next = 39;
1010
+ return post(options.scene, url, headers, body);
1011
+ case 39:
1012
+ res = _context.sent;
1013
+ case 40:
1014
+ if (!(res.code !== '0' || res.funcode !== '0')) {
1015
+ _context.next = 42;
1016
+ break;
1017
+ }
1018
+ return _context.abrupt("return", Promise.reject({
1019
+ position: 'https error',
1020
+ err: res,
1021
+ options: options,
1022
+ accountInfo: accountInfo,
1023
+ extInfo: extInfo
1024
+ }));
1025
+ case 42:
1026
+ return _context.abrupt("return", res.data);
1027
+ case 45:
1028
+ _context.prev = 45;
1029
+ _context.t0 = _context["catch"](25);
1030
+ return _context.abrupt("return", Promise.reject(_context.t0));
1031
+ case 48:
1032
+ case "end":
1033
+ return _context.stop();
1034
+ }
1035
+ }, _callee, null, [[25, 45]]);
1036
+ }));
1037
+ };
1038
+ // 检验参数是否合法
1039
+ var checkOptionsVaild = function checkOptionsVaild(options) {
1040
+ return options.servantName && options.funcName && Object.values(Scene).includes(options.scene);
1041
+ };
1042
+ // 检查是否支持sendPb
1043
+ var checkSendPbVaild = function checkSendPbVaild(scene) {
1044
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1045
+ var _a, _b, version, supportVersion;
1046
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1047
+ while (1) switch (_context2.prev = _context2.next) {
1048
+ case 0:
1049
+ if (!(scene === Scene.h5 && ((_b = (_a = window.browser) === null || _a === void 0 ? void 0 : _a.app) === null || _b === void 0 ? void 0 : _b.sendPb))) {
1050
+ _context2.next = 6;
1051
+ break;
1052
+ }
1053
+ _context2.next = 3;
1054
+ return getVersion(scene);
1055
+ case 3:
1056
+ version = _context2.sent;
1057
+ supportVersion = '13.8.2.0';
1058
+ return _context2.abrupt("return", compareVersionStrings(version, supportVersion) >= 0);
1059
+ case 6:
1060
+ return _context2.abrupt("return", false);
1061
+ case 7:
1062
+ case "end":
1063
+ return _context2.stop();
1064
+ }
1065
+ }, _callee2);
1066
+ }));
1067
+ };
1068
+ // 走h5端内的pbsend
1069
+ var sendPb = function sendPb(options, body) {
1070
+ return new Promise(function (resolve, reject) {
1071
+ var _a;
1072
+ try {
1073
+ var succCallback = function succCallback(rsp) {
1074
+ var res = parseJsonIfString(rsp);
1075
+ if (res.code !== 0 || res.funcode !== 0) {
1076
+ // 错误异常
1077
+ reject({
1078
+ position: 'sendPb succCb',
1079
+ err: res
1080
+ });
1081
+ } else {
1082
+ var data = JSON.parse(res.body);
1083
+ resolve(data);
1084
+ }
1085
+ };
1086
+ var errCallback = function errCallback(err) {
1087
+ reject({
1088
+ position: 'sendPb errCb',
1089
+ err: err
1090
+ });
1091
+ };
1092
+ // 将对象转换为 JSON 字符串
1093
+ var jsonString = JSON.stringify(body);
1094
+ // 使用 TextEncoder 将字符串转换为 UTF-8 编码
1095
+ var utf8Bytes = new TextEncoder().encode(jsonString);
1096
+ // 将 UTF-8 字节数组转换为 Base64 字符串
1097
+ var base64data = btoa(String.fromCharCode.apply(String, _toConsumableArray(utf8Bytes)));
1098
+ var pbOptions = {
1099
+ base64data: base64data,
1100
+ serviceName: 'h5_route',
1101
+ funcName: "/".concat(options.servantName, "/").concat(options.funcName),
1102
+ usePBProxy: true,
1103
+ encode: 'utf8',
1104
+ context: {
1105
+ unifyAuth: options.isAuth ? '1' : '0',
1106
+ service_encode_type: 'json',
1107
+ authType: (_a = options.authType) !== null && _a !== void 0 ? _a : '0',
1108
+ uskeyAuth: options.usKey ? '1' : '0'
1109
+ }
1110
+ };
1111
+ window.browser.app.sendPb(succCallback, errCallback, pbOptions);
1112
+ } catch (error) {
1113
+ return reject(error);
1114
+ }
1115
+ });
1116
+ };
1117
+ var post = function post(scene, url, headers, body) {
1118
+ return new Promise(function (resolve, reject) {
1119
+ // @ts-ignore
1120
+ if (scene === Scene.wxminiprogram && wx.request) {
1121
+ // 微信小程序业务场景
1122
+ // @ts-ignore
1123
+ wx.request({
1124
+ url: url,
1125
+ method: 'POST',
1126
+ headers: headers,
1127
+ data: body,
1128
+ success: function success(response) {
1129
+ var headers = response.header,
1130
+ status = response.statusCode;
1131
+ var code = headers['trpc-ret'];
1132
+ var funcode = headers['trpc-func-ret'];
1133
+ if (status >= 200 && status < 300 && code === '0' && funcode === '0') {
1134
+ return resolve({
1135
+ status: status,
1136
+ code: code,
1137
+ funcode: funcode,
1138
+ data: response.data
1139
+ });
1140
+ }
1141
+ reject({
1142
+ status: status,
1143
+ code: code,
1144
+ funcode: funcode,
1145
+ errmsg: headers['trpc-error-msg']
1146
+ });
1147
+ },
1148
+ fail: function fail(err) {
1149
+ reject({
1150
+ position: 'wx.request catch error',
1151
+ err: err
1152
+ });
1153
+ }
1154
+ });
1155
+ } else if (fetch) {
1156
+ // 正常其他有fetch原生方法的前端业务场景
1157
+ fetch(url, {
1158
+ method: 'POST',
1159
+ headers: headers,
1160
+ body: JSON.stringify(body)
1161
+ }).then(function (response) {
1162
+ var headers = response.headers,
1163
+ status = response.status;
1164
+ var code = headers.get('trpc-ret');
1165
+ var funcode = headers.get('trpc-func-ret');
1166
+ if (status >= 200 && status < 300 && code === '0' && funcode === '0') {
1167
+ return resolve({
1168
+ status: status,
1169
+ code: code,
1170
+ funcode: funcode,
1171
+ data: response.text()
1172
+ });
1173
+ }
1174
+ return resolve({
1175
+ status: status,
1176
+ code: code,
1177
+ funcode: funcode,
1178
+ errmsg: headers.get('trpc-error-msg')
1179
+ });
1180
+ })["catch"](function (err) {
1181
+ return reject({
1182
+ position: 'https catch error',
1183
+ err: err
1184
+ });
1185
+ });
1186
+ }
1187
+ });
1188
+ };
1189
+ // 校验是否已经登录
1190
+ var checkLogin = function checkLogin(scene, accountInfo) {
1191
+ var extInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1192
+ var _a;
1193
+ if (scene === Scene.h5 && !((accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.uin) && accountInfo.uin !== 'default_user')) {
1194
+ // 移动端内
1195
+ return false;
1196
+ } else if ((scene === Scene.windows || scene === Scene.mac) && !((accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.qbLoginInfo) || (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.isLogin))) {
1197
+ // pc端
1198
+ return false;
1199
+ } else if (scene === Scene.external && !((_a = extInfo === null || extInfo === void 0 ? void 0 : extInfo.loginInfo) === null || _a === void 0 ? void 0 : _a.qbid)) {
1200
+ // 端外
1201
+ return false;
1202
+ }
1203
+ return true;
1204
+ };
1205
+ // 获取请求url
1206
+ var getUrl = function getUrl(options) {
1207
+ var host = options.debug ? TESTHOST : REALHOST;
1208
+ var url = "".concat(host, "/").concat(options.servantName, "/").concat(options.funcName);
1209
+ return url;
1210
+ };
1211
+ // 获取请求headers
1212
+ var getHeaders = function getHeaders(options) {
1213
+ var extInfo = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1214
+ var accountInfo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
1215
+ var deviceInfo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
1216
+ return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
1217
+ var _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, headers, qbLoginInfo, timeStamp, requestId, busInfo, usKey;
1218
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1219
+ while (1) switch (_context3.prev = _context3.next) {
1220
+ case 0:
1221
+ headers = {
1222
+ 'Content-Type': 'application/json'
1223
+ };
1224
+ _context3.prev = 1;
1225
+ if (options.scene === Scene.h5) {
1226
+ // 移动端内
1227
+ headers['q-qbid'] = (_c = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.qbid) !== null && _c !== void 0 ? _c : '';
1228
+ headers['q-appid'] = (_d = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.appid) !== null && _d !== void 0 ? _d : '';
1229
+ headers['q-qbaccess-token'] = (_e = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.qbToken) !== null && _e !== void 0 ? _e : '';
1230
+ headers['q-openid'] = (_f = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.uin) !== null && _f !== void 0 ? _f : '';
1231
+ headers['q-account-type'] = (_g = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.type) !== null && _g !== void 0 ? _g : 0;
1232
+ headers['q-token'] = (_h = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.token) !== null && _h !== void 0 ? _h : '';
1233
+ headers['q-guid'] = (_j = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.guid) !== null && _j !== void 0 ? _j : '';
1234
+ headers['q-qua2'] = (_k = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.qua) !== null && _k !== void 0 ? _k : '';
1235
+ headers['q-qimei36'] = (_l = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.qimei36) !== null && _l !== void 0 ? _l : '';
1236
+ } else if (options.scene === Scene.windows || options.scene === Scene.mac) {
1237
+ // windows pc / mac pc
1238
+ qbLoginInfo = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.qbLoginInfo;
1239
+ headers['q-qbid'] = (_m = (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.qbid) || (qbLoginInfo === null || qbLoginInfo === void 0 ? void 0 : qbLoginInfo.qbid)) !== null && _m !== void 0 ? _m : '';
1240
+ headers['q-appid'] = (_o = (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.appid) || (qbLoginInfo === null || qbLoginInfo === void 0 ? void 0 : qbLoginInfo.appid)) !== null && _o !== void 0 ? _o : '';
1241
+ headers['q-qbaccess-token'] = (_p = qbLoginInfo === null || qbLoginInfo === void 0 ? void 0 : qbLoginInfo.qbCtk) !== null && _p !== void 0 ? _p : '';
1242
+ headers['q-openid'] = (_q = (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.openid) || (qbLoginInfo === null || qbLoginInfo === void 0 ? void 0 : qbLoginInfo.openid)) !== null && _q !== void 0 ? _q : '';
1243
+ headers['q-account-type'] = getLoginTypeByMode(options === null || options === void 0 ? void 0 : options.scene, (accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.mode) || (qbLoginInfo === null || qbLoginInfo === void 0 ? void 0 : qbLoginInfo.mode));
1244
+ headers['q-token'] = (_r = accountInfo === null || accountInfo === void 0 ? void 0 : accountInfo.ctk) !== null && _r !== void 0 ? _r : '';
1245
+ headers['q-guid'] = (_s = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.guid) !== null && _s !== void 0 ? _s : '';
1246
+ headers['q-qua2'] = (_t = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.qua2) !== null && _t !== void 0 ? _t : '';
1247
+ headers['q-qimei36'] = (_u = deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.qimei36) !== null && _u !== void 0 ? _u : '';
1248
+ } else {
1249
+ // 端外
1250
+ if (extInfo.loginInfo) {
1251
+ // 端外获取qb相关登录态字段后传入
1252
+ headers['q-qbid'] = (_v = extInfo.loginInfo.qbid) !== null && _v !== void 0 ? _v : '';
1253
+ headers['q-appid'] = (_w = extInfo.loginInfo.appid) !== null && _w !== void 0 ? _w : '';
1254
+ headers['q-qbaccess-token'] = (_x = extInfo.loginInfo.qbaccess_token) !== null && _x !== void 0 ? _x : '';
1255
+ headers['q-openid'] = (_y = extInfo.loginInfo.openid) !== null && _y !== void 0 ? _y : '';
1256
+ headers['q-account-type'] = (_z = extInfo.loginInfo.account_type) !== null && _z !== void 0 ? _z : 0;
1257
+ headers['q-token'] = (_0 = extInfo.loginInfo.access_token) !== null && _0 !== void 0 ? _0 : '';
1258
+ headers['q-guid'] = (_1 = extInfo.loginInfo.guid) !== null && _1 !== void 0 ? _1 : '';
1259
+ headers['q-qua2'] = '';
1260
+ headers['q-qimei36'] = '';
1261
+ }
1262
+ }
1263
+ if (!options.usKey) {
1264
+ _context3.next = 12;
1265
+ break;
1266
+ }
1267
+ // 需要uskey鉴权加密
1268
+ timeStamp = Date.now();
1269
+ requestId = getUuid();
1270
+ busInfo = "ts=".concat(timeStamp, "&qbid=").concat(headers['q-qbid'], "&traceid=").concat(requestId);
1271
+ _context3.next = 9;
1272
+ return getUsKey(options.scene, busInfo);
1273
+ case 9:
1274
+ usKey = _context3.sent;
1275
+ headers['q-businfo'] = btoa(busInfo);
1276
+ headers['q-usKey'] = usKey;
1277
+ case 12:
1278
+ // base64加密
1279
+ if (headers['q-qbid']) {
1280
+ headers['q-qbid'] = btoa(headers['q-qbid']);
1281
+ }
1282
+ if (headers['q-qbaccess-token']) {
1283
+ headers['q-qbaccess-token'] = btoa(headers['q-qbaccess-token']);
1284
+ }
1285
+ if (headers['q-openid']) {
1286
+ headers['q-openid'] = btoa(headers['q-openid']);
1287
+ }
1288
+ if (headers['q-token']) {
1289
+ headers['q-token'] = btoa(headers['q-token']);
1290
+ }
1291
+ if (!extInfo.overRideInfo) {
1292
+ _context3.next = 18;
1293
+ break;
1294
+ }
1295
+ return _context3.abrupt("return", Object.assign(Object.assign({}, headers), extInfo.overRideInfo));
1296
+ case 18:
1297
+ return _context3.abrupt("return", headers);
1298
+ case 21:
1299
+ _context3.prev = 21;
1300
+ _context3.t0 = _context3["catch"](1);
1301
+ console.error('getHeaders error: ', {
1302
+ error: _context3.t0,
1303
+ options: options,
1304
+ extInfo: extInfo,
1305
+ accountInfo: accountInfo,
1306
+ deviceInfo: deviceInfo
1307
+ });
1308
+ return _context3.abrupt("return", headers);
1309
+ case 25:
1310
+ case "end":
1311
+ return _context3.stop();
1312
+ }
1313
+ }, _callee3, null, [[1, 21]]);
1314
+ }));
1315
+ };
1316
+
1317
+ export { Scene, authSend };