wx2tg-puppet 2.2.0 → 2.2.2
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/dist/api/LoginApi.d.ts +10 -5
- package/dist/index.d.ts +9 -1
- package/dist/index.js +53 -37
- package/package.json +1 -1
package/dist/api/LoginApi.d.ts
CHANGED
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
import { ApiResponse } from '../types/ApiResponse';
|
|
2
2
|
import { AxiosResponse } from 'axios';
|
|
3
|
+
export interface ProxyInfo {
|
|
4
|
+
ProxyIp: string;
|
|
5
|
+
ProxyPassword: string;
|
|
6
|
+
ProxyUser: string;
|
|
7
|
+
}
|
|
3
8
|
export interface LoginA16LoginParam {
|
|
4
9
|
A16: string;
|
|
5
10
|
DeviceName: string;
|
|
6
11
|
Password: string;
|
|
7
|
-
Proxy?:
|
|
12
|
+
Proxy?: ProxyInfo;
|
|
8
13
|
UserName: string;
|
|
9
14
|
}
|
|
10
15
|
export interface LoginData62LoginReq {
|
|
11
16
|
Data62: string;
|
|
12
17
|
DeviceName: string;
|
|
13
18
|
Password: string;
|
|
14
|
-
Proxy?:
|
|
19
|
+
Proxy?: ProxyInfo;
|
|
15
20
|
UserName: string;
|
|
16
21
|
}
|
|
17
22
|
export interface LoginData62SMSAgainReq {
|
|
18
23
|
Cookie: string;
|
|
19
|
-
Proxy?:
|
|
24
|
+
Proxy?: ProxyInfo;
|
|
20
25
|
Url: string;
|
|
21
26
|
}
|
|
22
27
|
export interface LoginData62SMSVerifyReq {
|
|
23
28
|
Cookie: string;
|
|
24
|
-
Proxy?:
|
|
29
|
+
Proxy?: ProxyInfo;
|
|
25
30
|
Sms: string;
|
|
26
31
|
Url: string;
|
|
27
32
|
}
|
|
@@ -32,7 +37,7 @@ export interface LoginExtDeviceLoginConfirmParam {
|
|
|
32
37
|
export interface LoginGetQRReq {
|
|
33
38
|
DeviceID: string;
|
|
34
39
|
DeviceName: string;
|
|
35
|
-
Proxy?:
|
|
40
|
+
Proxy?: ProxyInfo;
|
|
36
41
|
}
|
|
37
42
|
export interface LoginVerificationcodeParam {
|
|
38
43
|
Code: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,9 @@ export interface WxBotOptions {
|
|
|
15
15
|
deviceType: 'ipad' | 'car' | 'mac' | 'pad' | 'win' | 'ipadX' | string;
|
|
16
16
|
mode?: 'polling' | 'callback' | string;
|
|
17
17
|
callbackPort?: number;
|
|
18
|
+
ProxyIp?: string;
|
|
19
|
+
ProxyPassword?: string;
|
|
20
|
+
ProxyUser?: string;
|
|
18
21
|
}
|
|
19
22
|
export declare class WxBot extends EventEmitter {
|
|
20
23
|
baseUrl: string;
|
|
@@ -22,6 +25,9 @@ export declare class WxBot extends EventEmitter {
|
|
|
22
25
|
deviceType: 'ipad' | 'car' | 'mac' | 'pad' | 'win' | 'ipadX' | string;
|
|
23
26
|
mode: 'polling' | 'callback' | string;
|
|
24
27
|
callbackPort: number;
|
|
28
|
+
ProxyIp?: string;
|
|
29
|
+
ProxyPassword?: string;
|
|
30
|
+
ProxyUser?: string;
|
|
25
31
|
private uuid;
|
|
26
32
|
private interval;
|
|
27
33
|
private heartbeatInterval;
|
|
@@ -30,7 +36,9 @@ export declare class WxBot extends EventEmitter {
|
|
|
30
36
|
private recentMsgIds;
|
|
31
37
|
private syncFailureCount;
|
|
32
38
|
private httpServer;
|
|
33
|
-
|
|
39
|
+
private loggingOut;
|
|
40
|
+
private loggingIn;
|
|
41
|
+
constructor({ baseUrl, databasePath, deviceType, mode, callbackPort, ProxyIp, ProxyPassword, ProxyUser }: WxBotOptions);
|
|
34
42
|
qrcode(style?: number): Promise<{
|
|
35
43
|
qrCode: any;
|
|
36
44
|
} | null>;
|
package/dist/index.js
CHANGED
|
@@ -41,9 +41,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
41
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
-
};
|
|
47
44
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
45
|
exports.UrlLink = exports.WeVideo = exports.Voice = exports.Emoji = exports.Message = exports.Room = exports.Contact = exports.WxBot = exports.AppDataSource = void 0;
|
|
49
46
|
require("reflect-metadata");
|
|
@@ -52,7 +49,6 @@ const data_source_1 = require("./database/data-source");
|
|
|
52
49
|
const LoginApi_1 = require("./api/LoginApi");
|
|
53
50
|
const MsgApi_1 = require("./api/MsgApi");
|
|
54
51
|
const FriendApi_1 = require("./api/FriendApi");
|
|
55
|
-
const qrcode_terminal_1 = __importDefault(require("qrcode-terminal"));
|
|
56
52
|
const config_service_1 = require("./services/config.service");
|
|
57
53
|
const events_1 = require("events");
|
|
58
54
|
const Message_1 = require("./core/Message");
|
|
@@ -78,7 +74,7 @@ const room_service_1 = require("./services/room.service");
|
|
|
78
74
|
const message_service_1 = require("./services/message.service");
|
|
79
75
|
const http = __importStar(require("http"));
|
|
80
76
|
class WxBot extends events_1.EventEmitter {
|
|
81
|
-
constructor({ baseUrl, databasePath, deviceType = 'ipad', mode = 'polling', callbackPort = 8056 }) {
|
|
77
|
+
constructor({ baseUrl, databasePath, deviceType = 'ipad', mode = 'polling', callbackPort = 8056, ProxyIp, ProxyPassword, ProxyUser }) {
|
|
82
78
|
super();
|
|
83
79
|
this.uuid = '';
|
|
84
80
|
this.interval = null;
|
|
@@ -88,11 +84,16 @@ class WxBot extends events_1.EventEmitter {
|
|
|
88
84
|
this.recentMsgIds = []; // Store recent message IDs
|
|
89
85
|
this.syncFailureCount = 0; // Sync failure counter
|
|
90
86
|
this.httpServer = null; // HTTP回调服务器
|
|
87
|
+
this.loggingOut = false; // Flag to prevent concurrent logOut calls
|
|
88
|
+
this.loggingIn = false; // Flag to prevent concurrent login calls
|
|
91
89
|
this.baseUrl = baseUrl;
|
|
92
90
|
this.databasePath = databasePath;
|
|
93
91
|
this.deviceType = deviceType;
|
|
94
92
|
this.mode = mode;
|
|
95
93
|
this.callbackPort = callbackPort;
|
|
94
|
+
this.ProxyIp = ProxyIp;
|
|
95
|
+
this.ProxyPassword = ProxyPassword;
|
|
96
|
+
this.ProxyUser = ProxyUser;
|
|
96
97
|
(0, axiosInstance_1.setBaseUrl)(baseUrl);
|
|
97
98
|
}
|
|
98
99
|
qrcode(style) {
|
|
@@ -126,9 +127,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
126
127
|
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
127
128
|
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
128
129
|
"Proxy": {
|
|
129
|
-
"ProxyIp": "",
|
|
130
|
-
"ProxyPassword": "",
|
|
131
|
-
"ProxyUser": ""
|
|
130
|
+
"ProxyIp": this.ProxyIp || "",
|
|
131
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
132
|
+
"ProxyUser": this.ProxyUser || ""
|
|
132
133
|
}
|
|
133
134
|
});
|
|
134
135
|
break;
|
|
@@ -137,9 +138,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
137
138
|
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
138
139
|
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
139
140
|
"Proxy": {
|
|
140
|
-
"ProxyIp": "",
|
|
141
|
-
"ProxyPassword": "",
|
|
142
|
-
"ProxyUser": ""
|
|
141
|
+
"ProxyIp": this.ProxyIp || "",
|
|
142
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
143
|
+
"ProxyUser": this.ProxyUser || ""
|
|
143
144
|
}
|
|
144
145
|
});
|
|
145
146
|
break;
|
|
@@ -148,9 +149,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
148
149
|
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
149
150
|
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
150
151
|
"Proxy": {
|
|
151
|
-
"ProxyIp": "",
|
|
152
|
-
"ProxyPassword": "",
|
|
153
|
-
"ProxyUser": ""
|
|
152
|
+
"ProxyIp": this.ProxyIp || "",
|
|
153
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
154
|
+
"ProxyUser": this.ProxyUser || ""
|
|
154
155
|
}
|
|
155
156
|
});
|
|
156
157
|
break;
|
|
@@ -159,9 +160,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
159
160
|
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
160
161
|
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
161
162
|
"Proxy": {
|
|
162
|
-
"ProxyIp": "",
|
|
163
|
-
"ProxyPassword": "",
|
|
164
|
-
"ProxyUser": ""
|
|
163
|
+
"ProxyIp": this.ProxyIp || "",
|
|
164
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
165
|
+
"ProxyUser": this.ProxyUser || ""
|
|
165
166
|
}
|
|
166
167
|
});
|
|
167
168
|
break;
|
|
@@ -170,9 +171,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
170
171
|
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
171
172
|
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
172
173
|
"Proxy": {
|
|
173
|
-
"ProxyIp": "",
|
|
174
|
-
"ProxyPassword": "",
|
|
175
|
-
"ProxyUser": ""
|
|
174
|
+
"ProxyIp": this.ProxyIp || "",
|
|
175
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
176
|
+
"ProxyUser": this.ProxyUser || ""
|
|
176
177
|
}
|
|
177
178
|
});
|
|
178
179
|
break;
|
|
@@ -182,9 +183,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
182
183
|
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
183
184
|
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
184
185
|
"Proxy": {
|
|
185
|
-
"ProxyIp": "",
|
|
186
|
-
"ProxyPassword": "",
|
|
187
|
-
"ProxyUser": ""
|
|
186
|
+
"ProxyIp": this.ProxyIp || "",
|
|
187
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
188
|
+
"ProxyUser": this.ProxyUser || ""
|
|
188
189
|
}
|
|
189
190
|
});
|
|
190
191
|
break;
|
|
@@ -194,8 +195,6 @@ class WxBot extends events_1.EventEmitter {
|
|
|
194
195
|
const match = data.Data.QrUrl.match(/[?&]data=([^&]+)/);
|
|
195
196
|
if (match && match[1]) {
|
|
196
197
|
const qrLink = decodeURIComponent(match[1]);
|
|
197
|
-
console.log('二维码内容链接:', qrLink);
|
|
198
|
-
qrcode_terminal_1.default.generate(qrLink, { small: true });
|
|
199
198
|
this.emit('scan', {
|
|
200
199
|
content: qrLink
|
|
201
200
|
});
|
|
@@ -253,7 +252,6 @@ class WxBot extends events_1.EventEmitter {
|
|
|
253
252
|
}
|
|
254
253
|
}
|
|
255
254
|
else if (statusData.Message.includes('数据不存在') || statusData.Message.includes('未知的错误')) {
|
|
256
|
-
console.log('二维码已失效,正在获取新的二维码...');
|
|
257
255
|
yield this.fetchAndShowQRCode();
|
|
258
256
|
}
|
|
259
257
|
else {
|
|
@@ -438,7 +436,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
438
436
|
checkLoginAfterDelay(userName) {
|
|
439
437
|
return __awaiter(this, void 0, void 0, function* () {
|
|
440
438
|
// 等待20秒
|
|
441
|
-
yield new Promise(resolve => setTimeout(resolve,
|
|
439
|
+
yield new Promise(resolve => setTimeout(resolve, 60000));
|
|
442
440
|
// 再次检查登录状态
|
|
443
441
|
const resp = yield MsgApi_1.msgApi.Sync({
|
|
444
442
|
"Wxid": userName,
|
|
@@ -464,7 +462,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
464
462
|
this.syncFailureCount = 0; // 重置计数器
|
|
465
463
|
// 先尝试二次登录
|
|
466
464
|
yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
|
|
467
|
-
// 等待
|
|
465
|
+
// 等待60秒后再次检查
|
|
468
466
|
if (yield this.checkLoginAfterDelay(userName)) {
|
|
469
467
|
return true;
|
|
470
468
|
}
|
|
@@ -478,7 +476,7 @@ class WxBot extends events_1.EventEmitter {
|
|
|
478
476
|
if (data.Message === '用户可能退出') {
|
|
479
477
|
// 先尝试二次登录
|
|
480
478
|
yield LoginApi_1.loginApi.LoginTwiceAutoAuth(userName);
|
|
481
|
-
// 等待
|
|
479
|
+
// 等待60秒后再次检查
|
|
482
480
|
if (yield this.checkLoginAfterDelay(userName)) {
|
|
483
481
|
return true;
|
|
484
482
|
}
|
|
@@ -578,9 +576,18 @@ class WxBot extends events_1.EventEmitter {
|
|
|
578
576
|
}
|
|
579
577
|
logOut() {
|
|
580
578
|
return __awaiter(this, void 0, void 0, function* () {
|
|
581
|
-
this.
|
|
582
|
-
|
|
583
|
-
|
|
579
|
+
if (this.loggingOut) {
|
|
580
|
+
return; // Already logging out, prevent concurrent execution
|
|
581
|
+
}
|
|
582
|
+
try {
|
|
583
|
+
this.loggingOut = true;
|
|
584
|
+
this.clearAllIntervals(); // 确保清理所有定时器
|
|
585
|
+
this.syncFailureCount = 0; // 重置失败计数器
|
|
586
|
+
this.emit('logout');
|
|
587
|
+
}
|
|
588
|
+
finally {
|
|
589
|
+
this.loggingOut = false;
|
|
590
|
+
}
|
|
584
591
|
});
|
|
585
592
|
}
|
|
586
593
|
/**
|
|
@@ -601,11 +608,20 @@ class WxBot extends events_1.EventEmitter {
|
|
|
601
608
|
}
|
|
602
609
|
login() {
|
|
603
610
|
return __awaiter(this, void 0, void 0, function* () {
|
|
604
|
-
this.
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
611
|
+
if (this.loggingIn) {
|
|
612
|
+
return; // Already logging in, prevent concurrent execution
|
|
613
|
+
}
|
|
614
|
+
try {
|
|
615
|
+
this.loggingIn = true;
|
|
616
|
+
this.clearAllIntervals(); // 确保清理所有定时器
|
|
617
|
+
yield this.fetchAndShowQRCode();
|
|
618
|
+
this.interval = setInterval(() => {
|
|
619
|
+
this.checkLoginStatus();
|
|
620
|
+
}, 2000);
|
|
621
|
+
}
|
|
622
|
+
finally {
|
|
623
|
+
this.loggingIn = false;
|
|
624
|
+
}
|
|
609
625
|
});
|
|
610
626
|
}
|
|
611
627
|
start() {
|