node-easywechat 3.0.0-beta.3 → 3.0.0

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 (64) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +36 -1
  3. package/dist/Core/Contracts/RefreshableAccessTokenInterface.d.ts +2 -2
  4. package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +2 -2
  5. package/dist/Core/Http/Minxins/MessageMixin.js +1 -2
  6. package/dist/Core/Http/ServerRequest.d.ts +1 -1
  7. package/dist/Core/Http/ServerRequest.js +16 -6
  8. package/dist/Core/HttpClient/HttpClient.d.ts +7 -0
  9. package/dist/Core/HttpClient/HttpClient.js +43 -7
  10. package/dist/Core/HttpClient/HttpClientResponse.d.ts +16 -5
  11. package/dist/Core/HttpClient/HttpClientResponse.js +64 -22
  12. package/dist/Core/HttpClient/Mixins/PresetMixin.d.ts +20 -1
  13. package/dist/Core/HttpClient/Mixins/PresetMixin.js +41 -2
  14. package/dist/Core/Message.d.ts +0 -127
  15. package/dist/Core/Message.js +5 -1
  16. package/dist/Core/Mixins/DecryptXmlMessageMixin.js +1 -1
  17. package/dist/Core/Mixins/ResponseXmlMessageMixin.js +2 -2
  18. package/dist/Core/Support/PrivateKey.d.ts +20 -0
  19. package/dist/Core/Support/PrivateKey.js +38 -0
  20. package/dist/Core/Support/PublicKey.d.ts +14 -0
  21. package/dist/Core/Support/PublicKey.js +36 -0
  22. package/dist/Core/Support/RSA.d.ts +2 -2
  23. package/dist/Core/Support/RSA.js +4 -4
  24. package/dist/Core/Support/Utils.d.ts +6 -0
  25. package/dist/Core/Support/Utils.js +15 -1
  26. package/dist/MiniApp/Application.d.ts +4 -4
  27. package/dist/MiniApp/Contracts/ApplicationInterface.d.ts +2 -2
  28. package/dist/OfficialAccount/AccessToken.d.ts +2 -2
  29. package/dist/OfficialAccount/AccessToken.js +2 -2
  30. package/dist/OfficialAccount/Application.d.ts +4 -4
  31. package/dist/OfficialAccount/Application.js +0 -5
  32. package/dist/OfficialAccount/Contracts/ApplicationInterface.d.ts +2 -2
  33. package/dist/OfficialAccount/JsApiTicket.js +2 -2
  34. package/dist/OfficialAccount/Message.d.ts +139 -0
  35. package/dist/OfficialAccount/Message.js +1 -0
  36. package/dist/OfficialAccount/Server.js +1 -1
  37. package/dist/Pay/Application.d.ts +52 -0
  38. package/dist/Pay/Application.js +96 -0
  39. package/dist/Pay/Client.d.ts +42 -0
  40. package/dist/Pay/Client.js +125 -0
  41. package/dist/Pay/Config.d.ts +5 -0
  42. package/dist/Pay/Config.js +17 -0
  43. package/dist/Pay/Contracts/ApplicationInterface.d.ts +50 -0
  44. package/dist/Pay/Contracts/ApplicationInterface.js +45 -0
  45. package/dist/Pay/Contracts/MerchantInterface.d.ts +35 -0
  46. package/dist/Pay/Contracts/MerchantInterface.js +35 -0
  47. package/dist/Pay/Contracts/ResponseValidatorInterface.d.ts +9 -0
  48. package/dist/Pay/Contracts/ResponseValidatorInterface.js +10 -0
  49. package/dist/Pay/LegacySignature.d.ts +12 -0
  50. package/dist/Pay/LegacySignature.js +59 -0
  51. package/dist/Pay/Merchant.d.ts +25 -0
  52. package/dist/Pay/Merchant.js +53 -0
  53. package/dist/Pay/Message.d.ts +175 -0
  54. package/dist/Pay/Message.js +24 -0
  55. package/dist/Pay/Server.d.ts +41 -0
  56. package/dist/Pay/Server.js +122 -0
  57. package/dist/Pay/Signature.d.ts +15 -0
  58. package/dist/Pay/Signature.js +44 -0
  59. package/dist/Pay/Utils.d.ts +54 -0
  60. package/dist/Pay/Utils.js +142 -0
  61. package/dist/Types/global.d.ts +114 -1
  62. package/dist/index.d.ts +3 -3
  63. package/dist/index.js +3 -3
  64. package/package.json +2 -2
@@ -27,132 +27,5 @@ declare class Message {
27
27
  toString(): string;
28
28
  }
29
29
  interface Message extends HasAttributesMixin {
30
- /**
31
- * 消息密文,兼容模式、安全模式才有
32
- */
33
- Encrypt?: string;
34
- /**
35
- * 开发者微信号
36
- */
37
- ToUserName?: string;
38
- /**
39
- * 发送方帐号 OpenId
40
- */
41
- FromUserName?: string;
42
- /**
43
- * 消息创建时间
44
- */
45
- CreateTime?: number;
46
- /**
47
- * 消息类型,'event':事件,'text':文本,'image':图片,'voice':语音,'video':视频,'shortvideo':小视频,'location':地理位置,'link':链接
48
- */
49
- MsgType?: string;
50
- /**
51
- * 消息id,64位整型
52
- * @scope MsgType='text' | 'image' | 'voice' | 'video' | 'shortvideo' | 'location'
53
- */
54
- MsgId?: string;
55
- /**
56
- * 文本消息内容
57
- * @scope MsgType='text'
58
- */
59
- Content?: string;
60
- /**
61
- * 图片链接
62
- * @scope MsgType='image'
63
- */
64
- PicUrl?: string;
65
- /**
66
- * 媒体id,可以调用获取临时素材接口拉取数据
67
- * @scope MsgType='image' | 'voice'
68
- */
69
- MediaId?: string;
70
- /**
71
- * 语音格式,如amr,speex等
72
- * @scope MsgType='voice'
73
- */
74
- Format?: string;
75
- /**
76
- * 语音识别结果,UTF8编码
77
- * @scope MsgType='voice'
78
- */
79
- Recognition?: string;
80
- /**
81
- * 缩略图的媒体id
82
- * @scope MsgType='video' | 'shortvideo'
83
- */
84
- ThumbMediaId?: string;
85
- /**
86
- * 纬度
87
- * @scope MsgType='location'
88
- */
89
- Location_X?: number;
90
- /**
91
- * 经度
92
- * @scope MsgType='location'
93
- */
94
- Location_Y?: number;
95
- /**
96
- * 地图缩放大小
97
- * @scope MsgType='location'
98
- */
99
- Scale?: number;
100
- /**
101
- * 地理位置信息
102
- * @scope MsgType='location'
103
- */
104
- Label?: number;
105
- /**
106
- * 消息标题
107
- * @scope MsgType='link'
108
- */
109
- Title?: string;
110
- /**
111
- * 消息描述
112
- * @scope MsgType='link'
113
- */
114
- Description?: string;
115
- /**
116
- * 消息链接
117
- * @scope MsgType='link'
118
- */
119
- Url?: string;
120
- /**
121
- * 事件类型,subscribe:关注,unsubscribe:取消关注,SCAN:扫描(用户已关注),LOCATION:地理位置;CLICK:自定义菜单事件,VIEW:点击菜单跳转链接
122
- * @scope MsgType='event'
123
- */
124
- Event?: string;
125
- /**
126
- * 事件KEY值
127
- *
128
- * Event='subscribe' | 'SCAN'时:qrscene_为前缀,后面为二维码的参数值
129
- *
130
- * Event='CLICK'时:自定义菜单接口中KEY值对应
131
- *
132
- * Event='VIEW'时:设置的跳转URL
133
- *
134
- * @scope MsgType='event' && Event='subscribe' | 'SCAN' | 'CLICK' | 'VIEW'
135
- */
136
- EventKey?: string;
137
- /**
138
- * 二维码的ticket,可用来换取二维码图片
139
- * @scope MsgType='event' && Event='subscribe' | 'SCAN'
140
- */
141
- Ticket?: string;
142
- /**
143
- * 纬度
144
- * @scope MsgType='event' && Event='LOCATION'
145
- */
146
- Latitude?: number;
147
- /**
148
- * 经度
149
- * @scope MsgType='event' && Event='LOCATION'
150
- */
151
- Longitude?: number;
152
- /**
153
- * 位置精度
154
- * @scope MsgType='event' && Event='LOCATION'
155
- */
156
- Precision?: number;
157
30
  }
158
31
  export = Message;
@@ -49,7 +49,11 @@ class Message {
49
49
  */
50
50
  static createFromRequest(request) {
51
51
  return __awaiter(this, void 0, void 0, function* () {
52
- let originContent = request.getBody().toString();
52
+ let originContent = '';
53
+ let body = request.getBody();
54
+ if (body) {
55
+ originContent = body.toString();
56
+ }
53
57
  let attributes = {};
54
58
  if ('<' === originContent.substring(0, 1)) {
55
59
  attributes = yield (0, Utils_1.parseXml)(originContent);
@@ -16,7 +16,7 @@ class DecryptXmlMessageMixin {
16
16
  */
17
17
  decryptMessage(message, encryptor, signature, timestamp, nonce) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
- let ciphertext = message.Encrypt;
19
+ let ciphertext = message['Encrypt'];
20
20
  this.validateSignature(encryptor.getToken(), ciphertext, signature, timestamp, nonce);
21
21
  let attributes = yield (0, Utils_1.parseXml)(encryptor.decrypt(ciphertext, signature, nonce, timestamp));
22
22
  message.merge(attributes);
@@ -25,8 +25,8 @@ class ResponseXmlMessageMixin {
25
25
  return new Response_1.default(200, {}, 'success');
26
26
  }
27
27
  let attributes = merge_1.default.recursive({
28
- ToUserName: message.FromUserName,
29
- FromUserName: message.ToUserName,
28
+ ToUserName: message['FromUserName'],
29
+ FromUserName: message['ToUserName'],
30
30
  CreateTime: (0, Utils_1.getTimestamp)(),
31
31
  }, yield this.normalizeResponse(response));
32
32
  return this.createXmlResponse(attributes, encryptor);
@@ -0,0 +1,20 @@
1
+ export declare class PrivateKey {
2
+ protected key: string;
3
+ protected passphrase?: string;
4
+ constructor(key: string, passphrase?: string);
5
+ /**
6
+ * 获取私钥
7
+ * @returns
8
+ */
9
+ getKey(): string;
10
+ /**
11
+ * 获取密码
12
+ * @returns
13
+ */
14
+ getPassphrase(): string;
15
+ /**
16
+ * 转为字符串
17
+ * @returns
18
+ */
19
+ toString(): string;
20
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PrivateKey = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ class PrivateKey {
9
+ constructor(key, passphrase) {
10
+ this.key = key;
11
+ this.passphrase = passphrase;
12
+ if (fs_1.default.existsSync(key)) {
13
+ this.key = fs_1.default.readFileSync(key, 'utf8') || '';
14
+ }
15
+ }
16
+ /**
17
+ * 获取私钥
18
+ * @returns
19
+ */
20
+ getKey() {
21
+ return this.key;
22
+ }
23
+ /**
24
+ * 获取密码
25
+ * @returns
26
+ */
27
+ getPassphrase() {
28
+ return this.passphrase;
29
+ }
30
+ /**
31
+ * 转为字符串
32
+ * @returns
33
+ */
34
+ toString() {
35
+ return this.getKey();
36
+ }
37
+ }
38
+ exports.PrivateKey = PrivateKey;
@@ -0,0 +1,14 @@
1
+ export declare class PublicKey {
2
+ certificate: string;
3
+ constructor(certificate: string);
4
+ /**
5
+ * 获取公钥的序列号
6
+ * @returns
7
+ */
8
+ getSerialNo(): string;
9
+ /**
10
+ * 转为字符串
11
+ * @returns
12
+ */
13
+ toString(): string;
14
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PublicKey = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const crypto_1 = require("crypto");
9
+ class PublicKey {
10
+ constructor(certificate) {
11
+ this.certificate = certificate;
12
+ if (fs_1.default.existsSync(certificate)) {
13
+ this.certificate = fs_1.default.readFileSync(certificate, 'utf8') || '';
14
+ }
15
+ }
16
+ /**
17
+ * 获取公钥的序列号
18
+ * @returns
19
+ */
20
+ getSerialNo() {
21
+ try {
22
+ return new crypto_1.X509Certificate(this.certificate).serialNumber;
23
+ }
24
+ catch (e) {
25
+ throw new Error('Read the $certificate failed, please check it whether or nor correct');
26
+ }
27
+ }
28
+ /**
29
+ * 转为字符串
30
+ * @returns
31
+ */
32
+ toString() {
33
+ return this.certificate;
34
+ }
35
+ }
36
+ exports.PublicKey = PublicKey;
@@ -23,7 +23,7 @@ declare class RSA {
23
23
  * 加密
24
24
  * @param plaintext 待加密文本
25
25
  * @param encoding 编码,默认:'base64'
26
- * @param hashType 哈希方式,默认:'sha1'
26
+ * @param hashType 哈希方式,默认:'sha256'
27
27
  * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
28
28
  * @returns
29
29
  */
@@ -32,7 +32,7 @@ declare class RSA {
32
32
  * 解密
33
33
  * @param ciphertext 待解密文本
34
34
  * @param encoding 编码,默认:'base64'
35
- * @param hashType 哈希方式,默认:'sha1'
35
+ * @param hashType 哈希方式,默认:'sha256'
36
36
  * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
37
37
  * @returns
38
38
  */
@@ -34,11 +34,11 @@ class RSA {
34
34
  * 加密
35
35
  * @param plaintext 待加密文本
36
36
  * @param encoding 编码,默认:'base64'
37
- * @param hashType 哈希方式,默认:'sha1'
37
+ * @param hashType 哈希方式,默认:'sha256'
38
38
  * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
39
39
  * @returns
40
40
  */
41
- encrypt(plaintext, encoding = 'base64', hashType = 'sha1', padding = crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING) {
41
+ encrypt(plaintext, encoding = 'base64', hashType = 'sha256', padding = crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING) {
42
42
  let encryptedData = crypto_1.default.publicEncrypt({
43
43
  key: this.publicKey,
44
44
  padding,
@@ -50,11 +50,11 @@ class RSA {
50
50
  * 解密
51
51
  * @param ciphertext 待解密文本
52
52
  * @param encoding 编码,默认:'base64'
53
- * @param hashType 哈希方式,默认:'sha1'
53
+ * @param hashType 哈希方式,默认:'sha256'
54
54
  * @param padding 补位方式,默认:crypto.constants.RSA_PKCS1_OAEP_PADDING
55
55
  * @returns
56
56
  */
57
- decrypt(ciphertext, encoding = 'base64', hashType = 'sha1', padding = crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING) {
57
+ decrypt(ciphertext, encoding = 'base64', hashType = 'sha256', padding = crypto_1.default.constants.RSA_PKCS1_OAEP_PADDING) {
58
58
  let decryptedData = crypto_1.default.privateDecrypt({
59
59
  key: this.privateKey,
60
60
  padding,
@@ -93,3 +93,9 @@ export declare const parseXml: (xml: string) => Promise<Record<string, any>>;
93
93
  * @returns
94
94
  */
95
95
  export declare const buildXml: (data: Record<string, any>, rootName?: string) => string;
96
+ /**
97
+ * 创建UserAgent
98
+ * @param appends 可选,附加的字符串列表
99
+ * @returns
100
+ */
101
+ export declare const createUserAgent: (appends?: string[]) => string;
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.buildXml = exports.parseXml = exports.singleItem = exports.strSnake = exports.strCamel = exports.strStudly = exports.strLcwords = exports.strUcwords = exports.rtrim = exports.ltrim = exports.trim = exports.applyMixins = exports.inArray = exports.isIp = exports.isIpv6 = exports.isIpv4 = exports.isFunction = exports.isObject = exports.isNumber = exports.isArray = exports.isString = exports.makeSignature = exports.randomString = exports.parseQueryString = exports.buildQueryString = exports.getTimestamp = exports.md5File = exports.createHmac = exports.createHash = void 0;
15
+ exports.createUserAgent = exports.buildXml = exports.parseXml = exports.singleItem = exports.strSnake = exports.strCamel = exports.strStudly = exports.strLcwords = exports.strUcwords = exports.rtrim = exports.ltrim = exports.trim = exports.applyMixins = exports.inArray = exports.isIp = exports.isIpv6 = exports.isIpv4 = exports.isFunction = exports.isObject = exports.isNumber = exports.isArray = exports.isString = exports.makeSignature = exports.randomString = exports.parseQueryString = exports.buildQueryString = exports.getTimestamp = exports.md5File = exports.createHmac = exports.createHash = void 0;
16
16
  const crypto_1 = __importDefault(require("crypto"));
17
17
  const qs_1 = __importDefault(require("qs"));
18
18
  const xml2js_1 = __importDefault(require("xml2js"));
19
19
  const stream_1 = __importDefault(require("stream"));
20
20
  const fs_1 = __importDefault(require("fs"));
21
+ const axios_1 = __importDefault(require("axios"));
21
22
  const createHash = function (str, type = 'sha1') {
22
23
  return crypto_1.default.createHash(type).update(str).digest('hex');
23
24
  };
@@ -321,3 +322,16 @@ const buildXml = function (data, rootName = 'xml') {
321
322
  return XmlBuilder.buildObject(data).replace('<?xml version="1.0"?>', '');
322
323
  };
323
324
  exports.buildXml = buildXml;
325
+ /**
326
+ * 创建UserAgent
327
+ * @param appends 可选,附加的字符串列表
328
+ * @returns
329
+ */
330
+ const createUserAgent = function (appends = []) {
331
+ let values = [];
332
+ values.push(`node-easywechat/${require('../../../package.json').version}`);
333
+ values.push(`axios/${axios_1.default.VERSION}`);
334
+ values = values.concat(appends);
335
+ return values.join(' ');
336
+ };
337
+ exports.createUserAgent = createUserAgent;
@@ -1,4 +1,3 @@
1
- import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
2
1
  import ConfigInterface from '../Core/Contracts/ConfigInterface';
3
2
  import ServerInterface from '../Core/Contracts/ServerInterface';
4
3
  import Encryptor from '../Core/Encryptor';
@@ -12,6 +11,7 @@ import { MiniAppConfig } from '../Types/global';
12
11
  import AccountInterface from './Contracts/AccountInterface';
13
12
  import ApplicationInterface from './Contracts/ApplicationInterface';
14
13
  import Utils from './Utils';
14
+ import RefreshableAccessTokenInterface from '../Core/Contracts/RefreshableAccessTokenInterface';
15
15
  /**
16
16
  * 小程序应用
17
17
  */
@@ -20,7 +20,7 @@ declare class Application implements ApplicationInterface {
20
20
  protected account: AccountInterface;
21
21
  protected encryptor: Encryptor;
22
22
  protected server: ServerInterface;
23
- protected accessToken: AccessTokenInterface;
23
+ protected accessToken: RefreshableAccessTokenInterface;
24
24
  getAccount(): AccountInterface;
25
25
  /**
26
26
  * 设置当前账户实例
@@ -42,13 +42,13 @@ declare class Application implements ApplicationInterface {
42
42
  * @returns
43
43
  */
44
44
  setServer(server: ServerInterface): this;
45
- getAccessToken(): AccessTokenInterface;
45
+ getAccessToken(): RefreshableAccessTokenInterface;
46
46
  /**
47
47
  * 设置AccessToken实例
48
48
  * @param accessToken
49
49
  * @returns
50
50
  */
51
- setAccessToken(accessToken: AccessTokenInterface): this;
51
+ setAccessToken(accessToken: RefreshableAccessTokenInterface): this;
52
52
  getUtils(): Utils;
53
53
  createClient(): AccessTokenAwareClient;
54
54
  /**
@@ -1,4 +1,3 @@
1
- import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
2
1
  import CacheInterface from "../../Core/Contracts/CacheInterface";
3
2
  import ConfigInterface from "../../Core/Contracts/ConfigInterface";
4
3
  import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
@@ -8,6 +7,7 @@ import ServerRequestInterface from "../../Core/Http/Contracts/ServerRequestInter
8
7
  import Encryptor from "../../Core/Encryptor";
9
8
  import AccountInterface from "./AccountInterface";
10
9
  import Utils from "../Utils";
10
+ import RefreshableAccessTokenInterface from "../../Core/Contracts/RefreshableAccessTokenInterface";
11
11
  declare abstract class ApplicationInterface {
12
12
  /**
13
13
  * 获取当前账户实例
@@ -53,7 +53,7 @@ declare abstract class ApplicationInterface {
53
53
  * 获取AccessToken实例
54
54
  * @returns
55
55
  */
56
- getAccessToken(): AccessTokenInterface;
56
+ getAccessToken(): RefreshableAccessTokenInterface;
57
57
  /**
58
58
  * 获取缓存实例
59
59
  * @returns
@@ -1,7 +1,7 @@
1
1
  import CacheInterface from "../Core/Contracts/CacheInterface";
2
2
  import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
3
- import RefreshableAccessToken from "../Core/Contracts/RefreshableAccessTokenInterface";
4
- declare class AccessToken implements RefreshableAccessToken {
3
+ import RefreshableAccessTokenInterface from "../Core/Contracts/RefreshableAccessTokenInterface";
4
+ declare class AccessToken implements RefreshableAccessTokenInterface {
5
5
  protected appId: string;
6
6
  protected secret: string;
7
7
  protected key: string;
@@ -66,13 +66,13 @@ class AccessToken {
66
66
  }
67
67
  refresh() {
68
68
  return __awaiter(this, void 0, void 0, function* () {
69
- let response = yield (yield this.httpClient.request('get', 'cgi-bin/token', {
69
+ let response = (yield this.httpClient.request('get', 'cgi-bin/token', {
70
70
  params: {
71
71
  grant_type: 'client_credential',
72
72
  appid: this.appId,
73
73
  secret: this.secret,
74
74
  }
75
- })).toObject(false);
75
+ })).toObject();
76
76
  if (!response['access_token']) {
77
77
  throw new Error('Failed to get access_token: ' + JSON.stringify(response));
78
78
  }
@@ -1,5 +1,4 @@
1
1
  import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
2
- import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
3
2
  import ConfigInterface from '../Core/Contracts/ConfigInterface';
4
3
  import ServerInterface from '../Core/Contracts/ServerInterface';
5
4
  import Encryptor from '../Core/Encryptor';
@@ -14,6 +13,7 @@ import AccountInterface from './Contracts/AccountInterface';
14
13
  import ApplicationInterface from './Contracts/ApplicationInterface';
15
14
  import JsApiTicket from './JsApiTicket';
16
15
  import Utils from './Utils';
16
+ import RefreshableAccessTokenInterface from '../Core/Contracts/RefreshableAccessTokenInterface';
17
17
  /**
18
18
  * 公众号应用
19
19
  */
@@ -22,7 +22,7 @@ declare class Application implements ApplicationInterface {
22
22
  protected account: AccountInterface;
23
23
  protected encryptor: Encryptor;
24
24
  protected server: ServerInterface;
25
- protected accessToken: AccessTokenInterface;
25
+ protected accessToken: RefreshableAccessTokenInterface;
26
26
  protected oauthFactory: OfficialAccountOAuthFactory;
27
27
  protected ticket: JsApiTicket;
28
28
  getAccount(): AccountInterface;
@@ -46,13 +46,13 @@ declare class Application implements ApplicationInterface {
46
46
  * @returns
47
47
  */
48
48
  setServer(server: ServerInterface): this;
49
- getAccessToken(): AccessTokenInterface;
49
+ getAccessToken(): RefreshableAccessTokenInterface;
50
50
  /**
51
51
  * 设置AccessToken实例
52
52
  * @param accessToken
53
53
  * @returns
54
54
  */
55
- setAccessToken(accessToken: AccessTokenInterface): this;
55
+ setAccessToken(accessToken: RefreshableAccessTokenInterface): this;
56
56
  setOAuthFactory(oauthFactory: OfficialAccountOAuthFactory): this;
57
57
  getOAuth(): ProviderInterface;
58
58
  getTicket(): JsApiTicket;
@@ -75,11 +75,6 @@ class Application {
75
75
  }
76
76
  getServer() {
77
77
  if (!this.server) {
78
- let token = this.getAccount().getToken();
79
- let aesKey = this.getAccount().getAesKey();
80
- if (!token || !aesKey) {
81
- throw new Error('token or aes_key cannot be empty.');
82
- }
83
78
  this.server = new Server_1.default(this.getRequest(), this.getAccount().getAesKey() ? this.getEncryptor() : null);
84
79
  }
85
80
  return this.server;
@@ -1,5 +1,4 @@
1
1
  import ProviderInterface from "node-socialite/dist/Core/ProviderInterface";
2
- import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
3
2
  import CacheInterface from "../../Core/Contracts/CacheInterface";
4
3
  import ConfigInterface from "../../Core/Contracts/ConfigInterface";
5
4
  import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
@@ -11,6 +10,7 @@ import AccountInterface from "./AccountInterface";
11
10
  import { OfficialAccountOAuthFactory } from "../../Types/global";
12
11
  import JsApiTicket from "../JsApiTicket";
13
12
  import Utils from "../Utils";
13
+ import RefreshableAccessTokenInterface from "../../Core/Contracts/RefreshableAccessTokenInterface";
14
14
  declare abstract class ApplicationInterface {
15
15
  /**
16
16
  * 获取当前账户实例
@@ -56,7 +56,7 @@ declare abstract class ApplicationInterface {
56
56
  * 获取AccessToken实例
57
57
  * @returns
58
58
  */
59
- getAccessToken(): AccessTokenInterface;
59
+ getAccessToken(): RefreshableAccessTokenInterface;
60
60
  /**
61
61
  * 获取缓存实例
62
62
  * @returns
@@ -35,11 +35,11 @@ class JsApiTicket extends AccessToken_1.default {
35
35
  if (!!ticket && typeof ticket === 'string') {
36
36
  return ticket;
37
37
  }
38
- let response = yield (yield this.httpClient.request('get', '/cgi-bin/ticket/getticket', {
38
+ let response = (yield this.httpClient.request('get', '/cgi-bin/ticket/getticket', {
39
39
  params: {
40
40
  type: 'jsapi',
41
41
  }
42
- })).toObject(false);
42
+ })).toObject();
43
43
  if (!response['ticket']) {
44
44
  throw new Error('Failed to get jssdk_ticket: ' + JSON.stringify(response));
45
45
  }