node-easywechat 3.1.4 → 3.3.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 (69) hide show
  1. package/.github/workflows/build-2.yml +21 -0
  2. package/.github/workflows/build-3.yml +21 -0
  3. package/.github/workflows/publish-npm-2.yml +24 -0
  4. package/.github/workflows/publish-npm-3.yml +24 -0
  5. package/CHANGELOG.md +15 -0
  6. package/README.md +23 -2
  7. package/dist/MiniApp/Application.d.ts +4 -4
  8. package/dist/OfficialAccount/Application.d.ts +4 -4
  9. package/dist/OpenPlatform/Application.d.ts +5 -5
  10. package/dist/OpenPlatform/Application.js +1 -1
  11. package/dist/OpenWork/Account.d.ts +17 -0
  12. package/dist/OpenWork/Account.js +30 -0
  13. package/dist/OpenWork/Application.d.ts +120 -0
  14. package/dist/OpenWork/Application.js +294 -0
  15. package/dist/OpenWork/Authorization.d.ts +12 -0
  16. package/dist/OpenWork/Authorization.js +49 -0
  17. package/dist/OpenWork/AuthorizerAccessToken.d.ts +38 -0
  18. package/dist/OpenWork/AuthorizerAccessToken.js +105 -0
  19. package/dist/OpenWork/Config.d.ts +5 -0
  20. package/dist/OpenWork/Config.js +19 -0
  21. package/dist/OpenWork/Contracts/AccountInterface.d.ts +33 -0
  22. package/dist/OpenWork/Contracts/AccountInterface.js +35 -0
  23. package/dist/OpenWork/Contracts/ApplicationInterface.d.ts +108 -0
  24. package/dist/OpenWork/Contracts/ApplicationInterface.js +96 -0
  25. package/dist/OpenWork/Contracts/SuiteTicketInterface.d.ts +23 -0
  26. package/dist/OpenWork/Contracts/SuiteTicketInterface.js +25 -0
  27. package/dist/OpenWork/Encryptor.d.ts +9 -0
  28. package/dist/OpenWork/Encryptor.js +17 -0
  29. package/dist/OpenWork/JsApiTicket.d.ts +50 -0
  30. package/dist/OpenWork/JsApiTicket.js +152 -0
  31. package/dist/OpenWork/Message.d.ts +78 -0
  32. package/dist/OpenWork/Message.js +9 -0
  33. package/dist/OpenWork/ProviderAccessToken.d.ts +26 -0
  34. package/dist/OpenWork/ProviderAccessToken.js +84 -0
  35. package/dist/OpenWork/Server.d.ts +103 -0
  36. package/dist/OpenWork/Server.js +242 -0
  37. package/dist/OpenWork/SuiteAccessToken.d.ts +28 -0
  38. package/dist/OpenWork/SuiteAccessToken.js +86 -0
  39. package/dist/OpenWork/SuiteEncryptor.d.ts +9 -0
  40. package/dist/OpenWork/SuiteEncryptor.js +17 -0
  41. package/dist/OpenWork/SuiteTicket.d.ts +13 -0
  42. package/dist/OpenWork/SuiteTicket.js +49 -0
  43. package/dist/Pay/Application.d.ts +4 -4
  44. package/dist/Types/global.d.ts +19 -1
  45. package/dist/Work/AccessToken.d.ts +26 -0
  46. package/dist/Work/AccessToken.js +84 -0
  47. package/dist/Work/Account.d.ts +13 -0
  48. package/dist/Work/Account.js +25 -0
  49. package/dist/Work/Application.d.ts +75 -0
  50. package/dist/Work/Application.js +177 -0
  51. package/dist/Work/Config.d.ts +5 -0
  52. package/dist/Work/Config.js +17 -0
  53. package/dist/Work/Contracts/AccountInterface.d.ts +23 -0
  54. package/dist/Work/Contracts/AccountInterface.js +25 -0
  55. package/dist/Work/Contracts/ApplicationInterface.d.ts +87 -0
  56. package/dist/Work/Contracts/ApplicationInterface.js +76 -0
  57. package/dist/Work/Encryptor.d.ts +9 -0
  58. package/dist/Work/Encryptor.js +17 -0
  59. package/dist/Work/JsApiTicket.d.ts +45 -0
  60. package/dist/Work/JsApiTicket.js +141 -0
  61. package/dist/Work/Message.d.ts +142 -0
  62. package/dist/Work/Message.js +9 -0
  63. package/dist/Work/Server.d.ts +90 -0
  64. package/dist/Work/Server.js +212 -0
  65. package/dist/Work/Utils.d.ts +25 -0
  66. package/dist/Work/Utils.js +56 -0
  67. package/dist/index.d.ts +4 -2
  68. package/dist/index.js +5 -1
  69. package/package.json +2 -2
@@ -0,0 +1,103 @@
1
+ import ServerRequestInterface from '../Core/Http/Contracts/ServerRequestInterface';
2
+ import Encryptor from '../Core/Encryptor';
3
+ import ServerInterface from '../Core/Contracts/ServerInterface';
4
+ import Response from '../Core/Http/Response';
5
+ import Message from './Message';
6
+ import { ServerHandlerClosure } from '../Types/global';
7
+ declare class Server extends ServerInterface {
8
+ protected encryptor: Encryptor;
9
+ protected providerEncryptor: Encryptor;
10
+ protected request: ServerRequestInterface;
11
+ protected defaultSuiteTicketHandler: ServerHandlerClosure;
12
+ constructor(encryptor: Encryptor, providerEncryptor: Encryptor, request?: ServerRequestInterface);
13
+ /**
14
+ * 服务端消息处理
15
+ * @returns
16
+ */
17
+ serve(): Promise<Response>;
18
+ withDefaultSuiteTicketHandler(handler: ServerHandlerClosure): this;
19
+ /**
20
+ * 设置联系人变化的消息处理器
21
+ * @param handler
22
+ */
23
+ handleSuiteTicketRefreshed(handler: ServerHandlerClosure): this;
24
+ /**
25
+ * 设置授权成功的消息处理器
26
+ * @param handler
27
+ */
28
+ handleAuthCreated(handler: ServerHandlerClosure): this;
29
+ /**
30
+ * 设置变更授权的消息处理器
31
+ * @param handler
32
+ */
33
+ handleAuthUpdated(handler: ServerHandlerClosure): this;
34
+ /**
35
+ * 设置取消授权的消息处理器
36
+ * @param handler
37
+ */
38
+ handleAuthCancelled(handler: ServerHandlerClosure): this;
39
+ /**
40
+ * 设置用户创建的消息处理器
41
+ * @param handler
42
+ */
43
+ handleUserCreated(handler: ServerHandlerClosure): this;
44
+ /**
45
+ * 设置用户更新的消息处理器
46
+ * @param handler
47
+ */
48
+ handleUserUpdated(handler: ServerHandlerClosure): this;
49
+ /**
50
+ * 设置用户删除的消息处理器
51
+ * @param handler
52
+ */
53
+ handleUserDeleted(handler: ServerHandlerClosure): this;
54
+ /**
55
+ * 设置部门创建的消息处理器
56
+ * @param handler
57
+ */
58
+ handlePartyCreated(handler: ServerHandlerClosure): this;
59
+ /**
60
+ * 设置部门更新的消息处理器
61
+ * @param handler
62
+ */
63
+ handlePartyUpdated(handler: ServerHandlerClosure): this;
64
+ /**
65
+ * 设置部门删除的消息处理器
66
+ * @param handler
67
+ */
68
+ handlePartyDeleted(handler: ServerHandlerClosure): this;
69
+ /**
70
+ * 设置用户标签变化的消息处理器
71
+ * @param handler
72
+ */
73
+ handleUserTagUpdated(handler: ServerHandlerClosure): this;
74
+ /**
75
+ * 设置共享应用事件的消息处理器
76
+ * @param handler
77
+ */
78
+ handleShareAgentChanged(handler: ServerHandlerClosure): this;
79
+ /**
80
+ * 设置重置永久授权码的消息处理器
81
+ * @param handler
82
+ */
83
+ handleResetPermanentCode(handler: ServerHandlerClosure): this;
84
+ /**
85
+ * 设置应用管理员变更的消息处理器
86
+ * @param handler
87
+ */
88
+ handleChangeAppAdmin(handler: ServerHandlerClosure): this;
89
+ /**
90
+ * 获取来自微信服务器的推送消息
91
+ * @param request 未设置该参数时,则从当前服务端收到的请求中获取
92
+ * @returns
93
+ */
94
+ getRequestMessage(request?: ServerRequestInterface): Promise<Message>;
95
+ protected decryptRequestMessage(query: Record<string, any>): ServerHandlerClosure;
96
+ /**
97
+ * 获取解密后的消息
98
+ * @param request 未设置该参数时,则从当前服务端收到的请求中获取
99
+ * @returns
100
+ */
101
+ getDecryptedMessage(request?: ServerRequestInterface): Promise<import("../Core/Message")>;
102
+ }
103
+ export = Server;
@@ -0,0 +1,242 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ const ServerInterface_1 = __importDefault(require("../Core/Contracts/ServerInterface"));
15
+ const Response_1 = __importDefault(require("../Core/Http/Response"));
16
+ const Message_1 = __importDefault(require("./Message"));
17
+ class Server extends ServerInterface_1.default {
18
+ constructor(encryptor, providerEncryptor, request = null) {
19
+ super();
20
+ this.encryptor = encryptor;
21
+ this.providerEncryptor = providerEncryptor;
22
+ this.request = request;
23
+ this.defaultSuiteTicketHandler = null;
24
+ }
25
+ /**
26
+ * 服务端消息处理
27
+ * @returns
28
+ */
29
+ serve() {
30
+ var _a, _b, _c;
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ let query = this.request.getQueryParams();
33
+ if (!!query['echostr']) {
34
+ let echostr = this.providerEncryptor.decrypt(query['echostr'], (_a = query['msg_signature']) !== null && _a !== void 0 ? _a : '', (_b = query['nonce']) !== null && _b !== void 0 ? _b : '', (_c = query['timestamp']) !== null && _c !== void 0 ? _c : '');
35
+ return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
36
+ }
37
+ let message = yield this.getRequestMessage(this.request);
38
+ this.prepend(this.decryptRequestMessage(query));
39
+ let response = yield this.handle(new Response_1.default(200, {}, 'success'), message);
40
+ if (!(response instanceof Response_1.default)) {
41
+ response = yield this.transformToReply(response, message, this.encryptor);
42
+ }
43
+ return response;
44
+ });
45
+ }
46
+ withDefaultSuiteTicketHandler(handler) {
47
+ this.defaultSuiteTicketHandler = function () {
48
+ return handler.call(null, arguments);
49
+ };
50
+ return this.handleSuiteTicketRefreshed(handler);
51
+ }
52
+ /**
53
+ * 设置联系人变化的消息处理器
54
+ * @param handler
55
+ */
56
+ handleSuiteTicketRefreshed(handler) {
57
+ if (this.defaultSuiteTicketHandler) {
58
+ this.withoutHandler(this.defaultSuiteTicketHandler);
59
+ }
60
+ return this.with(function (message, next) {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return message.InfoType === 'suite_ticket' ? handler(message, next) : next(message);
63
+ });
64
+ });
65
+ }
66
+ /**
67
+ * 设置授权成功的消息处理器
68
+ * @param handler
69
+ */
70
+ handleAuthCreated(handler) {
71
+ return this.with(function (message, next) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ return message.InfoType === 'create_auth' ? handler(message, next) : next(message);
74
+ });
75
+ });
76
+ }
77
+ /**
78
+ * 设置变更授权的消息处理器
79
+ * @param handler
80
+ */
81
+ handleAuthUpdated(handler) {
82
+ return this.with(function (message, next) {
83
+ return __awaiter(this, void 0, void 0, function* () {
84
+ return message.InfoType === 'change_auth' ? handler(message, next) : next(message);
85
+ });
86
+ });
87
+ }
88
+ /**
89
+ * 设置取消授权的消息处理器
90
+ * @param handler
91
+ */
92
+ handleAuthCancelled(handler) {
93
+ return this.with(function (message, next) {
94
+ return __awaiter(this, void 0, void 0, function* () {
95
+ return message.InfoType === 'cancel_auth' ? handler(message, next) : next(message);
96
+ });
97
+ });
98
+ }
99
+ /**
100
+ * 设置用户创建的消息处理器
101
+ * @param handler
102
+ */
103
+ handleUserCreated(handler) {
104
+ return this.with(function (message, next) {
105
+ return __awaiter(this, void 0, void 0, function* () {
106
+ return message.InfoType === 'change_contact' && message.ChangeType === 'create_user' ? handler(message, next) : next(message);
107
+ });
108
+ });
109
+ }
110
+ /**
111
+ * 设置用户更新的消息处理器
112
+ * @param handler
113
+ */
114
+ handleUserUpdated(handler) {
115
+ return this.with(function (message, next) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ return message.InfoType === 'change_contact' && message.ChangeType === 'update_user' ? handler(message, next) : next(message);
118
+ });
119
+ });
120
+ }
121
+ /**
122
+ * 设置用户删除的消息处理器
123
+ * @param handler
124
+ */
125
+ handleUserDeleted(handler) {
126
+ return this.with(function (message, next) {
127
+ return __awaiter(this, void 0, void 0, function* () {
128
+ return message.InfoType === 'change_contact' && message.ChangeType === 'delete_user' ? handler(message, next) : next(message);
129
+ });
130
+ });
131
+ }
132
+ /**
133
+ * 设置部门创建的消息处理器
134
+ * @param handler
135
+ */
136
+ handlePartyCreated(handler) {
137
+ return this.with(function (message, next) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ return message.InfoType === 'change_contact' && message.ChangeType === 'create_party' ? handler(message, next) : next(message);
140
+ });
141
+ });
142
+ }
143
+ /**
144
+ * 设置部门更新的消息处理器
145
+ * @param handler
146
+ */
147
+ handlePartyUpdated(handler) {
148
+ return this.with(function (message, next) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ return message.InfoType === 'change_contact' && message.ChangeType === 'update_party' ? handler(message, next) : next(message);
151
+ });
152
+ });
153
+ }
154
+ /**
155
+ * 设置部门删除的消息处理器
156
+ * @param handler
157
+ */
158
+ handlePartyDeleted(handler) {
159
+ return this.with(function (message, next) {
160
+ return __awaiter(this, void 0, void 0, function* () {
161
+ return message.InfoType === 'change_contact' && message.ChangeType === 'delete_party' ? handler(message, next) : next(message);
162
+ });
163
+ });
164
+ }
165
+ /**
166
+ * 设置用户标签变化的消息处理器
167
+ * @param handler
168
+ */
169
+ handleUserTagUpdated(handler) {
170
+ return this.with(function (message, next) {
171
+ return __awaiter(this, void 0, void 0, function* () {
172
+ return message.InfoType === 'change_contact' && message.ChangeType === 'update_tag' ? handler(message, next) : next(message);
173
+ });
174
+ });
175
+ }
176
+ /**
177
+ * 设置共享应用事件的消息处理器
178
+ * @param handler
179
+ */
180
+ handleShareAgentChanged(handler) {
181
+ return this.with(function (message, next) {
182
+ return __awaiter(this, void 0, void 0, function* () {
183
+ return message.InfoType === 'share_agent_change' ? handler(message, next) : next(message);
184
+ });
185
+ });
186
+ }
187
+ /**
188
+ * 设置重置永久授权码的消息处理器
189
+ * @param handler
190
+ */
191
+ handleResetPermanentCode(handler) {
192
+ return this.with(function (message, next) {
193
+ return __awaiter(this, void 0, void 0, function* () {
194
+ return message.InfoType === 'reset_permanent_code' ? handler(message, next) : next(message);
195
+ });
196
+ });
197
+ }
198
+ /**
199
+ * 设置应用管理员变更的消息处理器
200
+ * @param handler
201
+ */
202
+ handleChangeAppAdmin(handler) {
203
+ return this.with(function (message, next) {
204
+ return __awaiter(this, void 0, void 0, function* () {
205
+ return message.MsgType === 'event' && message.Event === 'change_app_admin' ? handler(message, next) : next(message);
206
+ });
207
+ });
208
+ }
209
+ /**
210
+ * 获取来自微信服务器的推送消息
211
+ * @param request 未设置该参数时,则从当前服务端收到的请求中获取
212
+ * @returns
213
+ */
214
+ getRequestMessage(request = null) {
215
+ return Message_1.default.createFromRequest(request !== null && request !== void 0 ? request : this.request);
216
+ }
217
+ decryptRequestMessage(query) {
218
+ return (message, next) => __awaiter(this, void 0, void 0, function* () {
219
+ var _a, _b, _c;
220
+ if (!this.encryptor)
221
+ return null;
222
+ yield this.decryptMessage(message, this.encryptor, (_a = query['msg_signature']) !== null && _a !== void 0 ? _a : '', (_b = query['timestamp']) !== null && _b !== void 0 ? _b : '', (_c = query['nonce']) !== null && _c !== void 0 ? _c : '');
223
+ return next(message);
224
+ });
225
+ }
226
+ /**
227
+ * 获取解密后的消息
228
+ * @param request 未设置该参数时,则从当前服务端收到的请求中获取
229
+ * @returns
230
+ */
231
+ getDecryptedMessage(request = null) {
232
+ var _a, _b, _c;
233
+ return __awaiter(this, void 0, void 0, function* () {
234
+ request = request !== null && request !== void 0 ? request : this.request;
235
+ let message = yield this.getRequestMessage(request);
236
+ let query = request.getQueryParams();
237
+ return yield this.decryptMessage(message, this.encryptor, (_a = query['msg_signature']) !== null && _a !== void 0 ? _a : '', (_b = query['timestamp']) !== null && _b !== void 0 ? _b : '', (_c = query['nonce']) !== null && _c !== void 0 ? _c : '');
238
+ });
239
+ }
240
+ }
241
+ ;
242
+ module.exports = Server;
@@ -0,0 +1,28 @@
1
+ import CacheInterface from "../Core/Contracts/CacheInterface";
2
+ import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
3
+ import RefreshableAccessTokenInterface from "../Core/Contracts/RefreshableAccessTokenInterface";
4
+ import SuiteTicketInterface from "./Contracts/SuiteTicketInterface";
5
+ declare class SuiteAccessToken implements RefreshableAccessTokenInterface {
6
+ protected suiteId: string;
7
+ protected suiteSecret: string;
8
+ protected suiteTicket: SuiteTicketInterface;
9
+ protected key: string;
10
+ protected cache: CacheInterface;
11
+ protected httpClient: HttpClientInterface;
12
+ constructor(suiteId: string, suiteSecret: string, suiteTicket: SuiteTicketInterface, key?: string, cache?: CacheInterface, httpClient?: HttpClientInterface);
13
+ /**
14
+ * 获取access_token的缓存名称
15
+ * @returns
16
+ */
17
+ getKey(): string;
18
+ /**
19
+ * 设置access_token的缓存名称
20
+ * @param key
21
+ * @returns
22
+ */
23
+ setKey(key: string): this;
24
+ getToken(): Promise<string>;
25
+ toQuery(): Promise<Record<string, any>>;
26
+ refresh(): Promise<string>;
27
+ }
28
+ export = SuiteAccessToken;
@@ -0,0 +1,86 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
15
+ class SuiteAccessToken {
16
+ constructor(suiteId, suiteSecret, suiteTicket, key = null, cache = null, httpClient = null) {
17
+ this.suiteId = suiteId;
18
+ this.suiteSecret = suiteSecret;
19
+ this.suiteTicket = suiteTicket;
20
+ this.key = key;
21
+ this.cache = cache;
22
+ this.httpClient = httpClient;
23
+ if (!this.httpClient) {
24
+ this.httpClient = HttpClient_1.default.create({
25
+ baseURL: 'https://qyapi.weixin.qq.com/',
26
+ });
27
+ }
28
+ }
29
+ /**
30
+ * 获取access_token的缓存名称
31
+ * @returns
32
+ */
33
+ getKey() {
34
+ if (!this.key) {
35
+ this.key = `open_work.suite_access_token.${this.suiteId}`;
36
+ }
37
+ return this.key;
38
+ }
39
+ /**
40
+ * 设置access_token的缓存名称
41
+ * @param key
42
+ * @returns
43
+ */
44
+ setKey(key) {
45
+ this.key = key;
46
+ return this;
47
+ }
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
+ });
59
+ }
60
+ toQuery() {
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ return {
63
+ suite_access_token: yield this.getToken(),
64
+ };
65
+ });
66
+ }
67
+ refresh() {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ let response = (yield this.httpClient.request('post', 'cgi-bin/service/get_suite_token', {
70
+ params: {
71
+ suite_id: this.suiteId,
72
+ suite_secret: this.suiteSecret,
73
+ suite_ticket: yield this.suiteTicket.getTicket(),
74
+ }
75
+ })).toObject();
76
+ if (!response['suite_access_token']) {
77
+ throw new Error('Failed to get suite_access_token: ' + JSON.stringify(response));
78
+ }
79
+ if (this.cache) {
80
+ yield this.cache.set(this.getKey(), response['suite_access_token'], parseInt(response['expires_in']) - 100);
81
+ }
82
+ return response['suite_access_token'];
83
+ });
84
+ }
85
+ }
86
+ module.exports = SuiteAccessToken;
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import BaseEncryptor from '../Core/Encryptor';
3
+ declare class SuiteEncryptor extends BaseEncryptor {
4
+ protected suiteId: string;
5
+ protected token: string;
6
+ protected aesKey: string | Buffer;
7
+ constructor(suiteId?: string, token?: string, aesKey?: string | Buffer);
8
+ }
9
+ export = SuiteEncryptor;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const Encryptor_1 = __importDefault(require("../Core/Encryptor"));
6
+ class SuiteEncryptor extends Encryptor_1.default {
7
+ constructor(suiteId = null, token = null, aesKey = null) {
8
+ super(suiteId, token, aesKey, null);
9
+ this.suiteId = suiteId;
10
+ this.token = token;
11
+ this.aesKey = aesKey;
12
+ if (typeof this.aesKey === 'string') {
13
+ this.aesKey = Buffer.from(this.aesKey + '=', 'base64');
14
+ }
15
+ }
16
+ }
17
+ module.exports = SuiteEncryptor;
@@ -0,0 +1,13 @@
1
+ import CacheInterface from '../Core/Contracts/CacheInterface';
2
+ import SuiteTicketInterface from './Contracts/SuiteTicketInterface';
3
+ declare class SuiteTicket implements SuiteTicketInterface {
4
+ protected suiteId: string;
5
+ protected cache: CacheInterface;
6
+ protected key: string;
7
+ constructor(suiteId: string, cache?: CacheInterface, key?: string);
8
+ getKey(): string;
9
+ setKey(key: string): this;
10
+ setTicket(ticket: string): Promise<this>;
11
+ getTicket(): Promise<string>;
12
+ }
13
+ export = SuiteTicket;
@@ -0,0 +1,49 @@
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
+ class SuiteTicket {
12
+ constructor(suiteId, cache = null, key = null) {
13
+ this.suiteId = suiteId;
14
+ this.cache = cache;
15
+ this.key = key;
16
+ }
17
+ getKey() {
18
+ if (!this.key) {
19
+ this.key = `open_work.suite_ticket.${this.suiteId}`;
20
+ }
21
+ return this.key;
22
+ }
23
+ setKey(key) {
24
+ this.key = key;
25
+ return this;
26
+ }
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
+ });
34
+ }
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 suite_ticket found.');
43
+ }
44
+ return ticket;
45
+ });
46
+ }
47
+ }
48
+ ;
49
+ module.exports = SuiteTicket;
@@ -1,5 +1,4 @@
1
1
  import ConfigInterface from '../Core/Contracts/ConfigInterface';
2
- import ServerInterface from '../Core/Contracts/ServerInterface';
3
2
  import Encryptor from '../Core/Encryptor';
4
3
  import CacheMixin from '../Core/Mixins/CacheMixin';
5
4
  import ConfigMixin from '../Core/Mixins/ConfigMixin';
@@ -8,6 +7,7 @@ import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
8
7
  import { PayConfig } from '../Types/global';
9
8
  import MerchantInterface from './Contracts/MerchantInterface';
10
9
  import ApplicationInterface from './Contracts/ApplicationInterface';
10
+ import Server from './Server';
11
11
  import Utils from './Utils';
12
12
  import Client from './Client';
13
13
  /**
@@ -17,7 +17,7 @@ declare class Application implements ApplicationInterface {
17
17
  constructor(config: ConfigInterface | PayConfig);
18
18
  protected merchant: MerchantInterface;
19
19
  protected encryptor: Encryptor;
20
- protected server: ServerInterface;
20
+ protected server: Server;
21
21
  protected client: Client;
22
22
  getMerchant(): MerchantInterface;
23
23
  /**
@@ -26,13 +26,13 @@ declare class Application implements ApplicationInterface {
26
26
  * @returns
27
27
  */
28
28
  setMerchant(merchant: MerchantInterface): this;
29
- getServer(): ServerInterface;
29
+ getServer(): Server;
30
30
  /**
31
31
  * 设置服务端实例
32
32
  * @param server
33
33
  * @returns
34
34
  */
35
- setServer(server: ServerInterface): this;
35
+ setServer(server: Server): this;
36
36
  getUtils(): Utils;
37
37
  getClient(): Client;
38
38
  /**
@@ -1,6 +1,7 @@
1
1
  import { AxiosRequestConfig, AxiosResponse } from 'axios';
2
2
  import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
3
3
  import OfficialAccountApplicationInterface from '../OfficialAccount/Contracts/ApplicationInterface';
4
+ import WorkApplicationInterface from '../Work/Contracts/ApplicationInterface';
4
5
  import Message from '../Core/Message';
5
6
  import HttpClientResponseInterface from '../Core/HttpClient/Contracts/HttpClientResponseInterface';
6
7
  import { PublicKey } from "../Core/Support/PublicKey";
@@ -274,7 +275,17 @@ export declare interface OpenWorkConfig extends BaseConfig {
274
275
  /**
275
276
  * 企业微信 secret
276
277
  */
277
- secret?: string;
278
+ provider_secret?: string;
279
+
280
+ /**
281
+ * 第三方应用的 app_id
282
+ */
283
+ suite_id?: string;
284
+
285
+ /**
286
+ * 第三方应用的 secret
287
+ */
288
+ suite_secret?: string;
278
289
 
279
290
  /**
280
291
  * 企业微信服务端接口验证 token
@@ -294,6 +305,13 @@ export declare interface OpenWorkConfig extends BaseConfig {
294
305
  */
295
306
  export declare type OfficialAccountOAuthFactory = (app: OfficialAccountApplicationInterface) => ProviderInterface;
296
307
 
308
+ /**
309
+ * 企业微信OAuth工厂方法
310
+ * @param app 企业微信应用实例
311
+ * @returns OAuth服务供应商实例
312
+ */
313
+ export declare type WorkOAuthFactory = (app: WorkApplicationInterface) => ProviderInterface;
314
+
297
315
  /**
298
316
  * 服务端通知处理项
299
317
  */
@@ -0,0 +1,26 @@
1
+ import CacheInterface from "../Core/Contracts/CacheInterface";
2
+ import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
3
+ import RefreshableAccessTokenInterface from "../Core/Contracts/RefreshableAccessTokenInterface";
4
+ declare class AccessToken implements RefreshableAccessTokenInterface {
5
+ protected corpId: string;
6
+ protected secret: string;
7
+ protected key: string;
8
+ protected cache: CacheInterface;
9
+ protected httpClient: HttpClientInterface;
10
+ constructor(corpId: string, secret: string, key?: string, cache?: CacheInterface, httpClient?: HttpClientInterface);
11
+ /**
12
+ * 获取access_token的缓存名称
13
+ * @returns
14
+ */
15
+ getKey(): string;
16
+ /**
17
+ * 设置access_token的缓存名称
18
+ * @param key
19
+ * @returns
20
+ */
21
+ setKey(key: string): this;
22
+ getToken(): Promise<string>;
23
+ toQuery(): Promise<Record<string, any>>;
24
+ refresh(): Promise<string>;
25
+ }
26
+ export = AccessToken;