node-easywechat 3.0.0 → 3.0.1

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,7 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
- ## v3.0.0 (2022-07-28)
4
+ ## v3.0.1 (2022-08-26)
5
+
6
+ - Fix: 修复with方法无效的问题
7
+
8
+ ## v3.0.0, origin/3.x (2022-07-28)
5
9
 
6
10
  - Feat: 请求后自动解析响应结果,简化获取数据的方式
7
11
  - Feat: 新增微信支付模块的公共调用方法
@@ -17,6 +21,7 @@
17
21
  - Fix: 调整默认Message提示的作用域为公众号和小程序
18
22
  - Fix: 修复AccessToken对象声明错误的问题
19
23
 
24
+ - Docs: 更新client调用方法说明
20
25
  - Docs: 增加微信支付相关说明文档
21
26
 
22
27
  ## v3.0.0-beta.5 (2022-06-29)
@@ -62,18 +62,6 @@ declare class PresetMixin {
62
62
  * @returns
63
63
  */
64
64
  withSecret(new_secret?: string): this;
65
- /**
66
- * 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
67
- * @param new_mch_id
68
- * @returns
69
- */
70
- withMchId(new_mch_id?: string): this;
71
- /**
72
- * 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
73
- * @param new_alias
74
- * @returns
75
- */
76
- withMchIdAs(new_alias?: string): this;
77
65
  /**
78
66
  * 预设置文件
79
67
  * @param file 文件路径或可读文件流
@@ -109,24 +109,6 @@ class PresetMixin {
109
109
  this.with('secret', new_secret);
110
110
  return this;
111
111
  }
112
- /**
113
- * 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
114
- * @param new_mch_id
115
- * @returns
116
- */
117
- withMchId(new_mch_id = null) {
118
- this.with('mch_id', new_mch_id);
119
- return this;
120
- }
121
- /**
122
- * 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
123
- * @param new_alias
124
- * @returns
125
- */
126
- withMchIdAs(new_alias = null) {
127
- this.with(new_alias, this.presets['mch_id']);
128
- return this;
129
- }
130
112
  /**
131
113
  * 预设置文件
132
114
  * @param file 文件路径或可读文件流
@@ -9,7 +9,7 @@ import { PayConfig } from '../Types/global';
9
9
  import MerchantInterface from './Contracts/MerchantInterface';
10
10
  import ApplicationInterface from './Contracts/ApplicationInterface';
11
11
  import Utils from './Utils';
12
- import HttpClientInterface from '../Core/HttpClient/Contracts/HttpClientInterface';
12
+ import Client from './Client';
13
13
  /**
14
14
  * 微信支付应用
15
15
  */
@@ -18,7 +18,7 @@ declare class Application implements ApplicationInterface {
18
18
  protected merchant: MerchantInterface;
19
19
  protected encryptor: Encryptor;
20
20
  protected server: ServerInterface;
21
- protected client: HttpClientInterface;
21
+ protected client: Client;
22
22
  getMerchant(): MerchantInterface;
23
23
  /**
24
24
  * 设置当前账户实例
@@ -34,13 +34,13 @@ declare class Application implements ApplicationInterface {
34
34
  */
35
35
  setServer(server: ServerInterface): this;
36
36
  getUtils(): Utils;
37
- getClient(): HttpClientInterface;
37
+ getClient(): Client;
38
38
  /**
39
39
  * 设置客户端
40
40
  * @param client
41
41
  * @returns
42
42
  */
43
- setClient(client: HttpClientInterface): this;
43
+ setClient(client: Client): this;
44
44
  /**
45
45
  * 获取请求默认配置
46
46
  * @returns
@@ -77,7 +77,7 @@ class Application {
77
77
  * @returns
78
78
  */
79
79
  setClient(client) {
80
- this.client = client;
80
+ this.client = client.setPresets(this.config.all());
81
81
  return this;
82
82
  }
83
83
  /**
@@ -36,6 +36,18 @@ declare class Client implements HttpClientInterface {
36
36
  * @returns
37
37
  */
38
38
  protected attachLegacySignature(body: Record<string, any>): Record<string, string | number>;
39
+ /**
40
+ * 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
41
+ * @param new_mch_id
42
+ * @returns
43
+ */
44
+ withMchId(new_mch_id?: string): this;
45
+ /**
46
+ * 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
47
+ * @param new_alias
48
+ * @returns
49
+ */
50
+ withMchIdAs(new_alias?: string): this;
39
51
  }
40
52
  interface Client extends HttpClientMethodsMixin, PresetMixin {
41
53
  }
@@ -81,6 +81,9 @@ class Client {
81
81
  payload.headers['content-type'] = 'text/xml';
82
82
  }
83
83
  }
84
+ if (this.prependData && Object.keys(this.prependData).length > 0) {
85
+ payload.data = Object.assign(Object.assign({}, this.prependData), payload.data);
86
+ }
84
87
  if (this.prependHeaders && Object.keys(this.prependHeaders).length > 0) {
85
88
  payload.headers = Object.assign(Object.assign({}, this.prependHeaders), payload.headers);
86
89
  }
@@ -119,6 +122,24 @@ class Client {
119
122
  attachLegacySignature(body) {
120
123
  return (new LegacySignature_1.default(this.merchant)).sign(body);
121
124
  }
125
+ /**
126
+ * 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
127
+ * @param new_mch_id
128
+ * @returns
129
+ */
130
+ withMchId(new_mch_id = null) {
131
+ this.with('mch_id', new_mch_id);
132
+ return this;
133
+ }
134
+ /**
135
+ * 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
136
+ * @param new_alias
137
+ * @returns
138
+ */
139
+ withMchIdAs(new_alias = null) {
140
+ this.with(new_alias, this.presets['mch_id']);
141
+ return this;
142
+ }
122
143
  }
123
144
  ;
124
145
  (0, Utils_1.applyMixins)(Client, [HttpClientMethodsMixin_1.default, PresetMixin_1.default]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {