node-easywechat 3.5.2 → 3.5.5

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,16 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.5.5 (2023-12-02)
5
+
6
+ - Fix: 修复获取服务端实例时,没有获取到最新请求实例的问题 (#47)
7
+
8
+ ## v3.5.4 (2023-11-15)
9
+
10
+ - Fix: 修复生成支付参数中,时间戳类型错误 (#45)
11
+ - Fix: 修复计算支付签名时证书调用错误
12
+ - Fix: 证书文件无法访问时抛出异常
13
+
4
14
  ## v3.5.2 (2023-11-11)
5
15
 
6
16
  - Fix: 更新依赖包
@@ -2,6 +2,7 @@ import ResponseInterface from "../Http/Contracts/ResponseInterface";
2
2
  import DecryptXmlMessageMixin from "../Mixins/DecryptXmlMessageMixin";
3
3
  import HandlersMixin from "../Mixins/HandlersMixin";
4
4
  import ResponseXmlMessageMixin from "../Mixins/ResponseXmlMessageMixin";
5
+ import ServerRequestMixin from "../Mixins/ServerRequestMixin";
5
6
  declare abstract class ServerInterface {
6
7
  constructor();
7
8
  /**
@@ -9,6 +10,6 @@ declare abstract class ServerInterface {
9
10
  */
10
11
  serve(): Promise<ResponseInterface>;
11
12
  }
12
- interface ServerInterface extends HandlersMixin, DecryptXmlMessageMixin, ResponseXmlMessageMixin {
13
+ interface ServerInterface extends HandlersMixin, DecryptXmlMessageMixin, ResponseXmlMessageMixin, ServerRequestMixin {
13
14
  }
14
15
  export = ServerInterface;
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  const DecryptXmlMessageMixin_1 = __importDefault(require("../Mixins/DecryptXmlMessageMixin"));
15
15
  const HandlersMixin_1 = __importDefault(require("../Mixins/HandlersMixin"));
16
16
  const ResponseXmlMessageMixin_1 = __importDefault(require("../Mixins/ResponseXmlMessageMixin"));
17
+ const ServerRequestMixin_1 = __importDefault(require("../Mixins/ServerRequestMixin"));
17
18
  const Utils_1 = require("../Support/Utils");
18
19
  class ServerInterface {
19
20
  constructor() {
@@ -28,5 +29,5 @@ class ServerInterface {
28
29
  }
29
30
  ;
30
31
  ;
31
- (0, Utils_1.applyMixins)(ServerInterface, [HandlersMixin_1.default, DecryptXmlMessageMixin_1.default, ResponseXmlMessageMixin_1.default]);
32
+ (0, Utils_1.applyMixins)(ServerInterface, [HandlersMixin_1.default, DecryptXmlMessageMixin_1.default, ResponseXmlMessageMixin_1.default, ServerRequestMixin_1.default]);
32
33
  module.exports = ServerInterface;
@@ -11,6 +11,9 @@ class PrivateKey {
11
11
  if (fs_1.default.existsSync(key)) {
12
12
  this.key = fs_1.default.readFileSync(key) || Buffer.from('');
13
13
  }
14
+ else {
15
+ throw new Error('Fail to read PrivateKey file');
16
+ }
14
17
  }
15
18
  /**
16
19
  * 获取私钥内容
@@ -11,6 +11,9 @@ class PublicKey {
11
11
  if (fs_1.default.existsSync(certificate)) {
12
12
  this.certificate = fs_1.default.readFileSync(certificate) || Buffer.from('');
13
13
  }
14
+ else {
15
+ throw new Error('Fail to read PublicKey file');
16
+ }
14
17
  }
15
18
  /**
16
19
  * 获取公钥的序列号
@@ -77,6 +77,9 @@ class Application {
77
77
  }
78
78
  this.server = new Server_1.default(this.getRequest(), this.getAccount().getAesKey() ? this.getEncryptor() : null);
79
79
  }
80
+ else {
81
+ this.server.setRequest(this.getRequest());
82
+ }
80
83
  return this.server;
81
84
  }
82
85
  /**
@@ -77,6 +77,9 @@ class Application {
77
77
  if (!this.server) {
78
78
  this.server = new Server_1.default(this.getRequest(), this.getAccount().getAesKey() ? this.getEncryptor() : null);
79
79
  }
80
+ else {
81
+ this.server.setRequest(this.getRequest());
82
+ }
80
83
  return this.server;
81
84
  }
82
85
  /**
@@ -98,6 +98,9 @@ class Application {
98
98
  if (!this.server) {
99
99
  this.server = new Server_1.default(this.getAccount().getAesKey() ? this.getEncryptor() : null, this.getRequest());
100
100
  }
101
+ else {
102
+ this.server.setRequest(this.getRequest());
103
+ }
101
104
  return this.server;
102
105
  }
103
106
  /**
@@ -117,6 +117,9 @@ class Application {
117
117
  return next(message);
118
118
  }));
119
119
  }
120
+ else {
121
+ this.server.setRequest(this.getRequest());
122
+ }
120
123
  return this.server;
121
124
  }
122
125
  /**
@@ -49,6 +49,9 @@ class Application {
49
49
  if (!this.server) {
50
50
  this.server = new Server_1.default(this.getMerchant(), this.getRequest());
51
51
  }
52
+ else {
53
+ this.server.setRequest(this.getRequest());
54
+ }
52
55
  return this.server;
53
56
  }
54
57
  /**
@@ -36,8 +36,8 @@ class Signature {
36
36
  }
37
37
  let signString = `${method.toUpperCase()}\n${pathname}\n${timestamp}\n${nonce}\n${body}\n`;
38
38
  let rsa = new RSA_1.default;
39
- rsa.setPublicKey(this.merchant.getCertificate().getValue());
40
- rsa.setPrivateKey(this.merchant.getPrivateKey().getKey());
39
+ rsa.setPublicKey(this.merchant.getCertificate().toString());
40
+ rsa.setPrivateKey(this.merchant.getPrivateKey().toString());
41
41
  let sign = rsa.sign(signString);
42
42
  return `WECHATPAY2-SHA256-RSA2048 mchid="${this.merchant.getMerchantId()}",nonce_str="${nonce}",timestamp="${timestamp}",serial_no="${this.merchant.getCertificate().getSerialNo()}",signature="${sign}"`;
43
43
  }
@@ -24,7 +24,7 @@ declare class Utils {
24
24
  * @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
25
25
  * @returns
26
26
  */
27
- buildBridgeConfig(prepayId: string, appId: string, signType?: string): PayBridgeConfig;
27
+ buildBridgeConfig(prepayId: string, appId: string, signType?: 'RSA' | 'MD5' | 'HMAC-SHA256'): PayBridgeConfig;
28
28
  /**
29
29
  * 构建JS-SDK支付参数
30
30
  * @see https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#58
@@ -32,7 +32,7 @@ declare class Utils {
32
32
  * @param appId 应用id
33
33
  * @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
34
34
  */
35
- buildSdkConfig(prepayId: string, appId: string, signType?: string): PaySdkConfig;
35
+ buildSdkConfig(prepayId: string, appId: string, signType?: 'RSA' | 'MD5' | 'HMAC-SHA256'): PaySdkConfig;
36
36
  /**
37
37
  * 构建小程序支付参数
38
38
  * @see https://developers.weixin.qq.com/miniprogram/dev/api/payment/wx.requestPayment.html
@@ -41,7 +41,7 @@ declare class Utils {
41
41
  * @param signType v3仅支持RSA,V2支持MD5、HMAC-SHA256
42
42
  * @returns
43
43
  */
44
- buildMiniAppConfig(prepayId: string, appId: string, signType?: string): PayBridgeConfig;
44
+ buildMiniAppConfig(prepayId: string, appId: string, signType?: 'RSA' | 'MD5' | 'HMAC-SHA256'): PayBridgeConfig;
45
45
  /**
46
46
  * 构建App支付参数
47
47
  * @see https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter4_2_4.shtml
package/dist/Pay/Utils.js CHANGED
@@ -70,7 +70,7 @@ class Utils {
70
70
  buildBridgeConfig(prepayId, appId, signType = 'RSA') {
71
71
  let params = {
72
72
  appId,
73
- timeStamp: (0, Utils_1.getTimestamp)(),
73
+ timeStamp: '' + (0, Utils_1.getTimestamp)(),
74
74
  nonceStr: (0, Utils_1.randomString)(),
75
75
  package: 'prepay_id=' + prepayId,
76
76
  signType,
@@ -129,7 +129,7 @@ class Utils {
129
129
  partnerid: this.merchant.getMerchantId(),
130
130
  prepayid: prepayId,
131
131
  nonceStr: (0, Utils_1.randomString)(),
132
- timestamp: (0, Utils_1.getTimestamp)(),
132
+ timestamp: '' + (0, Utils_1.getTimestamp)(),
133
133
  package: 'Sign=WXPay',
134
134
  sign: '',
135
135
  };
@@ -398,7 +398,7 @@ export interface PayBridgeConfig {
398
398
  /**
399
399
  * 时间戳
400
400
  */
401
- timeStamp: number;
401
+ timeStamp: string;
402
402
  /**
403
403
  * 随机字符串
404
404
  */
@@ -428,7 +428,7 @@ export interface PaySdkConfig {
428
428
  /**
429
429
  * 时间戳
430
430
  */
431
- timestamp: number;
431
+ timestamp: string;
432
432
  /**
433
433
  * 随机字符串
434
434
  */
@@ -474,7 +474,7 @@ export interface PayAppConfig {
474
474
  /**
475
475
  * 时间戳
476
476
  */
477
- timestamp: number;
477
+ timestamp: string;
478
478
  /**
479
479
  * 签名
480
480
  */
@@ -85,6 +85,9 @@ class Application {
85
85
  if (!this.server) {
86
86
  this.server = new Server_1.default(this.getEncryptor(), this.getRequest());
87
87
  }
88
+ else {
89
+ this.server.setRequest(this.getRequest());
90
+ }
88
91
  return this.server;
89
92
  }
90
93
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.5.2",
3
+ "version": "3.5.5",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {