node-easywechat 3.0.0-alpha.1 → 3.0.0-beta.2
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 +29 -0
- package/README.md +156 -19
- package/dist/Core/Config.d.ts +1 -1
- package/dist/Core/Config.js +2 -2
- 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/Encryptor.d.ts +3 -3
- package/dist/Core/Encryptor.js +6 -7
- 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 -3
- package/dist/Core/HttpClient/HttpClientResponse.d.ts +9 -3
- package/dist/Core/HttpClient/HttpClientResponse.js +41 -8
- 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 +14 -0
- package/dist/Core/Message.js +14 -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 +9 -0
- package/dist/MiniApp/AccessToken.js +18 -0
- package/dist/MiniApp/Account.d.ts +4 -0
- package/dist/MiniApp/Account.js +8 -0
- package/dist/MiniApp/Application.d.ts +62 -0
- package/dist/MiniApp/Application.js +126 -0
- package/dist/MiniApp/Contracts/AccountInterface.d.ts +23 -0
- package/dist/MiniApp/Contracts/AccountInterface.js +25 -0
- package/dist/MiniApp/Contracts/ApplicationInterface.d.ts +68 -0
- package/dist/MiniApp/Contracts/ApplicationInterface.js +60 -0
- package/dist/MiniApp/Decryptor.d.ts +4 -0
- package/dist/MiniApp/Decryptor.js +20 -0
- package/dist/MiniApp/Server.d.ts +4 -0
- package/dist/MiniApp/Server.js +9 -0
- package/dist/MiniApp/Utils.d.ts +22 -0
- package/dist/MiniApp/Utils.js +56 -0
- package/dist/OfficialAccount/AccessToken.js +10 -9
- package/dist/OfficialAccount/Account.js +0 -4
- package/dist/OfficialAccount/Application.d.ts +3 -0
- package/dist/OfficialAccount/Application.js +5 -2
- package/dist/OfficialAccount/Server.d.ts +1 -6
- package/dist/OfficialAccount/Server.js +3 -10
- package/dist/OfficialAccount/Utils.js +0 -1
- package/dist/Types/global.d.ts +45 -66
- package/dist/index.d.ts +14 -0
- package/dist/index.js +18 -0
- package/mini_app.access_token.mock-access_token-appid.cache +1 -0
- package/official_account.access_token.mock-access_token-appid.cache +1 -1
- package/official_account.jsapi_ticket.mock-ticket-appid.cache +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare abstract class AccountInterface {
|
|
2
|
+
/**
|
|
3
|
+
* 获取appid
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
getAppId(): string;
|
|
7
|
+
/**
|
|
8
|
+
* 获取secret
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
getSecret(): string;
|
|
12
|
+
/**
|
|
13
|
+
* 获取token
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getToken(): string;
|
|
17
|
+
/**
|
|
18
|
+
* 获取aesKey
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getAesKey(): string;
|
|
22
|
+
}
|
|
23
|
+
export = AccountInterface;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class AccountInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取appid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getAppId() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取secret
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getSecret() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取token
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getToken() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取aesKey
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getAesKey() { return null; }
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
module.exports = AccountInterface;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
2
|
+
import CacheInterface from "../../Core/Contracts/CacheInterface";
|
|
3
|
+
import ConfigInterface from "../../Core/Contracts/ConfigInterface";
|
|
4
|
+
import AccessTokenAwareClient from "../../Core/HttpClient/AccessTokenAwareClient";
|
|
5
|
+
import HttpClientInterface from "../../Core/HttpClient/Contracts/HttpClientInterface";
|
|
6
|
+
import ServerInterface from "../../Core/Contracts/ServerInterface";
|
|
7
|
+
import ServerRequestInterface from "../../Core/Http/Contracts/ServerRequestInterface";
|
|
8
|
+
import Encryptor from "../../Core/Encryptor";
|
|
9
|
+
import AccountInterface from "./AccountInterface";
|
|
10
|
+
import Utils from "../Utils";
|
|
11
|
+
declare abstract class ApplicationInterface {
|
|
12
|
+
/**
|
|
13
|
+
* 获取当前账户实例
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getAccount(): AccountInterface;
|
|
17
|
+
/**
|
|
18
|
+
* 获取加密机实例
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getEncryptor(): Encryptor;
|
|
22
|
+
/**
|
|
23
|
+
* 获取服务端实例
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
getServer(): ServerInterface;
|
|
27
|
+
/**
|
|
28
|
+
* 获取当前请求实例
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
getRequest(): ServerRequestInterface;
|
|
32
|
+
/**
|
|
33
|
+
* 获取客户端实例
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
getClient(): AccessTokenAwareClient;
|
|
37
|
+
/**
|
|
38
|
+
* 创建客户端实例
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
createClient(): AccessTokenAwareClient;
|
|
42
|
+
/**
|
|
43
|
+
* 获取网络请求客户端实例
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
getHttpClient(): HttpClientInterface;
|
|
47
|
+
/**
|
|
48
|
+
* 获取配置信息实例
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
getConfig(): ConfigInterface;
|
|
52
|
+
/**
|
|
53
|
+
* 获取AccessToken实例
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
getAccessToken(): AccessTokenInterface;
|
|
57
|
+
/**
|
|
58
|
+
* 获取缓存实例
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
getCache(): CacheInterface;
|
|
62
|
+
/**
|
|
63
|
+
* 获取工具实例
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
getUtils(): Utils;
|
|
67
|
+
}
|
|
68
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class ApplicationInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取当前账户实例
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getAccount() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取加密机实例
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getEncryptor() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取服务端实例
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getServer() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取当前请求实例
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getRequest() { return null; }
|
|
23
|
+
/**
|
|
24
|
+
* 获取客户端实例
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getClient() { return null; }
|
|
28
|
+
/**
|
|
29
|
+
* 创建客户端实例
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
createClient() { return null; }
|
|
33
|
+
/**
|
|
34
|
+
* 获取网络请求客户端实例
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getHttpClient() { return null; }
|
|
38
|
+
/**
|
|
39
|
+
* 获取配置信息实例
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getConfig() { return null; }
|
|
43
|
+
/**
|
|
44
|
+
* 获取AccessToken实例
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getAccessToken() { return null; }
|
|
48
|
+
/**
|
|
49
|
+
* 获取缓存实例
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
getCache() { return null; }
|
|
53
|
+
/**
|
|
54
|
+
* 获取工具实例
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getUtils() { return null; }
|
|
58
|
+
}
|
|
59
|
+
;
|
|
60
|
+
module.exports = ApplicationInterface;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const AES_1 = require("../Core/Support/AES");
|
|
3
|
+
class Decryptor {
|
|
4
|
+
static decrypt(sessionKey, iv, ciphertext) {
|
|
5
|
+
let decrypted = null;
|
|
6
|
+
try {
|
|
7
|
+
// 解密
|
|
8
|
+
decrypted = AES_1.AES.decrypt(Buffer.from(ciphertext, 'base64'), Buffer.from(sessionKey, 'base64'), Buffer.from(iv, 'base64'), true, 'aes-128-cbc').toString('utf8');
|
|
9
|
+
decrypted = JSON.parse(decrypted);
|
|
10
|
+
if (!decrypted || typeof decrypted !== 'object') {
|
|
11
|
+
throw new Error('The given payload is invalid.');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
catch (e) {
|
|
15
|
+
throw new Error(`Fail to decrypt data: ${e.message}`);
|
|
16
|
+
}
|
|
17
|
+
return decrypted;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
module.exports = Decryptor;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Server_1 = __importDefault(require("../OfficialAccount/Server"));
|
|
6
|
+
class Server extends Server_1.default {
|
|
7
|
+
}
|
|
8
|
+
;
|
|
9
|
+
module.exports = Server;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Application from './Application';
|
|
2
|
+
declare class Utils {
|
|
3
|
+
protected app: Application;
|
|
4
|
+
constructor(app: Application);
|
|
5
|
+
/**
|
|
6
|
+
* 登录凭证校验
|
|
7
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
|
|
8
|
+
* @param code
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
codeToSession(code: string): Promise<Record<string, any>>;
|
|
12
|
+
/**
|
|
13
|
+
* 数据解密
|
|
14
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html#加密数据解密算法
|
|
15
|
+
* @param sessionKey
|
|
16
|
+
* @param iv
|
|
17
|
+
* @param ciphertext
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
decryptSession(sessionKey: string, iv: string, ciphertext: string): object;
|
|
21
|
+
}
|
|
22
|
+
export = Utils;
|
|
@@ -0,0 +1,56 @@
|
|
|
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 Decryptor_1 = __importDefault(require("./Decryptor"));
|
|
15
|
+
class Utils {
|
|
16
|
+
constructor(app) {
|
|
17
|
+
this.app = null;
|
|
18
|
+
this.app = app;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* 登录凭证校验
|
|
22
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
|
|
23
|
+
* @param code
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
codeToSession(code) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
let client = this.app.getHttpClient();
|
|
29
|
+
let response = yield (yield client.request('GET', '/sns/jscode2session', {
|
|
30
|
+
params: {
|
|
31
|
+
appid: this.app.getAccount().getAppId(),
|
|
32
|
+
secret: this.app.getAccount().getSecret(),
|
|
33
|
+
js_code: code,
|
|
34
|
+
grant_type: 'authorization_code',
|
|
35
|
+
}
|
|
36
|
+
})).toObject();
|
|
37
|
+
if (!response['openid']) {
|
|
38
|
+
throw new Error(`code2Session error: ${JSON.stringify(response)}`);
|
|
39
|
+
}
|
|
40
|
+
return response;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 数据解密
|
|
45
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/signature.html#加密数据解密算法
|
|
46
|
+
* @param sessionKey
|
|
47
|
+
* @param iv
|
|
48
|
+
* @param ciphertext
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
decryptSession(sessionKey, iv, ciphertext) {
|
|
52
|
+
return Decryptor_1.default.decrypt(sessionKey, iv, ciphertext);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
;
|
|
56
|
+
module.exports = Utils;
|
|
@@ -15,18 +15,19 @@ const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
|
|
|
15
15
|
const FileCache_1 = __importDefault(require("../Core/Cache/FileCache"));
|
|
16
16
|
class AccessToken {
|
|
17
17
|
constructor(appId, secret, key = null, cache = null, httpClient = null) {
|
|
18
|
-
this.appId = null;
|
|
19
|
-
this.secret = null;
|
|
20
|
-
this.key = null;
|
|
21
|
-
this.cache = null;
|
|
22
|
-
this.httpClient = null;
|
|
23
18
|
this.appId = appId;
|
|
24
19
|
this.secret = secret;
|
|
25
20
|
this.key = key;
|
|
26
|
-
this.cache = cache
|
|
27
|
-
this.httpClient = httpClient
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
this.cache = cache;
|
|
22
|
+
this.httpClient = httpClient;
|
|
23
|
+
if (!this.cache) {
|
|
24
|
+
this.cache = new FileCache_1.default();
|
|
25
|
+
}
|
|
26
|
+
if (!this.httpClient) {
|
|
27
|
+
this.httpClient = HttpClient_1.default.create({
|
|
28
|
+
baseURL: 'https://api.weixin.qq.com/',
|
|
29
|
+
});
|
|
30
|
+
}
|
|
30
31
|
}
|
|
31
32
|
/**
|
|
32
33
|
* 获取access_token的缓存名称
|
|
@@ -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;
|
|
@@ -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,12 @@ 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) {
|
|
22
|
-
|
|
23
|
-
this.encryptor = null;
|
|
24
|
-
this.handlers = [];
|
|
19
|
+
super();
|
|
25
20
|
this.request = request;
|
|
26
21
|
this.encryptor = encryptor;
|
|
27
22
|
}
|
|
@@ -91,6 +86,4 @@ class Server {
|
|
|
91
86
|
}
|
|
92
87
|
}
|
|
93
88
|
;
|
|
94
|
-
;
|
|
95
|
-
(0, Utils_1.applyMixins)(Server, [HandlersMixin_1.default, DecryptXmlMessageMixin_1.default, ResponseXmlMessageMixin_1.default]);
|
|
96
89
|
module.exports = Server;
|
|
@@ -14,7 +14,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
const merge_1 = __importDefault(require("merge"));
|
|
15
15
|
class Utils {
|
|
16
16
|
constructor(app) {
|
|
17
|
-
this.app = null;
|
|
18
17
|
this.app = app;
|
|
19
18
|
}
|
|
20
19
|
buildJsSdkConfig(url, jsApiList = [], openTagList = [], debug = false) {
|
package/dist/Types/global.d.ts
CHANGED
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"data":"mock-access_token","lifeTime":1655828727}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"data":"mock-access_token","lifeTime":
|
|
1
|
+
{"data":"mock-access_token","lifeTime":1655828727}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"data":"mock-ticket","lifeTime":
|
|
1
|
+
{"data":"mock-ticket","lifeTime":1655834427}
|