node-easywechat 3.1.4 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build-2.yml +21 -0
- package/.github/workflows/build-3.yml +21 -0
- package/.github/workflows/publish-npm-2.yml +24 -0
- package/.github/workflows/publish-npm-3.yml +24 -0
- package/CHANGELOG.md +15 -0
- package/README.md +23 -2
- package/dist/MiniApp/Application.d.ts +4 -4
- package/dist/OfficialAccount/Application.d.ts +4 -4
- package/dist/OpenPlatform/Application.d.ts +5 -5
- package/dist/OpenPlatform/Application.js +1 -1
- package/dist/OpenWork/Account.d.ts +17 -0
- package/dist/OpenWork/Account.js +30 -0
- package/dist/OpenWork/Application.d.ts +120 -0
- package/dist/OpenWork/Application.js +294 -0
- package/dist/OpenWork/Authorization.d.ts +12 -0
- package/dist/OpenWork/Authorization.js +49 -0
- package/dist/OpenWork/AuthorizerAccessToken.d.ts +38 -0
- package/dist/OpenWork/AuthorizerAccessToken.js +105 -0
- package/dist/OpenWork/Config.d.ts +5 -0
- package/dist/OpenWork/Config.js +19 -0
- package/dist/OpenWork/Contracts/AccountInterface.d.ts +33 -0
- package/dist/OpenWork/Contracts/AccountInterface.js +35 -0
- package/dist/OpenWork/Contracts/ApplicationInterface.d.ts +108 -0
- package/dist/OpenWork/Contracts/ApplicationInterface.js +96 -0
- package/dist/OpenWork/Contracts/SuiteTicketInterface.d.ts +23 -0
- package/dist/OpenWork/Contracts/SuiteTicketInterface.js +25 -0
- package/dist/OpenWork/Encryptor.d.ts +9 -0
- package/dist/OpenWork/Encryptor.js +17 -0
- package/dist/OpenWork/JsApiTicket.d.ts +50 -0
- package/dist/OpenWork/JsApiTicket.js +152 -0
- package/dist/OpenWork/Message.d.ts +78 -0
- package/dist/OpenWork/Message.js +9 -0
- package/dist/OpenWork/ProviderAccessToken.d.ts +26 -0
- package/dist/OpenWork/ProviderAccessToken.js +84 -0
- package/dist/OpenWork/Server.d.ts +103 -0
- package/dist/OpenWork/Server.js +242 -0
- package/dist/OpenWork/SuiteAccessToken.d.ts +28 -0
- package/dist/OpenWork/SuiteAccessToken.js +86 -0
- package/dist/OpenWork/SuiteEncryptor.d.ts +9 -0
- package/dist/OpenWork/SuiteEncryptor.js +17 -0
- package/dist/OpenWork/SuiteTicket.d.ts +13 -0
- package/dist/OpenWork/SuiteTicket.js +49 -0
- package/dist/Pay/Application.d.ts +4 -4
- package/dist/Types/global.d.ts +19 -1
- package/dist/Work/AccessToken.d.ts +26 -0
- package/dist/Work/AccessToken.js +84 -0
- package/dist/Work/Account.d.ts +13 -0
- package/dist/Work/Account.js +25 -0
- package/dist/Work/Application.d.ts +75 -0
- package/dist/Work/Application.js +177 -0
- package/dist/Work/Config.d.ts +5 -0
- package/dist/Work/Config.js +17 -0
- package/dist/Work/Contracts/AccountInterface.d.ts +23 -0
- package/dist/Work/Contracts/AccountInterface.js +25 -0
- package/dist/Work/Contracts/ApplicationInterface.d.ts +87 -0
- package/dist/Work/Contracts/ApplicationInterface.js +76 -0
- package/dist/Work/Encryptor.d.ts +9 -0
- package/dist/Work/Encryptor.js +17 -0
- package/dist/Work/JsApiTicket.d.ts +45 -0
- package/dist/Work/JsApiTicket.js +141 -0
- package/dist/Work/Message.d.ts +142 -0
- package/dist/Work/Message.js +9 -0
- package/dist/Work/Server.d.ts +90 -0
- package/dist/Work/Server.js +212 -0
- package/dist/Work/Utils.d.ts +25 -0
- package/dist/Work/Utils.js +56 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +5 -1
- package/package.json +2 -2
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
const HttpClient_1 = __importDefault(require("../Core/HttpClient/HttpClient"));
|
|
15
|
+
class AccessToken {
|
|
16
|
+
constructor(corpId, secret, key = null, cache = null, httpClient = null) {
|
|
17
|
+
this.corpId = corpId;
|
|
18
|
+
this.secret = secret;
|
|
19
|
+
this.key = key;
|
|
20
|
+
this.cache = cache;
|
|
21
|
+
this.httpClient = httpClient;
|
|
22
|
+
if (!this.httpClient) {
|
|
23
|
+
this.httpClient = HttpClient_1.default.create({
|
|
24
|
+
baseURL: 'https://qyapi.weixin.qq.com/',
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* 获取access_token的缓存名称
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getKey() {
|
|
33
|
+
if (!this.key) {
|
|
34
|
+
this.key = `work.access_token.${this.corpId}`;
|
|
35
|
+
}
|
|
36
|
+
return this.key;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 设置access_token的缓存名称
|
|
40
|
+
* @param key
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
setKey(key) {
|
|
44
|
+
this.key = key;
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
getToken() {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
let token = '';
|
|
50
|
+
if (this.cache) {
|
|
51
|
+
token = yield this.cache.get(this.getKey());
|
|
52
|
+
}
|
|
53
|
+
if (!!token && typeof token === 'string') {
|
|
54
|
+
return token;
|
|
55
|
+
}
|
|
56
|
+
return this.refresh();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
toQuery() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
return {
|
|
62
|
+
access_token: yield this.getToken(),
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
refresh() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
let response = (yield this.httpClient.request('get', 'cgi-bin/gettoken', {
|
|
69
|
+
params: {
|
|
70
|
+
corpid: this.corpId,
|
|
71
|
+
corpsecret: this.secret,
|
|
72
|
+
}
|
|
73
|
+
})).toObject();
|
|
74
|
+
if (!response['access_token']) {
|
|
75
|
+
throw new Error('Failed to get access_token: ' + JSON.stringify(response));
|
|
76
|
+
}
|
|
77
|
+
if (this.cache) {
|
|
78
|
+
yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']));
|
|
79
|
+
}
|
|
80
|
+
return response['access_token'];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
module.exports = AccessToken;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AccountInterface from "./Contracts/AccountInterface";
|
|
2
|
+
declare class Account implements AccountInterface {
|
|
3
|
+
protected corpId: string;
|
|
4
|
+
protected secret: string;
|
|
5
|
+
protected token: string;
|
|
6
|
+
protected aesKey: string;
|
|
7
|
+
constructor(corpId: string, secret: string, token?: string, aesKey?: string);
|
|
8
|
+
getCorpId(): string;
|
|
9
|
+
getSecret(): string;
|
|
10
|
+
getToken(): string;
|
|
11
|
+
getAesKey(): string;
|
|
12
|
+
}
|
|
13
|
+
export = Account;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class Account {
|
|
3
|
+
constructor(corpId, secret, token = null, aesKey = null) {
|
|
4
|
+
this.corpId = corpId;
|
|
5
|
+
this.secret = secret;
|
|
6
|
+
this.token = token;
|
|
7
|
+
this.aesKey = aesKey;
|
|
8
|
+
}
|
|
9
|
+
getCorpId() {
|
|
10
|
+
return this.corpId;
|
|
11
|
+
}
|
|
12
|
+
getSecret() {
|
|
13
|
+
if (null === this.secret) {
|
|
14
|
+
throw new Error("No secret configured.");
|
|
15
|
+
}
|
|
16
|
+
return this.secret;
|
|
17
|
+
}
|
|
18
|
+
getToken() {
|
|
19
|
+
return this.token;
|
|
20
|
+
}
|
|
21
|
+
getAesKey() {
|
|
22
|
+
return this.aesKey;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
module.exports = Account;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import ProviderInterface from 'node-socialite/dist/Core/ProviderInterface';
|
|
2
|
+
import ConfigInterface from '../Core/Contracts/ConfigInterface';
|
|
3
|
+
import Encryptor from './Encryptor';
|
|
4
|
+
import AccessTokenAwareClient from '../Core/HttpClient/AccessTokenAwareClient';
|
|
5
|
+
import CacheMixin from '../Core/Mixins/CacheMixin';
|
|
6
|
+
import ClientMixin from '../Core/Mixins/ClientMixin';
|
|
7
|
+
import ConfigMixin from '../Core/Mixins/ConfigMixin';
|
|
8
|
+
import HttpClientMixin from '../Core/Mixins/HttpClientMixin';
|
|
9
|
+
import ServerRequestMixin from '../Core/Mixins/ServerRequestMixin';
|
|
10
|
+
import { WorkConfig, WorkOAuthFactory } from '../Types/global';
|
|
11
|
+
import AccountInterface from './Contracts/AccountInterface';
|
|
12
|
+
import ApplicationInterface from './Contracts/ApplicationInterface';
|
|
13
|
+
import JsApiTicket from './JsApiTicket';
|
|
14
|
+
import Server from './Server';
|
|
15
|
+
import Utils from './Utils';
|
|
16
|
+
import AccessTokenInterface from '../Core/Contracts/AccessTokenInterface';
|
|
17
|
+
/**
|
|
18
|
+
* 企业微信应用
|
|
19
|
+
*/
|
|
20
|
+
declare class Application implements ApplicationInterface {
|
|
21
|
+
constructor(config: ConfigInterface | WorkConfig);
|
|
22
|
+
protected account: AccountInterface;
|
|
23
|
+
protected encryptor: Encryptor;
|
|
24
|
+
protected server: Server;
|
|
25
|
+
protected accessToken: AccessTokenInterface;
|
|
26
|
+
protected oauthFactory: WorkOAuthFactory;
|
|
27
|
+
protected ticket: JsApiTicket;
|
|
28
|
+
getAccount(): AccountInterface;
|
|
29
|
+
/**
|
|
30
|
+
* 设置当前账户实例
|
|
31
|
+
* @param account
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
setAccount(account: AccountInterface): this;
|
|
35
|
+
getEncryptor(): Encryptor;
|
|
36
|
+
/**
|
|
37
|
+
* 设置加密机实例
|
|
38
|
+
* @param encryptor
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
setEncryptor(encryptor: Encryptor): this;
|
|
42
|
+
getServer(): Server;
|
|
43
|
+
/**
|
|
44
|
+
* 设置服务端实例
|
|
45
|
+
* @param server
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
setServer(server: Server): this;
|
|
49
|
+
getAccessToken(): AccessTokenInterface;
|
|
50
|
+
/**
|
|
51
|
+
* 设置AccessToken实例
|
|
52
|
+
* @param accessToken
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
setAccessToken(accessToken: AccessTokenInterface): this;
|
|
56
|
+
setOAuthFactory(oauthFactory: WorkOAuthFactory): this;
|
|
57
|
+
getOAuth(): Promise<ProviderInterface>;
|
|
58
|
+
getTicket(): JsApiTicket;
|
|
59
|
+
/**
|
|
60
|
+
* 设置JsApiTicket实例
|
|
61
|
+
* @param ticket
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
setTicket(ticket: JsApiTicket): this;
|
|
65
|
+
getUtils(): Utils;
|
|
66
|
+
createClient(): AccessTokenAwareClient;
|
|
67
|
+
/**
|
|
68
|
+
* 获取请求默认配置
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
protected getHttpClientDefaultOptions(): Record<string, any>;
|
|
72
|
+
}
|
|
73
|
+
interface Application extends ConfigMixin, CacheMixin, ClientMixin, ServerRequestMixin, HttpClientMixin {
|
|
74
|
+
}
|
|
75
|
+
export = Application;
|
|
@@ -0,0 +1,177 @@
|
|
|
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 merge_1 = __importDefault(require("merge"));
|
|
15
|
+
const WeWork_1 = __importDefault(require("node-socialite/dist/Providers/WeWork"));
|
|
16
|
+
const Config_1 = __importDefault(require("./Config"));
|
|
17
|
+
const ConfigInterface_1 = __importDefault(require("../Core/Contracts/ConfigInterface"));
|
|
18
|
+
const Encryptor_1 = __importDefault(require("./Encryptor"));
|
|
19
|
+
const AccessTokenAwareClient_1 = __importDefault(require("../Core/HttpClient/AccessTokenAwareClient"));
|
|
20
|
+
const CacheMixin_1 = __importDefault(require("../Core/Mixins/CacheMixin"));
|
|
21
|
+
const ClientMixin_1 = __importDefault(require("../Core/Mixins/ClientMixin"));
|
|
22
|
+
const ConfigMixin_1 = __importDefault(require("../Core/Mixins/ConfigMixin"));
|
|
23
|
+
const HttpClientMixin_1 = __importDefault(require("../Core/Mixins/HttpClientMixin"));
|
|
24
|
+
const ServerRequestMixin_1 = __importDefault(require("../Core/Mixins/ServerRequestMixin"));
|
|
25
|
+
const Utils_1 = require("../Core/Support/Utils");
|
|
26
|
+
const AccessToken_1 = __importDefault(require("./AccessToken"));
|
|
27
|
+
const Account_1 = __importDefault(require("./Account"));
|
|
28
|
+
const JsApiTicket_1 = __importDefault(require("./JsApiTicket"));
|
|
29
|
+
const Server_1 = __importDefault(require("./Server"));
|
|
30
|
+
const Utils_2 = __importDefault(require("./Utils"));
|
|
31
|
+
/**
|
|
32
|
+
* 企业微信应用
|
|
33
|
+
*/
|
|
34
|
+
class Application {
|
|
35
|
+
constructor(config) {
|
|
36
|
+
this.account = null;
|
|
37
|
+
this.encryptor = null;
|
|
38
|
+
this.server = null;
|
|
39
|
+
this.accessToken = null;
|
|
40
|
+
this.oauthFactory = null;
|
|
41
|
+
this.ticket = null;
|
|
42
|
+
if (config instanceof ConfigInterface_1.default) {
|
|
43
|
+
this.setConfig(config);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
this.setConfig(new Config_1.default(config));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
getAccount() {
|
|
50
|
+
if (!this.account) {
|
|
51
|
+
this.account = new Account_1.default(this.config.get('corp_id'), this.config.get('secret'), this.config.get('token'), this.config.get('aes_key'));
|
|
52
|
+
}
|
|
53
|
+
return this.account;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 设置当前账户实例
|
|
57
|
+
* @param account
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
setAccount(account) {
|
|
61
|
+
this.account = account;
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
getEncryptor() {
|
|
65
|
+
if (!this.encryptor) {
|
|
66
|
+
let token = this.getAccount().getToken();
|
|
67
|
+
let aesKey = this.getAccount().getAesKey();
|
|
68
|
+
if (!token || !aesKey) {
|
|
69
|
+
throw new Error('token or aes_key cannot be empty.');
|
|
70
|
+
}
|
|
71
|
+
this.encryptor = new Encryptor_1.default(this.getAccount().getCorpId(), token, aesKey);
|
|
72
|
+
}
|
|
73
|
+
return this.encryptor;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 设置加密机实例
|
|
77
|
+
* @param encryptor
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
setEncryptor(encryptor) {
|
|
81
|
+
this.encryptor = encryptor;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
getServer() {
|
|
85
|
+
if (!this.server) {
|
|
86
|
+
this.server = new Server_1.default(this.getEncryptor(), this.getRequest());
|
|
87
|
+
}
|
|
88
|
+
return this.server;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 设置服务端实例
|
|
92
|
+
* @param server
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
setServer(server) {
|
|
96
|
+
this.server = server;
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
getAccessToken() {
|
|
100
|
+
if (!this.accessToken) {
|
|
101
|
+
this.accessToken = new AccessToken_1.default(this.getAccount().getCorpId(), this.getAccount().getSecret(), null, this.getCache(), this.getHttpClient());
|
|
102
|
+
}
|
|
103
|
+
return this.accessToken;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 设置AccessToken实例
|
|
107
|
+
* @param accessToken
|
|
108
|
+
* @returns
|
|
109
|
+
*/
|
|
110
|
+
setAccessToken(accessToken) {
|
|
111
|
+
this.accessToken = accessToken;
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
setOAuthFactory(oauthFactory) {
|
|
115
|
+
this.oauthFactory = oauthFactory;
|
|
116
|
+
return this;
|
|
117
|
+
}
|
|
118
|
+
getOAuth() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
if (!this.oauthFactory) {
|
|
121
|
+
this.oauthFactory = ((app) => {
|
|
122
|
+
return new WeWork_1.default({
|
|
123
|
+
client_id: app.getAccount().getCorpId(),
|
|
124
|
+
client_secret: app.getAccount().getSecret(),
|
|
125
|
+
redirect: app.getConfig().get('oauth.redirect_url'),
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
let provider = this.oauthFactory.call(null, this);
|
|
130
|
+
if (!(provider instanceof WeWork_1.default)) {
|
|
131
|
+
throw new Error(`The factory must return a \`ProviderInterface\` instance.`);
|
|
132
|
+
}
|
|
133
|
+
provider.withApiAccessToken(yield this.getAccessToken().getToken());
|
|
134
|
+
provider.scopes(this.getConfig().get('oauth.scopes', 'snsapi_userinfo'));
|
|
135
|
+
let agent_id = parseInt(this.config.get('agent_id')) || null;
|
|
136
|
+
if (agent_id) {
|
|
137
|
+
provider.setAgentId(agent_id);
|
|
138
|
+
}
|
|
139
|
+
return provider;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
getTicket() {
|
|
143
|
+
if (!this.ticket) {
|
|
144
|
+
this.ticket = new JsApiTicket_1.default(this.getAccount().getCorpId(), this.getAccount().getSecret(), null, this.getCache(), this.getClient());
|
|
145
|
+
}
|
|
146
|
+
return this.ticket;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* 设置JsApiTicket实例
|
|
150
|
+
* @param ticket
|
|
151
|
+
* @returns
|
|
152
|
+
*/
|
|
153
|
+
setTicket(ticket) {
|
|
154
|
+
this.ticket = ticket;
|
|
155
|
+
return this;
|
|
156
|
+
}
|
|
157
|
+
getUtils() {
|
|
158
|
+
return new Utils_2.default(this);
|
|
159
|
+
}
|
|
160
|
+
createClient() {
|
|
161
|
+
return (new AccessTokenAwareClient_1.default(this.getHttpClient(), this.getAccessToken(), (response) => { var _a; return (_a = response.toObject()['errcode']) !== null && _a !== void 0 ? _a : 0; }, this.getConfig().get('http.throw', true)))
|
|
162
|
+
.setPresets(this.getConfig().all());
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 获取请求默认配置
|
|
166
|
+
* @returns
|
|
167
|
+
*/
|
|
168
|
+
getHttpClientDefaultOptions() {
|
|
169
|
+
return (0, merge_1.default)(true, {
|
|
170
|
+
baseURL: 'https://qyapi.weixin.qq.com/',
|
|
171
|
+
}, this.getConfig().get('http'));
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
;
|
|
175
|
+
;
|
|
176
|
+
(0, Utils_1.applyMixins)(Application, [ConfigMixin_1.default, CacheMixin_1.default, ClientMixin_1.default, ServerRequestMixin_1.default, HttpClientMixin_1.default]);
|
|
177
|
+
module.exports = Application;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Config_1 = __importDefault(require("../Core/Config"));
|
|
6
|
+
class Config extends Config_1.default {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(...arguments);
|
|
9
|
+
this.requiredKeys = [
|
|
10
|
+
'corp_id',
|
|
11
|
+
'secret',
|
|
12
|
+
'token',
|
|
13
|
+
'aes_key',
|
|
14
|
+
];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
module.exports = Config;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare abstract class AccountInterface {
|
|
2
|
+
/**
|
|
3
|
+
* 获取corpid
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
getCorpId(): 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
|
+
* 获取corpid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getCorpId() { 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,87 @@
|
|
|
1
|
+
import ProviderInterface from "node-socialite/dist/Core/ProviderInterface";
|
|
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 { WorkOAuthFactory } from "../../Types/global";
|
|
11
|
+
import JsApiTicket from "../JsApiTicket";
|
|
12
|
+
import Utils from "../Utils";
|
|
13
|
+
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
14
|
+
declare abstract class ApplicationInterface {
|
|
15
|
+
/**
|
|
16
|
+
* 获取当前账户实例
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
getAccount(): AccountInterface;
|
|
20
|
+
/**
|
|
21
|
+
* 获取加密机实例
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
getEncryptor(): Encryptor;
|
|
25
|
+
/**
|
|
26
|
+
* 获取服务端实例
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getServer(): ServerInterface;
|
|
30
|
+
/**
|
|
31
|
+
* 获取当前请求实例
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
getRequest(): ServerRequestInterface;
|
|
35
|
+
/**
|
|
36
|
+
* 获取客户端实例
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
getClient(): AccessTokenAwareClient;
|
|
40
|
+
/**
|
|
41
|
+
* 创建客户端实例
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
createClient(): AccessTokenAwareClient;
|
|
45
|
+
/**
|
|
46
|
+
* 获取网络请求客户端实例
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
getHttpClient(): HttpClientInterface;
|
|
50
|
+
/**
|
|
51
|
+
* 获取配置信息实例
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
getConfig(): ConfigInterface;
|
|
55
|
+
/**
|
|
56
|
+
* 获取AccessToken实例
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
getAccessToken(): AccessTokenInterface;
|
|
60
|
+
/**
|
|
61
|
+
* 获取缓存实例
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getCache(): CacheInterface;
|
|
65
|
+
/**
|
|
66
|
+
* 获取OAuth实例
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
getOAuth(): Promise<ProviderInterface>;
|
|
70
|
+
/**
|
|
71
|
+
* 获取JsApiTicket实例
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
getTicket(): JsApiTicket;
|
|
75
|
+
/**
|
|
76
|
+
* 获取工具实例
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
getUtils(): Utils;
|
|
80
|
+
/**
|
|
81
|
+
* 设置OAuth工厂方法
|
|
82
|
+
* @param oauthFactory
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
setOAuthFactory(oauthFactory: WorkOAuthFactory): this;
|
|
86
|
+
}
|
|
87
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
* 获取OAuth实例
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getOAuth() { return null; }
|
|
58
|
+
/**
|
|
59
|
+
* 获取JsApiTicket实例
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
getTicket() { return null; }
|
|
63
|
+
/**
|
|
64
|
+
* 获取工具实例
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
getUtils() { return null; }
|
|
68
|
+
/**
|
|
69
|
+
* 设置OAuth工厂方法
|
|
70
|
+
* @param oauthFactory
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
setOAuthFactory(oauthFactory) { return this; }
|
|
74
|
+
}
|
|
75
|
+
;
|
|
76
|
+
module.exports = ApplicationInterface;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import BaseEncryptor from '../Core/Encryptor';
|
|
3
|
+
declare class Encryptor extends BaseEncryptor {
|
|
4
|
+
protected corpId: string;
|
|
5
|
+
protected token: string;
|
|
6
|
+
protected aesKey: string | Buffer;
|
|
7
|
+
constructor(corpId?: string, token?: string, aesKey?: string | Buffer);
|
|
8
|
+
}
|
|
9
|
+
export = Encryptor;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
const Encryptor_1 = __importDefault(require("../Core/Encryptor"));
|
|
6
|
+
class Encryptor extends Encryptor_1.default {
|
|
7
|
+
constructor(corpId = null, token = null, aesKey = null) {
|
|
8
|
+
super(corpId, token, aesKey, null);
|
|
9
|
+
this.corpId = corpId;
|
|
10
|
+
this.token = token;
|
|
11
|
+
this.aesKey = aesKey;
|
|
12
|
+
if (typeof this.aesKey === 'string') {
|
|
13
|
+
this.aesKey = Buffer.from(this.aesKey + '=', 'base64');
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
module.exports = Encryptor;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import AccessToken from './AccessToken';
|
|
2
|
+
declare class JsApiTicket extends AccessToken {
|
|
3
|
+
protected agentKey: string;
|
|
4
|
+
/**
|
|
5
|
+
* 获取jsapi_ticket的缓存名称
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
getKey(): string;
|
|
9
|
+
/**
|
|
10
|
+
* 获取签名凭证jsapi_ticket
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
getTicket(): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* 获取签名配置
|
|
16
|
+
* @param url 完整URL地址
|
|
17
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
18
|
+
* @param timestamp 时间长,默认:当前时间
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
createConfigSignature(url: string, nonce?: string, timestamp?: number): Promise<Record<string, any>>;
|
|
22
|
+
protected getTicketSignature(ticket: string, nonce: string, timestamp: number, url: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* 获取代理应用的签名配置
|
|
25
|
+
* @param agentId 代理应用的id
|
|
26
|
+
* @param url 完整URL地址
|
|
27
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
28
|
+
* @param timestamp 时间长,默认:当前时间
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
createAgentConfigSignature(agentId: number, url: string, nonce?: string, timestamp?: number): Promise<Record<string, any>>;
|
|
32
|
+
/**
|
|
33
|
+
* 获取代理应用的签名凭证jsapi_ticket
|
|
34
|
+
* @param agentId 代理应用的id
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getAgentTicket(agentId: number): Promise<string>;
|
|
38
|
+
/**
|
|
39
|
+
* 获取代理应用的jsapi_ticket的缓存名称
|
|
40
|
+
* @param agentId 代理应用的id
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getAgentKey(agentId: number): string;
|
|
44
|
+
}
|
|
45
|
+
export = JsApiTicket;
|