node-easywechat 3.5.1 → 3.5.4

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.4 (2023-11-15)
5
+
6
+ - Fix: 修复生成支付参数中,时间戳类型错误 (#45)
7
+ - Fix: 修复计算支付签名时证书调用错误
8
+ - Fix: 证书文件无法访问时抛出异常
9
+
10
+ ## v3.5.2 (2023-11-11)
11
+
12
+ - Fix: 更新依赖包
13
+
4
14
  ## v3.5.1 (2023-09-04)
5
15
 
6
16
  - Fix: 调整公众号、小程序access_token默认缓存名称的配置方式
@@ -86,7 +86,7 @@ declare class HttpClientResponse implements HttpClientResponseInterface {
86
86
  getHeaders(throwError?: boolean): Record<string, any>;
87
87
  getContent(throwError?: boolean): any;
88
88
  cancel(): void;
89
- getInfo(type?: string): import("axios").AxiosRequestConfig<any>;
89
+ getInfo(type?: string): import("axios").InternalAxiosRequestConfig<any>;
90
90
  offsetExists(key: any): Promise<boolean>;
91
91
  offsetGet(key: any): Promise<any>;
92
92
  }
@@ -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
  * 获取公钥的序列号
@@ -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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.5.1",
3
+ "version": "3.5.4",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -29,13 +29,13 @@
29
29
  "typescript": "^4.6.3"
30
30
  },
31
31
  "dependencies": {
32
- "axios": "^0.26.1",
33
- "axios-retry": "^3.3.1",
32
+ "axios": "^1.6.1",
33
+ "axios-retry": "^3.8.1",
34
34
  "form-data": "^4.0.0",
35
35
  "merge": "^2.1.1",
36
- "node-socialite": "^1.3.2",
37
- "qs": "^6.10.3",
38
- "raw-body": "^2.5.1",
39
- "xml2js": "^0.5.0"
36
+ "node-socialite": "^1.4.1",
37
+ "qs": "^6.11.2",
38
+ "raw-body": "^2.5.2",
39
+ "xml2js": "^0.6.2"
40
40
  }
41
41
  }