node-easywechat 3.7.0 → 3.7.2

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.
Files changed (56) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +7 -3
  3. package/dist/Channel/Application.js +1 -1
  4. package/dist/Core/Cache/FileCache.js +46 -63
  5. package/dist/Core/Contracts/AccessTokenInterface.js +2 -15
  6. package/dist/Core/Contracts/CacheInterface.js +4 -21
  7. package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +1 -12
  8. package/dist/Core/Contracts/ServerInterface.js +1 -12
  9. package/dist/Core/Http/ServerRequest.js +34 -49
  10. package/dist/Core/HttpClient/AccessTokenAwareClient.js +6 -17
  11. package/dist/Core/HttpClient/Contracts/HttpClientInterface.js +1 -12
  12. package/dist/Core/HttpClient/HttpClient.js +74 -85
  13. package/dist/Core/HttpClient/HttpClientResponse.js +35 -50
  14. package/dist/Core/HttpClient/Mixins/HttpClientMethodsMixin.js +34 -59
  15. package/dist/Core/HttpClient/Mixins/PresetMixin.js +8 -11
  16. package/dist/Core/Message.js +20 -31
  17. package/dist/Core/Mixins/DecryptMessageMixin.js +13 -24
  18. package/dist/Core/Mixins/HandlersMixin.js +18 -31
  19. package/dist/Core/Mixins/ResponseMessageMixin.js +31 -44
  20. package/dist/Core/Support/Utils.js +8 -19
  21. package/dist/MiniApp/Application.js +1 -1
  22. package/dist/MiniApp/Utils.js +13 -24
  23. package/dist/OfficialAccount/AccessToken.js +42 -59
  24. package/dist/OfficialAccount/Application.js +1 -1
  25. package/dist/OfficialAccount/JsApiTicket.js +31 -44
  26. package/dist/OfficialAccount/Server.d.ts +6 -0
  27. package/dist/OfficialAccount/Server.js +39 -42
  28. package/dist/OfficialAccount/Utils.js +6 -17
  29. package/dist/OpenPlatform/Application.js +62 -86
  30. package/dist/OpenPlatform/Authorizer/MiniApp/Utils.js +14 -25
  31. package/dist/OpenPlatform/AuthorizerAccessToken.js +6 -19
  32. package/dist/OpenPlatform/ComponentAccessToken.js +27 -42
  33. package/dist/OpenPlatform/Server.d.ts +1 -1
  34. package/dist/OpenPlatform/Server.js +34 -56
  35. package/dist/OpenPlatform/VerifyTicket.js +14 -27
  36. package/dist/OpenWork/Application.js +61 -84
  37. package/dist/OpenWork/AuthorizerAccessToken.js +32 -47
  38. package/dist/OpenWork/JsApiTicket.js +64 -81
  39. package/dist/OpenWork/ProviderAccessToken.js +26 -41
  40. package/dist/OpenWork/Server.js +54 -95
  41. package/dist/OpenWork/SuiteAccessToken.js +27 -42
  42. package/dist/OpenWork/SuiteTicket.js +14 -27
  43. package/dist/Pay/Application.js +1 -2
  44. package/dist/Pay/Client.js +63 -77
  45. package/dist/Pay/LegacySignature.js +2 -3
  46. package/dist/Pay/Merchant.js +36 -52
  47. package/dist/Pay/Server.js +55 -70
  48. package/dist/Pay/Utils.js +13 -26
  49. package/dist/Pay/Validator.js +28 -39
  50. package/dist/Work/AccessToken.js +26 -41
  51. package/dist/Work/Application.js +21 -32
  52. package/dist/Work/JsApiTicket.js +60 -77
  53. package/dist/Work/Server.js +51 -87
  54. package/dist/Work/Utils.js +12 -25
  55. package/package.json +1 -1
  56. package/tsconfig.json +2 -2
@@ -1,13 +1,4 @@
1
1
  'use strict';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -145,19 +136,17 @@ class Application {
145
136
  * @param authorizationCode
146
137
  * @returns
147
138
  */
148
- getAuthorization(authorizationCode) {
149
- return __awaiter(this, void 0, void 0, function* () {
150
- let response = (yield this.getClient().request('post', 'cgi-bin/component/api_query_auth', {
151
- json: {
152
- component_appid: this.getAccount().getAppId(),
153
- authorization_code: authorizationCode,
154
- }
155
- })).toObject();
156
- if (!response['authorization_info']) {
157
- throw new Error('Failed to get authorization_info: ' + JSON.stringify(response));
139
+ async getAuthorization(authorizationCode) {
140
+ let response = (await this.getClient().request('post', 'cgi-bin/component/api_query_auth', {
141
+ json: {
142
+ component_appid: this.getAccount().getAppId(),
143
+ authorization_code: authorizationCode,
158
144
  }
159
- return new Authorization_1.default(response);
160
- });
145
+ })).toObject();
146
+ if (!response['authorization_info']) {
147
+ throw new Error('Failed to get authorization_info: ' + JSON.stringify(response));
148
+ }
149
+ return new Authorization_1.default(response);
161
150
  }
162
151
  /**
163
152
  * 获取/刷新接口调用令牌
@@ -166,38 +155,34 @@ class Application {
166
155
  * @param authorizerRefreshToken
167
156
  * @returns
168
157
  */
169
- refreshAuthorizerToken(authorizerAppId, authorizerRefreshToken) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- let response = (yield this.getClient().request('post', 'cgi-bin/component/api_authorizer_token', {
172
- json: {
173
- component_appid: this.getAccount().getAppId(),
174
- authorizer_appid: authorizerAppId,
175
- authorizer_refresh_token: authorizerRefreshToken,
176
- }
177
- })).toObject();
178
- if (!response['authorizer_access_token']) {
179
- throw new Error('Failed to get authorizer_access_token: ' + JSON.stringify(response));
158
+ async refreshAuthorizerToken(authorizerAppId, authorizerRefreshToken) {
159
+ let response = (await this.getClient().request('post', 'cgi-bin/component/api_authorizer_token', {
160
+ json: {
161
+ component_appid: this.getAccount().getAppId(),
162
+ authorizer_appid: authorizerAppId,
163
+ authorizer_refresh_token: authorizerRefreshToken,
180
164
  }
181
- return response;
182
- });
165
+ })).toObject();
166
+ if (!response['authorizer_access_token']) {
167
+ throw new Error('Failed to get authorizer_access_token: ' + JSON.stringify(response));
168
+ }
169
+ return response;
183
170
  }
184
171
  /**
185
172
  * 获取预授权码
186
173
  * @see https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/token/pre_auth_code.html
187
174
  * @returns
188
175
  */
189
- createPreAuthorizationCode() {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- let response = (yield this.getClient().request('post', 'cgi-bin/component/api_create_preauthcode', {
192
- json: {
193
- component_appid: this.getAccount().getAppId(),
194
- }
195
- })).toObject();
196
- if (!response['pre_auth_code']) {
197
- throw new Error('Failed to get pre_auth_code: ' + JSON.stringify(response));
176
+ async createPreAuthorizationCode() {
177
+ let response = (await this.getClient().request('post', 'cgi-bin/component/api_create_preauthcode', {
178
+ json: {
179
+ component_appid: this.getAccount().getAppId(),
198
180
  }
199
- return response;
200
- });
181
+ })).toObject();
182
+ if (!response['pre_auth_code']) {
183
+ throw new Error('Failed to get pre_auth_code: ' + JSON.stringify(response));
184
+ }
185
+ return response;
201
186
  }
202
187
  /**
203
188
  * 生成授权页地址
@@ -205,24 +190,22 @@ class Application {
205
190
  * @param optional 预授权码,不传
206
191
  * @returns
207
192
  */
208
- createPreAuthorizationUrl(callbackUrl, optional) {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- if (typeof optional === 'string') {
211
- optional = {
212
- pre_auth_code: optional,
213
- };
214
- }
215
- else if (!optional || !optional['pre_auth_code']) {
216
- optional = {
217
- pre_auth_code: (yield this.createPreAuthorizationCode()).pre_auth_code,
218
- };
219
- }
220
- let queries = (0, merge_1.default)({
221
- component_appid: this.getAccount().getAppId(),
222
- redirect_uri: callbackUrl,
223
- }, optional);
224
- return `https://mp.weixin.qq.com/cgi-bin/componentloginpage?${(0, Utils_1.buildQueryString)(queries)}`;
225
- });
193
+ async createPreAuthorizationUrl(callbackUrl, optional) {
194
+ if (typeof optional === 'string') {
195
+ optional = {
196
+ pre_auth_code: optional,
197
+ };
198
+ }
199
+ else if (!optional || !optional['pre_auth_code']) {
200
+ optional = {
201
+ pre_auth_code: (await this.createPreAuthorizationCode()).pre_auth_code,
202
+ };
203
+ }
204
+ let queries = (0, merge_1.default)({
205
+ component_appid: this.getAccount().getAppId(),
206
+ redirect_uri: callbackUrl,
207
+ }, optional);
208
+ return `https://mp.weixin.qq.com/cgi-bin/componentloginpage?${(0, Utils_1.buildQueryString)(queries)}`;
226
209
  }
227
210
  getOAuth() {
228
211
  let oauthFactory = ((app) => {
@@ -245,10 +228,8 @@ class Application {
245
228
  * @param config
246
229
  * @returns
247
230
  */
248
- getOfficialAccountWithRefreshToken(appId_1, refreshToken_1) {
249
- return __awaiter(this, arguments, void 0, function* (appId, refreshToken, config = {}) {
250
- return this.getOfficialAccountWithAccessToken(appId, yield this.getAuthorizerAccessToken(appId, refreshToken), config);
251
- });
231
+ async getOfficialAccountWithRefreshToken(appId, refreshToken, config = {}) {
232
+ return this.getOfficialAccountWithAccessToken(appId, await this.getAuthorizerAccessToken(appId, refreshToken), config);
252
233
  }
253
234
  /**
254
235
  * 根据访问令牌获取公众号实例
@@ -313,10 +294,8 @@ class Application {
313
294
  * @param config
314
295
  * @returns
315
296
  */
316
- getMiniAppWithRefreshToken(appId_1, refreshToken_1) {
317
- return __awaiter(this, arguments, void 0, function* (appId, refreshToken, config = {}) {
318
- return this.getMiniAppWithAccessToken(appId, yield this.getAuthorizerAccessToken(appId, refreshToken), config);
319
- });
297
+ async getMiniAppWithRefreshToken(appId, refreshToken, config = {}) {
298
+ return this.getMiniAppWithAccessToken(appId, await this.getAuthorizerAccessToken(appId, refreshToken), config);
320
299
  }
321
300
  /**
322
301
  * 根据访问令牌获取小程序实例
@@ -361,23 +340,20 @@ class Application {
361
340
  * @param refreshToken
362
341
  * @returns
363
342
  */
364
- getAuthorizerAccessToken(appId, refreshToken) {
365
- return __awaiter(this, void 0, void 0, function* () {
366
- var _a;
367
- let md5RefreshToken = (0, Utils_1.createHash)(refreshToken, 'md5');
368
- let cacheKey = `open-platform.authorizer_access_token.${appId}.${md5RefreshToken}`;
369
- let cache = this.getCache();
370
- let authorizerAccessToken = yield cache.get(cacheKey);
371
- if (!authorizerAccessToken) {
372
- let response = yield this.refreshAuthorizerToken(appId, refreshToken);
373
- authorizerAccessToken = response['authorizer_access_token'];
374
- yield cache.set(cacheKey, authorizerAccessToken, ((_a = parseInt(response['expires_in'])) !== null && _a !== void 0 ? _a : 7200) - 500);
375
- }
376
- return authorizerAccessToken;
377
- });
343
+ async getAuthorizerAccessToken(appId, refreshToken) {
344
+ let md5RefreshToken = (0, Utils_1.createHash)(refreshToken, 'md5');
345
+ let cacheKey = `open-platform.authorizer_access_token.${appId}.${md5RefreshToken}`;
346
+ let cache = this.getCache();
347
+ let authorizerAccessToken = await cache.get(cacheKey);
348
+ if (!authorizerAccessToken) {
349
+ let response = await this.refreshAuthorizerToken(appId, refreshToken);
350
+ authorizerAccessToken = response['authorizer_access_token'];
351
+ await cache.set(cacheKey, authorizerAccessToken, (parseInt(response['expires_in']) ?? 7200) - 500);
352
+ }
353
+ return authorizerAccessToken;
378
354
  }
379
355
  createClient() {
380
- return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) => { var _a; return (_a = response.toObject()['errcode']) !== null && _a !== void 0 ? _a : 0; }, this.getConfig().get('http.throw', true)))
356
+ return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) => response.toObject()['errcode'] ?? 0, this.getConfig().get('http.throw', true)))
381
357
  .setPresets(this.getConfig().all());
382
358
  }
383
359
  /**
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -24,24 +15,22 @@ class Utils extends Utils_1.default {
24
15
  * @param code
25
16
  * @returns
26
17
  */
27
- code2Session(code) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- let client = this.app.getHttpClient();
30
- let response = yield client.request('GET', '/sns/component/jscode2session', {
31
- params: {
32
- component_access_token: yield this.app.getComponentApp().getAccessToken().getToken(),
33
- component_appid: this.app.getComponentApp().getAccount().getAppId(),
34
- appid: this.app.getAccount().getAppId(),
35
- js_code: code,
36
- grant_type: 'authorization_code',
37
- }
38
- });
39
- let data = response.toObject();
40
- if (!data['openid']) {
41
- throw new Error(`code2Session error: ${JSON.stringify(data)}`);
18
+ async code2Session(code) {
19
+ let client = this.app.getHttpClient();
20
+ let response = await client.request('GET', '/sns/component/jscode2session', {
21
+ params: {
22
+ component_access_token: await this.app.getComponentApp().getAccessToken().getToken(),
23
+ component_appid: this.app.getComponentApp().getAccount().getAppId(),
24
+ appid: this.app.getAccount().getAppId(),
25
+ js_code: code,
26
+ grant_type: 'authorization_code',
42
27
  }
43
- return data;
44
28
  });
29
+ let data = response.toObject();
30
+ if (!data['openid']) {
31
+ throw new Error(`code2Session error: ${JSON.stringify(data)}`);
32
+ }
33
+ return data;
45
34
  }
46
35
  }
47
36
  ;
@@ -1,13 +1,4 @@
1
1
  'use strict';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  class AuthorizerAccessToken {
12
3
  constructor(appId, accessToken) {
13
4
  this.appId = appId;
@@ -20,17 +11,13 @@ class AuthorizerAccessToken {
20
11
  getAppId() {
21
12
  return this.appId;
22
13
  }
23
- getToken() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- return this.accessToken;
26
- });
14
+ async getToken() {
15
+ return this.accessToken;
27
16
  }
28
- toQuery() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- return {
31
- 'access_token': yield this.getToken(),
32
- };
33
- });
17
+ async toQuery() {
18
+ return {
19
+ 'access_token': await this.getToken(),
20
+ };
34
21
  }
35
22
  /**
36
23
  * 转为字符串
@@ -1,13 +1,4 @@
1
1
  'use strict';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -45,42 +36,36 @@ class ComponentAccessToken {
45
36
  this.key = key;
46
37
  return this;
47
38
  }
48
- getToken() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- let token = '';
51
- if (this.cache) {
52
- token = yield this.cache.get(this.getKey());
53
- }
54
- if (!!token && typeof token === 'string') {
55
- return token;
56
- }
57
- return this.refresh();
58
- });
39
+ async getToken() {
40
+ let token = '';
41
+ if (this.cache) {
42
+ token = await this.cache.get(this.getKey());
43
+ }
44
+ if (!!token && typeof token === 'string') {
45
+ return token;
46
+ }
47
+ return this.refresh();
59
48
  }
60
- toQuery() {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return {
63
- component_access_token: yield this.getToken(),
64
- };
65
- });
49
+ async toQuery() {
50
+ return {
51
+ component_access_token: await this.getToken(),
52
+ };
66
53
  }
67
- refresh() {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- let response = (yield this.httpClient.request('post', 'cgi-bin/component/api_component_token', {
70
- data: {
71
- component_appid: this.appId,
72
- component_appsecret: this.secret,
73
- component_verify_ticket: yield this.verifyTicket.getTicket(),
74
- }
75
- })).toObject();
76
- if (!response['component_access_token']) {
77
- throw new Error('Failed to get component_access_token: ' + JSON.stringify(response));
78
- }
79
- if (this.cache) {
80
- yield this.cache.set(this.getKey(), response['component_access_token'], parseInt(response['expires_in']) - 100);
54
+ async refresh() {
55
+ let response = (await this.httpClient.request('post', 'cgi-bin/component/api_component_token', {
56
+ data: {
57
+ component_appid: this.appId,
58
+ component_appsecret: this.secret,
59
+ component_verify_ticket: await this.verifyTicket.getTicket(),
81
60
  }
82
- return response['component_access_token'];
83
- });
61
+ })).toObject();
62
+ if (!response['component_access_token']) {
63
+ throw new Error('Failed to get component_access_token: ' + JSON.stringify(response));
64
+ }
65
+ if (this.cache) {
66
+ await this.cache.set(this.getKey(), response['component_access_token'], parseInt(response['expires_in']) - 100);
67
+ }
68
+ return response['component_access_token'];
84
69
  }
85
70
  }
86
71
  module.exports = ComponentAccessToken;
@@ -50,7 +50,7 @@ declare class Server extends ServerInterface {
50
50
  * @returns
51
51
  */
52
52
  handleThirdFastRegister(handler: ServerHandlerClosure<Message>): this;
53
- protected decryptRequestMessage(): ServerHandlerClosure<Message>;
53
+ protected decryptRequestMessage(query: Record<string, any>): ServerHandlerClosure<Message>;
54
54
  /**
55
55
  * 获取来自微信服务器的推送消息
56
56
  * @param request 未设置该参数时,则从当前服务端收到的请求中获取
@@ -1,13 +1,4 @@
1
1
  'use strict';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -25,20 +16,21 @@ class Server extends ServerInterface_1.default {
25
16
  * 服务端消息处理
26
17
  * @returns
27
18
  */
28
- serve() {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- let echostr = this.request.getQueryParams()['echostr'] || '';
31
- if (!!echostr) {
32
- return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
33
- }
34
- let message = yield this.getRequestMessage(this.request);
35
- this.prepend(this.decryptRequestMessage());
36
- let response = yield this.handle(new Response_1.default(200, {}, 'success'), message);
37
- if (!(response instanceof Response_1.default)) {
38
- response = yield this.transformToReply(response, message, this.encryptor);
39
- }
40
- return response;
41
- });
19
+ async serve() {
20
+ let query = this.request.getQueryParams();
21
+ let echostr = query['echostr'] || '';
22
+ if (!!echostr) {
23
+ return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
24
+ }
25
+ let message = await this.getRequestMessage(this.request);
26
+ if (this.encryptor && query['msg_signature']) {
27
+ this.prepend(this.decryptRequestMessage(query));
28
+ }
29
+ let response = await this.handle(new Response_1.default(200, {}, 'success'), message);
30
+ if (!(response instanceof Response_1.default)) {
31
+ response = await this.transformToReply(response, message, this.encryptor);
32
+ }
33
+ return response;
42
34
  }
43
35
  /**
44
36
  * 处理授权成功通知
@@ -46,10 +38,8 @@ class Server extends ServerInterface_1.default {
46
38
  * @returns
47
39
  */
48
40
  handleAuthorized(handler) {
49
- return this.with(function (message, next) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- return message.InfoType === 'authorized' ? handler(message, next) : next(message);
52
- });
41
+ return this.with(async function (message, next) {
42
+ return message.InfoType === 'authorized' ? handler(message, next) : next(message);
53
43
  });
54
44
  }
55
45
  /**
@@ -58,10 +48,8 @@ class Server extends ServerInterface_1.default {
58
48
  * @returns
59
49
  */
60
50
  handleUnauthorized(handler) {
61
- return this.with(function (message, next) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- return message.InfoType === 'unauthorized' ? handler(message, next) : next(message);
64
- });
51
+ return this.with(async function (message, next) {
52
+ return message.InfoType === 'unauthorized' ? handler(message, next) : next(message);
65
53
  });
66
54
  }
67
55
  /**
@@ -70,10 +58,8 @@ class Server extends ServerInterface_1.default {
70
58
  * @returns
71
59
  */
72
60
  handleAuthorizeUpdated(handler) {
73
- return this.with(function (message, next) {
74
- return __awaiter(this, void 0, void 0, function* () {
75
- return message.InfoType === 'updateauthorized' ? handler(message, next) : next(message);
76
- });
61
+ return this.with(async function (message, next) {
62
+ return message.InfoType === 'updateauthorized' ? handler(message, next) : next(message);
77
63
  });
78
64
  }
79
65
  /**
@@ -96,10 +82,8 @@ class Server extends ServerInterface_1.default {
96
82
  if (this.defaultVerifyTicketHandler) {
97
83
  this.withoutHandler(this.defaultVerifyTicketHandler);
98
84
  }
99
- return this.with(function (message, next) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- return message.InfoType === 'component_verify_ticket' ? handler(message, next) : next(message);
102
- });
85
+ return this.with(async function (message, next) {
86
+ return message.InfoType === 'component_verify_ticket' ? handler(message, next) : next(message);
103
87
  });
104
88
  }
105
89
  /**
@@ -108,18 +92,15 @@ class Server extends ServerInterface_1.default {
108
92
  * @returns
109
93
  */
110
94
  handleThirdFastRegister(handler) {
111
- return this.with(function (message, next) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- return message.InfoType === 'notify_third_fasteregister' ? handler(message, next) : next(message);
114
- });
95
+ return this.with(async function (message, next) {
96
+ return message.InfoType === 'notify_third_fasteregister' ? handler(message, next) : next(message);
115
97
  });
116
98
  }
117
- decryptRequestMessage() {
118
- let query = this.request.getQueryParams();
119
- return (message, next) => __awaiter(this, void 0, void 0, function* () {
120
- yield this.decryptMessage(message, this.encryptor, query['msg_signature'] || '', query['timestamp'] || '', query['nonce'] || '');
99
+ decryptRequestMessage(query) {
100
+ return async (message, next) => {
101
+ message = await this.decryptMessage(message, this.encryptor, query['msg_signature'] || '', query['timestamp'] || '', query['nonce'] || '');
121
102
  return next(message);
122
- });
103
+ };
123
104
  }
124
105
  /**
125
106
  * 获取来自微信服务器的推送消息
@@ -134,14 +115,11 @@ class Server extends ServerInterface_1.default {
134
115
  * @param request 未设置该参数时,则从当前服务端收到的请求中获取
135
116
  * @returns
136
117
  */
137
- getDecryptedMessage() {
138
- return __awaiter(this, arguments, void 0, function* (request = null) {
139
- if (!request)
140
- request = this.request;
141
- let message = yield Message_1.default.createFromRequest(request);
142
- let query = request.getQueryParams();
143
- return this.decryptMessage(message, this.encryptor, query['msg_signature'] || '', query['timestamp'] || '', query['nonce'] || '');
144
- });
118
+ async getDecryptedMessage(request = null) {
119
+ request = request ?? this.request;
120
+ let message = await this.getRequestMessage(request);
121
+ let query = request.getQueryParams();
122
+ return this.decryptMessage(message, this.encryptor, query['msg_signature'] || '', query['timestamp'] || '', query['nonce'] || '');
145
123
  }
146
124
  }
147
125
  ;
@@ -1,13 +1,4 @@
1
1
  'use strict';
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  class VerifyTicket {
12
3
  constructor(appId, key = null, cache = null) {
13
4
  this.appId = appId;
@@ -24,25 +15,21 @@ class VerifyTicket {
24
15
  this.key = key;
25
16
  return this;
26
17
  }
27
- setTicket(ticket) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- if (this.cache) {
30
- yield this.cache.set(this.getKey(), ticket, 6000);
31
- }
32
- return this;
33
- });
18
+ async setTicket(ticket) {
19
+ if (this.cache) {
20
+ await this.cache.set(this.getKey(), ticket, 6000);
21
+ }
22
+ return this;
34
23
  }
35
- getTicket() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- let ticket = '';
38
- if (this.cache) {
39
- ticket = yield this.cache.get(this.getKey());
40
- }
41
- if (!ticket || typeof ticket != 'string') {
42
- throw new Error('No component_verify_ticket found.');
43
- }
44
- return ticket;
45
- });
24
+ async getTicket() {
25
+ let ticket = '';
26
+ if (this.cache) {
27
+ ticket = await this.cache.get(this.getKey());
28
+ }
29
+ if (!ticket || typeof ticket != 'string') {
30
+ throw new Error('No component_verify_ticket found.');
31
+ }
32
+ return ticket;
46
33
  }
47
34
  }
48
35
  ;