node-easywechat 3.5.11 → 3.5.12

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/CHANGELOG.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.5.12 (2023-12-19)
5
+
6
+ - Fix: 修复类型错误
7
+
4
8
  ## v3.5.11 (2023-12-19)
5
9
 
6
10
  - Fix: 微信支付获取平台证书优化为随用随获取的方式,并增加缓存 (#57)
@@ -5,12 +5,14 @@ import ConfigMixin from '../Core/Mixins/ConfigMixin';
5
5
  import HttpClientMixin from '../Core/Mixins/HttpClientMixin';
6
6
  import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
7
7
  import { PayConfig } from '../Types/global';
8
+ import Merchant from './Merchant';
8
9
  import MerchantInterface from './Contracts/MerchantInterface';
9
10
  import ApplicationInterface from './Contracts/ApplicationInterface';
10
11
  import Server from './Server';
11
12
  import Utils from './Utils';
12
13
  import Client from './Client';
13
14
  import Validator from './Validator';
15
+ import ValidatorInterface from './Contracts/ValidatorInterface';
14
16
  /**
15
17
  * 微信支付应用
16
18
  */
@@ -21,8 +23,8 @@ declare class Application implements ApplicationInterface {
21
23
  protected server: Server;
22
24
  protected client: Client;
23
25
  protected utils: Utils;
24
- protected validator: Validator;
25
- getMerchant(): MerchantInterface;
26
+ protected validator: ValidatorInterface;
27
+ getMerchant(): Merchant;
26
28
  /**
27
29
  * 设置当前账户实例
28
30
  * @param merchant
@@ -46,7 +48,7 @@ declare class Application implements ApplicationInterface {
46
48
  * 设置验证器实例
47
49
  * @param validator
48
50
  */
49
- setValidator(validator: Validator): void;
51
+ setValidator(validator: ValidatorInterface): void;
50
52
  getValidator(): Validator;
51
53
  getClient(): Client;
52
54
  /**
@@ -42,9 +42,9 @@ declare abstract class MerchantInterface {
42
42
  getPlatformCert(serial: string): Promise<PublicKey>;
43
43
  /**
44
44
  * 获取平台证书
45
- * @param force 是否强制刷新缓存
45
+ * @param force 是否强制刷新缓存,默认:false
46
46
  */
47
- loadPlatformCerts(force: boolean): void;
47
+ loadPlatformCerts(force?: boolean): Promise<void>;
48
48
  /**
49
49
  * 设置平台证书
50
50
  * @param certs 键名:序列号,键值:PublicKey实例或者文件内容字符串
@@ -41,9 +41,9 @@ class MerchantInterface {
41
41
  getPlatformCert(serial) { return null; }
42
42
  /**
43
43
  * 获取平台证书
44
- * @param force 是否强制刷新缓存
44
+ * @param force 是否强制刷新缓存,默认:false
45
45
  */
46
- loadPlatformCerts(force) { }
46
+ loadPlatformCerts(force = false) { return; }
47
47
  /**
48
48
  * 设置平台证书
49
49
  * @param certs 键名:序列号,键值:PublicKey实例或者文件内容字符串
@@ -27,6 +27,6 @@ declare class Merchant implements MerchantInterface {
27
27
  setPlatformCerts(certs: Record<string, PublicKey | string>): void;
28
28
  getPlatformCertKey(): string;
29
29
  setPlatformCertKey(key: string): this;
30
- loadPlatformCerts(force?: boolean): Promise<Record<string, string>>;
30
+ loadPlatformCerts(force?: boolean): Promise<void>;
31
31
  }
32
32
  export = Merchant;
@@ -108,13 +108,13 @@ class Merchant {
108
108
  certs = {};
109
109
  let response = yield this.app.getClient().get('/v3/certificates');
110
110
  let data = response.toObject();
111
- if (!data || !data.data || data.data.length === 0)
112
- return certs;
113
- data.data.forEach((item) => {
114
- let content = AES_1.AES_GCM.decrypt(item.encrypt_certificate.ciphertext, this.app.getConfig().get('secret_key'), item.encrypt_certificate.nonce, item.encrypt_certificate.associated_data).toString();
115
- certs[item.serial_no] = content;
116
- });
117
- yield cache.set(cacheKey, certs, 36000); // 缓存10小时
111
+ if (data && data.data && data.data.length > 0) {
112
+ data.data.forEach((item) => {
113
+ let content = AES_1.AES_GCM.decrypt(item.encrypt_certificate.ciphertext, this.app.getConfig().get('secret_key'), item.encrypt_certificate.nonce, item.encrypt_certificate.associated_data).toString();
114
+ certs[item.serial_no] = content;
115
+ });
116
+ yield cache.set(cacheKey, certs, 36000); // 缓存10小时
117
+ }
118
118
  }
119
119
  this.setPlatformCerts(certs);
120
120
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.5.11",
3
+ "version": "3.5.12",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {