node-easywechat 3.7.0 → 3.7.1

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 (53) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/Channel/Application.js +1 -1
  3. package/dist/Core/Cache/FileCache.js +46 -63
  4. package/dist/Core/Contracts/AccessTokenInterface.js +2 -15
  5. package/dist/Core/Contracts/CacheInterface.js +4 -21
  6. package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +1 -12
  7. package/dist/Core/Contracts/ServerInterface.js +1 -12
  8. package/dist/Core/Http/ServerRequest.js +34 -49
  9. package/dist/Core/HttpClient/AccessTokenAwareClient.js +6 -17
  10. package/dist/Core/HttpClient/Contracts/HttpClientInterface.js +1 -12
  11. package/dist/Core/HttpClient/HttpClient.js +74 -85
  12. package/dist/Core/HttpClient/HttpClientResponse.js +35 -50
  13. package/dist/Core/HttpClient/Mixins/HttpClientMethodsMixin.js +34 -59
  14. package/dist/Core/HttpClient/Mixins/PresetMixin.js +8 -11
  15. package/dist/Core/Message.js +20 -31
  16. package/dist/Core/Mixins/DecryptMessageMixin.js +13 -24
  17. package/dist/Core/Mixins/HandlersMixin.js +18 -31
  18. package/dist/Core/Mixins/ResponseMessageMixin.js +31 -44
  19. package/dist/Core/Support/Utils.js +8 -19
  20. package/dist/MiniApp/Application.js +1 -1
  21. package/dist/MiniApp/Utils.js +13 -24
  22. package/dist/OfficialAccount/AccessToken.js +42 -59
  23. package/dist/OfficialAccount/Application.js +1 -1
  24. package/dist/OfficialAccount/JsApiTicket.js +31 -44
  25. package/dist/OfficialAccount/Server.js +25 -40
  26. package/dist/OfficialAccount/Utils.js +6 -17
  27. package/dist/OpenPlatform/Application.js +62 -86
  28. package/dist/OpenPlatform/Authorizer/MiniApp/Utils.js +14 -25
  29. package/dist/OpenPlatform/AuthorizerAccessToken.js +6 -19
  30. package/dist/OpenPlatform/ComponentAccessToken.js +27 -42
  31. package/dist/OpenPlatform/Server.js +31 -54
  32. package/dist/OpenPlatform/VerifyTicket.js +14 -27
  33. package/dist/OpenWork/Application.js +61 -84
  34. package/dist/OpenWork/AuthorizerAccessToken.js +32 -47
  35. package/dist/OpenWork/JsApiTicket.js +64 -81
  36. package/dist/OpenWork/ProviderAccessToken.js +26 -41
  37. package/dist/OpenWork/Server.js +50 -94
  38. package/dist/OpenWork/SuiteAccessToken.js +27 -42
  39. package/dist/OpenWork/SuiteTicket.js +14 -27
  40. package/dist/Pay/Application.js +1 -2
  41. package/dist/Pay/Client.js +63 -77
  42. package/dist/Pay/LegacySignature.js +2 -3
  43. package/dist/Pay/Merchant.js +36 -52
  44. package/dist/Pay/Server.js +55 -70
  45. package/dist/Pay/Utils.js +13 -26
  46. package/dist/Pay/Validator.js +28 -39
  47. package/dist/Work/AccessToken.js +26 -41
  48. package/dist/Work/Application.js +21 -32
  49. package/dist/Work/JsApiTicket.js +60 -77
  50. package/dist/Work/Server.js +47 -86
  51. package/dist/Work/Utils.js +12 -25
  52. package/package.json +1 -1
  53. package/tsconfig.json +2 -2
package/dist/Pay/Utils.js CHANGED
@@ -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
  };
@@ -23,14 +14,12 @@ class Utils {
23
14
  * 获取加密所用的平台证书
24
15
  * @returns
25
16
  */
26
- getPlatformCert() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- let certs = yield this.merchant.getPlatformCerts();
29
- if (!certs || Object.keys(certs).length === 0) {
30
- throw new Error('Fail to get platform certs');
31
- }
32
- return certs[Object.keys(certs)[0]];
33
- });
17
+ async getPlatformCert() {
18
+ let certs = await this.merchant.getPlatformCerts();
19
+ if (!certs || Object.keys(certs).length === 0) {
20
+ throw new Error('Fail to get platform certs');
21
+ }
22
+ return certs[Object.keys(certs)[0]];
34
23
  }
35
24
  /**
36
25
  * 获取敏感信息加密机
@@ -38,15 +27,13 @@ class Utils {
38
27
  * @param platformCert PublicKey封装过的平台证书
39
28
  * @returns
40
29
  */
41
- getEncryptor() {
42
- return __awaiter(this, arguments, void 0, function* (platformCert = null) {
43
- if (!platformCert || !(platformCert instanceof PublicKey_1.PublicKey)) {
44
- platformCert = yield this.getPlatformCert();
45
- }
46
- let encryptor = new Encryptor_1.default;
47
- encryptor.setCerts(platformCert, this.merchant.getPrivateKey());
48
- return encryptor;
49
- });
30
+ async getEncryptor(platformCert = null) {
31
+ if (!platformCert || !(platformCert instanceof PublicKey_1.PublicKey)) {
32
+ platformCert = await this.getPlatformCert();
33
+ }
34
+ let encryptor = new Encryptor_1.default;
35
+ encryptor.setCerts(platformCert, this.merchant.getPrivateKey());
36
+ return encryptor;
50
37
  }
51
38
  /**
52
39
  * 创建签名(V3),并返回签名字符串
@@ -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
  };
@@ -18,38 +9,36 @@ class Validator {
18
9
  constructor(merchant) {
19
10
  this.merchant = merchant;
20
11
  }
21
- validate(request) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- [
24
- Validator.HEADER_TIMESTAMP,
25
- Validator.HEADER_NONCE,
26
- Validator.HEADER_SERIAL,
27
- Validator.HEADER_SIGNATURE,
28
- ].forEach(key => {
29
- if (!request.hasHeader(key)) {
30
- throw new Error(`Missing Header: ${key}`);
31
- }
32
- });
33
- let timestamp = request.getHeader(Validator.HEADER_TIMESTAMP) || '';
34
- let nonce = request.getHeader(Validator.HEADER_NONCE) || '';
35
- let serial = request.getHeader(Validator.HEADER_SERIAL) || '';
36
- let signature = request.getHeader(Validator.HEADER_SIGNATURE) || '';
37
- let body = request.getBody().toString();
38
- let message = `${timestamp}\n${nonce}\n${body}\n`;
39
- if ((0, Utils_1.getTimestamp)() - parseInt(timestamp) > Validator.MAX_ALLOWED_CLOCK_OFFSET) {
40
- throw new Error('Clock Offset Exceeded');
41
- }
42
- let publicKey = yield this.merchant.getPlatformCert(serial);
43
- if (!publicKey) {
44
- throw new Error(`No platform certs found for serial: ${serial}, please download from wechat pay and set it in merchant config with key \`platform_certs\`.`);
12
+ async validate(request) {
13
+ [
14
+ Validator.HEADER_TIMESTAMP,
15
+ Validator.HEADER_NONCE,
16
+ Validator.HEADER_SERIAL,
17
+ Validator.HEADER_SIGNATURE,
18
+ ].forEach(key => {
19
+ if (!request.hasHeader(key)) {
20
+ throw new Error(`Missing Header: ${key}`);
45
21
  }
46
- let rsa = new RSA_1.default;
47
- rsa.setPublicKey(publicKey.getValue());
48
- if (false === rsa.verify(signature, message)) {
49
- throw new Error('Invalid Signature');
50
- }
51
- return true;
52
22
  });
23
+ let timestamp = request.getHeader(Validator.HEADER_TIMESTAMP) || '';
24
+ let nonce = request.getHeader(Validator.HEADER_NONCE) || '';
25
+ let serial = request.getHeader(Validator.HEADER_SERIAL) || '';
26
+ let signature = request.getHeader(Validator.HEADER_SIGNATURE) || '';
27
+ let body = request.getBody().toString();
28
+ let message = `${timestamp}\n${nonce}\n${body}\n`;
29
+ if ((0, Utils_1.getTimestamp)() - parseInt(timestamp) > Validator.MAX_ALLOWED_CLOCK_OFFSET) {
30
+ throw new Error('Clock Offset Exceeded');
31
+ }
32
+ let publicKey = await this.merchant.getPlatformCert(serial);
33
+ if (!publicKey) {
34
+ throw new Error(`No platform certs found for serial: ${serial}, please download from wechat pay and set it in merchant config with key \`platform_certs\`.`);
35
+ }
36
+ let rsa = new RSA_1.default;
37
+ rsa.setPublicKey(publicKey.getValue());
38
+ if (false === rsa.verify(signature, message)) {
39
+ throw new Error('Invalid Signature');
40
+ }
41
+ return true;
53
42
  }
54
43
  validateV2(message) {
55
44
  let messageSign = (message.get('sign') + '' || '').toUpperCase();
@@ -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
  };
@@ -44,41 +35,35 @@ class AccessToken {
44
35
  this.key = key;
45
36
  return this;
46
37
  }
47
- getToken() {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- let token = '';
50
- if (this.cache) {
51
- token = yield this.cache.get(this.getKey());
52
- }
53
- if (!!token && typeof token === 'string') {
54
- return token;
55
- }
56
- return this.refresh();
57
- });
38
+ async getToken() {
39
+ let token = '';
40
+ if (this.cache) {
41
+ token = await this.cache.get(this.getKey());
42
+ }
43
+ if (!!token && typeof token === 'string') {
44
+ return token;
45
+ }
46
+ return this.refresh();
58
47
  }
59
- toQuery() {
60
- return __awaiter(this, void 0, void 0, function* () {
61
- return {
62
- access_token: yield this.getToken(),
63
- };
64
- });
48
+ async toQuery() {
49
+ return {
50
+ access_token: await this.getToken(),
51
+ };
65
52
  }
66
- refresh() {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- let response = (yield this.httpClient.request('get', 'cgi-bin/gettoken', {
69
- params: {
70
- corpid: this.corpId,
71
- corpsecret: this.secret,
72
- }
73
- })).toObject();
74
- if (!response['access_token']) {
75
- throw new Error('Failed to get access_token: ' + JSON.stringify(response));
76
- }
77
- if (this.cache) {
78
- yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
53
+ async refresh() {
54
+ let response = (await this.httpClient.request('get', 'cgi-bin/gettoken', {
55
+ params: {
56
+ corpid: this.corpId,
57
+ corpsecret: this.secret,
79
58
  }
80
- return response['access_token'];
81
- });
59
+ })).toObject();
60
+ if (!response['access_token']) {
61
+ throw new Error('Failed to get access_token: ' + JSON.stringify(response));
62
+ }
63
+ if (this.cache) {
64
+ await this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
65
+ }
66
+ return response['access_token'];
82
67
  }
83
68
  }
84
69
  module.exports = AccessToken;
@@ -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
  };
@@ -119,29 +110,27 @@ class Application {
119
110
  this.oauthFactory = oauthFactory;
120
111
  return this;
121
112
  }
122
- getOAuth() {
123
- return __awaiter(this, void 0, void 0, function* () {
124
- if (!this.oauthFactory) {
125
- this.oauthFactory = ((app) => {
126
- return new WeWork_1.default({
127
- client_id: app.getAccount().getCorpId(),
128
- client_secret: app.getAccount().getSecret(),
129
- redirect: app.getConfig().get('oauth.redirect_url'),
130
- });
113
+ async getOAuth() {
114
+ if (!this.oauthFactory) {
115
+ this.oauthFactory = ((app) => {
116
+ return new WeWork_1.default({
117
+ client_id: app.getAccount().getCorpId(),
118
+ client_secret: app.getAccount().getSecret(),
119
+ redirect: app.getConfig().get('oauth.redirect_url'),
131
120
  });
132
- }
133
- let provider = this.oauthFactory.call(null, this);
134
- if (!(provider instanceof WeWork_1.default)) {
135
- throw new Error(`The factory must return a \`ProviderInterface\` instance.`);
136
- }
137
- provider.withApiAccessToken(yield this.getAccessToken().getToken());
138
- provider.scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
139
- let agent_id = parseInt(this.config.get('agent_id')) || null;
140
- if (agent_id) {
141
- provider.setAgentId(agent_id);
142
- }
143
- return provider;
144
- });
121
+ });
122
+ }
123
+ let provider = this.oauthFactory.call(null, this);
124
+ if (!(provider instanceof WeWork_1.default)) {
125
+ throw new Error(`The factory must return a \`ProviderInterface\` instance.`);
126
+ }
127
+ provider.withApiAccessToken(await this.getAccessToken().getToken());
128
+ provider.scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
129
+ let agent_id = parseInt(this.config.get('agent_id')) || null;
130
+ if (agent_id) {
131
+ provider.setAgentId(agent_id);
132
+ }
133
+ return provider;
145
134
  }
146
135
  getTicket() {
147
136
  if (!this.ticket) {
@@ -172,7 +161,7 @@ class Application {
172
161
  return this.utils;
173
162
  }
174
163
  createClient() {
175
- 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)))
164
+ return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) => response.toObject()['errcode'] ?? 0, this.getConfig().get('http.throw', true)))
176
165
  .setPresets(this.getConfig().all());
177
166
  }
178
167
  /**
@@ -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
  };
@@ -32,25 +23,23 @@ class JsApiTicket extends AccessToken_1.default {
32
23
  * 获取签名凭证jsapi_ticket
33
24
  * @returns
34
25
  */
35
- getTicket() {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- let key = this.getKey();
38
- let ticket = '';
39
- if (this.cache) {
40
- ticket = yield this.cache.get(key);
41
- }
42
- if (!!ticket && typeof ticket === 'string') {
43
- return ticket;
44
- }
45
- let response = (yield this.httpClient.request('get', '/cgi-bin/get_jsapi_ticket', {})).toObject();
46
- if (!response['ticket']) {
47
- throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
48
- }
49
- if (this.cache) {
50
- yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
51
- }
52
- return response['ticket'];
53
- });
26
+ async getTicket() {
27
+ let key = this.getKey();
28
+ let ticket = '';
29
+ if (this.cache) {
30
+ ticket = await this.cache.get(key);
31
+ }
32
+ if (!!ticket && typeof ticket === 'string') {
33
+ return ticket;
34
+ }
35
+ let response = (await this.httpClient.request('get', '/cgi-bin/get_jsapi_ticket', {})).toObject();
36
+ if (!response['ticket']) {
37
+ throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
38
+ }
39
+ if (this.cache) {
40
+ await this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
41
+ }
42
+ return response['ticket'];
54
43
  }
55
44
  /**
56
45
  * 获取签名配置
@@ -59,19 +48,17 @@ class JsApiTicket extends AccessToken_1.default {
59
48
  * @param timestamp 时间长,默认:当前时间
60
49
  * @returns
61
50
  */
62
- createConfigSignature(url_1) {
63
- return __awaiter(this, arguments, void 0, function* (url, nonce = null, timestamp = null) {
64
- nonce = nonce || (0, Utils_1.randomString)(10);
65
- timestamp = timestamp || (0, Utils_1.getTimestamp)();
66
- let ticket = yield this.getTicket();
67
- return {
68
- url,
69
- nonceStr: nonce,
70
- timestamp,
71
- appId: this.corpId,
72
- signature: this.getTicketSignature(ticket, nonce, timestamp, url),
73
- };
74
- });
51
+ async createConfigSignature(url, nonce = null, timestamp = null) {
52
+ nonce = nonce || (0, Utils_1.randomString)(10);
53
+ timestamp = timestamp || (0, Utils_1.getTimestamp)();
54
+ let ticket = await this.getTicket();
55
+ return {
56
+ url,
57
+ nonceStr: nonce,
58
+ timestamp,
59
+ appId: this.corpId,
60
+ signature: this.getTicketSignature(ticket, nonce, timestamp, url),
61
+ };
75
62
  }
76
63
  getTicketSignature(ticket, nonce, timestamp, url) {
77
64
  return (0, Utils_1.createHash)(`jsapi_ticket=${ticket}&noncestr=${nonce}&timestamp=${timestamp}&url=${url}`, 'sha1');
@@ -84,49 +71,45 @@ class JsApiTicket extends AccessToken_1.default {
84
71
  * @param timestamp 时间长,默认:当前时间
85
72
  * @returns
86
73
  */
87
- createAgentConfigSignature(agentId_1, url_1) {
88
- return __awaiter(this, arguments, void 0, function* (agentId, url, nonce = null, timestamp = null) {
89
- nonce = nonce || (0, Utils_1.randomString)(10);
90
- timestamp = timestamp || (0, Utils_1.getTimestamp)();
91
- let ticket = yield this.getTicket();
92
- return {
93
- corpid: this.corpId,
94
- agentid: agentId,
95
- url,
96
- nonceStr: nonce,
97
- timestamp,
98
- signature: this.getTicketSignature(ticket, nonce, timestamp, url),
99
- };
100
- });
74
+ async createAgentConfigSignature(agentId, url, nonce = null, timestamp = null) {
75
+ nonce = nonce || (0, Utils_1.randomString)(10);
76
+ timestamp = timestamp || (0, Utils_1.getTimestamp)();
77
+ let ticket = await this.getTicket();
78
+ return {
79
+ corpid: this.corpId,
80
+ agentid: agentId,
81
+ url,
82
+ nonceStr: nonce,
83
+ timestamp,
84
+ signature: this.getTicketSignature(ticket, nonce, timestamp, url),
85
+ };
101
86
  }
102
87
  /**
103
88
  * 获取代理应用的签名凭证jsapi_ticket
104
89
  * @param agentId 代理应用的id
105
90
  * @returns
106
91
  */
107
- getAgentTicket(agentId) {
108
- return __awaiter(this, void 0, void 0, function* () {
109
- let key = this.getAgentKey(agentId);
110
- let ticket = '';
111
- if (this.cache) {
112
- ticket = yield this.cache.get(key);
113
- }
114
- if (!!ticket && typeof ticket === 'string') {
115
- return ticket;
116
- }
117
- let response = (yield this.httpClient.request('get', '/cgi-bin/ticket/get', {
118
- params: {
119
- type: 'agent_config',
120
- }
121
- })).toObject();
122
- if (!response['ticket']) {
123
- throw new Error('Failed to get jssdk agentTicket: ' + JSON.stringify(response));
124
- }
125
- if (this.cache) {
126
- yield this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
92
+ async getAgentTicket(agentId) {
93
+ let key = this.getAgentKey(agentId);
94
+ let ticket = '';
95
+ if (this.cache) {
96
+ ticket = await this.cache.get(key);
97
+ }
98
+ if (!!ticket && typeof ticket === 'string') {
99
+ return ticket;
100
+ }
101
+ let response = (await this.httpClient.request('get', '/cgi-bin/ticket/get', {
102
+ params: {
103
+ type: 'agent_config',
127
104
  }
128
- return response['ticket'];
129
- });
105
+ })).toObject();
106
+ if (!response['ticket']) {
107
+ throw new Error('Failed to get jssdk agentTicket: ' + JSON.stringify(response));
108
+ }
109
+ if (this.cache) {
110
+ await this.cache.set(key, response['ticket'], parseInt(response['expires_in']));
111
+ }
112
+ return response['ticket'];
130
113
  }
131
114
  /**
132
115
  * 获取代理应用的jsapi_ticket的缓存名称