node-easywechat 3.0.0-alpha.2 → 3.0.0-beta.3
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 +30 -0
- package/README.md +156 -19
- package/dist/Core/Contracts/AccessTokenInterface.d.ts +1 -1
- 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/AccessTokenAwareClient.d.ts +5 -3
- package/dist/Core/HttpClient/AccessTokenAwareClient.js +9 -3
- package/dist/Core/HttpClient/Contracts/HttpClientInterface.d.ts +5 -0
- package/dist/Core/HttpClient/Contracts/HttpClientInterface.js +4 -0
- package/dist/Core/HttpClient/HttpClient.d.ts +10 -1
- package/dist/Core/HttpClient/HttpClient.js +20 -0
- package/dist/Core/HttpClient/HttpClientResponse.d.ts +3 -3
- package/dist/Core/HttpClient/HttpClientResponse.js +5 -4
- package/dist/Core/HttpClient/Mixins/PresetMixin.d.ts +79 -0
- package/dist/Core/HttpClient/Mixins/PresetMixin.js +155 -0
- package/dist/Core/Message.d.ts +3 -0
- package/dist/Core/Message.js +3 -0
- package/dist/Core/Mixins/ClientMixin.d.ts +6 -1
- package/dist/Core/Mixins/ClientMixin.js +3 -0
- package/dist/Core/Mixins/ServerRequestMixin.js +3 -0
- package/dist/Core/Support/Utils.d.ts +6 -0
- package/dist/Core/Support/Utils.js +10 -1
- package/dist/MiniApp/AccessToken.d.ts +5 -0
- package/dist/MiniApp/AccessToken.js +10 -0
- package/dist/MiniApp/Application.d.ts +3 -0
- package/dist/MiniApp/Application.js +5 -2
- package/dist/OfficialAccount/Application.d.ts +3 -0
- package/dist/OfficialAccount/Application.js +6 -3
- package/dist/OfficialAccount/Server.d.ts +1 -6
- package/dist/OfficialAccount/Server.js +3 -8
- package/dist/OfficialAccount/Utils.d.ts +8 -0
- package/dist/OfficialAccount/Utils.js +8 -0
- package/dist/Types/global.d.ts +46 -67
- package/dist/index.d.ts +14 -0
- package/dist/index.js +18 -0
- package/package.json +1 -1
- package/official_account.access_token.mock-access_token-appid.cache +0 -1
- package/official_account.jsapi_ticket.mock-ticket-appid.cache +0 -1
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const merge_1 = __importDefault(require("merge"));
|
|
6
|
+
class PresetMixin {
|
|
7
|
+
constructor() {
|
|
8
|
+
/**
|
|
9
|
+
* 存储预置参数
|
|
10
|
+
*/
|
|
11
|
+
this.presets = {};
|
|
12
|
+
/**
|
|
13
|
+
* 存储预置headers数据
|
|
14
|
+
*/
|
|
15
|
+
this.prependHeaders = {};
|
|
16
|
+
/**
|
|
17
|
+
* 存储预置数据
|
|
18
|
+
*/
|
|
19
|
+
this.prependData = {};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 设置预置参数
|
|
23
|
+
* @param presets
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
setPresets(presets) {
|
|
27
|
+
this.presets = presets;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 设置单个预置header
|
|
32
|
+
* @param key
|
|
33
|
+
* @param value
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
withHeader(key, value) {
|
|
37
|
+
if (typeof this.prependHeaders !== 'object') {
|
|
38
|
+
this.prependHeaders = {};
|
|
39
|
+
}
|
|
40
|
+
this.prependHeaders[key] = value;
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 批量设置预置headers
|
|
45
|
+
* @param headers
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
withHeaders(headers) {
|
|
49
|
+
headers.map((value, key) => {
|
|
50
|
+
this.withHeader(key, value);
|
|
51
|
+
});
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* 设置预置数据
|
|
56
|
+
* @param key 参数名
|
|
57
|
+
* @param value 参数值,不设置则尝试从预置参数中获取
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
with(key, value = null) {
|
|
61
|
+
if (Array.isArray(key)) {
|
|
62
|
+
key.map((k) => {
|
|
63
|
+
var _a;
|
|
64
|
+
this.with(k, (_a = this.presets[k]) !== null && _a !== void 0 ? _a : null);
|
|
65
|
+
});
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
else if (typeof key === 'object') {
|
|
69
|
+
key.map((v, k) => {
|
|
70
|
+
var _a;
|
|
71
|
+
this.with(k, (_a = v !== null && v !== void 0 ? v : this.presets[k]) !== null && _a !== void 0 ? _a : null);
|
|
72
|
+
});
|
|
73
|
+
return this;
|
|
74
|
+
}
|
|
75
|
+
if (typeof this.prependData !== 'object') {
|
|
76
|
+
this.prependData = {};
|
|
77
|
+
}
|
|
78
|
+
this.prependData[key] = value || this.presets[key] || null;
|
|
79
|
+
return this;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 预设置app_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
83
|
+
* @param new_appid
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
withAppId(new_appid = null) {
|
|
87
|
+
this.with('app_id', new_appid);
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 预设置app_id的别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
92
|
+
* @param new_alias
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
withAppIdAs(new_alias) {
|
|
96
|
+
this.with(new_alias, this.presets['app_id']);
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 预设置secret(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
101
|
+
* @param new_secret
|
|
102
|
+
* @returns
|
|
103
|
+
*/
|
|
104
|
+
withSecret(new_secret = null) {
|
|
105
|
+
this.with('secret', new_secret);
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 预设置mch_id(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
110
|
+
* @param new_mch_id
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
withMchId(new_mch_id = null) {
|
|
114
|
+
this.with('mch_id', new_mch_id);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 预设置mch_id别名(因nodejs不支持魔术方法,只好预先设置几个常用的方法)
|
|
119
|
+
* @param new_alias
|
|
120
|
+
* @returns
|
|
121
|
+
*/
|
|
122
|
+
withMchIdAs(new_alias = null) {
|
|
123
|
+
this.with(new_alias, this.presets['mch_id']);
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 合并预置参数并清空预置数据
|
|
128
|
+
* @param payload
|
|
129
|
+
* @param method
|
|
130
|
+
* @returns
|
|
131
|
+
*/
|
|
132
|
+
mergeThenResetPrepends(payload, method = 'get') {
|
|
133
|
+
var _a, _b, _c, _d;
|
|
134
|
+
let field = method.toLowerCase() === 'get' ? 'params' : 'data';
|
|
135
|
+
let options = merge_1.default.recursive(true, payload);
|
|
136
|
+
if (!options.headers)
|
|
137
|
+
options.headers = {};
|
|
138
|
+
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
|
+
field = 'json';
|
|
140
|
+
}
|
|
141
|
+
if (((_d = (_c = options.headers['Content-Type']) !== null && _c !== void 0 ? _c : options.headers['content-type']) !== null && _d !== void 0 ? _d : null) === 'text/xml' || !!options.xml) {
|
|
142
|
+
field = 'xml';
|
|
143
|
+
}
|
|
144
|
+
if (this.prependData && Object.keys(this.prependData).length > 0) {
|
|
145
|
+
options[field] = Object.assign(Object.assign({}, this.prependData), options[field]);
|
|
146
|
+
}
|
|
147
|
+
if (this.prependHeaders && Object.keys(this.prependHeaders).length > 0) {
|
|
148
|
+
options.headers = Object.assign(Object.assign({}, this.prependHeaders), options.headers);
|
|
149
|
+
}
|
|
150
|
+
this.prependData = {};
|
|
151
|
+
this.prependHeaders = {};
|
|
152
|
+
return options;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
module.exports = PresetMixin;
|
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
|
/**
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import AccessTokenAwareClient from "../HttpClient/AccessTokenAwareClient";
|
|
2
|
-
declare class ClientMixin {
|
|
2
|
+
declare abstract class ClientMixin {
|
|
3
3
|
protected client: AccessTokenAwareClient;
|
|
4
|
+
/**
|
|
5
|
+
* 创建客户端实例
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
abstract createClient(): AccessTokenAwareClient;
|
|
4
9
|
/**
|
|
5
10
|
* 获取客户端实例
|
|
6
11
|
* @returns
|
|
@@ -68,6 +68,12 @@ export declare const strStudly: (value: string) => string;
|
|
|
68
68
|
* @returns
|
|
69
69
|
*/
|
|
70
70
|
export declare const strCamel: (value: string) => string;
|
|
71
|
+
/**
|
|
72
|
+
* 蛇形(下划线分隔,全小写),'helloWorld' => 'hello_world'
|
|
73
|
+
* @param value
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
export declare const strSnake: (value: string) => string;
|
|
71
77
|
/**
|
|
72
78
|
* 如果只有一个同名、同级节点,则不当作数组
|
|
73
79
|
* @param obj
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.buildXml = exports.parseXml = exports.singleItem = exports.strCamel = exports.strStudly = exports.strLcwords = exports.strUcwords = exports.rtrim = exports.ltrim = exports.trim = exports.applyMixins = exports.inArray = exports.isIp = exports.isIpv6 = exports.isIpv4 = exports.isFunction = exports.isObject = exports.isNumber = exports.isArray = exports.isString = exports.makeSignature = exports.randomString = exports.parseQueryString = exports.buildQueryString = exports.getTimestamp = exports.md5File = exports.createHmac = exports.createHash = void 0;
|
|
15
|
+
exports.buildXml = exports.parseXml = exports.singleItem = exports.strSnake = exports.strCamel = exports.strStudly = exports.strLcwords = exports.strUcwords = exports.rtrim = exports.ltrim = exports.trim = exports.applyMixins = exports.inArray = exports.isIp = exports.isIpv6 = exports.isIpv4 = exports.isFunction = exports.isObject = exports.isNumber = exports.isArray = exports.isString = exports.makeSignature = exports.randomString = exports.parseQueryString = exports.buildQueryString = exports.getTimestamp = exports.md5File = exports.createHmac = exports.createHash = void 0;
|
|
16
16
|
const crypto_1 = __importDefault(require("crypto"));
|
|
17
17
|
const qs_1 = __importDefault(require("qs"));
|
|
18
18
|
const xml2js_1 = __importDefault(require("xml2js"));
|
|
@@ -252,6 +252,15 @@ const strCamel = function (value) {
|
|
|
252
252
|
return (0, exports.strLcwords)((0, exports.strStudly)(value));
|
|
253
253
|
};
|
|
254
254
|
exports.strCamel = strCamel;
|
|
255
|
+
/**
|
|
256
|
+
* 蛇形(下划线分隔,全小写),'helloWorld' => 'hello_world'
|
|
257
|
+
* @param value
|
|
258
|
+
* @returns
|
|
259
|
+
*/
|
|
260
|
+
const strSnake = function (value) {
|
|
261
|
+
return value.replace(/([A-Z])/g, "_$1").toLowerCase().substring(1);
|
|
262
|
+
};
|
|
263
|
+
exports.strSnake = strSnake;
|
|
255
264
|
/**
|
|
256
265
|
* 如果只有一个同名、同级节点,则不当作数组
|
|
257
266
|
* @param obj
|
|
@@ -4,5 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const AccessToken_1 = __importDefault(require("../OfficialAccount/AccessToken"));
|
|
6
6
|
class AccessToken extends AccessToken_1.default {
|
|
7
|
+
/**
|
|
8
|
+
* 获取access_token的缓存名称
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
getKey() {
|
|
12
|
+
if (!this.key) {
|
|
13
|
+
this.key = `mini_app.access_token.${this.appId}`;
|
|
14
|
+
}
|
|
15
|
+
return this.key;
|
|
16
|
+
}
|
|
7
17
|
}
|
|
8
18
|
module.exports = AccessToken;
|
|
@@ -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;
|
|
@@ -104,8 +107,8 @@ class Application {
|
|
|
104
107
|
return new Utils_2.default(this);
|
|
105
108
|
}
|
|
106
109
|
createClient() {
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken()))
|
|
111
|
+
.setPresets(this.getConfig().all());
|
|
109
112
|
}
|
|
110
113
|
/**
|
|
111
114
|
* 获取请求默认配置
|
|
@@ -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
|
}
|
|
@@ -144,8 +147,8 @@ class Application {
|
|
|
144
147
|
return new Utils_2.default(this);
|
|
145
148
|
}
|
|
146
149
|
createClient() {
|
|
147
|
-
|
|
148
|
-
|
|
150
|
+
return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken()))
|
|
151
|
+
.setPresets(this.getConfig().all());
|
|
149
152
|
}
|
|
150
153
|
/**
|
|
151
154
|
* 获取请求默认配置
|
|
@@ -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
|
* 服务端消息处理
|
|
@@ -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';
|
|
@@ -17,6 +17,21 @@ declare module 'axios' {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* 微信接口响应数据格式
|
|
22
|
+
*/
|
|
23
|
+
export declare interface WeixinResponse extends Record<string, any> {
|
|
24
|
+
/**
|
|
25
|
+
* 错误代码
|
|
26
|
+
*/
|
|
27
|
+
errcode?: string,
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 错误信息
|
|
31
|
+
*/
|
|
32
|
+
errmsg?: string,
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
/**
|
|
21
36
|
* 公众号网页授权相关配置
|
|
22
37
|
*/
|
|
@@ -54,10 +69,25 @@ export declare interface CacheFileConfig {
|
|
|
54
69
|
ext: string
|
|
55
70
|
}
|
|
56
71
|
|
|
72
|
+
/**
|
|
73
|
+
* 基础配置
|
|
74
|
+
*/
|
|
75
|
+
export declare interface BaseConfig {
|
|
76
|
+
/**
|
|
77
|
+
* 网络请求相关配置
|
|
78
|
+
*/
|
|
79
|
+
http?: AxiosRequestConfig;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 文件缓存相关配置
|
|
83
|
+
*/
|
|
84
|
+
file_cache?: CacheFileConfig;
|
|
85
|
+
}
|
|
86
|
+
|
|
57
87
|
/**
|
|
58
88
|
* 公众号配置
|
|
59
89
|
*/
|
|
60
|
-
export declare interface OfficialAccountConfig {
|
|
90
|
+
export declare interface OfficialAccountConfig extends BaseConfig {
|
|
61
91
|
/**
|
|
62
92
|
* 公众号 app_id
|
|
63
93
|
*/
|
|
@@ -82,22 +112,12 @@ export declare interface OfficialAccountConfig {
|
|
|
82
112
|
* 网页授权相关配置
|
|
83
113
|
*/
|
|
84
114
|
oauth?: OauthConfig;
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 网络请求相关配置
|
|
88
|
-
*/
|
|
89
|
-
http?: AxiosRequestConfig;
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 文件缓存相关配置
|
|
93
|
-
*/
|
|
94
|
-
file_cache?: CacheFileConfig;
|
|
95
115
|
}
|
|
96
116
|
|
|
97
117
|
/**
|
|
98
118
|
* 小程序配置
|
|
99
119
|
*/
|
|
100
|
-
export declare interface MiniAppConfig {
|
|
120
|
+
export declare interface MiniAppConfig extends BaseConfig {
|
|
101
121
|
/**
|
|
102
122
|
* 小程序 app_id
|
|
103
123
|
*/
|
|
@@ -117,22 +137,12 @@ export declare interface MiniAppConfig {
|
|
|
117
137
|
* 服务端消息加解密密钥 aes_key
|
|
118
138
|
*/
|
|
119
139
|
aes_key?: string;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 网络请求相关配置
|
|
123
|
-
*/
|
|
124
|
-
http?: AxiosRequestConfig;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 文件缓存相关配置
|
|
128
|
-
*/
|
|
129
|
-
file_cache?: CacheFileConfig;
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
/**
|
|
133
143
|
* 微信支付配置
|
|
134
144
|
*/
|
|
135
|
-
export declare interface PayConfig {
|
|
145
|
+
export declare interface PayConfig extends BaseConfig {
|
|
136
146
|
/**
|
|
137
147
|
* 商户号
|
|
138
148
|
*/
|
|
@@ -152,22 +162,12 @@ export declare interface PayConfig {
|
|
|
152
162
|
* v2 API密钥
|
|
153
163
|
*/
|
|
154
164
|
v2_secret_key?: string;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 网络请求相关配置
|
|
158
|
-
*/
|
|
159
|
-
http?: AxiosRequestConfig;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 文件缓存相关配置
|
|
163
|
-
*/
|
|
164
|
-
file_cache?: CacheFileConfig;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
/**
|
|
168
168
|
* 开发平台配置
|
|
169
169
|
*/
|
|
170
|
-
export declare interface OpenPlatformConfig {
|
|
170
|
+
export declare interface OpenPlatformConfig extends BaseConfig {
|
|
171
171
|
/**
|
|
172
172
|
* 开发平台 app_id
|
|
173
173
|
*/
|
|
@@ -187,22 +187,12 @@ export declare interface OpenPlatformConfig {
|
|
|
187
187
|
* 开发平台服务端消息加解密密钥 aes_key
|
|
188
188
|
*/
|
|
189
189
|
aes_key?: string;
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* 网络请求相关配置
|
|
193
|
-
*/
|
|
194
|
-
http?: AxiosRequestConfig;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* 文件缓存相关配置
|
|
198
|
-
*/
|
|
199
|
-
file_cache?: CacheFileConfig;
|
|
200
190
|
}
|
|
201
191
|
|
|
202
192
|
/**
|
|
203
193
|
* 企业微信配置
|
|
204
194
|
*/
|
|
205
|
-
export declare interface WorkConfig {
|
|
195
|
+
export declare interface WorkConfig extends BaseConfig {
|
|
206
196
|
/**
|
|
207
197
|
* 企业微信 corp_id
|
|
208
198
|
*/
|
|
@@ -222,22 +212,12 @@ export declare interface WorkConfig {
|
|
|
222
212
|
* 企业微信服务端消息加解密密钥 aes_key
|
|
223
213
|
*/
|
|
224
214
|
aes_key?: string;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* 网络请求相关配置
|
|
228
|
-
*/
|
|
229
|
-
http?: AxiosRequestConfig;
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* 文件缓存相关配置
|
|
233
|
-
*/
|
|
234
|
-
file_cache?: CacheFileConfig;
|
|
235
215
|
}
|
|
236
216
|
|
|
237
217
|
/**
|
|
238
218
|
* 企业微信开放平台配置
|
|
239
219
|
*/
|
|
240
|
-
export declare interface OpenWorkConfig {
|
|
220
|
+
export declare interface OpenWorkConfig extends BaseConfig {
|
|
241
221
|
/**
|
|
242
222
|
* 企业微信 corp_id
|
|
243
223
|
*/
|
|
@@ -257,16 +237,6 @@ export declare interface OpenWorkConfig {
|
|
|
257
237
|
* 企业微信服务端消息加解密密钥 aes_key
|
|
258
238
|
*/
|
|
259
239
|
aes_key?: string;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* 网络请求相关配置
|
|
263
|
-
*/
|
|
264
|
-
http?: AxiosRequestConfig;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* 文件缓存相关配置
|
|
268
|
-
*/
|
|
269
|
-
file_cache?: CacheFileConfig;
|
|
270
240
|
}
|
|
271
241
|
|
|
272
242
|
/**
|
|
@@ -341,3 +311,12 @@ export declare type PaymentRefundedHandler = (message: Message, reqInfo: object,
|
|
|
341
311
|
* @param alert 业务错误处理函数
|
|
342
312
|
*/
|
|
343
313
|
export declare type PaymentScannedHandler = (message: Message, fail: PaymentFailHandler, alert: PaymentAlertHandler) => void;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* 日志处理方法
|
|
317
|
+
* @param type before:请求前,after:请求后
|
|
318
|
+
* @param options 请求选项
|
|
319
|
+
* @param usedTime 请求耗时,单位ms,仅在 type 为 after 时返回
|
|
320
|
+
* @param response 响应对象,仅在 type 为 after 时返回
|
|
321
|
+
*/
|
|
322
|
+
export declare type LogHandler = (type: 'before' | 'after', options: AxiosRequestConfig, usedTime?: number, response?: AxiosResponse) => void | Promise<void>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OfficialAccountConfig, MiniAppConfig, LogHandler, ServerEventType, ServerHandlerClosure } from './Types/global';
|
|
2
|
+
import OfficialAccount from './OfficialAccount/Application';
|
|
3
|
+
import MiniApp from './MiniApp/Application';
|
|
4
|
+
import CacheInterface from './Core/Contracts/CacheInterface';
|
|
5
|
+
import ServerRequest from './Core/Http/ServerRequest';
|
|
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
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FormData = exports.Message = exports.ServerRequest = exports.CacheInterface = exports.MiniApp = exports.OfficialAccount = void 0;
|
|
7
|
+
const Application_1 = __importDefault(require("./OfficialAccount/Application"));
|
|
8
|
+
exports.OfficialAccount = Application_1.default;
|
|
9
|
+
const Application_2 = __importDefault(require("./MiniApp/Application"));
|
|
10
|
+
exports.MiniApp = Application_2.default;
|
|
11
|
+
const CacheInterface_1 = __importDefault(require("./Core/Contracts/CacheInterface"));
|
|
12
|
+
exports.CacheInterface = CacheInterface_1.default;
|
|
13
|
+
const ServerRequest_1 = __importDefault(require("./Core/Http/ServerRequest"));
|
|
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;
|