hunter-open-sdk 0.0.21 → 0.0.22

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,27 @@
1
+ var exec = require('child_process').exec;
2
+ export function command(cmd) {
3
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
4
+ // 任何你期望执行的cmd命令,ls都可以
5
+ var cmdStr1 = cmd;
6
+ var cmdPath = path;
7
+ // 子进程名称
8
+ var workerProcess;
9
+ runExec(cmdStr1);
10
+ function runExec(cmdStr) {
11
+ workerProcess = exec(cmdStr, {
12
+ cwd: cmdPath
13
+ });
14
+ // 打印正常的后台可执行程序输出
15
+ workerProcess.stdout.on('data', function (data) {
16
+ console.log('stdout: ' + data);
17
+ });
18
+ // 打印错误的后台可执行程序输出
19
+ workerProcess.stderr.on('data', function (data) {
20
+ console.log('stderr: ' + data);
21
+ });
22
+ // 退出之后的输出
23
+ workerProcess.on('close', function (code) {
24
+ console.log('out code:' + code);
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,40 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import { isMac, isWin, isDev, isProd } from "../../utils/utils";
4
+ import { command } from "./command";
5
+ import { checkHasDriver, downloadDriver } from "./winDriver";
6
+ var path = require('path');
7
+ var Service = /*#__PURE__*/function () {
8
+ function Service() {
9
+ _classCallCheck(this, Service);
10
+ }
11
+ _createClass(Service, [{
12
+ key: "setup",
13
+ value:
14
+ // constructor () {}
15
+ function setup(mainWindow) {
16
+ console.log('Service setup');
17
+ if (isMac()) {
18
+ if (isDev()) {
19
+ command(path.join(process.cwd(), './extraResources/ightools'));
20
+ }
21
+ if (isProd()) {
22
+ command('nohup ' + path.join(process.resourcesPath, './extraResources/ightools') + ' > /dev/null 2>&1 & > ' + path.join(process.resourcesPath, './log/ightools.log'));
23
+ }
24
+ }
25
+ if (isWin()) {
26
+ checkHasDriver().then(function (res) {
27
+ console.log('------------checkHasDriver', res);
28
+ if (res) {
29
+ mainWindow.webContents.send("checkDriver", true);
30
+ } else {
31
+ mainWindow.webContents.send("checkDriver", false);
32
+ downloadDriver(mainWindow);
33
+ }
34
+ });
35
+ }
36
+ }
37
+ }]);
38
+ return Service;
39
+ }();
40
+ export default Service;
@@ -0,0 +1,222 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import { isDev } from "../../utils/utils";
4
+ // import { app } from 'electron'
5
+ import { command } from "../../utils/utils.command";
6
+ var sudo = require('sudo-prompt');
7
+ var path = require('path');
8
+ var fs = require('fs');
9
+ var childProcess = require('child_process');
10
+ var compressing = require('compressing');
11
+ var exec = childProcess.exec;
12
+ var options = {
13
+ name: 'Electron'
14
+ };
15
+ var msiStr = 'AppleMobileDeviceService';
16
+ var reddirPath = 'C:/Program Files (x86)/Common Files/Apple/Apple Application Support';
17
+ var cmdStr = process.platform === 'win32' ? 'tasklist' : 'ps aux';
18
+ var CACHE_PATH = isDev() ? path.join(process.cwd(), './cache') : path.join(process.resourcesPath, './cache');
19
+ var filePath = path.join(CACHE_PATH, './iTunesOL_Lite_64_12.10.0.7.zip');
20
+ var mainWindowObj;
21
+ var checkProcess = function checkProcess() {
22
+ return new Promise(function (resolve, reject) {
23
+ exec(cmdStr, function (err, stdout, stderr) {
24
+ // console.log('stdout>>>', stdout)
25
+ // console.log('stderr>>>', stderr)
26
+ if (err) {
27
+ return reject(err);
28
+ }
29
+ if (stdout) {
30
+ var hasRroess = false;
31
+ stdout.split('\n').filter(function (line) {
32
+ var processMessage = line.trim().split(/\s+/);
33
+ var processName = processMessage[0];
34
+ // console.log('names.....', processName)
35
+ if (processName.indexOf(msiStr) > -1) {
36
+ hasRroess = true;
37
+ }
38
+ });
39
+ resolve(hasRroess);
40
+ }
41
+ });
42
+ });
43
+ };
44
+ var checkFs = function checkFs(paths) {
45
+ return new Promise(function (resolve) {
46
+ fs.readdir(paths, function (err) {
47
+ resolve(err ? false : true);
48
+ });
49
+ });
50
+ };
51
+ var checkCache = function checkCache() {
52
+ return new Promise(function (resolve) {
53
+ fs.readFile(filePath, function (err) {
54
+ resolve(err ? false : true);
55
+ });
56
+ });
57
+ };
58
+
59
+ // 轮询检测是否存在进程
60
+ var checkProcessTimer = function checkProcessTimer() {
61
+ var timer = null;
62
+ clearTimeout(timer);
63
+ timer = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
64
+ var hasDriver;
65
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
66
+ while (1) switch (_context.prev = _context.next) {
67
+ case 0:
68
+ _context.next = 2;
69
+ return checkProcess();
70
+ case 2:
71
+ hasDriver = _context.sent;
72
+ if (!hasDriver) {
73
+ _context.next = 6;
74
+ break;
75
+ }
76
+ mainWindowObj.webContents.send("driverDone");
77
+ return _context.abrupt("return");
78
+ case 6:
79
+ checkProcessTimer();
80
+ case 7:
81
+ case "end":
82
+ return _context.stop();
83
+ }
84
+ }, _callee);
85
+ })), 1000);
86
+ };
87
+ var installDriver = function installDriver() {
88
+ var AppleApplicationSupport = path.join(CACHE_PATH, './AppleApplicationSupport.msi');
89
+ var AppleApplicationSupport64 = path.join(CACHE_PATH, './AppleApplicationSupport64.msi');
90
+ var AppleMobileDeviceSupport64 = path.join(CACHE_PATH, './AppleMobileDeviceSupport64.msi');
91
+ var Bonjour64 = path.join(CACHE_PATH, './Bonjour64.msi');
92
+ var cmdStr = "start /i /wait ".concat(AppleApplicationSupport, " /qn && start /i /wait ").concat(AppleApplicationSupport64, " /qn && start /i /wait ").concat(AppleMobileDeviceSupport64, " /qn && start /i /wait ").concat(Bonjour64, " /qn");
93
+ sudo.exec(cmdStr, options, function (error, stdout, stderr) {
94
+ console.log('安装 error>>', error);
95
+ console.log('安装 stdout>>>', stdout);
96
+ console.log('安装 stderr>>>', stderr);
97
+ if (isDev()) {
98
+ command(path.join(process.cwd(), './extraResources/ightools.exe'));
99
+ } else {
100
+ command(path.join(process.resourcesPath, './extraResources/ightools.exe'));
101
+ }
102
+ checkProcessTimer();
103
+ });
104
+ };
105
+ // 解压文件
106
+ var uncopressingFile = function uncopressingFile(filePath) {
107
+ return new Promise(function (resolve) {
108
+ compressing.zip.uncompress(filePath, CACHE_PATH).then(function (res) {
109
+ resolve(true);
110
+ }).catch(function (err) {
111
+ resolve(false);
112
+ console.log('error', err);
113
+ });
114
+ });
115
+ };
116
+ export function downloadDriver(mainWindow) {
117
+ mainWindowObj = mainWindow;
118
+ mainWindow.webContents.downloadURL('http://ljtools.zhuanstatic.com/download/iTunesDriver/iTunesOL_Lite_64_12.10.0.7.zip');
119
+ mainWindow.webContents.session.on('will-download', function (e, item) {
120
+ // 文件总大小
121
+ var totalBytes = item.getTotalBytes();
122
+ // 设置保存路径
123
+ var rootPath = path.join(CACHE_PATH, item.getFilename());
124
+ item.setSavePath(rootPath);
125
+ item.on('updated', function () {
126
+ try {
127
+ // 获取进度,设置进度条
128
+ var _process = item.getReceivedBytes() / totalBytes;
129
+ _process = Math.round(_process * 100);
130
+ mainWindow.webContents.send('downloadProcess', _process);
131
+ } catch (e) {
132
+ console.log('驱动下载失败');
133
+ }
134
+ });
135
+ // 下载完成
136
+ item.on('done', /*#__PURE__*/function () {
137
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(e, start) {
138
+ var uncopressing;
139
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
140
+ while (1) switch (_context2.prev = _context2.next) {
141
+ case 0:
142
+ _context2.next = 2;
143
+ return uncopressingFile(filePath);
144
+ case 2:
145
+ uncopressing = _context2.sent;
146
+ if (uncopressing) installDriver();
147
+ mainWindow.webContents.send('downloadDriverDone');
148
+ case 5:
149
+ case "end":
150
+ return _context2.stop();
151
+ }
152
+ }, _callee2);
153
+ }));
154
+ return function (_x, _x2) {
155
+ return _ref2.apply(this, arguments);
156
+ };
157
+ }());
158
+ item.on('error', function () {
159
+ console.log('驱动下载失败');
160
+ });
161
+ });
162
+ }
163
+ export function checkHasDriver() {
164
+ return _checkHasDriver.apply(this, arguments);
165
+ }
166
+ function _checkHasDriver() {
167
+ _checkHasDriver = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
168
+ var hasDriver, hasCache, state, uncopressing;
169
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
170
+ while (1) switch (_context3.prev = _context3.next) {
171
+ case 0:
172
+ _context3.next = 2;
173
+ return checkProcess();
174
+ case 2:
175
+ if (!_context3.sent) {
176
+ _context3.next = 6;
177
+ break;
178
+ }
179
+ _context3.t0 = 1;
180
+ _context3.next = 7;
181
+ break;
182
+ case 6:
183
+ _context3.t0 = 0;
184
+ case 7:
185
+ hasDriver = _context3.t0;
186
+ _context3.next = 10;
187
+ return checkCache();
188
+ case 10:
189
+ if (!_context3.sent) {
190
+ _context3.next = 14;
191
+ break;
192
+ }
193
+ _context3.t1 = 2;
194
+ _context3.next = 15;
195
+ break;
196
+ case 14:
197
+ _context3.t1 = 0;
198
+ case 15:
199
+ hasCache = _context3.t1;
200
+ state = hasDriver + hasCache;
201
+ _context3.t2 = state;
202
+ _context3.next = _context3.t2 === 3 ? 20 : _context3.t2 === 1 ? 20 : _context3.t2 === 2 ? 21 : 26;
203
+ break;
204
+ case 20:
205
+ return _context3.abrupt("return", true);
206
+ case 21:
207
+ _context3.next = 23;
208
+ return uncopressingFile(filePath);
209
+ case 23:
210
+ uncopressing = _context3.sent;
211
+ if (uncopressing) installDriver();
212
+ return _context3.abrupt("return", true);
213
+ case 26:
214
+ return _context3.abrupt("return", false);
215
+ case 27:
216
+ case "end":
217
+ return _context3.stop();
218
+ }
219
+ }, _callee3);
220
+ }));
221
+ return _checkHasDriver.apply(this, arguments);
222
+ }
@@ -0,0 +1,9 @@
1
+ import { HunterInspectionKit } from "../utils/utils.initDll";
2
+ var GetGeneralReport = function GetGeneralReport(params, callBack) {
3
+ var reportRes = HunterInspectionKit.InspectionKit(biz, cmd, params);
4
+ console.log('========reportRes', reportRes);
5
+ callBack({
6
+ data: reportRes
7
+ });
8
+ };
9
+ export default GetGeneralReport;
package/es/index.js ADDED
@@ -0,0 +1,8 @@
1
+ import registerEvent from "./registerEvent";
2
+ import getGeneralReport from "./getGeneralReport";
3
+
4
+ // 初始化
5
+ export default {
6
+ registerEvent: registerEvent,
7
+ getGeneralReport: getGeneralReport
8
+ };
@@ -0,0 +1,138 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
+ import _createClass from "@babel/runtime/helpers/createClass";
4
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import { isWin, isDev } from "../utils/utils";
6
+ import { HunterInspectionKit } from "../utils/utils.initDll";
7
+ import { checkHasDriver, downloadDriver } from "../events/driver/winDriver";
8
+ var usbmux = require('usbmux');
9
+ var path = require('path');
10
+
11
+ // usb 监听
12
+ var usbListener;
13
+
14
+ // saas回调
15
+ var saasCallBack;
16
+
17
+ /**
18
+ * 配对
19
+ * @param {String} udid 设备id
20
+ * @returns
21
+ */
22
+ var DevicePair = function DevicePair() {
23
+ var udid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
24
+ var params = arguments.length > 1 ? arguments[1] : undefined;
25
+ // 通过调用read_pair来判断是否已配对【信任】
26
+ var paramsObj = JSON.parse(params);
27
+ Object.assign(paramsObj, {
28
+ udid: udid
29
+ });
30
+ var devicePair = HunterInspectionKit.TheForceKit(JSON.stringify(paramsObj));
31
+ console.log('======devicePair', devicePair);
32
+ if (devicePair) {
33
+ // 配对成功
34
+ saasCallBack({
35
+ data: {
36
+ eventName: 'type_trust_result',
37
+ udid: udid,
38
+ eventCode: 0
39
+ }
40
+ });
41
+ }
42
+ };
43
+
44
+ /**
45
+ * 更新下载dll文件 并重写本地版本号
46
+ * @param {String} udid 设备id
47
+ * @returns
48
+ */
49
+ var updateDllFile = function updateDllFile(versionData) {
50
+ var upgradeInfo = versionData.upgradeInfo;
51
+ // 若不需要更新,则直接声明dll函数
52
+ if (!upgradeInfo) return declareDllFn();
53
+ // 若需要更新 则下载完成后 覆盖本地dll文件并重写version文件内容
54
+ var packageUrl = upgradeInfo.packageUrl,
55
+ verCodeName = upgradeInfo.verCodeName;
56
+ var dllOutPath = path.resolve(__dirname, "../resources/dll/x64.dll");
57
+ var dllStream = fs.createWriteStream(dllOutPath);
58
+ request(packageUrl).pipe(dllStream).on("close", function (err) {
59
+ console.log("========下载sdk完毕");
60
+ fs.writeFile(versionPath, verCodeName, function (err) {
61
+ if (err) return console.log(err);
62
+ console.log('========写入version成功');
63
+ Object.assign(window.SDK_APP_INFO, {
64
+ version: verCodeName
65
+ });
66
+ });
67
+ declareDllFn();
68
+ });
69
+ };
70
+ var RegisterEvent = /*#__PURE__*/function () {
71
+ function RegisterEvent() {
72
+ _classCallCheck(this, RegisterEvent);
73
+ }
74
+ _createClass(RegisterEvent, [{
75
+ key: "init",
76
+ value: function () {
77
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params, callBack) {
78
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
79
+ while (1) switch (_context2.prev = _context2.next) {
80
+ case 0:
81
+ saasCallBack = callBack;
82
+ usbListener = new usbmux.createListener().on('attached', /*#__PURE__*/function () {
83
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(udid) {
84
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
85
+ while (1) switch (_context.prev = _context.next) {
86
+ case 0:
87
+ if (udid) {
88
+ _context.next = 2;
89
+ break;
90
+ }
91
+ return _context.abrupt("return");
92
+ case 2:
93
+ if (isWin()) {
94
+ // windows检查驱动 mac不需要
95
+ // 检查是否有驱动
96
+ checkHasDriver().then(function (res) {
97
+ if (res) {
98
+ // 有驱动,直接运行脚本
99
+ DevicePair(udid, params);
100
+ } else {
101
+ downloadDriver();
102
+ }
103
+ });
104
+ } else {
105
+ // 有驱动,直接运行脚本
106
+ DevicePair(udid, params);
107
+ }
108
+ case 3:
109
+ case "end":
110
+ return _context.stop();
111
+ }
112
+ }, _callee);
113
+ }));
114
+ return function (_x3) {
115
+ return _ref.apply(this, arguments);
116
+ };
117
+ }()).on('detached', function (udid) {
118
+ // clearInterval(pairTimer)
119
+ }).on('error', function (err) {
120
+ console.log('usb连接错误:', err);
121
+ var errMsg = "usb\u8FDE\u63A5\u9519\u8BEF\uFF1A".concat(err);
122
+ throw new Error(errMsg);
123
+ });
124
+ case 2:
125
+ case "end":
126
+ return _context2.stop();
127
+ }
128
+ }, _callee2);
129
+ }));
130
+ function init(_x, _x2) {
131
+ return _init.apply(this, arguments);
132
+ }
133
+ return init;
134
+ }()
135
+ }]);
136
+ return RegisterEvent;
137
+ }();
138
+ export default RegisterEvent;
@@ -0,0 +1 @@
1
+ 0.0.3
Binary file
@@ -0,0 +1,58 @@
1
+ /**
2
+ * 封装回调函数,放入全局中 state 代表状态 0:成功获取报告 -1:获取报告失败 1:usb插入成功 2:正在查询报告 3:usb拔出
3
+ * @ignore
4
+ */
5
+ export var ActualCallback = function ActualCallback(callbackName, callback, del) {
6
+ window[callbackName] = function (state, res, msg) {
7
+ console.log('科洛桑sdk返回的state', state, '返回的数据', res);
8
+ switch (state) {
9
+ case 0:
10
+ try {
11
+ callback({
12
+ code: 0,
13
+ data: res
14
+ }, '报告获取成功');
15
+ } catch (e) {
16
+ console.log('[ActualCallback.error]:', e);
17
+ }
18
+ break;
19
+ case 1:
20
+ // callback({ loading: true }, '正在获取报告')
21
+ callback({
22
+ code: 1,
23
+ data: res
24
+ }, 'usb连接成功');
25
+ break;
26
+ case 2:
27
+ callback({
28
+ code: 2,
29
+ data: res
30
+ }, '报告查询中,请稍后');
31
+ break;
32
+ case 3:
33
+ callback({
34
+ code: 3,
35
+ data: null
36
+ }, 'usb已断开');
37
+ break;
38
+ case -1:
39
+ callback({
40
+ code: -1,
41
+ data: null,
42
+ msg: msg
43
+ }, '获取报告失败');
44
+ break;
45
+ default:
46
+ callback(null, '科洛桑没有匹配到state');
47
+ break;
48
+ }
49
+ if (del) delete window[callbackName];
50
+ };
51
+ };
52
+ /**
53
+ * 执行回调函数
54
+ * @ignore
55
+ */
56
+ export var ExecuteCallBack = function ExecuteCallBack(callbackName, state, data, msg) {
57
+ window[callbackName](state, data, msg);
58
+ };
@@ -0,0 +1,27 @@
1
+ var exec = require('child_process').exec;
2
+ export function command(cmd) {
3
+ var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : './';
4
+ // 任何你期望执行的cmd命令,ls都可以
5
+ var cmdStr1 = cmd;
6
+ var cmdPath = path;
7
+ // 子进程名称
8
+ var workerProcess;
9
+ runExec(cmdStr1);
10
+ function runExec(cmdStr) {
11
+ workerProcess = exec(cmdStr, {
12
+ cwd: cmdPath
13
+ });
14
+ // 打印正常的后台可执行程序输出
15
+ workerProcess.stdout.on('data', function (data) {
16
+ console.log('stdout: ' + data);
17
+ });
18
+ // 打印错误的后台可执行程序输出
19
+ workerProcess.stderr.on('data', function (data) {
20
+ console.log('stderr: ' + data);
21
+ });
22
+ // 退出之后的输出
23
+ workerProcess.on('close', function (code) {
24
+ console.log('out code:' + code);
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,23 @@
1
+ import { isWin, isDev } from "./utils";
2
+ var ffi = require('ffi-napi');
3
+
4
+ /**
5
+ * 声明dll函数
6
+ * @param {String} udid 设备id
7
+ * @returns
8
+ */
9
+
10
+ export var HunterInspectionKit = function HunterInspectionKit() {
11
+ var dllPath = path.resolve(__dirname, '../resources/dll/x64.dll');
12
+ if (!isDev()) {
13
+ // 如果是生产模式 则替换app.asar 路径 为了在生产调用dll
14
+ dllPath = dllPath.replace('app.asar', 'app.asar.unpacked');
15
+ }
16
+ var HunterInspectionKit = new ffi.Library(dllPath, {
17
+ 'InspectionKit': ['string', ['string', 'string', 'string']],
18
+ 'TheForceKit': ['string', ['string']]
19
+ });
20
+ // 挂载全局window
21
+ window.HunterInspectionKit = HunterInspectionKit;
22
+ return HunterInspectionKit;
23
+ };
@@ -0,0 +1,21 @@
1
+ export var isMac = function isMac() {
2
+ return process.platform === 'darwin';
3
+ };
4
+ export var isWin = function isWin() {
5
+ return process.platform === 'win32';
6
+ };
7
+ export var isLinux = function isLinux() {
8
+ return process.platform === 'linux';
9
+ };
10
+ export var isDev = function isDev() {
11
+ return process.env.WEBPACK_DEV_SERVER === 'true';
12
+ };
13
+ export var isProd = function isProd() {
14
+ return process.env.NODE_ENV === 'production';
15
+ };
16
+ export var isArm64 = function isArm64() {
17
+ return process.arch === 'arm64';
18
+ };
19
+ export var isAmd64 = function isAmd64() {
20
+ return process.arch === 'x64';
21
+ };
@@ -0,0 +1,87 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ // import request from './utils.request'
5
+ import zzfetch from '@zz/fetch';
6
+ import { url } from '@zz-yp/hunter-js-utils';
7
+
8
+ // lego上报的接口
9
+ var legoUrl = 'https://lego.zhuanzhuan.com/page/mark';
10
+
11
+ // 获取本地ip的接口
12
+ var getIpUrl = 'https://api.ipify.org?format=json';
13
+
14
+ // 获取ip省市区的接口
15
+ var getIpInfoUrl = 'https://hunterapi.zhuanspirit.com/api/ip/owner';
16
+
17
+ // 获取普通验机报告
18
+ export var lego = function lego(_ref) {
19
+ var pagetype = _ref.pagetype,
20
+ actiontype = _ref.actiontype,
21
+ _ref$backup = _ref.backup,
22
+ backup = _ref$backup === void 0 ? {} : _ref$backup;
23
+ var legoParams = {
24
+ pagetype: pagetype,
25
+ actiontype: actiontype,
26
+ backup: JSON.stringify(_objectSpread({}, backup)),
27
+ timestamp: new Date().getTime(),
28
+ clienttime: new Date().getTime(),
29
+ appid: 'ZHUANZHUAN',
30
+ cookieid: backup.uid
31
+ };
32
+ var apiUrl = url.setParams(legoParams, legoUrl);
33
+ zzfetch({
34
+ url: apiUrl,
35
+ method: "post"
36
+ });
37
+ };
38
+ var fetchIpInfo = function fetchIpInfo(type) {
39
+ return zzfetch({
40
+ url: getIpUrl,
41
+ method: 'get'
42
+ }).then(function (response) {
43
+ var ip = response.ip;
44
+ if (ip) {
45
+ zzfetch({
46
+ url: "".concat(getIpInfoUrl, "?ip=").concat(ip),
47
+ method: 'get'
48
+ }).then(function (res) {
49
+ var data = res.data,
50
+ code = res.code;
51
+ if (code == 0) {
52
+ lego({
53
+ pagetype: 'hunter_inspection_kit',
54
+ actiontype: type,
55
+ backup: _objectSpread(_objectSpread(_objectSpread({}, window.SDK_APP_INFO), data), {}, {
56
+ system_type: 'windows',
57
+ ip: ip
58
+ })
59
+ });
60
+ } else {
61
+ lego({
62
+ pagetype: 'hunter_inspection_kit',
63
+ actiontype: type,
64
+ backup: _objectSpread(_objectSpread({}, window.SDK_APP_INFO), {}, {
65
+ system_type: 'windows',
66
+ ip: ip
67
+ })
68
+ });
69
+ }
70
+ });
71
+ } else {
72
+ lego({
73
+ pagetype: 'hunter_inspection_kit',
74
+ actiontype: type,
75
+ backup: _objectSpread(_objectSpread({}, window.SDK_APP_INFO), {}, {
76
+ system_type: 'windows',
77
+ ip: '--'
78
+ })
79
+ });
80
+ }
81
+ });
82
+ };
83
+
84
+ // 上报lego 携带ip等信息
85
+ export var ReportLegoData = function ReportLegoData(type) {
86
+ fetchIpInfo(type);
87
+ };
@@ -0,0 +1,10 @@
1
+ var path = require('path');
2
+
3
+ /**
4
+ * 当前环境地址转换
5
+ * @param {*} path
6
+ * @returns
7
+ */
8
+ export var currentEnvPath = function currentEnvPath(filePath) {
9
+ return path.resolve(__dirname, filePath);
10
+ };
@@ -0,0 +1,34 @@
1
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ import zzfetch from '@zz/fetch';
4
+
5
+ // 获取authApp的下载路径
6
+ export var getAuthAppUrlApi = /*#__PURE__*/function () {
7
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
8
+ var params,
9
+ res,
10
+ respData,
11
+ _args = arguments;
12
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
13
+ while (1) switch (_context.prev = _context.next) {
14
+ case 0:
15
+ params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
16
+ _context.next = 3;
17
+ return zzfetch({
18
+ url: "https://feconf.zhuanzhuan.com/feconf/hunter?keys=hunter_coruscant_sdk_config",
19
+ method: "get"
20
+ });
21
+ case 3:
22
+ res = _context.sent;
23
+ respData = res.respData;
24
+ return _context.abrupt("return", Promise.resolve(respData === null || respData === void 0 ? void 0 : respData.authAppZipUrl));
25
+ case 6:
26
+ case "end":
27
+ return _context.stop();
28
+ }
29
+ }, _callee);
30
+ }));
31
+ return function getAuthAppUrlApi() {
32
+ return _ref.apply(this, arguments);
33
+ };
34
+ }();
@@ -0,0 +1,164 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ import zzfetch from '@zz/fetch';
7
+ var baseUrl = 'https://app.zhuanzhuan.com/';
8
+
9
+ // 上报原力信息
10
+ export var AppearAndGetBaseForIOS = /*#__PURE__*/function () {
11
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
12
+ var params,
13
+ res,
14
+ _args = arguments;
15
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
16
+ while (1) switch (_context.prev = _context.next) {
17
+ case 0:
18
+ params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
19
+ res = zzfetch({
20
+ url: "".concat(baseUrl, "zzopen/hunter_force_api/appearAndGetBaseForIOS"),
21
+ method: "post",
22
+ params: {
23
+ param: JSON.stringify(_objectSpread(_objectSpread({}, params), window.SDK_APP_INFO))
24
+ }
25
+ });
26
+ return _context.abrupt("return", res);
27
+ case 3:
28
+ case "end":
29
+ return _context.stop();
30
+ }
31
+ }, _callee);
32
+ }));
33
+ return function AppearAndGetBaseForIOS() {
34
+ return _ref.apply(this, arguments);
35
+ };
36
+ }();
37
+
38
+ // 获取专业原始报告
39
+ export var GetOriginalReport = /*#__PURE__*/function () {
40
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
41
+ var params,
42
+ opts,
43
+ res,
44
+ _args2 = arguments;
45
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
46
+ while (1) switch (_context2.prev = _context2.next) {
47
+ case 0:
48
+ params = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {};
49
+ opts = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {};
50
+ res = zzfetch({
51
+ url: "".concat(baseUrl, "zzopen/hunter_force_api/getOriginalReport"),
52
+ method: "post",
53
+ params: {
54
+ param: JSON.stringify(_objectSpread(_objectSpread({}, params), window.SDK_APP_INFO))
55
+ }
56
+ });
57
+ return _context2.abrupt("return", res);
58
+ case 4:
59
+ case "end":
60
+ return _context2.stop();
61
+ }
62
+ }, _callee2);
63
+ }));
64
+ return function GetOriginalReport() {
65
+ return _ref2.apply(this, arguments);
66
+ };
67
+ }();
68
+
69
+ // 获取安卓报告
70
+ export var GetOriginalAndroidReport = /*#__PURE__*/function () {
71
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
72
+ var params,
73
+ opts,
74
+ channel,
75
+ url,
76
+ res,
77
+ _args3 = arguments;
78
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
79
+ while (1) switch (_context3.prev = _context3.next) {
80
+ case 0:
81
+ params = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {};
82
+ opts = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : {};
83
+ channel = params.channel; // 请求接口区分抖音和其他渠道
84
+ url = channel === 'hunter_dance' ? "".concat(baseUrl, "zzopen/hunter_force_api/getAndroidReportForDy") : "".concat(baseUrl, "zzopen/hunter_force_api/getAndroidReport");
85
+ res = zzfetch({
86
+ url: url,
87
+ method: "post",
88
+ params: {
89
+ param: JSON.stringify(_objectSpread(_objectSpread({}, params), window.SDK_APP_INFO))
90
+ }
91
+ });
92
+ return _context3.abrupt("return", res);
93
+ case 6:
94
+ case "end":
95
+ return _context3.stop();
96
+ }
97
+ }, _callee3);
98
+ }));
99
+ return function GetOriginalAndroidReport() {
100
+ return _ref3.apply(this, arguments);
101
+ };
102
+ }();
103
+
104
+ // 获取快速报告
105
+ export var AppearAndGetAllForIOS = /*#__PURE__*/function () {
106
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
107
+ var params,
108
+ res,
109
+ _args4 = arguments;
110
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
111
+ while (1) switch (_context4.prev = _context4.next) {
112
+ case 0:
113
+ params = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {};
114
+ res = zzfetch({
115
+ url: "".concat(baseUrl, "zzopen/hunter_force_api/appearAndGetAllForIOS"),
116
+ method: "post",
117
+ params: {
118
+ param: JSON.stringify(_objectSpread(_objectSpread({}, params), window.SDK_APP_INFO))
119
+ }
120
+ });
121
+ return _context4.abrupt("return", res);
122
+ case 3:
123
+ case "end":
124
+ return _context4.stop();
125
+ }
126
+ }, _callee4);
127
+ }));
128
+ return function AppearAndGetAllForIOS() {
129
+ return _ref4.apply(this, arguments);
130
+ };
131
+ }();
132
+
133
+ // 存储当前原力报告数据
134
+ export var SaveForceInfo = function SaveForceInfo(data) {
135
+ window.FORCE_REPORT_INFO = data.info;
136
+ // window.DEVICE_ID = data.deviceId
137
+ };
138
+
139
+ // 上报智能质检各阶段时长
140
+ export var AppearStatisticalInfo = function AppearStatisticalInfo(_ref5, phoneReportId) {
141
+ var forceStartTime = _ref5.forceStartTime,
142
+ forceEndTime = _ref5.forceEndTime,
143
+ getReportStartTime = _ref5.getReportStartTime,
144
+ getReportEndTime = _ref5.getReportEndTime;
145
+ // 原力耗时
146
+ var forceTime = forceEndTime - forceStartTime;
147
+ // 获取报告耗时
148
+ var getReportTime = getReportEndTime - getReportStartTime;
149
+ // 总时长
150
+ var allTestTime = forceTime + getReportTime;
151
+ var res = zzfetch({
152
+ url: "".concat(baseUrl, "zzopen/hunter_force_api/appearStatisticalInfo"),
153
+ method: "post",
154
+ params: {
155
+ param: JSON.stringify(_objectSpread(_objectSpread({}, window.SDK_APP_INFO), {}, {
156
+ reportId: phoneReportId,
157
+ forceTime: forceTime,
158
+ getReportTime: getReportTime,
159
+ allTestTime: allTestTime
160
+ }))
161
+ }
162
+ });
163
+ return res;
164
+ };
@@ -0,0 +1,21 @@
1
+ import axios from 'axios';
2
+ axios.defaults.withCredentials = true;
3
+
4
+ // 请求拦截 设置统一header
5
+ axios.interceptors.request.use(function (config) {
6
+ return config;
7
+ }, function (error) {
8
+ console.log(error);
9
+ return Promise.reject(error);
10
+ });
11
+
12
+ // 响应拦截
13
+ axios.interceptors.response.use(function (response) {
14
+ var data = response.data;
15
+ return data;
16
+ }, function (error) {
17
+ // 错误提醒
18
+ console.log(error);
19
+ return Promise.reject(error);
20
+ });
21
+ export default axios;
@@ -8,58 +8,167 @@ exports.default = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _usb = require("usb");
11
+ var _utils = require("../utils/utils");
12
+ var _utils2 = require("../utils/utils.sn");
13
+ var childProcess = require('child_process');
14
+ var exec = childProcess.exec;
15
+
16
+ // mac获取sn
17
+ var getMacSn = /*#__PURE__*/function () {
18
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device, callBack) {
19
+ var attachDeviceId, customWebUSB, deviceList, currentDevice;
20
+ return _regenerator.default.wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ // 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
24
+ attachDeviceId = device.deviceAddress;
25
+ customWebUSB = new _usb.WebUSB({
26
+ allowAllDevices: true
27
+ });
28
+ _context.next = 4;
29
+ return customWebUSB.getDevices();
30
+ case 4:
31
+ deviceList = _context.sent;
32
+ if (attachDeviceId) {
33
+ _context.next = 7;
34
+ break;
35
+ }
36
+ return _context.abrupt("return");
37
+ case 7:
38
+ // 删选出当前的设备信息 为获取到serialNumber
39
+ currentDevice = deviceList.filter(function (item) {
40
+ return item.device.deviceAddress == attachDeviceId;
41
+ });
42
+ if (currentDevice.length) {
43
+ _context.next = 11;
44
+ break;
45
+ }
46
+ callBack({
47
+ code: -1,
48
+ data: {},
49
+ message: '获取SN失败'
50
+ });
51
+ return _context.abrupt("return");
52
+ case 11:
53
+ callBack({
54
+ code: 0,
55
+ data: {
56
+ SN: currentDevice[0].serialNumber
57
+ },
58
+ message: '获取SN成功'
59
+ });
60
+ case 12:
61
+ case "end":
62
+ return _context.stop();
63
+ }
64
+ }, _callee);
65
+ }));
66
+ return function getMacSn(_x, _x2) {
67
+ return _ref.apply(this, arguments);
68
+ };
69
+ }();
70
+
71
+ // win获取sn
72
+ var getWinSn = /*#__PURE__*/function () {
73
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(device, callBack) {
74
+ var cmdStr;
75
+ return _regenerator.default.wrap(function _callee2$(_context2) {
76
+ while (1) switch (_context2.prev = _context2.next) {
77
+ case 0:
78
+ // windows 需要运行命令获取sn
79
+ cmdStr = "wmic path Win32_PnPEntity where \"DeviceID like 'USB%'\" get Name, PNPDeviceID /value";
80
+ exec(cmdStr, function (err, stdout, stderr) {
81
+ if (err) {
82
+ // 运行失败 则直接返回获取失败
83
+ callBack({
84
+ code: -1,
85
+ data: {},
86
+ message: "windows\u8FD0\u884C\u7A0B\u5E8F\u83B7\u53D6SN\u5931\u8D25err: ".concat(err)
87
+ });
88
+ return;
89
+ }
90
+ if (stderr) {
91
+ // 运行失败 则直接返回获取失败
92
+ callBack({
93
+ code: -1,
94
+ data: {},
95
+ message: "windows\u8FD0\u884C\u7A0B\u5E8F\u83B7\u53D6SN\u5931\u8D25stderr: ".concat(stderr)
96
+ });
97
+ return;
98
+ }
99
+
100
+ // 处理WMIC输出并提取手机序列号
101
+ var phoneDevices = (0, _utils2.parseWmicOutput)(stdout);
102
+ if (phoneDevices.length === 0) {
103
+ callBack({
104
+ code: -1,
105
+ data: {},
106
+ message: "\u672A\u68C0\u6D4B\u5230\u624B\u673AUSB\u8BBE\u5907"
107
+ });
108
+ } else {
109
+ console.log('检测到的手机设备:');
110
+ var sn = phoneDevices[0].serial;
111
+ callBack({
112
+ code: 0,
113
+ data: {
114
+ SN: sn
115
+ },
116
+ message: "\u83B7\u53D6SN\u6210\u529F"
117
+ });
118
+ // phoneDevices.forEach(device => {
119
+ // console.log(`设备名称: ${device.name}`);
120
+ // console.log(`序列号: ${device.serial}`);
121
+ // console.log(`PNPDeviceID: ${device.pnpDeviceId}`);
122
+ // console.log('---');
123
+ // });
124
+ }
125
+ });
126
+ case 2:
127
+ case "end":
128
+ return _context2.stop();
129
+ }
130
+ }, _callee2);
131
+ }));
132
+ return function getWinSn(_x3, _x4) {
133
+ return _ref2.apply(this, arguments);
134
+ };
135
+ }();
136
+
137
+ /**
138
+ * 获取Android SN
139
+ * @param {Object} params - 参数
140
+ * @param {Function} callBack - 回调函数
141
+ */
11
142
  var GetAndroidSn = function GetAndroidSn(params, callBack) {
143
+ console.log('GetAndroidSn params', params);
12
144
  _usb.usb.on('attach', /*#__PURE__*/function () {
13
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(device) {
14
- var attachDeviceId, customWebUSB, deviceList, currentDevice;
15
- return _regenerator.default.wrap(function _callee$(_context) {
16
- while (1) switch (_context.prev = _context.next) {
145
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(device) {
146
+ return _regenerator.default.wrap(function _callee3$(_context3) {
147
+ while (1) switch (_context3.prev = _context3.next) {
17
148
  case 0:
18
- // 拿到当前连接的设备deviceAddress 作为标识去usb列表筛选
19
- attachDeviceId = device.deviceAddress;
20
- customWebUSB = new _usb.WebUSB({
21
- allowAllDevices: true
22
- });
23
- _context.next = 4;
24
- return customWebUSB.getDevices();
25
- case 4:
26
- deviceList = _context.sent;
27
- if (attachDeviceId) {
28
- _context.next = 7;
149
+ if (!(0, _utils.isMac)()) {
150
+ _context3.next = 3;
29
151
  break;
30
152
  }
31
- return _context.abrupt("return");
32
- case 7:
33
- // 删选出当前的设备信息 为获取到serialNumber
34
- currentDevice = deviceList.filter(function (item) {
35
- return item.device.deviceAddress == attachDeviceId;
36
- });
37
- if (currentDevice.length) {
38
- _context.next = 11;
153
+ // mac获取sn
154
+ getMacSn(device, callBack);
155
+ return _context3.abrupt("return");
156
+ case 3:
157
+ if (!(0, _utils.isWin)()) {
158
+ _context3.next = 6;
39
159
  break;
40
160
  }
41
- callBack({
42
- code: -1,
43
- data: {},
44
- message: '获取SN失败'
45
- });
46
- return _context.abrupt("return");
47
- case 11:
48
- callBack({
49
- code: 0,
50
- data: {
51
- SN: currentDevice[0].serialNumber
52
- },
53
- message: '获取SN成功'
54
- });
55
- case 12:
161
+ // win获取sn
162
+ getWinSn(device, callBack);
163
+ return _context3.abrupt("return");
164
+ case 6:
56
165
  case "end":
57
- return _context.stop();
166
+ return _context3.stop();
58
167
  }
59
- }, _callee);
168
+ }, _callee3);
60
169
  }));
61
- return function (_x) {
62
- return _ref.apply(this, arguments);
170
+ return function (_x5) {
171
+ return _ref3.apply(this, arguments);
63
172
  };
64
173
  }());
65
174
  _usb.usb.on('detach', function () {});
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseWmicOutput = parseWmicOutput;
7
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
8
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
9
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
10
+ /**
11
+ * 判断设备是否为手机设备
12
+ * @param {Object} device - 设备信息
13
+ * @returns {boolean} 是否为手机设备
14
+ */
15
+ function isPhoneDevice(device) {
16
+ var name = device.name.toLowerCase();
17
+ var pnpId = device.pnpDeviceId.toLowerCase();
18
+
19
+ // 常见手机设备关键词
20
+ var phoneKeywords = ['android', 'phone', 'mobile', 'iphone', 'samsung', 'huawei', 'xiaomi', 'oppo', 'vivo', 'meizu', 'google', 'pixel', 'oneplus', 'nokia', 'sony'];
21
+
22
+ // 常见手机厂商VID
23
+ var phoneVendors = ['VID_18D1',
24
+ // Google
25
+ 'VID_22B8',
26
+ // Motorola
27
+ 'VID_04E8',
28
+ // Samsung
29
+ 'VID_0FCE',
30
+ // Sony Ericsson
31
+ 'VID_1004',
32
+ // LG
33
+ 'VID_12D1',
34
+ // Huawei
35
+ 'VID_2717',
36
+ // Xiaomi
37
+ 'VID_2A45',
38
+ // OnePlus
39
+ 'VID_05C6',
40
+ // Qualcomm
41
+ 'VID_0BB4' // HTC
42
+ ];
43
+
44
+ // 检查名称中是否包含手机关键词
45
+ var isPhoneByName = phoneKeywords.some(function (keyword) {
46
+ return name.includes(keyword);
47
+ });
48
+
49
+ // 检查PNPDeviceID中是否包含手机厂商VID
50
+ var isPhoneByVendor = phoneVendors.some(function (vendor) {
51
+ return pnpId.includes(vendor.toLowerCase());
52
+ });
53
+ return isPhoneByName || isPhoneByVendor;
54
+ }
55
+
56
+ /**
57
+ * 从PNPDeviceID中提取序列号
58
+ * @param {string} pnpDeviceId - PNPDeviceID
59
+ * @returns {string} 序列号
60
+ */
61
+ function extractSerialNumber(pnpDeviceId) {
62
+ // USB设备ID格式通常为: USB\VID_v(4)&PID_d(4)\序列号
63
+ var parts = pnpDeviceId.split('\\');
64
+ if (parts.length >= 3) {
65
+ var serialPart = parts[parts.length - 1];
66
+
67
+ // 验证序列号格式(通常不包含&和#等特殊字符)
68
+ if (serialPart && !serialPart.includes('&') && !serialPart.includes('#')) {
69
+ return serialPart;
70
+ }
71
+ }
72
+
73
+ // 如果无法提取序列号,返回空字符串
74
+ return '';
75
+ }
76
+ /**
77
+ * 解析WMIC输出并提取手机设备信息
78
+ * @param {string} output - WMIC命令输出
79
+ * @returns {Array} 手机设备信息数组
80
+ */
81
+ function parseWmicOutput(output) {
82
+ var devices = [];
83
+ var lines = output.split('\r\n');
84
+ var currentDevice = {};
85
+ var _iterator = _createForOfIteratorHelper(lines),
86
+ _step;
87
+ try {
88
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
89
+ var line = _step.value;
90
+ // 跳过空行
91
+ if (!line.trim()) {
92
+ // 如果当前设备有数据,则保存
93
+ if (currentDevice.name && currentDevice.pnpDeviceId) {
94
+ // 检查是否为手机设备
95
+ if (isPhoneDevice(currentDevice)) {
96
+ // 提取序列号
97
+ currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
98
+ devices.push(currentDevice);
99
+ }
100
+ }
101
+ currentDevice = {};
102
+ continue;
103
+ }
104
+
105
+ // 解析Name和PNPDeviceID
106
+ if (line.startsWith('Name=')) {
107
+ currentDevice.name = line.substring(5).trim();
108
+ } else if (line.startsWith('PNPDeviceID=')) {
109
+ currentDevice.pnpDeviceId = line.substring(12).trim();
110
+ }
111
+ }
112
+
113
+ // 处理最后一个设备
114
+ } catch (err) {
115
+ _iterator.e(err);
116
+ } finally {
117
+ _iterator.f();
118
+ }
119
+ if (currentDevice.name && currentDevice.pnpDeviceId && isPhoneDevice(currentDevice)) {
120
+ currentDevice.serial = extractSerialNumber(currentDevice.pnpDeviceId);
121
+ devices.push(currentDevice);
122
+ }
123
+ return devices;
124
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hunter-open-sdk",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "采货侠SaaS版本桌面端sdk",
5
5
  "scripts": {
6
6
  "start": "zz dev",