node-easywechat 3.0.0-beta.1 → 3.0.0-beta.4
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 +15 -0
- package/dist/Core/Contracts/CacheInterface.d.ts +3 -0
- package/dist/Core/Contracts/CacheInterface.js +3 -0
- package/dist/Core/Contracts/ServerInterface.d.ts +6 -0
- package/dist/Core/Contracts/ServerInterface.js +12 -0
- package/dist/Core/Http/ServerRequest.d.ts +3 -0
- package/dist/Core/Http/ServerRequest.js +3 -0
- package/dist/Core/HttpClient/HttpClient.d.ts +7 -0
- package/dist/Core/HttpClient/HttpClient.js +40 -6
- package/dist/Core/HttpClient/HttpClientResponse.js +1 -1
- package/dist/Core/HttpClient/Mixins/PresetMixin.d.ts +20 -1
- package/dist/Core/HttpClient/Mixins/PresetMixin.js +41 -2
- package/dist/Core/Message.d.ts +3 -0
- package/dist/Core/Message.js +3 -0
- package/dist/MiniApp/Application.d.ts +3 -0
- package/dist/MiniApp/Application.js +3 -0
- package/dist/OfficialAccount/Application.d.ts +3 -0
- package/dist/OfficialAccount/Application.js +4 -1
- package/dist/OfficialAccount/Server.d.ts +1 -6
- package/dist/OfficialAccount/Server.js +4 -9
- package/dist/OfficialAccount/Utils.d.ts +8 -0
- package/dist/OfficialAccount/Utils.js +8 -0
- package/dist/Types/global.d.ts +5 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +5 -1
- package/package.json +2 -2
- package/mini_app.access_token.mock-access_token-appid.cache +0 -1
- package/official_account.access_token.mock-access_token-appid.cache +0 -1
- package/official_account.jsapi_ticket.mock-ticket-appid.cache +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v3.0.0-beta.4 (2022-06-24)
|
|
5
|
+
|
|
6
|
+
- Feat: 请求接口数据增加 FormData 实例的支持
|
|
7
|
+
|
|
8
|
+
## v3.0.0-beta.3 (2022-06-22)
|
|
9
|
+
|
|
10
|
+
- Fix: 修复获取js ticket时无法自动获取access_token的问题
|
|
11
|
+
- Fix: 修复日志处理回调函数的参数提示异常的问题
|
|
12
|
+
|
|
13
|
+
## v3.0.0-beta.2 (2022-06-21)
|
|
14
|
+
|
|
15
|
+
- Feat: 统一调用入口增加一些常用的类
|
|
16
|
+
|
|
17
|
+
- Fix: 修复获取的服务端实例没有代码提示的问题
|
|
18
|
+
|
|
4
19
|
## v3.0.0-beta.1 (2022-06-21)
|
|
5
20
|
|
|
6
21
|
- Feat: 新增设置预置参数相关方法
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import ResponseInterface from "../Http/Contracts/ResponseInterface";
|
|
2
|
+
import DecryptXmlMessageMixin from "../Mixins/DecryptXmlMessageMixin";
|
|
3
|
+
import HandlersMixin from "../Mixins/HandlersMixin";
|
|
4
|
+
import ResponseXmlMessageMixin from "../Mixins/ResponseXmlMessageMixin";
|
|
2
5
|
declare abstract class ServerInterface {
|
|
6
|
+
constructor();
|
|
3
7
|
/**
|
|
4
8
|
* 处理消息
|
|
5
9
|
*/
|
|
6
10
|
serve(): Promise<ResponseInterface>;
|
|
7
11
|
}
|
|
12
|
+
interface ServerInterface extends HandlersMixin, DecryptXmlMessageMixin, ResponseXmlMessageMixin {
|
|
13
|
+
}
|
|
8
14
|
export = ServerInterface;
|
|
@@ -8,7 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const DecryptXmlMessageMixin_1 = __importDefault(require("../Mixins/DecryptXmlMessageMixin"));
|
|
15
|
+
const HandlersMixin_1 = __importDefault(require("../Mixins/HandlersMixin"));
|
|
16
|
+
const ResponseXmlMessageMixin_1 = __importDefault(require("../Mixins/ResponseXmlMessageMixin"));
|
|
17
|
+
const Utils_1 = require("../Support/Utils");
|
|
11
18
|
class ServerInterface {
|
|
19
|
+
constructor() {
|
|
20
|
+
this.handlers = [];
|
|
21
|
+
}
|
|
12
22
|
/**
|
|
13
23
|
* 处理消息
|
|
14
24
|
*/
|
|
@@ -17,4 +27,6 @@ class ServerInterface {
|
|
|
17
27
|
}
|
|
18
28
|
}
|
|
19
29
|
;
|
|
30
|
+
;
|
|
31
|
+
(0, Utils_1.applyMixins)(ServerInterface, [HandlersMixin_1.default, DecryptXmlMessageMixin_1.default, ResponseXmlMessageMixin_1.default]);
|
|
20
32
|
module.exports = ServerInterface;
|
|
@@ -3,6 +3,9 @@ import { IncomingMessage } from "http";
|
|
|
3
3
|
import ServerRequestInterface from "./Contracts/ServerRequestInterface";
|
|
4
4
|
import MessageMixin from "./Minxins/MessageMixin";
|
|
5
5
|
import RequestMixin from "./Minxins/RequestMixin";
|
|
6
|
+
/**
|
|
7
|
+
* 服务器收到的请求对象
|
|
8
|
+
*/
|
|
6
9
|
declare class ServerRequest implements ServerRequestInterface {
|
|
7
10
|
protected attributes: Record<string, any>;
|
|
8
11
|
protected cookieParams: Record<string, any>;
|
|
@@ -8,6 +8,9 @@ const url_1 = require("url");
|
|
|
8
8
|
const Utils_1 = require("../Support/Utils");
|
|
9
9
|
const MessageMixin_1 = __importDefault(require("./Minxins/MessageMixin"));
|
|
10
10
|
const RequestMixin_1 = __importDefault(require("./Minxins/RequestMixin"));
|
|
11
|
+
/**
|
|
12
|
+
* 服务器收到的请求对象
|
|
13
|
+
*/
|
|
11
14
|
class ServerRequest {
|
|
12
15
|
constructor(method, url, headers = {}, body = null, version = 'v1.1', serverParams = {}) {
|
|
13
16
|
this.attributes = {};
|
|
@@ -2,6 +2,7 @@ import { AxiosInstance, AxiosRequestConfig, Method } from 'axios';
|
|
|
2
2
|
import HttpClientInterface from './Contracts/HttpClientInterface';
|
|
3
3
|
import HttpClientResponse from './HttpClientResponse';
|
|
4
4
|
import { HttpClientFailureJudgeClosure, LogHandler } from '../../Types/global';
|
|
5
|
+
import FormData from 'form-data';
|
|
5
6
|
declare class HttpClient implements HttpClientInterface {
|
|
6
7
|
protected axios: AxiosInstance;
|
|
7
8
|
protected failureJudge: HttpClientFailureJudgeClosure;
|
|
@@ -19,6 +20,12 @@ declare class HttpClient implements HttpClientInterface {
|
|
|
19
20
|
request(method: Method, url: string, payload?: AxiosRequestConfig<any>): Promise<HttpClientResponse>;
|
|
20
21
|
getInstance(): AxiosInstance;
|
|
21
22
|
setInstance(instance: AxiosInstance): this;
|
|
23
|
+
/**
|
|
24
|
+
* 获取 FormData 对象的 headers
|
|
25
|
+
* @param formData
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
protected getFormDataHeaders(formData: FormData): Promise<Record<string, string | number>>;
|
|
22
29
|
/**
|
|
23
30
|
* 创建http客户端
|
|
24
31
|
* @param config
|
|
@@ -11,10 +11,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
|
-
const merge_1 = __importDefault(require("merge"));
|
|
15
14
|
const axios_1 = __importDefault(require("axios"));
|
|
16
15
|
const HttpClientResponse_1 = __importDefault(require("./HttpClientResponse"));
|
|
17
16
|
const Utils_1 = require("../Support/Utils");
|
|
17
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
18
18
|
class HttpClient {
|
|
19
19
|
constructor(axios, failureJudge = null, throwError = false) {
|
|
20
20
|
this.axios = axios;
|
|
@@ -35,7 +35,9 @@ class HttpClient {
|
|
|
35
35
|
}
|
|
36
36
|
request(method, url, payload = {}) {
|
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
let options =
|
|
38
|
+
let options = Object.assign({}, payload);
|
|
39
|
+
if (!options.headers)
|
|
40
|
+
options.headers = {};
|
|
39
41
|
options.method = method;
|
|
40
42
|
options.url = url;
|
|
41
43
|
if (options['xml'] !== undefined) {
|
|
@@ -49,8 +51,6 @@ class HttpClient {
|
|
|
49
51
|
else {
|
|
50
52
|
throw new Error('The type of `xml` must be string or object.');
|
|
51
53
|
}
|
|
52
|
-
if (!options.headers)
|
|
53
|
-
options.headers = {};
|
|
54
54
|
if (!options.headers['Content-Type'] && !options.headers['content-type']) {
|
|
55
55
|
options.headers['content-type'] = 'text/xml';
|
|
56
56
|
}
|
|
@@ -69,8 +69,6 @@ class HttpClient {
|
|
|
69
69
|
else {
|
|
70
70
|
throw new Error('The type of `json` must be string or object.');
|
|
71
71
|
}
|
|
72
|
-
if (!options.headers)
|
|
73
|
-
options.headers = {};
|
|
74
72
|
if (!options.headers['Content-Type'] && !options.headers['content-type']) {
|
|
75
73
|
options.headers['content-type'] = 'application/json';
|
|
76
74
|
}
|
|
@@ -78,6 +76,23 @@ class HttpClient {
|
|
|
78
76
|
options['json'] = undefined;
|
|
79
77
|
delete options['json'];
|
|
80
78
|
}
|
|
79
|
+
if (options['formData'] && Object.keys(options['formData']).length > 0) {
|
|
80
|
+
let formData = new form_data_1.default();
|
|
81
|
+
for (let key in options['formData']) {
|
|
82
|
+
formData.append(key, options['formData'][key]);
|
|
83
|
+
}
|
|
84
|
+
if (options.data)
|
|
85
|
+
for (let key in options.data) {
|
|
86
|
+
formData.append(key, options.data[key]);
|
|
87
|
+
}
|
|
88
|
+
options.data = formData;
|
|
89
|
+
options['formData'] = undefined;
|
|
90
|
+
delete options['formData'];
|
|
91
|
+
}
|
|
92
|
+
// 如果 data 是 FormData 对象,则从中提取 headers
|
|
93
|
+
if (options.data && options.data instanceof form_data_1.default) {
|
|
94
|
+
options.headers = Object.assign(Object.assign({}, (yield this.getFormDataHeaders(options.data))), options.headers);
|
|
95
|
+
}
|
|
81
96
|
let starttime = Date.now();
|
|
82
97
|
if (typeof this.logger === 'function') {
|
|
83
98
|
yield this.logger('before', options);
|
|
@@ -97,6 +112,25 @@ class HttpClient {
|
|
|
97
112
|
this.axios = instance;
|
|
98
113
|
return this;
|
|
99
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* 获取 FormData 对象的 headers
|
|
117
|
+
* @param formData
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
getFormDataHeaders(formData) {
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
let headers = formData.getHeaders();
|
|
123
|
+
formData.getLength(function (err, length) {
|
|
124
|
+
if (err) {
|
|
125
|
+
headers['content-length'] = 0;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
headers['content-length'] = length;
|
|
129
|
+
}
|
|
130
|
+
resolve(headers);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
}
|
|
100
134
|
/**
|
|
101
135
|
* 创建http客户端
|
|
102
136
|
* @param config
|
|
@@ -117,7 +117,7 @@ class HttpClientResponse {
|
|
|
117
117
|
* @returns
|
|
118
118
|
*/
|
|
119
119
|
toDataUrl() {
|
|
120
|
-
return 'data:' + this.getHeader('content-type') + ';base64,' + this.response.data;
|
|
120
|
+
return 'data:' + this.getHeader('content-type') + ';base64,' + this.response.data.toString('base64');
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* 判断 content-type 是否指定类型
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { AxiosRequestConfig, Method } from "axios";
|
|
3
|
+
import fs from "fs";
|
|
2
4
|
declare class PresetMixin {
|
|
3
5
|
/**
|
|
4
6
|
* 存储预置参数
|
|
@@ -12,6 +14,10 @@ declare class PresetMixin {
|
|
|
12
14
|
* 存储预置数据
|
|
13
15
|
*/
|
|
14
16
|
protected prependData: Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* 存储预置文件数据
|
|
19
|
+
*/
|
|
20
|
+
protected prependFiles: Record<string, fs.ReadStream>;
|
|
15
21
|
/**
|
|
16
22
|
* 设置预置参数
|
|
17
23
|
* @param presets
|
|
@@ -68,12 +74,25 @@ declare class PresetMixin {
|
|
|
68
74
|
* @returns
|
|
69
75
|
*/
|
|
70
76
|
withMchIdAs(new_alias?: string): this;
|
|
77
|
+
/**
|
|
78
|
+
* 预设置文件
|
|
79
|
+
* @param file 文件路径或可读文件流
|
|
80
|
+
* @param key 参数名,默认:'file'
|
|
81
|
+
* @returns
|
|
82
|
+
*/
|
|
83
|
+
withFile(file: string | fs.ReadStream, key?: string): this;
|
|
84
|
+
/**
|
|
85
|
+
* 预设置多个文件
|
|
86
|
+
* @param files 键名:文件名,键值:文件路径或可读文件流
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
withFiles(files: Record<string, string | fs.ReadStream>): this;
|
|
71
90
|
/**
|
|
72
91
|
* 合并预置参数并清空预置数据
|
|
73
92
|
* @param payload
|
|
74
93
|
* @param method
|
|
75
94
|
* @returns
|
|
76
95
|
*/
|
|
77
|
-
mergeThenResetPrepends(payload: AxiosRequestConfig, method?: Method): any
|
|
96
|
+
mergeThenResetPrepends(payload: AxiosRequestConfig, method?: Method): AxiosRequestConfig<any>;
|
|
78
97
|
}
|
|
79
98
|
export = PresetMixin;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
-
const
|
|
5
|
+
const fs_1 = __importDefault(require("fs"));
|
|
6
6
|
class PresetMixin {
|
|
7
7
|
constructor() {
|
|
8
8
|
/**
|
|
@@ -17,6 +17,10 @@ class PresetMixin {
|
|
|
17
17
|
* 存储预置数据
|
|
18
18
|
*/
|
|
19
19
|
this.prependData = {};
|
|
20
|
+
/**
|
|
21
|
+
* 存储预置文件数据
|
|
22
|
+
*/
|
|
23
|
+
this.prependFiles = {};
|
|
20
24
|
}
|
|
21
25
|
/**
|
|
22
26
|
* 设置预置参数
|
|
@@ -123,6 +127,35 @@ class PresetMixin {
|
|
|
123
127
|
this.with(new_alias, this.presets['mch_id']);
|
|
124
128
|
return this;
|
|
125
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* 预设置文件
|
|
132
|
+
* @param file 文件路径或可读文件流
|
|
133
|
+
* @param key 参数名,默认:'file'
|
|
134
|
+
* @returns
|
|
135
|
+
*/
|
|
136
|
+
withFile(file, key = 'file') {
|
|
137
|
+
if (typeof this.prependFiles !== 'object') {
|
|
138
|
+
this.prependFiles = {};
|
|
139
|
+
}
|
|
140
|
+
if (file instanceof fs_1.default.ReadStream) {
|
|
141
|
+
this.prependFiles[key] = file;
|
|
142
|
+
}
|
|
143
|
+
else if (typeof file === 'string') {
|
|
144
|
+
this.prependFiles[key] = fs_1.default.createReadStream(file);
|
|
145
|
+
}
|
|
146
|
+
return this;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 预设置多个文件
|
|
150
|
+
* @param files 键名:文件名,键值:文件路径或可读文件流
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
withFiles(files) {
|
|
154
|
+
for (const key in files) {
|
|
155
|
+
this.withFile(files[key], key);
|
|
156
|
+
}
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
126
159
|
/**
|
|
127
160
|
* 合并预置参数并清空预置数据
|
|
128
161
|
* @param payload
|
|
@@ -132,9 +165,11 @@ class PresetMixin {
|
|
|
132
165
|
mergeThenResetPrepends(payload, method = 'get') {
|
|
133
166
|
var _a, _b, _c, _d;
|
|
134
167
|
let field = method.toLowerCase() === 'get' ? 'params' : 'data';
|
|
135
|
-
let options =
|
|
168
|
+
let options = Object.assign({}, payload);
|
|
136
169
|
if (!options.headers)
|
|
137
170
|
options.headers = {};
|
|
171
|
+
if (!options.formData)
|
|
172
|
+
options.formData = {};
|
|
138
173
|
if (((_b = (_a = options.headers['Content-Type']) !== null && _a !== void 0 ? _a : options.headers['content-type']) !== null && _b !== void 0 ? _b : null) === 'application/json' || !!options.json) {
|
|
139
174
|
field = 'json';
|
|
140
175
|
}
|
|
@@ -147,8 +182,12 @@ class PresetMixin {
|
|
|
147
182
|
if (this.prependHeaders && Object.keys(this.prependHeaders).length > 0) {
|
|
148
183
|
options.headers = Object.assign(Object.assign({}, this.prependHeaders), options.headers);
|
|
149
184
|
}
|
|
185
|
+
if (this.prependFiles && Object.keys(this.prependFiles).length > 0) {
|
|
186
|
+
options.formData = Object.assign(Object.assign({}, this.prependFiles), options.formData);
|
|
187
|
+
}
|
|
150
188
|
this.prependData = {};
|
|
151
189
|
this.prependHeaders = {};
|
|
190
|
+
this.prependFiles = {};
|
|
152
191
|
return options;
|
|
153
192
|
}
|
|
154
193
|
}
|
package/dist/Core/Message.d.ts
CHANGED
package/dist/Core/Message.js
CHANGED
|
@@ -13,6 +13,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
const HasAttributesMixin_1 = __importDefault(require("./Mixins/HasAttributesMixin"));
|
|
15
15
|
const Utils_1 = require("./Support/Utils");
|
|
16
|
+
/**
|
|
17
|
+
* 消息对象
|
|
18
|
+
*/
|
|
16
19
|
class Message {
|
|
17
20
|
constructor(attributes, originContent = '') {
|
|
18
21
|
/**
|
|
@@ -12,6 +12,9 @@ import { MiniAppConfig } from '../Types/global';
|
|
|
12
12
|
import AccountInterface from './Contracts/AccountInterface';
|
|
13
13
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
14
14
|
import Utils from './Utils';
|
|
15
|
+
/**
|
|
16
|
+
* 小程序应用
|
|
17
|
+
*/
|
|
15
18
|
declare class Application implements ApplicationInterface {
|
|
16
19
|
constructor(config: ConfigInterface | MiniAppConfig);
|
|
17
20
|
protected account: AccountInterface;
|
|
@@ -17,6 +17,9 @@ const Account_1 = __importDefault(require("./Account"));
|
|
|
17
17
|
const Server_1 = __importDefault(require("./Server"));
|
|
18
18
|
const Utils_2 = __importDefault(require("./Utils"));
|
|
19
19
|
const Config_1 = __importDefault(require("../OfficialAccount/Config"));
|
|
20
|
+
/**
|
|
21
|
+
* 小程序应用
|
|
22
|
+
*/
|
|
20
23
|
class Application {
|
|
21
24
|
constructor(config) {
|
|
22
25
|
this.account = null;
|
|
@@ -14,6 +14,9 @@ import AccountInterface from './Contracts/AccountInterface';
|
|
|
14
14
|
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
15
15
|
import JsApiTicket from './JsApiTicket';
|
|
16
16
|
import Utils from './Utils';
|
|
17
|
+
/**
|
|
18
|
+
* 公众号应用
|
|
19
|
+
*/
|
|
17
20
|
declare class Application implements ApplicationInterface {
|
|
18
21
|
constructor(config: ConfigInterface | OfficialAccountConfig);
|
|
19
22
|
protected account: AccountInterface;
|
|
@@ -20,6 +20,9 @@ const Account_1 = __importDefault(require("./Account"));
|
|
|
20
20
|
const JsApiTicket_1 = __importDefault(require("./JsApiTicket"));
|
|
21
21
|
const Server_1 = __importDefault(require("./Server"));
|
|
22
22
|
const Utils_2 = __importDefault(require("./Utils"));
|
|
23
|
+
/**
|
|
24
|
+
* 公众号应用
|
|
25
|
+
*/
|
|
23
26
|
class Application {
|
|
24
27
|
constructor(config) {
|
|
25
28
|
this.account = null;
|
|
@@ -127,7 +130,7 @@ class Application {
|
|
|
127
130
|
}
|
|
128
131
|
getTicket() {
|
|
129
132
|
if (!this.ticket) {
|
|
130
|
-
this.ticket = new JsApiTicket_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.
|
|
133
|
+
this.ticket = new JsApiTicket_1.default(this.getAccount().getAppId(), this.getAccount().getSecret(), null, this.getCache(), this.getClient());
|
|
131
134
|
}
|
|
132
135
|
return this.ticket;
|
|
133
136
|
}
|
|
@@ -3,11 +3,8 @@ import Encryptor from '../Core/Encryptor';
|
|
|
3
3
|
import ServerInterface from '../Core/Contracts/ServerInterface';
|
|
4
4
|
import Response from '../Core/Http/Response';
|
|
5
5
|
import Message from './Message';
|
|
6
|
-
import HandlersMixin from '../Core/Mixins/HandlersMixin';
|
|
7
|
-
import DecryptXmlMessageMixin from '../Core/Mixins/DecryptXmlMessageMixin';
|
|
8
6
|
import { ServerEventType, ServerHandlerClosure, ServerMessageType } from '../Types/global';
|
|
9
|
-
|
|
10
|
-
declare class Server implements ServerInterface {
|
|
7
|
+
declare class Server extends ServerInterface {
|
|
11
8
|
protected request: ServerRequestInterface;
|
|
12
9
|
protected encryptor: Encryptor;
|
|
13
10
|
constructor(request?: ServerRequestInterface, encryptor?: Encryptor);
|
|
@@ -38,6 +35,4 @@ declare class Server implements ServerInterface {
|
|
|
38
35
|
getRequestMessage(request?: ServerRequestInterface): Promise<Message>;
|
|
39
36
|
protected decryptRequestMessage(query: Record<string, any>): ServerHandlerClosure;
|
|
40
37
|
}
|
|
41
|
-
interface Server extends HandlersMixin, DecryptXmlMessageMixin, ResponseXmlMessageMixin {
|
|
42
|
-
}
|
|
43
38
|
export = Server;
|
|
@@ -11,17 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
|
+
const ServerInterface_1 = __importDefault(require("../Core/Contracts/ServerInterface"));
|
|
14
15
|
const Response_1 = __importDefault(require("../Core/Http/Response"));
|
|
15
16
|
const Message_1 = __importDefault(require("./Message"));
|
|
16
|
-
|
|
17
|
-
const Utils_1 = require("../Core/Support/Utils");
|
|
18
|
-
const DecryptXmlMessageMixin_1 = __importDefault(require("../Core/Mixins/DecryptXmlMessageMixin"));
|
|
19
|
-
const ResponseXmlMessageMixin_1 = __importDefault(require("../Core/Mixins/ResponseXmlMessageMixin"));
|
|
20
|
-
class Server {
|
|
17
|
+
class Server extends ServerInterface_1.default {
|
|
21
18
|
constructor(request = null, encryptor = null) {
|
|
19
|
+
super();
|
|
22
20
|
this.request = request;
|
|
23
21
|
this.encryptor = encryptor;
|
|
24
|
-
this.handlers = [];
|
|
25
22
|
}
|
|
26
23
|
/**
|
|
27
24
|
* 服务端消息处理
|
|
@@ -31,7 +28,7 @@ class Server {
|
|
|
31
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
32
29
|
let echostr = this.request.getQueryParams()['echostr'] || '';
|
|
33
30
|
if (!!echostr) {
|
|
34
|
-
return new Response_1.default(200, {}, echostr);
|
|
31
|
+
return new Response_1.default(200, { 'Content-Type': 'text/html' }, echostr);
|
|
35
32
|
}
|
|
36
33
|
let message = yield this.getRequestMessage(this.request);
|
|
37
34
|
let query = this.request.getQueryParams();
|
|
@@ -89,6 +86,4 @@ class Server {
|
|
|
89
86
|
}
|
|
90
87
|
}
|
|
91
88
|
;
|
|
92
|
-
;
|
|
93
|
-
(0, Utils_1.applyMixins)(Server, [HandlersMixin_1.default, DecryptXmlMessageMixin_1.default, ResponseXmlMessageMixin_1.default]);
|
|
94
89
|
module.exports = Server;
|
|
@@ -2,6 +2,14 @@ import Application from './Application';
|
|
|
2
2
|
declare class Utils {
|
|
3
3
|
protected app: Application;
|
|
4
4
|
constructor(app: Application);
|
|
5
|
+
/**
|
|
6
|
+
* 构建jssdk配置
|
|
7
|
+
* @param url 完整URL地址
|
|
8
|
+
* @param jsApiList api列表,默认:[]。可用列表:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#63
|
|
9
|
+
* @param openTagList 开放标签列表,默认:[]。可用列表:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html#附录-所有开放标签列表
|
|
10
|
+
* @param debug 是否开启调试模式,默认:false
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
5
13
|
buildJsSdkConfig(url: string, jsApiList?: string[], openTagList?: string[], debug?: boolean): Promise<Record<string, any>>;
|
|
6
14
|
}
|
|
7
15
|
export = Utils;
|
|
@@ -16,6 +16,14 @@ class Utils {
|
|
|
16
16
|
constructor(app) {
|
|
17
17
|
this.app = app;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* 构建jssdk配置
|
|
21
|
+
* @param url 完整URL地址
|
|
22
|
+
* @param jsApiList api列表,默认:[]。可用列表:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#63
|
|
23
|
+
* @param openTagList 开放标签列表,默认:[]。可用列表:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html#附录-所有开放标签列表
|
|
24
|
+
* @param debug 是否开启调试模式,默认:false
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
19
27
|
buildJsSdkConfig(url, jsApiList = [], openTagList = [], debug = false) {
|
|
20
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
29
|
return (0, merge_1.default)({
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosRequestConfig } from 'axios';
|
|
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
4
|
import Message from '../Core/Message';
|
|
@@ -14,6 +14,10 @@ declare module 'axios' {
|
|
|
14
14
|
* 要发送的json数据,会自动解析并赋值到data属性,同时设置content-type=application/json
|
|
15
15
|
*/
|
|
16
16
|
json?: string | Record<string, any>;
|
|
17
|
+
/**
|
|
18
|
+
* 要发送的FormData数据,会自动解析并赋值到data属性,同时设置根据内容提取headers
|
|
19
|
+
*/
|
|
20
|
+
formData?: Record<string, any>;
|
|
17
21
|
}
|
|
18
22
|
}
|
|
19
23
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import { OfficialAccountConfig, MiniAppConfig, LogHandler } from './Types/global';
|
|
1
|
+
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure } from './Types/global';
|
|
2
2
|
import OfficialAccount from './OfficialAccount/Application';
|
|
3
3
|
import MiniApp from './MiniApp/Application';
|
|
4
4
|
import CacheInterface from './Core/Contracts/CacheInterface';
|
|
5
5
|
import ServerRequest from './Core/Http/ServerRequest';
|
|
6
|
-
|
|
6
|
+
import Message from './Core/Message';
|
|
7
|
+
import FormData from 'form-data';
|
|
8
|
+
export { OfficialAccount, OfficialAccountConfig, MiniApp, MiniAppConfig, CacheInterface, ServerRequest, LogHandler, ServerEventType, ServerHandlerClosure, Message,
|
|
9
|
+
/**
|
|
10
|
+
* 表单对象
|
|
11
|
+
* @see https://github.com/axios/axios#formdata
|
|
12
|
+
* @see https://github.com/form-data/form-data#readme
|
|
13
|
+
*/
|
|
14
|
+
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.ServerRequest = exports.CacheInterface = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
6
|
+
exports.FormData = exports.Message = exports.ServerRequest = exports.CacheInterface = 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"));
|
|
@@ -12,3 +12,7 @@ const CacheInterface_1 = __importDefault(require("./Core/Contracts/CacheInterfac
|
|
|
12
12
|
exports.CacheInterface = CacheInterface_1.default;
|
|
13
13
|
const ServerRequest_1 = __importDefault(require("./Core/Http/ServerRequest"));
|
|
14
14
|
exports.ServerRequest = ServerRequest_1.default;
|
|
15
|
+
const Message_1 = __importDefault(require("./Core/Message"));
|
|
16
|
+
exports.Message = Message_1.default;
|
|
17
|
+
const form_data_1 = __importDefault(require("form-data"));
|
|
18
|
+
exports.FormData = form_data_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-easywechat",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.4",
|
|
4
4
|
"description": "EasyWechat SDK for Node.js (NOT OFFICIAL)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^17.0.23",
|
|
23
|
-
"axios-mock-adapter": "^1.
|
|
23
|
+
"axios-mock-adapter": "^1.21.1",
|
|
24
24
|
"mocha": "^9.2.2",
|
|
25
25
|
"package-release": "^1.0.2",
|
|
26
26
|
"typescript": "^4.6.3"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"data":"mock-access_token","lifeTime":1655744193}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"data":"mock-access_token","lifeTime":1655744193}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"data":"mock-ticket","lifeTime":1655749893}
|