wx2tg-puppet 1.0.8 → 1.1.0

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.
@@ -27,6 +27,8 @@ declare class ToolsApi {
27
27
  UploadFile(body: any): Axios.IPromise<Axios.AxiosXHR<unknown>>;
28
28
  /** 设置/删除代理IP */
29
29
  setproxy(body: any): Axios.IPromise<Axios.AxiosXHR<unknown>>;
30
+ /** CDN图片下载 */
31
+ CdnDownloadImage(body: any): Axios.IPromise<Axios.AxiosXHR<unknown>>;
30
32
  }
31
33
  export declare const toolsApi: ToolsApi;
32
34
  export {};
@@ -59,5 +59,9 @@ class ToolsApi {
59
59
  setproxy(body) {
60
60
  return axiosInstance_1.axiosInstance.post('/Tools/setproxy', body);
61
61
  }
62
+ /** CDN图片下载 */
63
+ CdnDownloadImage(body) {
64
+ return axiosInstance_1.axiosInstance.post('/Tools/CdnDownloadImage', body);
65
+ }
62
66
  }
63
67
  exports.toolsApi = new ToolsApi();
@@ -341,10 +341,29 @@ class Message {
341
341
  }
342
342
  toFileBox() {
343
343
  return __awaiter(this, void 0, void 0, function* () {
344
+ var _a;
344
345
  if (this.type() === MessageType_1.MessageType.Image) {
345
346
  const xml = this.msg.Content;
346
347
  const json = Message.getXmlToJson(xml);
347
348
  const config = yield config_service_1.configService.get();
349
+ // 优先使用 cdn 下载
350
+ const aeskey = json.msg.img.aeskey;
351
+ let url = json.msg.img.cdnbigimgurl;
352
+ if (!url) {
353
+ url = json.msg.img.cdnmidimgurl;
354
+ }
355
+ else if (!url) {
356
+ url = json.msg.img.cdnthumburl;
357
+ }
358
+ const cdnResp = yield ToolsApi_1.toolsApi.CdnDownloadImage({
359
+ "FileAesKey": aeskey,
360
+ "FileNo": url,
361
+ "Wxid": (config === null || config === void 0 ? void 0 : config.wxid) || ''
362
+ });
363
+ if (((_a = cdnResp === null || cdnResp === void 0 ? void 0 : cdnResp.data) === null || _a === void 0 ? void 0 : _a.Message) === '成功') {
364
+ const fileBox = file_box_1.FileBox.fromBase64(cdnResp.data.Data.Image, `${this.msg.MsgId}.png`);
365
+ return fileBox;
366
+ }
348
367
  const totalSize = parseInt(json.msg.img.length);
349
368
  // Get initial chunk size from first request
350
369
  const firstChunk = FileChunkHelper_1.FileChunkHelper.getChunk(totalSize, 0);
@@ -2,4 +2,6 @@ export declare class Config {
2
2
  id: number;
3
3
  uuid: string;
4
4
  wxid: string;
5
+ deviceId: string;
6
+ DeviceName: string;
5
7
  }
@@ -26,6 +26,14 @@ __decorate([
26
26
  (0, typeorm_1.Column)({ nullable: true }),
27
27
  __metadata("design:type", String)
28
28
  ], Config.prototype, "wxid", void 0);
29
+ __decorate([
30
+ (0, typeorm_1.Column)({ nullable: true }),
31
+ __metadata("design:type", String)
32
+ ], Config.prototype, "deviceId", void 0);
33
+ __decorate([
34
+ (0, typeorm_1.Column)({ nullable: true }),
35
+ __metadata("design:type", String)
36
+ ], Config.prototype, "DeviceName", void 0);
29
37
  exports.Config = Config = __decorate([
30
38
  (0, typeorm_1.Entity)()
31
39
  ], Config);
package/dist/index.js CHANGED
@@ -51,9 +51,10 @@ class WxBot extends events_1.EventEmitter {
51
51
  fetchAndShowQRCode() {
52
52
  return __awaiter(this, void 0, void 0, function* () {
53
53
  try {
54
+ const config = yield config_service_1.configService.get();
54
55
  const response = yield LoginApi_1.loginApi.GetQR({
55
- "DeviceID": "",
56
- "DeviceName": "",
56
+ "DeviceID": (config === null || config === void 0 ? void 0 : config.deviceId) || "",
57
+ "DeviceName": (config === null || config === void 0 ? void 0 : config.DeviceName) || "",
57
58
  "OSModel": "",
58
59
  "Proxy": {
59
60
  "ProxyIp": "",
@@ -107,7 +108,10 @@ class WxBot extends events_1.EventEmitter {
107
108
  const statusData = statusResp.data;
108
109
  if (statusData.Success) {
109
110
  if (statusData.Message === '登陆成功') {
110
- yield config_service_1.configService.save(this.uuid, statusData.Data.acctSectResp.userName);
111
+ yield config_service_1.configService.save({
112
+ uuid: this.uuid,
113
+ wxid: statusData.Data.acctSectResp.userName,
114
+ });
111
115
  this.loginSuccess(statusData.Data.acctSectResp.userName);
112
116
  if (this.interval)
113
117
  clearInterval(this.interval);
@@ -165,6 +169,14 @@ class WxBot extends events_1.EventEmitter {
165
169
  return;
166
170
  }
167
171
  console.log('好友列表获取成功,开始更新联系人信息');
172
+ // 设置设备信息
173
+ const cacheInfo = yield LoginApi_1.loginApi.GetCacheInfo(userName);
174
+ if (cacheInfo.data.Message === '成功') {
175
+ yield config_service_1.configService.save({
176
+ deviceId: cacheInfo.data.Data.Deviceid_str,
177
+ DeviceName: cacheInfo.data.Data.DeviceName,
178
+ });
179
+ }
168
180
  // 获取详情
169
181
  const data = res.data;
170
182
  data.Data.ContactUsernameList.forEach((contact) => {
@@ -2,7 +2,7 @@ import { Config } from '../entities/config.entity';
2
2
  declare class ConfigService {
3
3
  private get repo();
4
4
  get(): Promise<Config | null>;
5
- save(uuid: string, wxid: string): Promise<Config>;
5
+ save(config: Partial<Config>): Promise<Config>;
6
6
  }
7
7
  export declare const configService: ConfigService;
8
8
  export {};
@@ -21,17 +21,17 @@ class ConfigService {
21
21
  return this.repo.findOne({ where: {} });
22
22
  });
23
23
  }
24
- save(uuid, wxid) {
24
+ save(config) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- let config = yield this.get();
27
- if (config) {
28
- config.uuid = uuid;
29
- config.wxid = wxid;
26
+ let existingConfig = yield this.get();
27
+ if (existingConfig) {
28
+ Object.assign(existingConfig, config);
29
+ return this.repo.save(existingConfig);
30
30
  }
31
31
  else {
32
- config = this.repo.create({ uuid, wxid });
32
+ const newConfig = this.repo.create(config);
33
+ return this.repo.save(newConfig);
33
34
  }
34
- return this.repo.save(config);
35
35
  });
36
36
  }
37
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wx2tg-puppet",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
package/README.md DELETED
@@ -1,40 +0,0 @@
1
- # wx2tg-puppet
2
-
3
- 微信机器人核心库,可作为依赖被其他项目引入。
4
-
5
- ## 安装
6
-
7
- ```bash
8
- npm install /path/to/your/wx2tg-puppet
9
- # 或发布到 npm 后
10
- npm install wx2tg-puppet
11
- ```
12
-
13
- ## 使用示例
14
-
15
- ```ts
16
- import { WxBot } from 'wx2tg-puppet';
17
-
18
- const bot = new WxBot({
19
- baseUrl: 'http://your-api-url',
20
- databasePath: './db.sqlite',
21
- });
22
-
23
- bot.on('scan', (qrcode) => {
24
- // 展示二维码
25
- });
26
- bot.on('login', (user) => {
27
- // 登录成功
28
- });
29
- bot.on('message', (msg) => {
30
- // 收到消息
31
- });
32
-
33
- bot.start();
34
- ```
35
-
36
- ## 导出内容
37
- - WxBot
38
- - Contact
39
- - Room
40
- - Message