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.
- package/CHANGELOG.md +4 -0
- package/dist/Channel/Application.js +1 -1
- package/dist/Core/Cache/FileCache.js +46 -63
- package/dist/Core/Contracts/AccessTokenInterface.js +2 -15
- package/dist/Core/Contracts/CacheInterface.js +4 -21
- package/dist/Core/Contracts/RefreshableAccessTokenInterface.js +1 -12
- package/dist/Core/Contracts/ServerInterface.js +1 -12
- package/dist/Core/Http/ServerRequest.js +34 -49
- package/dist/Core/HttpClient/AccessTokenAwareClient.js +6 -17
- package/dist/Core/HttpClient/Contracts/HttpClientInterface.js +1 -12
- package/dist/Core/HttpClient/HttpClient.js +74 -85
- package/dist/Core/HttpClient/HttpClientResponse.js +35 -50
- package/dist/Core/HttpClient/Mixins/HttpClientMethodsMixin.js +34 -59
- package/dist/Core/HttpClient/Mixins/PresetMixin.js +8 -11
- package/dist/Core/Message.js +20 -31
- package/dist/Core/Mixins/DecryptMessageMixin.js +13 -24
- package/dist/Core/Mixins/HandlersMixin.js +18 -31
- package/dist/Core/Mixins/ResponseMessageMixin.js +31 -44
- package/dist/Core/Support/Utils.js +8 -19
- package/dist/MiniApp/Application.js +1 -1
- package/dist/MiniApp/Utils.js +13 -24
- package/dist/OfficialAccount/AccessToken.js +42 -59
- package/dist/OfficialAccount/Application.js +1 -1
- package/dist/OfficialAccount/JsApiTicket.js +31 -44
- package/dist/OfficialAccount/Server.js +25 -40
- package/dist/OfficialAccount/Utils.js +6 -17
- package/dist/OpenPlatform/Application.js +62 -86
- package/dist/OpenPlatform/Authorizer/MiniApp/Utils.js +14 -25
- package/dist/OpenPlatform/AuthorizerAccessToken.js +6 -19
- package/dist/OpenPlatform/ComponentAccessToken.js +27 -42
- package/dist/OpenPlatform/Server.js +31 -54
- package/dist/OpenPlatform/VerifyTicket.js +14 -27
- package/dist/OpenWork/Application.js +61 -84
- package/dist/OpenWork/AuthorizerAccessToken.js +32 -47
- package/dist/OpenWork/JsApiTicket.js +64 -81
- package/dist/OpenWork/ProviderAccessToken.js +26 -41
- package/dist/OpenWork/Server.js +50 -94
- package/dist/OpenWork/SuiteAccessToken.js +27 -42
- package/dist/OpenWork/SuiteTicket.js +14 -27
- package/dist/Pay/Application.js +1 -2
- package/dist/Pay/Client.js +63 -77
- package/dist/Pay/LegacySignature.js +2 -3
- package/dist/Pay/Merchant.js +36 -52
- package/dist/Pay/Server.js +55 -70
- package/dist/Pay/Utils.js +13 -26
- package/dist/Pay/Validator.js +28 -39
- package/dist/Work/AccessToken.js +26 -41
- package/dist/Work/Application.js +21 -32
- package/dist/Work/JsApiTicket.js +60 -77
- package/dist/Work/Server.js +47 -86
- package/dist/Work/Utils.js +12 -25
- package/package.json +1 -1
- package/tsconfig.json +2 -2
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -35,46 +26,44 @@ class HttpClientResponse {
|
|
|
35
26
|
* @param throwError
|
|
36
27
|
* @returns
|
|
37
28
|
*/
|
|
38
|
-
parseContent() {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
29
|
+
async parseContent(throwError = false) {
|
|
30
|
+
throwError = throwError ?? this.throwError;
|
|
31
|
+
let content = this.response.data;
|
|
32
|
+
if (!content) {
|
|
33
|
+
if (throwError) {
|
|
34
|
+
throw new Error('Response body is empty.');
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (typeof content === 'string') {
|
|
39
|
+
if (this.is('xml') || content.indexOf('<xml>') > -1) {
|
|
40
|
+
this.parsedContent = await (0, Utils_1.parseXml)(content);
|
|
47
41
|
}
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
this.parsedContent =
|
|
42
|
+
else if (this.is('json')) {
|
|
43
|
+
try {
|
|
44
|
+
this.parsedContent = JSON.parse(content);
|
|
51
45
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
catch (e) {
|
|
57
|
-
if (throwError) {
|
|
58
|
-
throw new Error('Fail to parse JSON content.');
|
|
59
|
-
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (throwError) {
|
|
48
|
+
throw new Error('Fail to parse JSON content.');
|
|
60
49
|
}
|
|
61
50
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
this.parsedContent = {};
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
try {
|
|
54
|
+
this.parsedContent = (0, Utils_1.parseQueryString)(content);
|
|
55
|
+
}
|
|
56
|
+
catch (e) {
|
|
57
|
+
if (throwError) {
|
|
58
|
+
throw new Error('Fail to parse QueryString content.');
|
|
71
59
|
}
|
|
60
|
+
this.parsedContent = {};
|
|
72
61
|
}
|
|
73
62
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
63
|
+
}
|
|
64
|
+
else if (!Buffer.isBuffer(content)) {
|
|
65
|
+
this.parsedContent = content;
|
|
66
|
+
}
|
|
78
67
|
}
|
|
79
68
|
withThrowError(throwError) {
|
|
80
69
|
this.throwError = throwError;
|
|
@@ -232,15 +221,11 @@ class HttpClientResponse {
|
|
|
232
221
|
getInfo(type) {
|
|
233
222
|
return this.response.config;
|
|
234
223
|
}
|
|
235
|
-
offsetExists(key) {
|
|
236
|
-
return
|
|
237
|
-
return Object.keys(yield this.toObject()).findIndex(o => o === key) > -1;
|
|
238
|
-
});
|
|
224
|
+
async offsetExists(key) {
|
|
225
|
+
return Object.keys(await this.toObject()).findIndex(o => o === key) > -1;
|
|
239
226
|
}
|
|
240
|
-
offsetGet(key) {
|
|
241
|
-
return
|
|
242
|
-
return (yield this.toObject())[key] || null;
|
|
243
|
-
});
|
|
227
|
+
async offsetGet(key) {
|
|
228
|
+
return (await this.toObject())[key] || null;
|
|
244
229
|
}
|
|
245
230
|
/**
|
|
246
231
|
* 转换为标准的 http 响应类
|
|
@@ -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
|
};
|
|
@@ -20,10 +11,8 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
20
11
|
* @param payload axios配置项
|
|
21
12
|
* @returns
|
|
22
13
|
*/
|
|
23
|
-
get(
|
|
24
|
-
return
|
|
25
|
-
return this.request('get', url, payload);
|
|
26
|
-
});
|
|
14
|
+
async get(url, payload = {}) {
|
|
15
|
+
return this.request('get', url, payload);
|
|
27
16
|
}
|
|
28
17
|
/**
|
|
29
18
|
* 发送post请求
|
|
@@ -31,10 +20,8 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
31
20
|
* @param payload axios配置项
|
|
32
21
|
* @returns
|
|
33
22
|
*/
|
|
34
|
-
post(
|
|
35
|
-
return
|
|
36
|
-
return this.request('post', url, payload);
|
|
37
|
-
});
|
|
23
|
+
async post(url, payload = {}) {
|
|
24
|
+
return this.request('post', url, payload);
|
|
38
25
|
}
|
|
39
26
|
/**
|
|
40
27
|
* 发送patch请求
|
|
@@ -42,10 +29,8 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
42
29
|
* @param payload axios配置项
|
|
43
30
|
* @returns
|
|
44
31
|
*/
|
|
45
|
-
patch(
|
|
46
|
-
return
|
|
47
|
-
return this.request('patch', url, payload);
|
|
48
|
-
});
|
|
32
|
+
async patch(url, payload = {}) {
|
|
33
|
+
return this.request('patch', url, payload);
|
|
49
34
|
}
|
|
50
35
|
/**
|
|
51
36
|
* 发送put请求
|
|
@@ -53,10 +38,8 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
53
38
|
* @param payload axios配置项
|
|
54
39
|
* @returns
|
|
55
40
|
*/
|
|
56
|
-
put(
|
|
57
|
-
return
|
|
58
|
-
return this.request('put', url, payload);
|
|
59
|
-
});
|
|
41
|
+
async put(url, payload = {}) {
|
|
42
|
+
return this.request('put', url, payload);
|
|
60
43
|
}
|
|
61
44
|
/**
|
|
62
45
|
* 发送delete请求
|
|
@@ -64,10 +47,8 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
64
47
|
* @param payload axios配置项
|
|
65
48
|
* @returns
|
|
66
49
|
*/
|
|
67
|
-
delete(
|
|
68
|
-
return
|
|
69
|
-
return this.request('delete', url, payload);
|
|
70
|
-
});
|
|
50
|
+
async delete(url, payload = {}) {
|
|
51
|
+
return this.request('delete', url, payload);
|
|
71
52
|
}
|
|
72
53
|
/**
|
|
73
54
|
* 发送post请求(JSON数据)
|
|
@@ -76,16 +57,14 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
76
57
|
* @param payload axios配置项
|
|
77
58
|
* @returns
|
|
78
59
|
*/
|
|
79
|
-
postJson(
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return this.request('post', url, payload);
|
|
88
|
-
});
|
|
60
|
+
async postJson(url, data, payload = {}) {
|
|
61
|
+
if (!payload)
|
|
62
|
+
payload = {};
|
|
63
|
+
if (!payload['headers'])
|
|
64
|
+
payload['headers'] = {};
|
|
65
|
+
payload['headers']['Content-Type'] = 'application/json';
|
|
66
|
+
payload.json = merge_1.default.recursive({}, data);
|
|
67
|
+
return this.request('post', url, payload);
|
|
89
68
|
}
|
|
90
69
|
/**
|
|
91
70
|
* 发送patch请求(JSON数据)
|
|
@@ -94,16 +73,14 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
94
73
|
* @param payload axios配置项
|
|
95
74
|
* @returns
|
|
96
75
|
*/
|
|
97
|
-
patchJson(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return this.request('patch', url, payload);
|
|
106
|
-
});
|
|
76
|
+
async patchJson(url, data, payload = {}) {
|
|
77
|
+
if (!payload)
|
|
78
|
+
payload = {};
|
|
79
|
+
if (!payload['headers'])
|
|
80
|
+
payload['headers'] = {};
|
|
81
|
+
payload['headers']['Content-Type'] = 'application/json';
|
|
82
|
+
payload.json = merge_1.default.recursive({}, data);
|
|
83
|
+
return this.request('patch', url, payload);
|
|
107
84
|
}
|
|
108
85
|
/**
|
|
109
86
|
* 发送post请求(XML数据)
|
|
@@ -112,16 +89,14 @@ class HttpClientMethodsMixin extends HttpClientInterface_1.default {
|
|
|
112
89
|
* @param payload axios配置项
|
|
113
90
|
* @returns
|
|
114
91
|
*/
|
|
115
|
-
postXml(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
return this.request('post', url, payload);
|
|
124
|
-
});
|
|
92
|
+
async postXml(url, data, payload = {}) {
|
|
93
|
+
if (!payload)
|
|
94
|
+
payload = {};
|
|
95
|
+
if (!payload['headers'])
|
|
96
|
+
payload['headers'] = {};
|
|
97
|
+
payload['headers']['Content-Type'] = 'text/xml';
|
|
98
|
+
payload.xml = typeof data === 'object' ? merge_1.default.recursive({}, data) : data;
|
|
99
|
+
return this.request('post', url, payload);
|
|
125
100
|
}
|
|
126
101
|
}
|
|
127
102
|
module.exports = HttpClientMethodsMixin;
|
|
@@ -64,15 +64,13 @@ class PresetMixin {
|
|
|
64
64
|
with(key, value = null) {
|
|
65
65
|
if (Array.isArray(key)) {
|
|
66
66
|
key.map((k) => {
|
|
67
|
-
|
|
68
|
-
this.with(k, (_a = this.presets[k]) !== null && _a !== void 0 ? _a : null);
|
|
67
|
+
this.with(k, this.presets[k] ?? null);
|
|
69
68
|
});
|
|
70
69
|
return this;
|
|
71
70
|
}
|
|
72
71
|
else if (typeof key === 'object') {
|
|
73
72
|
key.map((v, k) => {
|
|
74
|
-
|
|
75
|
-
this.with(k, (_a = v !== null && v !== void 0 ? v : this.presets[k]) !== null && _a !== void 0 ? _a : null);
|
|
73
|
+
this.with(k, v ?? this.presets[k] ?? null);
|
|
76
74
|
});
|
|
77
75
|
return this;
|
|
78
76
|
}
|
|
@@ -145,27 +143,26 @@ class PresetMixin {
|
|
|
145
143
|
* @returns
|
|
146
144
|
*/
|
|
147
145
|
mergeThenResetPrepends(payload, method = 'get') {
|
|
148
|
-
var _a, _b, _c, _d;
|
|
149
146
|
let field = method.toLowerCase() === 'get' ? 'params' : 'data';
|
|
150
|
-
let options =
|
|
147
|
+
let options = { ...payload };
|
|
151
148
|
if (!options.headers)
|
|
152
149
|
options.headers = {};
|
|
153
150
|
if (!options.formData)
|
|
154
151
|
options.formData = {};
|
|
155
|
-
if ((
|
|
152
|
+
if ((options.headers['Content-Type'] ?? options.headers['content-type'] ?? null) === 'application/json' || !!options.json) {
|
|
156
153
|
field = 'json';
|
|
157
154
|
}
|
|
158
|
-
if ((
|
|
155
|
+
if ((options.headers['Content-Type'] ?? options.headers['content-type'] ?? null) === 'text/xml' || !!options.xml) {
|
|
159
156
|
field = 'xml';
|
|
160
157
|
}
|
|
161
158
|
if (this.prependData && Object.keys(this.prependData).length > 0) {
|
|
162
|
-
options[field] =
|
|
159
|
+
options[field] = { ...this.prependData, ...options[field] };
|
|
163
160
|
}
|
|
164
161
|
if (this.prependHeaders && Object.keys(this.prependHeaders).length > 0) {
|
|
165
|
-
options.headers =
|
|
162
|
+
options.headers = { ...this.prependHeaders, ...options.headers };
|
|
166
163
|
}
|
|
167
164
|
if (this.prependFiles && Object.keys(this.prependFiles).length > 0) {
|
|
168
|
-
options.formData =
|
|
165
|
+
options.formData = { ...this.prependFiles, ...options.formData };
|
|
169
166
|
}
|
|
170
167
|
this.prependData = {};
|
|
171
168
|
this.prependHeaders = {};
|
package/dist/Core/Message.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
|
};
|
|
@@ -51,29 +42,27 @@ class Message {
|
|
|
51
42
|
* @param request
|
|
52
43
|
* @returns
|
|
53
44
|
*/
|
|
54
|
-
static createFromRequest(request) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
attributes = JSON.parse(originContent);
|
|
69
|
-
}
|
|
70
|
-
catch (e) { }
|
|
71
|
-
}
|
|
72
|
-
if (Object.keys(attributes).length === 0) {
|
|
73
|
-
throw new Error('Failed to decode request contents.');
|
|
45
|
+
static async createFromRequest(request) {
|
|
46
|
+
let originContent = '';
|
|
47
|
+
let body = request.getBody();
|
|
48
|
+
if (body) {
|
|
49
|
+
originContent = body.toString();
|
|
50
|
+
}
|
|
51
|
+
let attributes = {};
|
|
52
|
+
if ('<' === originContent.substring(0, 1)) {
|
|
53
|
+
attributes = await (0, Utils_1.parseXml)(originContent);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Handle JSON format.
|
|
57
|
+
try {
|
|
58
|
+
attributes = JSON.parse(originContent);
|
|
74
59
|
}
|
|
75
|
-
|
|
76
|
-
}
|
|
60
|
+
catch (e) { }
|
|
61
|
+
}
|
|
62
|
+
if (Object.keys(attributes).length === 0) {
|
|
63
|
+
throw new Error('Failed to decode request contents.');
|
|
64
|
+
}
|
|
65
|
+
return new Message(attributes, originContent);
|
|
77
66
|
}
|
|
78
67
|
/**
|
|
79
68
|
* 获取原始消息内容
|
|
@@ -1,34 +1,23 @@
|
|
|
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
|
const Utils_1 = require("../Support/Utils");
|
|
12
3
|
class DecryptMessageMixin {
|
|
13
4
|
/**
|
|
14
5
|
* 解密消息
|
|
15
6
|
* @returns
|
|
16
7
|
*/
|
|
17
|
-
decryptMessage(message, encryptor, signature, timestamp, nonce) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return message;
|
|
31
|
-
});
|
|
8
|
+
async decryptMessage(message, encryptor, signature, timestamp, nonce) {
|
|
9
|
+
const ciphertext = message['Encrypt'];
|
|
10
|
+
this.validateSignature(encryptor.getToken(), ciphertext, signature, timestamp, nonce);
|
|
11
|
+
const plaintext = encryptor.decrypt(ciphertext, signature, nonce, timestamp);
|
|
12
|
+
let attributes;
|
|
13
|
+
if (plaintext.substring(0, 1) === '<') {
|
|
14
|
+
attributes = await (0, Utils_1.parseXml)(plaintext);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
attributes = JSON.parse(plaintext);
|
|
18
|
+
}
|
|
19
|
+
message.merge(attributes);
|
|
20
|
+
return message;
|
|
32
21
|
}
|
|
33
22
|
validateSignature(token, ciphertext, signature, timestamp, nonce) {
|
|
34
23
|
if (!signature) {
|
|
@@ -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
|
const Utils_1 = require("../Support/Utils");
|
|
12
3
|
class HandlersMixin {
|
|
13
4
|
constructor() {
|
|
@@ -126,29 +117,25 @@ class HandlersMixin {
|
|
|
126
117
|
* @param payload
|
|
127
118
|
* @returns
|
|
128
119
|
*/
|
|
129
|
-
handle(result, payload) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
120
|
+
async handle(result, payload) {
|
|
121
|
+
// 默认返回值处理函数
|
|
122
|
+
let resultClosure = async (p) => { return result; };
|
|
123
|
+
if (typeof result === 'function') {
|
|
124
|
+
resultClosure = result;
|
|
125
|
+
}
|
|
126
|
+
let handlers = [...this.handlers];
|
|
127
|
+
const nextClosure = async function (p) {
|
|
128
|
+
if (handlers.length > 0) {
|
|
129
|
+
let item = handlers.shift();
|
|
130
|
+
let closureRes = await item.handler(p, nextClosure);
|
|
131
|
+
if (closureRes)
|
|
132
|
+
return closureRes;
|
|
135
133
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
let closureRes = yield item.handler(p, nextClosure);
|
|
142
|
-
if (closureRes)
|
|
143
|
-
return closureRes;
|
|
144
|
-
}
|
|
145
|
-
// 处理器无返回值则返回默认的返回值
|
|
146
|
-
return yield resultClosure(p);
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
// 开始处理
|
|
150
|
-
return yield nextClosure(payload);
|
|
151
|
-
});
|
|
134
|
+
// 处理器无返回值则返回默认的返回值
|
|
135
|
+
return await resultClosure(p);
|
|
136
|
+
};
|
|
137
|
+
// 开始处理
|
|
138
|
+
return await nextClosure(payload);
|
|
152
139
|
}
|
|
153
140
|
/**
|
|
154
141
|
* 判断处理器是否已存在
|
|
@@ -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
|
};
|
|
@@ -19,43 +10,39 @@ class ResponseMessageMixin {
|
|
|
19
10
|
* 转化为回复消息
|
|
20
11
|
* @returns
|
|
21
12
|
*/
|
|
22
|
-
transformToReply(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
});
|
|
13
|
+
async transformToReply(response, message, encryptor = null, isXml = true) {
|
|
14
|
+
if (!response || response === true) {
|
|
15
|
+
return new Response_1.default(200, {}, 'success');
|
|
16
|
+
}
|
|
17
|
+
let attributes = merge_1.default.recursive({
|
|
18
|
+
ToUserName: message['FromUserName'],
|
|
19
|
+
FromUserName: message['ToUserName'],
|
|
20
|
+
CreateTime: (0, Utils_1.getTimestamp)(),
|
|
21
|
+
}, await this.normalizeResponse(response));
|
|
22
|
+
if (isXml) {
|
|
23
|
+
return this.createXmlResponse(attributes, encryptor);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return this.createJsonResponse(attributes, encryptor);
|
|
27
|
+
}
|
|
39
28
|
}
|
|
40
|
-
normalizeResponse(response) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (
|
|
46
|
-
|
|
47
|
-
throw new Error('`MsgType` cannot be empty.');
|
|
48
|
-
}
|
|
49
|
-
return response;
|
|
50
|
-
}
|
|
51
|
-
if (typeof response === 'string' || typeof response === 'number') {
|
|
52
|
-
return {
|
|
53
|
-
MsgType: 'text',
|
|
54
|
-
Content: response,
|
|
55
|
-
};
|
|
29
|
+
async normalizeResponse(response) {
|
|
30
|
+
if (typeof response === 'function') {
|
|
31
|
+
response = await response();
|
|
32
|
+
}
|
|
33
|
+
if (typeof response === 'object') {
|
|
34
|
+
if (!response['MsgType']) {
|
|
35
|
+
throw new Error('`MsgType` cannot be empty.');
|
|
56
36
|
}
|
|
57
|
-
|
|
58
|
-
}
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
if (typeof response === 'string' || typeof response === 'number') {
|
|
40
|
+
return {
|
|
41
|
+
MsgType: 'text',
|
|
42
|
+
Content: response,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Invalid Response "${response.toString()}".`);
|
|
59
46
|
}
|
|
60
47
|
createXmlResponse(attributes, encryptor = null) {
|
|
61
48
|
let xml = (0, Utils_1.buildXml)(attributes);
|
|
@@ -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
|
};
|
|
@@ -292,16 +283,14 @@ exports.singleItem = singleItem;
|
|
|
292
283
|
* @param xml
|
|
293
284
|
* @returns
|
|
294
285
|
*/
|
|
295
|
-
const parseXml = function (xml) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return res;
|
|
304
|
-
});
|
|
286
|
+
const parseXml = async function (xml) {
|
|
287
|
+
let res = await xml2js_1.default.parseStringPromise(xml);
|
|
288
|
+
// fix [Object: null prototype]
|
|
289
|
+
res = JSON.parse(JSON.stringify(res));
|
|
290
|
+
res = (0, exports.singleItem)(res);
|
|
291
|
+
if (res['xml'])
|
|
292
|
+
res = res['xml'];
|
|
293
|
+
return res;
|
|
305
294
|
};
|
|
306
295
|
exports.parseXml = parseXml;
|
|
307
296
|
/**
|
|
@@ -121,7 +121,7 @@ class Application {
|
|
|
121
121
|
return this.utils;
|
|
122
122
|
}
|
|
123
123
|
createClient() {
|
|
124
|
-
return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) =>
|
|
124
|
+
return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) => (response.toObject()['errcode'] ?? 0) || (response.toObject()['error'] !== null && response.toObject()['error'] !== undefined), this.getConfig().get('http.throw', true)))
|
|
125
125
|
.setPresets(this.getConfig().all());
|
|
126
126
|
}
|
|
127
127
|
/**
|