node-easywechat 3.3.4 → 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,14 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.3.6 (2023-05-12)
5
+
6
+ - Fix: 修复微信支付v3签名错误
7
+
8
+ ## v3.3.5 (2023-04-28)
9
+
10
+ - Fix: 修复部分接口请求方式及请求参数设置方式异常的问题
11
+
4
12
  ## v3.3.4 (2023-04-23)
5
13
 
6
14
  - Fix: 更新依赖包node-socialite
@@ -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
  ;
@@ -136,7 +136,7 @@ class Application {
136
136
  getAuthorization(authorizationCode) {
137
137
  return __awaiter(this, void 0, void 0, function* () {
138
138
  let response = (yield this.getClient().request('post', 'cgi-bin/component/api_query_auth', {
139
- params: {
139
+ json: {
140
140
  component_appid: this.getAccount().getAppId(),
141
141
  authorization_code: authorizationCode,
142
142
  }
@@ -157,7 +157,7 @@ class Application {
157
157
  refreshAuthorizerToken(authorizerAppId, authorizerRefreshToken) {
158
158
  return __awaiter(this, void 0, void 0, function* () {
159
159
  let response = (yield this.getClient().request('post', 'cgi-bin/component/api_authorizer_token', {
160
- params: {
160
+ json: {
161
161
  component_appid: this.getAccount().getAppId(),
162
162
  authorizer_appid: authorizerAppId,
163
163
  authorizer_refresh_token: authorizerRefreshToken,
@@ -177,7 +177,7 @@ class Application {
177
177
  createPreAuthorizationCode() {
178
178
  return __awaiter(this, void 0, void 0, function* () {
179
179
  let response = (yield this.getClient().request('post', 'cgi-bin/component/api_create_preauthcode', {
180
- params: {
180
+ json: {
181
181
  component_appid: this.getAccount().getAppId(),
182
182
  }
183
183
  })).toObject();
@@ -67,7 +67,7 @@ class ComponentAccessToken {
67
67
  refresh() {
68
68
  return __awaiter(this, void 0, void 0, function* () {
69
69
  let response = (yield this.httpClient.request('post', 'cgi-bin/component/api_component_token', {
70
- params: {
70
+ data: {
71
71
  component_appid: this.appId,
72
72
  component_appsecret: this.secret,
73
73
  component_verify_ticket: yield this.verifyTicket.getTicket(),
@@ -210,7 +210,7 @@ class Application {
210
210
  return __awaiter(this, void 0, void 0, function* () {
211
211
  if (!suiteAccessToken)
212
212
  suiteAccessToken = this.getSuiteAccessToken();
213
- let response = (yield this.getClient().request('post', 'cgi-bin/service/get_pre_auth_code', {
213
+ let response = (yield this.getClient().request('get', 'cgi-bin/service/get_pre_auth_code', {
214
214
  params: {
215
215
  suite_access_token: yield suiteAccessToken.getToken(),
216
216
  }
@@ -67,7 +67,7 @@ class SuiteAccessToken {
67
67
  refresh() {
68
68
  return __awaiter(this, void 0, void 0, function* () {
69
69
  let response = (yield this.httpClient.request('post', 'cgi-bin/service/get_suite_token', {
70
- params: {
70
+ json: {
71
71
  suite_id: this.suiteId,
72
72
  suite_secret: this.suiteSecret,
73
73
  suite_ticket: yield this.suiteTicket.getTicket(),
@@ -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.4",
3
+ "version": "3.3.6",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {