wx2tg-puppet 1.1.0 → 1.1.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/core/Friendship.d.ts +32 -0
- package/dist/core/Friendship.js +121 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +36 -1
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface FriendshipConstructor {
|
|
2
|
+
fromnickname?: string;
|
|
3
|
+
nickName?: string;
|
|
4
|
+
fromusername: string;
|
|
5
|
+
encryptusername?: string;
|
|
6
|
+
v3?: string;
|
|
7
|
+
ticket?: string;
|
|
8
|
+
v4?: string;
|
|
9
|
+
BigHeadImgUrl?: string;
|
|
10
|
+
bigHeadImgUrl?: string;
|
|
11
|
+
SmallHeadImgUrl?: string;
|
|
12
|
+
smallHeadImgUrl?: string;
|
|
13
|
+
content?: string;
|
|
14
|
+
scene: number;
|
|
15
|
+
}
|
|
16
|
+
export declare class Friendship {
|
|
17
|
+
private fromName;
|
|
18
|
+
private formId;
|
|
19
|
+
private v3;
|
|
20
|
+
private v4;
|
|
21
|
+
private bigHeadImgUrl;
|
|
22
|
+
private smallHeadImgUrl;
|
|
23
|
+
private content;
|
|
24
|
+
private scene;
|
|
25
|
+
constructor(obj: FriendshipConstructor);
|
|
26
|
+
accept(): Promise<any>;
|
|
27
|
+
hello(): string;
|
|
28
|
+
type(): number;
|
|
29
|
+
static search(mobile: string): Promise<Friendship | undefined>;
|
|
30
|
+
static add(contact: Friendship, helloMessage?: string): Promise<any>;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.Friendship = void 0;
|
|
13
|
+
const FriendApi_1 = require("../api/FriendApi");
|
|
14
|
+
const config_service_1 = require("../services/config.service");
|
|
15
|
+
class Friendship {
|
|
16
|
+
constructor(obj) {
|
|
17
|
+
this.fromName = obj.fromnickname || obj.nickName || ''; // 代表联系人的信息
|
|
18
|
+
this.formId = obj.fromusername;
|
|
19
|
+
this.v3 = obj.encryptusername || obj.v3 || '';
|
|
20
|
+
this.v4 = obj.ticket || obj.v4 || '';
|
|
21
|
+
this.bigHeadImgUrl = obj.BigHeadImgUrl || obj.bigHeadImgUrl || '';
|
|
22
|
+
this.smallHeadImgUrl = obj.SmallHeadImgUrl || obj.smallHeadImgUrl || '';
|
|
23
|
+
this.content = obj.content || '';
|
|
24
|
+
this.scene = obj.scene;
|
|
25
|
+
/**
|
|
26
|
+
* 3 :微信号搜索
|
|
27
|
+
* 4 :QQ好友
|
|
28
|
+
* 8 :来自群聊
|
|
29
|
+
* 15:手机号
|
|
30
|
+
*/
|
|
31
|
+
}
|
|
32
|
+
// 实例方法1:accept()
|
|
33
|
+
accept() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const config = yield config_service_1.configService.get();
|
|
36
|
+
return FriendApi_1.friendApi.PassVerify({
|
|
37
|
+
"Scene": parseInt(this.scene + ''),
|
|
38
|
+
"V1": this.v3,
|
|
39
|
+
"V2": this.v4,
|
|
40
|
+
"Wxid": config === null || config === void 0 ? void 0 : config.wxid
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
// 实例方法2:hello()
|
|
45
|
+
hello() {
|
|
46
|
+
return this.content;
|
|
47
|
+
}
|
|
48
|
+
// 实例方法3:contact()
|
|
49
|
+
// contact(): Contact {
|
|
50
|
+
// const contactEntity: ContactEntity = {
|
|
51
|
+
// userName: this.formId,
|
|
52
|
+
// nickName: this.fromName,
|
|
53
|
+
// bigHeadImgUrl: this.bigHeadImgUrl,
|
|
54
|
+
// smallHeadImgUrl: this.smallHeadImgUrl,
|
|
55
|
+
// pyInitial: '',
|
|
56
|
+
// quanPin: '',
|
|
57
|
+
// sex: 0,
|
|
58
|
+
// remark: '',
|
|
59
|
+
// remarkPyInitial: '',
|
|
60
|
+
// remarkQuanPin: '',
|
|
61
|
+
// signature: '',
|
|
62
|
+
// alias: '',
|
|
63
|
+
// snsBgImg: '',
|
|
64
|
+
// country: '',
|
|
65
|
+
// description: '',
|
|
66
|
+
// cardImgUrl: '',
|
|
67
|
+
// labelList: '',
|
|
68
|
+
// province: '',
|
|
69
|
+
// city: '',
|
|
70
|
+
// phoneNumList: ''
|
|
71
|
+
// };
|
|
72
|
+
// return new Contact(contactEntity);
|
|
73
|
+
// }
|
|
74
|
+
// 实例方法4:type()
|
|
75
|
+
type() {
|
|
76
|
+
return this.scene;
|
|
77
|
+
}
|
|
78
|
+
static search(mobile) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
var _a, _b, _c;
|
|
81
|
+
try {
|
|
82
|
+
const config = yield config_service_1.configService.get();
|
|
83
|
+
const res = yield FriendApi_1.friendApi.Search({
|
|
84
|
+
"FromScene": 0,
|
|
85
|
+
"SearchScene": 1,
|
|
86
|
+
"ToUserName": mobile,
|
|
87
|
+
"Wxid": config === null || config === void 0 ? void 0 : config.wxid
|
|
88
|
+
});
|
|
89
|
+
if (res === null || res === void 0 ? void 0 : res.data) {
|
|
90
|
+
return new Friendship({
|
|
91
|
+
fromnickname: (_a = res.data.Data.NickName) === null || _a === void 0 ? void 0 : _a.string,
|
|
92
|
+
fromusername: (_b = res.data.Data.UserName) === null || _b === void 0 ? void 0 : _b.string,
|
|
93
|
+
v3: (_c = res.data.Data.UserName) === null || _c === void 0 ? void 0 : _c.string,
|
|
94
|
+
v4: res.data.Data.AntispamTicket,
|
|
95
|
+
bigHeadImgUrl: res.data.Data.BigHeadImgUrl,
|
|
96
|
+
smallHeadImgUrl: res.data.Data.SmallHeadImgUrl,
|
|
97
|
+
scene: 0
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
console.error('Error searching contact:', error);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
// 静态方法1:add()
|
|
107
|
+
static add(contact, helloMessage) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
const config = yield config_service_1.configService.get();
|
|
110
|
+
return FriendApi_1.friendApi.SendRequest({
|
|
111
|
+
"Opcode": 2,
|
|
112
|
+
"Scene": 0,
|
|
113
|
+
"V1": contact.v3,
|
|
114
|
+
"V2": contact.v4,
|
|
115
|
+
"VerifyContent": helloMessage || '',
|
|
116
|
+
"Wxid": config === null || config === void 0 ? void 0 : config.wxid
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.Friendship = Friendship;
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,9 @@ export declare class WxBot extends EventEmitter {
|
|
|
22
22
|
private msgInterval;
|
|
23
23
|
private recentMsgIds;
|
|
24
24
|
constructor({ baseUrl, databasePath }: WxBotOptions);
|
|
25
|
+
qrcode(style?: number): Promise<{
|
|
26
|
+
qrCode: any;
|
|
27
|
+
}>;
|
|
25
28
|
private fetchAndShowQRCode;
|
|
26
29
|
private setupHeartbeat;
|
|
27
30
|
private checkLoginStatus;
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,9 @@ const WEVIDEO_1 = require("./core/WEVIDEO");
|
|
|
36
36
|
Object.defineProperty(exports, "WeVideo", { enumerable: true, get: function () { return WEVIDEO_1.WeVideo; } });
|
|
37
37
|
const URLLINK_1 = require("./core/URLLINK");
|
|
38
38
|
Object.defineProperty(exports, "UrlLink", { enumerable: true, get: function () { return URLLINK_1.UrlLink; } });
|
|
39
|
+
const MessageType_1 = require("./type/MessageType");
|
|
40
|
+
const Friendship_1 = require("./core/Friendship");
|
|
41
|
+
const UserApi_1 = require("./api/UserApi");
|
|
39
42
|
class WxBot extends events_1.EventEmitter {
|
|
40
43
|
constructor({ baseUrl, databasePath }) {
|
|
41
44
|
super();
|
|
@@ -48,6 +51,18 @@ class WxBot extends events_1.EventEmitter {
|
|
|
48
51
|
this.databasePath = databasePath;
|
|
49
52
|
(0, axiosInstance_1.setBaseUrl)(baseUrl);
|
|
50
53
|
}
|
|
54
|
+
qrcode(style) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const config = yield config_service_1.configService.get();
|
|
57
|
+
const res = yield UserApi_1.userApi.GetQRCode({
|
|
58
|
+
"Style": style || 8,
|
|
59
|
+
"Wxid": config === null || config === void 0 ? void 0 : config.wxid
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
qrCode: res.data.Data.qrcode.buffer
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
51
66
|
fetchAndShowQRCode() {
|
|
52
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
53
68
|
try {
|
|
@@ -201,6 +216,9 @@ class WxBot extends events_1.EventEmitter {
|
|
|
201
216
|
if (data.Message === '当前未有新消息') {
|
|
202
217
|
return;
|
|
203
218
|
}
|
|
219
|
+
if (!data.Data.AddMsgs) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
204
222
|
// 更新联系人或者群组信息
|
|
205
223
|
// 新增:触发 message 事件
|
|
206
224
|
for (const msg of data.Data.AddMsgs) {
|
|
@@ -232,7 +250,24 @@ class WxBot extends events_1.EventEmitter {
|
|
|
232
250
|
IsSelf: msg.FromUserName.string === userName,
|
|
233
251
|
xml: msg.Content.string
|
|
234
252
|
});
|
|
235
|
-
|
|
253
|
+
if (message.type() === MessageType_1.MessageType.AddFriend) { // 好友请求
|
|
254
|
+
const obj = Message_1.Message.getXmlToJson(message.text());
|
|
255
|
+
console.log(obj);
|
|
256
|
+
const friendship = new Friendship_1.Friendship({
|
|
257
|
+
fromnickname: obj.msg.fromnickname,
|
|
258
|
+
v3: obj.msg.encryptusername,
|
|
259
|
+
v4: obj.msg.ticket,
|
|
260
|
+
scene: obj.msg.scene,
|
|
261
|
+
fromusername: obj.msg.fromusername,
|
|
262
|
+
bigHeadImgUrl: obj.msg.bigHeadImgUrl,
|
|
263
|
+
smallHeadImgUrl: obj.msg.smallHeadImgUrl,
|
|
264
|
+
content: obj.msg.content
|
|
265
|
+
});
|
|
266
|
+
this.emit('friendship', friendship);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
this.emit('message', message);
|
|
270
|
+
}
|
|
236
271
|
}
|
|
237
272
|
}
|
|
238
273
|
else if (data.Message === '用户可能退出') {
|