wx2tg-puppet 3.0.2 → 3.0.4
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 +2 -0
- package/dist/api/LoginApi.js +4 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +81 -34
- package/dist/utils/axiosInstance.d.ts +6 -0
- package/dist/utils/axiosInstance.js +42 -0
- package/package.json +1 -1
package/dist/api/LoginApi.d.ts
CHANGED
|
@@ -126,6 +126,8 @@ declare class LoginApi {
|
|
|
126
126
|
LoginGetQRWinUwp(body: LoginGetQRReq): Promise<AxiosResponse<ApiResponse>>;
|
|
127
127
|
/** 获取二维码(iPad-绕过验证码) */
|
|
128
128
|
LoginGetQRx(body: LoginGetQRReq): Promise<AxiosResponse<ApiResponse>>;
|
|
129
|
+
/** 获取二维码(绕过验证码-推送确认) */
|
|
130
|
+
LoginGetQRNotCodePush(body: LoginGetQRReq): Promise<AxiosResponse<ApiResponse>>;
|
|
129
131
|
/** 二次登录 */
|
|
130
132
|
LoginTwiceAutoAuth(wxid: string): Promise<AxiosResponse<ApiResponse>>;
|
|
131
133
|
/** 初始化 */
|
package/dist/api/LoginApi.js
CHANGED
|
@@ -163,6 +163,10 @@ class LoginApi {
|
|
|
163
163
|
LoginGetQRx(body) {
|
|
164
164
|
return axiosInstance_1.axiosInstance.post('/Login/LoginGetQRx', body);
|
|
165
165
|
}
|
|
166
|
+
/** 获取二维码(绕过验证码-推送确认) */
|
|
167
|
+
LoginGetQRNotCodePush(body) {
|
|
168
|
+
return axiosInstance_1.axiosInstance.post('/Login/LoginGetQRNotCodePush', body);
|
|
169
|
+
}
|
|
166
170
|
/** 二次登录 */
|
|
167
171
|
LoginTwiceAutoAuth(wxid) {
|
|
168
172
|
return axiosInstance_1.axiosInstance.post('/Login/LoginTwiceAutoAuth', null, { params: { wxid } });
|
package/dist/index.d.ts
CHANGED
|
@@ -47,6 +47,13 @@ export declare class WxBot extends EventEmitter {
|
|
|
47
47
|
private checkLoginStatus;
|
|
48
48
|
info(): Promise<Contact | null>;
|
|
49
49
|
private clearAllIntervals;
|
|
50
|
+
/**
|
|
51
|
+
* 递归获取所有联系人(支持分页)
|
|
52
|
+
* @param userName 微信ID
|
|
53
|
+
* @param currentWxSeq 当前微信联系人序列号
|
|
54
|
+
* @param currentChatroomSeq 当前群聊联系人序列号
|
|
55
|
+
*/
|
|
56
|
+
private fetchAllContacts;
|
|
50
57
|
private loginSuccess;
|
|
51
58
|
private startCallbackServer;
|
|
52
59
|
private handleCallbackMessage;
|
package/dist/index.js
CHANGED
|
@@ -167,15 +167,25 @@ class WxBot extends events_1.EventEmitter {
|
|
|
167
167
|
});
|
|
168
168
|
break;
|
|
169
169
|
case 'ipadX':
|
|
170
|
-
response =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
170
|
+
response = (0, axiosInstance_1.isNewProtocol)()
|
|
171
|
+
? yield LoginApi_1.loginApi.LoginGetQRNotCodePush({
|
|
172
|
+
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
173
|
+
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
174
|
+
"Proxy": {
|
|
175
|
+
"ProxyIp": this.ProxyIp || "",
|
|
176
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
177
|
+
"ProxyUser": this.ProxyUser || ""
|
|
178
|
+
}
|
|
179
|
+
})
|
|
180
|
+
: yield LoginApi_1.loginApi.LoginGetQRx({
|
|
181
|
+
"DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
|
|
182
|
+
"DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
|
|
183
|
+
"Proxy": {
|
|
184
|
+
"ProxyIp": this.ProxyIp || "",
|
|
185
|
+
"ProxyPassword": this.ProxyPassword || "",
|
|
186
|
+
"ProxyUser": this.ProxyUser || ""
|
|
187
|
+
}
|
|
188
|
+
});
|
|
179
189
|
break;
|
|
180
190
|
case 'ipad':
|
|
181
191
|
default:
|
|
@@ -300,23 +310,68 @@ class WxBot extends events_1.EventEmitter {
|
|
|
300
310
|
this.httpServer = null;
|
|
301
311
|
}
|
|
302
312
|
}
|
|
313
|
+
/**
|
|
314
|
+
* 递归获取所有联系人(支持分页)
|
|
315
|
+
* @param userName 微信ID
|
|
316
|
+
* @param currentWxSeq 当前微信联系人序列号
|
|
317
|
+
* @param currentChatroomSeq 当前群聊联系人序列号
|
|
318
|
+
*/
|
|
319
|
+
fetchAllContacts(userName_1) {
|
|
320
|
+
return __awaiter(this, arguments, void 0, function* (userName, currentWxSeq = 0, currentChatroomSeq = 0) {
|
|
321
|
+
try {
|
|
322
|
+
const res = yield FriendApi_1.friendApi.GetContractList({
|
|
323
|
+
"Wxid": userName,
|
|
324
|
+
"CurrentChatRoomContactSeq": currentChatroomSeq,
|
|
325
|
+
"CurrentWxcontactSeq": currentWxSeq,
|
|
326
|
+
});
|
|
327
|
+
if (res.data.Message === '用户可能退出') {
|
|
328
|
+
yield this.logOut();
|
|
329
|
+
yield this.login();
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
const data = res.data;
|
|
333
|
+
if (!data.Success) {
|
|
334
|
+
console.error('获取联系人列表失败:', data.Message);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
// 处理当前批次的联系人
|
|
338
|
+
if (data.Data && data.Data.ContactUsernameList) {
|
|
339
|
+
console.log(`获取到 ${data.Data.ContactUsernameList.length} 个联系人`);
|
|
340
|
+
data.Data.ContactUsernameList.forEach((contact) => {
|
|
341
|
+
if (!contact.endsWith('@chatroom')) {
|
|
342
|
+
Contact_1.Contact.fetchAndUpsertContactDetail(userName, contact);
|
|
343
|
+
}
|
|
344
|
+
else {
|
|
345
|
+
Room_1.Room.find({ id: contact });
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
// 检查是否还有更多联系人需要获取
|
|
350
|
+
// CountinueFlag 为 1 表示还有更多数据
|
|
351
|
+
if (data.Data && data.Data.CountinueFlag === 1) {
|
|
352
|
+
const nextWxSeq = data.Data.CurrentWxcontactSeq || 0;
|
|
353
|
+
const nextChatroomSeq = data.Data.CurrentChatRoomContactSeq || 0;
|
|
354
|
+
console.log(`还有更多联系人,继续获取... (WxSeq: ${nextWxSeq}, ChatroomSeq: ${nextChatroomSeq})`);
|
|
355
|
+
// 递归获取下一批联系人
|
|
356
|
+
yield this.fetchAllContacts(userName, nextWxSeq, nextChatroomSeq);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
console.log('联系人列表获取完成');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
console.error('获取联系人列表时发生错误:', error);
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
303
367
|
loginSuccess(userName) {
|
|
304
368
|
return __awaiter(this, void 0, void 0, function* () {
|
|
305
369
|
contact_service_1.contactService.clearRoom();
|
|
306
370
|
this.clearAllIntervals(); // 确保清理所有定时器
|
|
307
371
|
this.syncFailureCount = 0; // 重置失败计数器
|
|
308
|
-
//
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
"CurrentChatRoomContactSeq": 0,
|
|
312
|
-
"CurrentWxcontactSeq": 0,
|
|
313
|
-
});
|
|
314
|
-
if (res.data.Message === '用户可能退出') {
|
|
315
|
-
yield this.logOut();
|
|
316
|
-
yield this.login();
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
console.log('好友列表获取成功,开始更新联系人信息');
|
|
372
|
+
// 分页获取所有联系人
|
|
373
|
+
yield this.fetchAllContacts(userName, 0, 0);
|
|
374
|
+
console.log('所有联系人获取完成');
|
|
320
375
|
// 设置设备信息
|
|
321
376
|
const cacheInfo = yield LoginApi_1.loginApi.GetCacheInfo(userName);
|
|
322
377
|
if (cacheInfo.data.Message === '成功') {
|
|
@@ -326,16 +381,6 @@ class WxBot extends events_1.EventEmitter {
|
|
|
326
381
|
DeviceType: this.deviceType,
|
|
327
382
|
});
|
|
328
383
|
}
|
|
329
|
-
// 获取详情
|
|
330
|
-
const data = res.data;
|
|
331
|
-
data.Data.ContactUsernameList.forEach((contact) => {
|
|
332
|
-
if (!contact.endsWith('@chatroom')) {
|
|
333
|
-
Contact_1.Contact.fetchAndUpsertContactDetail(userName, contact);
|
|
334
|
-
}
|
|
335
|
-
else {
|
|
336
|
-
Room_1.Room.find({ id: contact });
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
384
|
// 设置心跳包
|
|
340
385
|
this.setupHeartbeat(userName);
|
|
341
386
|
// 根据模式选择消息监听方式
|
|
@@ -615,11 +660,12 @@ class WxBot extends events_1.EventEmitter {
|
|
|
615
660
|
login() {
|
|
616
661
|
return __awaiter(this, void 0, void 0, function* () {
|
|
617
662
|
if (this.loggingIn) {
|
|
618
|
-
return;
|
|
663
|
+
return;
|
|
619
664
|
}
|
|
620
665
|
try {
|
|
621
666
|
this.loggingIn = true;
|
|
622
|
-
|
|
667
|
+
yield (0, axiosInstance_1.detectProtocolVersion)();
|
|
668
|
+
this.clearAllIntervals();
|
|
623
669
|
yield this.fetchAndShowQRCode();
|
|
624
670
|
this.interval = setInterval(() => {
|
|
625
671
|
this.checkLoginStatus();
|
|
@@ -636,7 +682,8 @@ class WxBot extends events_1.EventEmitter {
|
|
|
636
682
|
try {
|
|
637
683
|
yield exports.AppDataSource.initialize();
|
|
638
684
|
console.log('Data Source has been initialized!');
|
|
639
|
-
|
|
685
|
+
yield (0, axiosInstance_1.detectProtocolVersion)();
|
|
686
|
+
this.clearAllIntervals();
|
|
640
687
|
const config = yield config_service_1.configService.get();
|
|
641
688
|
if (config && config.wxid) {
|
|
642
689
|
const resp = yield MsgApi_1.msgApi.Sync({
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
export declare const axiosInstance: import("axios").AxiosInstance;
|
|
2
2
|
export declare function setBaseUrl(baseUrl: string): void;
|
|
3
|
+
/**
|
|
4
|
+
* 检测服务端协议版本
|
|
5
|
+
* @returns 是否为新协议
|
|
6
|
+
*/
|
|
7
|
+
export declare function detectProtocolVersion(): Promise<boolean>;
|
|
8
|
+
export declare function isNewProtocol(): boolean;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
15
|
exports.axiosInstance = void 0;
|
|
7
16
|
exports.setBaseUrl = setBaseUrl;
|
|
17
|
+
exports.detectProtocolVersion = detectProtocolVersion;
|
|
18
|
+
exports.isNewProtocol = isNewProtocol;
|
|
8
19
|
const axios_1 = __importDefault(require("axios"));
|
|
9
20
|
const json_bigint_1 = __importDefault(require("json-bigint"));
|
|
10
21
|
const JSONbigString = (0, json_bigint_1.default)({
|
|
@@ -23,6 +34,37 @@ exports.axiosInstance = axios_1.default.create({
|
|
|
23
34
|
}
|
|
24
35
|
}
|
|
25
36
|
});
|
|
37
|
+
let protocolDetected = false;
|
|
38
|
+
let newProtocol = false;
|
|
26
39
|
function setBaseUrl(baseUrl) {
|
|
27
40
|
exports.axiosInstance.defaults.baseURL = baseUrl;
|
|
41
|
+
protocolDetected = false;
|
|
42
|
+
newProtocol = false;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 检测服务端协议版本
|
|
46
|
+
* @returns 是否为新协议
|
|
47
|
+
*/
|
|
48
|
+
function detectProtocolVersion() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
var _a, _b, _c;
|
|
51
|
+
if (protocolDetected)
|
|
52
|
+
return newProtocol;
|
|
53
|
+
protocolDetected = true;
|
|
54
|
+
try {
|
|
55
|
+
const resp = yield exports.axiosInstance.get('/Tools/Version');
|
|
56
|
+
if (((_a = resp.data) === null || _a === void 0 ? void 0 : _a.Code) === 0 && ((_b = resp.data) === null || _b === void 0 ? void 0 : _b.Success) && ((_c = resp.data) === null || _c === void 0 ? void 0 : _c.Data)) {
|
|
57
|
+
newProtocol = true;
|
|
58
|
+
console.log(`检测到新协议版本: ${resp.data.Data}`);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (_d) {
|
|
63
|
+
// Version 接口不可用,使用旧协议
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
function isNewProtocol() {
|
|
69
|
+
return newProtocol;
|
|
28
70
|
}
|