node-easywechat 3.2.0 → 3.3.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.
- package/.github/workflows/publish-npm-2.yml +1 -1
- package/.github/workflows/publish-npm-3.yml +1 -1
- package/CHANGELOG.md +13 -0
- package/README.md +3 -3
- package/dist/MiniApp/Application.d.ts +4 -4
- package/dist/OfficialAccount/Application.d.ts +4 -4
- package/dist/OpenPlatform/Application.d.ts +5 -5
- package/dist/OpenPlatform/Application.js +1 -1
- package/dist/OpenWork/Account.d.ts +17 -0
- package/dist/OpenWork/Account.js +30 -0
- package/dist/OpenWork/Application.d.ts +120 -0
- package/dist/OpenWork/Application.js +294 -0
- package/dist/OpenWork/Authorization.d.ts +12 -0
- package/dist/OpenWork/Authorization.js +49 -0
- package/dist/OpenWork/AuthorizerAccessToken.d.ts +38 -0
- package/dist/OpenWork/AuthorizerAccessToken.js +105 -0
- package/dist/OpenWork/Config.d.ts +5 -0
- package/dist/OpenWork/Config.js +19 -0
- package/dist/OpenWork/Contracts/AccountInterface.d.ts +33 -0
- package/dist/OpenWork/Contracts/AccountInterface.js +35 -0
- package/dist/OpenWork/Contracts/ApplicationInterface.d.ts +108 -0
- package/dist/OpenWork/Contracts/ApplicationInterface.js +96 -0
- package/dist/OpenWork/Contracts/SuiteTicketInterface.d.ts +23 -0
- package/dist/OpenWork/Contracts/SuiteTicketInterface.js +25 -0
- package/dist/OpenWork/Encryptor.d.ts +9 -0
- package/dist/OpenWork/Encryptor.js +17 -0
- package/dist/OpenWork/JsApiTicket.d.ts +50 -0
- package/dist/OpenWork/JsApiTicket.js +152 -0
- package/dist/OpenWork/Message.d.ts +78 -0
- package/dist/OpenWork/Message.js +9 -0
- package/dist/OpenWork/ProviderAccessToken.d.ts +26 -0
- package/dist/OpenWork/ProviderAccessToken.js +84 -0
- package/dist/OpenWork/Server.d.ts +103 -0
- package/dist/OpenWork/Server.js +242 -0
- package/dist/OpenWork/SuiteAccessToken.d.ts +28 -0
- package/dist/OpenWork/SuiteAccessToken.js +86 -0
- package/dist/OpenWork/SuiteEncryptor.d.ts +9 -0
- package/dist/OpenWork/SuiteEncryptor.js +17 -0
- package/dist/OpenWork/SuiteTicket.d.ts +13 -0
- package/dist/OpenWork/SuiteTicket.js +49 -0
- package/dist/Pay/Application.d.ts +4 -4
- package/dist/Types/global.d.ts +11 -1
- package/dist/Work/Application.d.ts +5 -5
- package/dist/Work/Application.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/package.json +2 -2
|
@@ -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:
|
|
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():
|
|
29
|
+
getServer(): Server;
|
|
30
30
|
/**
|
|
31
31
|
* 设置服务端实例
|
|
32
32
|
* @param server
|
|
33
33
|
* @returns
|
|
34
34
|
*/
|
|
35
|
-
setServer(server:
|
|
35
|
+
setServer(server: Server): this;
|
|
36
36
|
getUtils(): Utils;
|
|
37
37
|
getClient(): Client;
|
|
38
38
|
/**
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -275,7 +275,17 @@ export declare interface OpenWorkConfig extends BaseConfig {
|
|
|
275
275
|
/**
|
|
276
276
|
* 企业微信 secret
|
|
277
277
|
*/
|
|
278
|
-
|
|
278
|
+
provider_secret?: string;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* 第三方应用的 app_id
|
|
282
|
+
*/
|
|
283
|
+
suite_id?: string;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* 第三方应用的 secret
|
|
287
|
+
*/
|
|
288
|
+
suite_secret?: string;
|
|
279
289
|
|
|
280
290
|
/**
|
|
281
291
|
* 企业微信服务端接口验证 token
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
|
|
2
2
|
import ConfigInterface from '../Core/Contracts/ConfigInterface';
|
|
3
|
-
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
4
3
|
import Encryptor from './Encryptor';
|
|
5
4
|
import AccessTokenAwareClient from '../Core/HttpClient/AccessTokenAwareClient';
|
|
6
5
|
import CacheMixin from '../Core/Mixins/CacheMixin';
|
|
@@ -12,16 +11,17 @@ import { WorkConfig, WorkOAuthFactory } from '../Types/global';
|
|
|
12
11
|
import AccountInterface from './Contracts/AccountInterface';
|
|
13
12
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
14
13
|
import JsApiTicket from './JsApiTicket';
|
|
14
|
+
import Server from './Server';
|
|
15
15
|
import Utils from './Utils';
|
|
16
16
|
import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* 企业微信应用
|
|
19
19
|
*/
|
|
20
20
|
declare class Application implements ApplicationInterface {
|
|
21
21
|
constructor(config: ConfigInterface | WorkConfig);
|
|
22
22
|
protected account: AccountInterface;
|
|
23
23
|
protected encryptor: Encryptor;
|
|
24
|
-
protected server:
|
|
24
|
+
protected server: Server;
|
|
25
25
|
protected accessToken: AccessTokenInterface;
|
|
26
26
|
protected oauthFactory: WorkOAuthFactory;
|
|
27
27
|
protected ticket: JsApiTicket;
|
|
@@ -39,13 +39,13 @@ declare class Application implements ApplicationInterface {
|
|
|
39
39
|
* @returns
|
|
40
40
|
*/
|
|
41
41
|
setEncryptor(encryptor: Encryptor): this;
|
|
42
|
-
getServer():
|
|
42
|
+
getServer(): Server;
|
|
43
43
|
/**
|
|
44
44
|
* 设置服务端实例
|
|
45
45
|
* @param server
|
|
46
46
|
* @returns
|
|
47
47
|
*/
|
|
48
|
-
setServer(server:
|
|
48
|
+
setServer(server: Server): this;
|
|
49
49
|
getAccessToken(): AccessTokenInterface;
|
|
50
50
|
/**
|
|
51
51
|
* 设置AccessToken实例
|
package/dist/Work/Application.js
CHANGED
|
@@ -29,7 +29,7 @@ const JsApiTicket_1 = __importDefault(require("./JsApiTicket"));
|
|
|
29
29
|
const Server_1 = __importDefault(require("./Server"));
|
|
30
30
|
const Utils_2 = __importDefault(require("./Utils"));
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* 企业微信应用
|
|
33
33
|
*/
|
|
34
34
|
class Application {
|
|
35
35
|
constructor(config) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig, OpenPlatformConfig, WorkConfig } from './Types/global';
|
|
1
|
+
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure, PayConfig, OpenPlatformConfig, WorkConfig, OpenWorkConfig } from './Types/global';
|
|
2
2
|
import OfficialAccount from './OfficialAccount/Application';
|
|
3
3
|
import MiniApp from './MiniApp/Application';
|
|
4
4
|
import Pay from './Pay/Application';
|
|
5
5
|
import OpenPlatform from './OpenPlatform/Application';
|
|
6
6
|
import Work from './Work/Application';
|
|
7
|
+
import OpenWork from './OpenWork/Application';
|
|
7
8
|
import CacheInterface from './Core/Contracts/CacheInterface';
|
|
8
9
|
import ServerRequest from './Core/Http/ServerRequest';
|
|
9
10
|
import FormData from 'form-data';
|
|
10
|
-
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, PayConfig, OpenPlatform, OpenPlatformConfig, Work, WorkConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
11
|
+
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, Pay, PayConfig, OpenPlatform, OpenPlatformConfig, Work, WorkConfig, OpenWork, OpenWorkConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure,
|
|
11
12
|
/**
|
|
12
13
|
* 表单对象
|
|
13
14
|
* @see https://github.com/axios/axios#formdata
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.FormData = exports.ServerRequest = exports.CacheInterface = exports.Work = exports.OpenPlatform = exports.Pay = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
6
|
+
exports.FormData = exports.ServerRequest = exports.CacheInterface = exports.OpenWork = exports.Work = exports.OpenPlatform = exports.Pay = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
7
7
|
const Application_1 = __importDefault(require("./OfficialAccount/Application"));
|
|
8
8
|
exports.OfficialAccount = Application_1.default;
|
|
9
9
|
const Application_2 = __importDefault(require("./MiniApp/Application"));
|
|
@@ -14,6 +14,8 @@ const Application_4 = __importDefault(require("./OpenPlatform/Application"));
|
|
|
14
14
|
exports.OpenPlatform = Application_4.default;
|
|
15
15
|
const Application_5 = __importDefault(require("./Work/Application"));
|
|
16
16
|
exports.Work = Application_5.default;
|
|
17
|
+
const Application_6 = __importDefault(require("./OpenWork/Application"));
|
|
18
|
+
exports.OpenWork = Application_6.default;
|
|
17
19
|
const CacheInterface_1 = __importDefault(require("./Core/Contracts/CacheInterface"));
|
|
18
20
|
exports.CacheInterface = CacheInterface_1.default;
|
|
19
21
|
const ServerRequest_1 = __importDefault(require("./Core/Http/ServerRequest"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-easywechat",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.1",
|
|
4
4
|
"description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"axios-retry": "^3.3.1",
|
|
34
34
|
"form-data": "^4.0.0",
|
|
35
35
|
"merge": "^2.1.1",
|
|
36
|
-
"node-socialite": "^1.
|
|
36
|
+
"node-socialite": "^1.3.0",
|
|
37
37
|
"qs": "^6.10.3",
|
|
38
38
|
"raw-body": "^2.5.1",
|
|
39
39
|
"xml2js": "^0.4.23"
|