node-easywechat 3.5.4 → 3.5.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,16 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## v3.5.6 (2023-12-17)
5
+
6
+ - Fix: 修复获取代理公众号或小程序实例时,未设置配置项导致
7
+ - Fix: 修复响应结果类型判断异常导致结果解析错误的问题
8
+ - Fix: 修复开放平台服务端未自动处理ComponentVerifyTicket的问题
9
+
10
+ ## v3.5.5 (2023-12-02)
11
+
12
+ - Fix: 修复获取服务端实例时,没有获取到最新请求实例的问题 (#47)
13
+
4
14
  ## v3.5.4 (2023-11-15)
5
15
 
6
16
  - Fix: 修复生成支付参数中,时间戳类型错误 (#45)
@@ -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;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { IncomingMessage } from "http";
3
4
  import ServerRequestInterface from "./Contracts/ServerRequestInterface";
4
5
  import MessageMixin from "./Minxins/MessageMixin";
@@ -12,7 +12,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  const fs_1 = __importDefault(require("fs"));
15
- const merge_1 = __importDefault(require("merge"));
16
15
  const Utils_1 = require("../Support/Utils");
17
16
  class HttpClientResponse {
18
17
  constructor(response, failureJudge = null, throwError = false) {
@@ -46,7 +45,7 @@ class HttpClientResponse {
46
45
  return;
47
46
  }
48
47
  if (typeof content === 'string') {
49
- if (this.is('xml') && content.indexOf('<xml>') > -1) {
48
+ if (this.is('xml') || content.indexOf('<xml>') > -1) {
50
49
  this.parsedContent = yield (0, Utils_1.parseXml)(content);
51
50
  }
52
51
  else if (this.is('json')) {
@@ -59,7 +58,7 @@ class HttpClientResponse {
59
58
  }
60
59
  }
61
60
  }
62
- else if (this.is('text')) {
61
+ else {
63
62
  try {
64
63
  this.parsedContent = (0, Utils_1.parseQueryString)(content);
65
64
  }
@@ -67,6 +66,7 @@ class HttpClientResponse {
67
66
  if (throwError) {
68
67
  throw new Error('Fail to parse QueryString content.');
69
68
  }
69
+ this.parsedContent = {};
70
70
  }
71
71
  }
72
72
  }
@@ -216,13 +216,12 @@ class HttpClientResponse {
216
216
  return this.response.status;
217
217
  }
218
218
  getHeaders(throwError) {
219
- let headers = merge_1.default.recursive(true, this.response.headers);
220
219
  for (let key in this.response.headers) {
221
220
  if (key !== key.toLowerCase()) {
222
221
  this.response.headers[key.toLowerCase()] = this.response.headers[key];
223
222
  }
224
223
  }
225
- return headers;
224
+ return this.response.headers;
226
225
  }
227
226
  getContent(throwError) {
228
227
  return this.response.data;
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
2
4
  import { CipherGCMTypes, BinaryLike, CipherKey } from 'crypto';
3
5
  export declare class AES {
4
6
  /**
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import crypto, { BinaryToTextEncoding } from 'crypto';
3
4
  declare class RSA {
4
5
  protected publicKey: crypto.KeyObject;
@@ -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,18 @@ 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
+ }
104
+ if (this.server instanceof Server_1.default) {
105
+ this.server.withDefaultVerifyTicketHandler((message, next) => {
106
+ const ticket = this.getVerifyTicket();
107
+ if (typeof ticket.setTicket === 'function') {
108
+ ticket.setTicket(message.get('ComponentVerifyTicket'));
109
+ }
110
+ return next(message);
111
+ });
112
+ }
101
113
  return this.server;
102
114
  }
103
115
  /**
@@ -233,7 +245,7 @@ class Application {
233
245
  * @param config
234
246
  * @returns
235
247
  */
236
- getOfficialAccountWithRefreshToken(appId, refreshToken, config = null) {
248
+ getOfficialAccountWithRefreshToken(appId, refreshToken, config = {}) {
237
249
  return __awaiter(this, void 0, void 0, function* () {
238
250
  return this.getOfficialAccountWithAccessToken(appId, yield this.getAuthorizerAccessToken(appId, refreshToken), config);
239
251
  });
@@ -245,7 +257,7 @@ class Application {
245
257
  * @param config
246
258
  * @returns
247
259
  */
248
- getOfficialAccountWithAccessToken(appId, accessToken, config = null) {
260
+ getOfficialAccountWithAccessToken(appId, accessToken, config = {}) {
249
261
  return this.getOfficialAccount(new AuthorizerAccessToken_1.default(appId, accessToken), config);
250
262
  }
251
263
  /**
@@ -254,8 +266,10 @@ class Application {
254
266
  * @param config
255
267
  * @returns
256
268
  */
257
- getOfficialAccount(authorizerAccessToken, config = null) {
269
+ getOfficialAccount(authorizerAccessToken, config = {}) {
258
270
  if (!(config instanceof ConfigInterface_1.default)) {
271
+ if (typeof config !== 'object' || config === null)
272
+ config = {};
259
273
  config.app_id = authorizerAccessToken.getAppId();
260
274
  config.token = this.config.get('token');
261
275
  config.aes_key = this.config.get('aes_key');
@@ -299,7 +313,7 @@ class Application {
299
313
  * @param config
300
314
  * @returns
301
315
  */
302
- getMiniAppWithRefreshToken(appId, refreshToken, config = null) {
316
+ getMiniAppWithRefreshToken(appId, refreshToken, config = {}) {
303
317
  return __awaiter(this, void 0, void 0, function* () {
304
318
  return this.getMiniAppWithAccessToken(appId, yield this.getAuthorizerAccessToken(appId, refreshToken), config);
305
319
  });
@@ -311,7 +325,7 @@ class Application {
311
325
  * @param config
312
326
  * @returns
313
327
  */
314
- getMiniAppWithAccessToken(appId, accessToken, config = null) {
328
+ getMiniAppWithAccessToken(appId, accessToken, config = {}) {
315
329
  return this.getMiniApp(new AuthorizerAccessToken_1.default(appId, accessToken), config);
316
330
  }
317
331
  /**
@@ -320,8 +334,10 @@ class Application {
320
334
  * @param config
321
335
  * @returns
322
336
  */
323
- getMiniApp(authorizerAccessToken, config = null) {
337
+ getMiniApp(authorizerAccessToken, config = {}) {
324
338
  if (!(config instanceof ConfigInterface_1.default)) {
339
+ if (typeof config !== 'object' || config === null)
340
+ config = {};
325
341
  config.app_id = authorizerAccessToken.getAppId();
326
342
  config.token = this.config.get('token');
327
343
  config.aes_key = this.config.get('aes_key');
@@ -82,8 +82,8 @@ class Server extends ServerInterface_1.default {
82
82
  * @returns
83
83
  */
84
84
  withDefaultVerifyTicketHandler(handler) {
85
- this.defaultVerifyTicketHandler = () => {
86
- return handler.call(this, arguments);
85
+ this.defaultVerifyTicketHandler = function () {
86
+ return handler.apply(this, arguments);
87
87
  };
88
88
  this.handleVerifyTicketRefreshed(this.defaultVerifyTicketHandler);
89
89
  }
@@ -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
  /**
@@ -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.4",
3
+ "version": "3.5.6",
4
4
  "description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/node": "^17.0.23",
26
- "axios-mock-adapter": "^1.21.1",
26
+ "axios-mock-adapter": "^1.22.0",
27
27
  "mocha": "^9.2.2",
28
28
  "package-release": "^1.0.3",
29
29
  "typescript": "^4.6.3"