node-easywechat 3.3.5 → 3.3.6

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.3.6 (2023-05-12)
5
+
6
+ - Fix: 修复微信支付v3签名错误
7
+
4
8
  ## v3.3.5 (2023-04-28)
5
9
 
6
10
  - Fix: 修复部分接口请求方式及请求参数设置方式异常的问题
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import crypto from 'crypto';
2
+ import crypto, { BinaryToTextEncoding } from 'crypto';
3
3
  declare class RSA {
4
4
  protected publicKey: crypto.KeyObject;
5
5
  /**
@@ -40,21 +40,19 @@ declare class RSA {
40
40
  /**
41
41
  * 计算签名
42
42
  * @param data 待解密文本
43
- * @param hashType 哈希方式,默认:'sha256'
43
+ * @param hashType 哈希方式,默认:'RSA-SHA256'
44
44
  * @param encoding 编码,默认:'base64'
45
- * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_PSS_PADDING
46
45
  * @returns
47
46
  */
48
- sign(data: string, hashType?: string, encoding?: BufferEncoding, padding?: number): string;
47
+ sign(data: string, hashType?: string, encoding?: BinaryToTextEncoding): string;
49
48
  /**
50
49
  * 验证签名
51
50
  * @param signature 待验证签名字符串
52
51
  * @param data 待解密文本
53
- * @param hashType 哈希方式,默认:'sha256'
52
+ * @param hashType 哈希方式,默认:'RSA-SHA256'
54
53
  * @param encoding 编码,默认:'base64'
55
- * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_PSS_PADDING
56
54
  * @returns
57
55
  */
58
- verify(signature: string, data: string, hashType: string, encoding?: BufferEncoding, padding?: number): boolean;
56
+ verify(signature: string, data: string, hashType?: string, encoding?: BinaryToTextEncoding): boolean;
59
57
  }
60
58
  export = RSA;
@@ -65,33 +65,28 @@ class RSA {
65
65
  /**
66
66
  * 计算签名
67
67
  * @param data 待解密文本
68
- * @param hashType 哈希方式,默认:'sha256'
68
+ * @param hashType 哈希方式,默认:'RSA-SHA256'
69
69
  * @param encoding 编码,默认:'base64'
70
- * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_PSS_PADDING
71
70
  * @returns
72
71
  */
73
- sign(data, hashType = 'sha256', encoding = 'base64', padding = crypto_1.default.constants.RSA_PKCS1_PSS_PADDING) {
74
- let signature = crypto_1.default.sign(hashType, Buffer.from(data), {
75
- key: this.privateKey,
76
- padding,
77
- });
78
- return signature.toString(encoding);
72
+ sign(data, hashType = 'RSA-SHA256', encoding = 'base64') {
73
+ return crypto_1.default
74
+ .createSign(hashType)
75
+ .update(data)
76
+ .sign(this.privateKey, encoding);
79
77
  }
80
78
  /**
81
79
  * 验证签名
82
80
  * @param signature 待验证签名字符串
83
81
  * @param data 待解密文本
84
- * @param hashType 哈希方式,默认:'sha256'
82
+ * @param hashType 哈希方式,默认:'RSA-SHA256'
85
83
  * @param encoding 编码,默认:'base64'
86
- * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_PSS_PADDING
87
84
  * @returns
88
85
  */
89
- verify(signature, data, hashType, encoding = 'base64', padding = crypto_1.default.constants.RSA_PKCS1_PSS_PADDING) {
90
- let isVerified = crypto_1.default.verify(hashType, Buffer.from(data), {
91
- key: this.publicKey,
92
- padding,
93
- }, Buffer.from(signature, encoding));
94
- return !!isVerified;
86
+ verify(signature, data, hashType = 'RSA-SHA256', encoding = 'base64') {
87
+ const verify = crypto_1.default.createVerify(hashType);
88
+ verify.update(data);
89
+ return verify.verify(this.publicKey, signature, encoding);
95
90
  }
96
91
  }
97
92
  ;
@@ -84,7 +84,7 @@ class Application {
84
84
  */
85
85
  getHttpClientDefaultOptions() {
86
86
  return (0, merge_1.default)(true, {
87
- baseURL: 'https://api.weixin.qq.com/',
87
+ baseURL: 'https://api.mch.weixin.qq.com',
88
88
  }, this.getConfig().get('http'));
89
89
  }
90
90
  }
@@ -34,7 +34,7 @@ class Signature {
34
34
  body = payload.data;
35
35
  }
36
36
  }
37
- let signString = `${method.toUpperCase()}\n${pathname}\n${timestamp}\n${nonce}\n${body}`;
37
+ let signString = `${method.toUpperCase()}\n${pathname}\n${timestamp}\n${nonce}\n${body}\n`;
38
38
  let rsa = new RSA_1.default;
39
39
  rsa.setPublicKey(this.merchant.getCertificate().getValue());
40
40
  rsa.setPrivateKey(this.merchant.getPrivateKey().getKey());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-easywechat",
3
- "version": "3.3.5",
3
+ "version": "3.3.6",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {