node-easywechat 3.2.0 → 3.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish-npm-2.yml +1 -1
- package/.github/workflows/publish-npm-3.yml +1 -1
- package/CHANGELOG.md +13 -0
- package/README.md +3 -3
- 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 +11 -1
- package/dist/Work/Application.d.ts +5 -5
- package/dist/Work/Application.js +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/package.json +2 -2
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
const merge = __importStar(require("merge"));
|
|
29
|
+
const HasAttributesMixin_1 = __importDefault(require("../Core/Mixins/HasAttributesMixin"));
|
|
30
|
+
const Utils_1 = require("../Core/Support/Utils");
|
|
31
|
+
class Authorization {
|
|
32
|
+
constructor(attributes = null) {
|
|
33
|
+
if (attributes) {
|
|
34
|
+
this.attributes = merge.recursive({}, attributes);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 获取corpid
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
getCorpId() {
|
|
42
|
+
if (!this.attributes['auth_corp_info'])
|
|
43
|
+
return '';
|
|
44
|
+
return this.attributes['auth_corp_info']['corpid'] || '';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
;
|
|
48
|
+
(0, Utils_1.applyMixins)(Authorization, [HasAttributesMixin_1.default]);
|
|
49
|
+
module.exports = Authorization;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import AccessTokenInterface from "../Core/Contracts/AccessTokenInterface";
|
|
2
|
+
import CacheInterface from "../Core/Contracts/CacheInterface";
|
|
3
|
+
import RefreshableAccessTokenInterface from "../Core/Contracts/RefreshableAccessTokenInterface";
|
|
4
|
+
import HttpClientInterface from "../Core/HttpClient/Contracts/HttpClientInterface";
|
|
5
|
+
declare class AuthorizerAccessToken implements RefreshableAccessTokenInterface {
|
|
6
|
+
protected corpId: string;
|
|
7
|
+
protected permanentCodeOrAccessToken: string;
|
|
8
|
+
protected suiteAccessToken: AccessTokenInterface;
|
|
9
|
+
protected key: string;
|
|
10
|
+
protected cache: CacheInterface;
|
|
11
|
+
protected httpClient: HttpClientInterface;
|
|
12
|
+
constructor(corpId: string, permanentCodeOrAccessToken: string, suiteAccessToken?: AccessTokenInterface, key?: string, cache?: CacheInterface, httpClient?: HttpClientInterface);
|
|
13
|
+
/**
|
|
14
|
+
* 获取appId
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getCorpId(): string;
|
|
18
|
+
/**
|
|
19
|
+
* 获取access_token的缓存名称
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getKey(): string;
|
|
23
|
+
/**
|
|
24
|
+
* 设置access_token的缓存名称
|
|
25
|
+
* @param key
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
setKey(key: string): this;
|
|
29
|
+
getToken(): Promise<string>;
|
|
30
|
+
toQuery(): Promise<Record<string, any>>;
|
|
31
|
+
refresh(): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* 转为字符串
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
toString(): Promise<string>;
|
|
37
|
+
}
|
|
38
|
+
export = AuthorizerAccessToken;
|
|
@@ -0,0 +1,105 @@
|
|
|
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 AuthorizerAccessToken {
|
|
16
|
+
constructor(corpId, permanentCodeOrAccessToken, suiteAccessToken = null, key = null, cache = null, httpClient = null) {
|
|
17
|
+
this.corpId = corpId;
|
|
18
|
+
this.permanentCodeOrAccessToken = permanentCodeOrAccessToken;
|
|
19
|
+
this.suiteAccessToken = suiteAccessToken;
|
|
20
|
+
this.key = key;
|
|
21
|
+
this.cache = cache;
|
|
22
|
+
this.httpClient = httpClient;
|
|
23
|
+
if (!this.httpClient) {
|
|
24
|
+
this.httpClient = HttpClient_1.default.create({
|
|
25
|
+
baseURL: 'https://qyapi.weixin.qq.com/',
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 获取appId
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
getCorpId() {
|
|
34
|
+
return this.corpId;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 获取access_token的缓存名称
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
getKey() {
|
|
41
|
+
if (!this.key) {
|
|
42
|
+
this.key = `open_work.authorizer.access_token.${this.corpId}.${this.permanentCodeOrAccessToken}`;
|
|
43
|
+
}
|
|
44
|
+
return this.key;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 设置access_token的缓存名称
|
|
48
|
+
* @param key
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
setKey(key) {
|
|
52
|
+
this.key = key;
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
getToken() {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (!this.suiteAccessToken) {
|
|
58
|
+
return this.permanentCodeOrAccessToken;
|
|
59
|
+
}
|
|
60
|
+
let token = '';
|
|
61
|
+
if (this.cache) {
|
|
62
|
+
token = yield this.cache.get(this.getKey());
|
|
63
|
+
}
|
|
64
|
+
if (!!token && typeof token === 'string') {
|
|
65
|
+
return token;
|
|
66
|
+
}
|
|
67
|
+
return this.refresh();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
toQuery() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return {
|
|
73
|
+
access_token: yield this.getToken(),
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
refresh() {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
let response = (yield this.httpClient.request('post', 'cgi-bin/service/get_corp_token', {
|
|
80
|
+
params: {
|
|
81
|
+
suite_access_token: yield this.suiteAccessToken.getToken(),
|
|
82
|
+
},
|
|
83
|
+
json: {
|
|
84
|
+
auth_corpid: this.corpId,
|
|
85
|
+
permanent_code: this.permanentCodeOrAccessToken,
|
|
86
|
+
}
|
|
87
|
+
})).toObject();
|
|
88
|
+
if (!response['access_token']) {
|
|
89
|
+
throw new Error('Failed to get access_token: ' + JSON.stringify(response));
|
|
90
|
+
}
|
|
91
|
+
if (this.cache) {
|
|
92
|
+
yield this.cache.set(this.getKey(), response['access_token'], parseInt(response['expires_in']) - 100);
|
|
93
|
+
}
|
|
94
|
+
return response['access_token'];
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* 转为字符串
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
toString() {
|
|
102
|
+
return this.getToken();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
module.exports = AuthorizerAccessToken;
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
'suite_id',
|
|
12
|
+
'provider_secret',
|
|
13
|
+
'suite_secret',
|
|
14
|
+
'token',
|
|
15
|
+
'aes_key',
|
|
16
|
+
];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
module.exports = Config;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
declare abstract class AccountInterface {
|
|
2
|
+
/**
|
|
3
|
+
* 获取corpid
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
getCorpId(): string;
|
|
7
|
+
/**
|
|
8
|
+
* 获取provider secret
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
getProviderSecret(): string;
|
|
12
|
+
/**
|
|
13
|
+
* 获取suite id
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
getSuiteId(): string;
|
|
17
|
+
/**
|
|
18
|
+
* 获取suite secret
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getSuiteSecret(): string;
|
|
22
|
+
/**
|
|
23
|
+
* 获取token
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
getToken(): string;
|
|
27
|
+
/**
|
|
28
|
+
* 获取aesKey
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
getAesKey(): string;
|
|
32
|
+
}
|
|
33
|
+
export = AccountInterface;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class AccountInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取corpid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getCorpId() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 获取provider secret
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getProviderSecret() { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 获取suite id
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getSuiteId() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取suite secret
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getSuiteSecret() { return null; }
|
|
23
|
+
/**
|
|
24
|
+
* 获取token
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getToken() { return null; }
|
|
28
|
+
/**
|
|
29
|
+
* 获取aesKey
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getAesKey() { return null; }
|
|
33
|
+
}
|
|
34
|
+
;
|
|
35
|
+
module.exports = AccountInterface;
|
|
@@ -0,0 +1,108 @@
|
|
|
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 SuiteEncryptor from "../SuiteEncryptor";
|
|
10
|
+
import AccountInterface from "./AccountInterface";
|
|
11
|
+
import AccessTokenInterface from "../../Core/Contracts/AccessTokenInterface";
|
|
12
|
+
import SuiteTicketInterface from "./SuiteTicketInterface";
|
|
13
|
+
import SuiteAccessToken from "../SuiteAccessToken";
|
|
14
|
+
import JsApiTicket from "../JsApiTicket";
|
|
15
|
+
declare abstract class ApplicationInterface {
|
|
16
|
+
/**
|
|
17
|
+
* 获取当前账户实例
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
getAccount(): AccountInterface;
|
|
21
|
+
/**
|
|
22
|
+
* 获取加密机实例
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
getEncryptor(): Encryptor;
|
|
26
|
+
/**
|
|
27
|
+
* 获取授权应用的加密机实例
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
getSuiteEncryptor(): SuiteEncryptor;
|
|
31
|
+
/**
|
|
32
|
+
* 获取服务端实例
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
getServer(): ServerInterface;
|
|
36
|
+
/**
|
|
37
|
+
* 获取当前请求实例
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
getRequest(): ServerRequestInterface;
|
|
41
|
+
/**
|
|
42
|
+
* 获取客户端实例
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
getClient(): AccessTokenAwareClient;
|
|
46
|
+
/**
|
|
47
|
+
* 创建客户端实例
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
createClient(): AccessTokenAwareClient;
|
|
51
|
+
/**
|
|
52
|
+
* 获取企业的客户端实例
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
getAuthorizerClient(corpId: string, permanentCode: string, suiteAccessToken?: SuiteAccessToken): Promise<AccessTokenAwareClient>;
|
|
56
|
+
/**
|
|
57
|
+
* 获取jsapi ticket
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
getJsApiTicket(corpId: string, permanentCode: string, suiteAccessToken?: SuiteAccessToken): Promise<JsApiTicket>;
|
|
61
|
+
/**
|
|
62
|
+
* 获取网络请求客户端实例
|
|
63
|
+
* @returns
|
|
64
|
+
*/
|
|
65
|
+
getHttpClient(): HttpClientInterface;
|
|
66
|
+
/**
|
|
67
|
+
* 获取配置信息实例
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
getConfig(): ConfigInterface;
|
|
71
|
+
/**
|
|
72
|
+
* 获取开放平台应用的AccessToken实例
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
getProviderAccessToken(): AccessTokenInterface;
|
|
76
|
+
/**
|
|
77
|
+
* 获取授权应用的AccessToken实例
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
getSuiteAccessToken(): AccessTokenInterface;
|
|
81
|
+
/**
|
|
82
|
+
* 获取授权应用的Ticket实例
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
getSuiteTicket(): SuiteTicketInterface;
|
|
86
|
+
/**
|
|
87
|
+
* 获取缓存实例
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
getCache(): CacheInterface;
|
|
91
|
+
/**
|
|
92
|
+
* 获取授权应用的OAuth实例
|
|
93
|
+
* @param suiteId
|
|
94
|
+
* @param suiteAccessToken
|
|
95
|
+
* @https://developer.work.weixin.qq.com/document/path/91120#构造第三方应用oauth2链接
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
getOAuth(suiteId: string, suiteAccessToken?: SuiteAccessToken): Promise<ProviderInterface>;
|
|
99
|
+
/**
|
|
100
|
+
* 获取企业的OAuth实例
|
|
101
|
+
* @param corpId
|
|
102
|
+
* @param suiteAccessToken
|
|
103
|
+
* @see https://developer.work.weixin.qq.com/document/path/91120#构造企业oauth2链接
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
getCorpOAuth(corpId: string, suiteAccessToken?: SuiteAccessToken): Promise<ProviderInterface>;
|
|
107
|
+
}
|
|
108
|
+
export = ApplicationInterface;
|
|
@@ -0,0 +1,96 @@
|
|
|
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
|
+
getSuiteEncryptor() { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取服务端实例
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getServer() { return null; }
|
|
23
|
+
/**
|
|
24
|
+
* 获取当前请求实例
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getRequest() { return null; }
|
|
28
|
+
/**
|
|
29
|
+
* 获取客户端实例
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getClient() { return null; }
|
|
33
|
+
/**
|
|
34
|
+
* 创建客户端实例
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
createClient() { return null; }
|
|
38
|
+
/**
|
|
39
|
+
* 获取企业的客户端实例
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getAuthorizerClient(corpId, permanentCode, suiteAccessToken = null) { return null; }
|
|
43
|
+
/**
|
|
44
|
+
* 获取jsapi ticket
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getJsApiTicket(corpId, permanentCode, suiteAccessToken = null) { return null; }
|
|
48
|
+
/**
|
|
49
|
+
* 获取网络请求客户端实例
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
getHttpClient() { return null; }
|
|
53
|
+
/**
|
|
54
|
+
* 获取配置信息实例
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getConfig() { return null; }
|
|
58
|
+
/**
|
|
59
|
+
* 获取开放平台应用的AccessToken实例
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
getProviderAccessToken() { return null; }
|
|
63
|
+
/**
|
|
64
|
+
* 获取授权应用的AccessToken实例
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
getSuiteAccessToken() { return null; }
|
|
68
|
+
/**
|
|
69
|
+
* 获取授权应用的Ticket实例
|
|
70
|
+
* @returns
|
|
71
|
+
*/
|
|
72
|
+
getSuiteTicket() { return null; }
|
|
73
|
+
/**
|
|
74
|
+
* 获取缓存实例
|
|
75
|
+
* @returns
|
|
76
|
+
*/
|
|
77
|
+
getCache() { return null; }
|
|
78
|
+
/**
|
|
79
|
+
* 获取授权应用的OAuth实例
|
|
80
|
+
* @param suiteId
|
|
81
|
+
* @param suiteAccessToken
|
|
82
|
+
* @https://developer.work.weixin.qq.com/document/path/91120#构造第三方应用oauth2链接
|
|
83
|
+
* @returns
|
|
84
|
+
*/
|
|
85
|
+
getOAuth(suiteId, suiteAccessToken = null) { return null; }
|
|
86
|
+
/**
|
|
87
|
+
* 获取企业的OAuth实例
|
|
88
|
+
* @param corpId
|
|
89
|
+
* @param suiteAccessToken
|
|
90
|
+
* @see https://developer.work.weixin.qq.com/document/path/91120#构造企业oauth2链接
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
getCorpOAuth(corpId, suiteAccessToken = null) { return null; }
|
|
94
|
+
}
|
|
95
|
+
;
|
|
96
|
+
module.exports = ApplicationInterface;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
declare abstract class SuiteTicketInterface {
|
|
2
|
+
/**
|
|
3
|
+
* 获取ticket缓存名
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
getKey(): string;
|
|
7
|
+
/**
|
|
8
|
+
* 设置ticket缓存名
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
setKey(key: string): this;
|
|
12
|
+
/**
|
|
13
|
+
* 设置ticket
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
setTicket(key: string): Promise<this>;
|
|
17
|
+
/**
|
|
18
|
+
* 获取ticket
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
getTicket(): Promise<string>;
|
|
22
|
+
}
|
|
23
|
+
export = SuiteTicketInterface;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
class SuiteTicketInterface {
|
|
3
|
+
/**
|
|
4
|
+
* 获取ticket缓存名
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
getKey() { return null; }
|
|
8
|
+
/**
|
|
9
|
+
* 设置ticket缓存名
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
setKey(key) { return null; }
|
|
13
|
+
/**
|
|
14
|
+
* 设置ticket
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
setTicket(key) { return null; }
|
|
18
|
+
/**
|
|
19
|
+
* 获取ticket
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getTicket() { return null; }
|
|
23
|
+
}
|
|
24
|
+
;
|
|
25
|
+
module.exports = SuiteTicketInterface;
|
|
@@ -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,50 @@
|
|
|
1
|
+
import CacheInterface from '../Core/Contracts/CacheInterface';
|
|
2
|
+
import HttpClientInterface from '../Core/HttpClient/Contracts/HttpClientInterface';
|
|
3
|
+
declare class JsApiTicket {
|
|
4
|
+
protected corpId: string;
|
|
5
|
+
protected key: string;
|
|
6
|
+
protected cache: CacheInterface;
|
|
7
|
+
protected httpClient: HttpClientInterface;
|
|
8
|
+
constructor(corpId: string, key?: string, cache?: CacheInterface, httpClient?: HttpClientInterface);
|
|
9
|
+
/**
|
|
10
|
+
* 获取签名配置
|
|
11
|
+
* @param url 完整URL地址
|
|
12
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
13
|
+
* @param timestamp 时间长,默认:当前时间
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
createConfigSignature(url: string, nonce?: string, timestamp?: number, jsApiList?: string[], debug?: boolean, beta?: boolean): Promise<Record<string, any>>;
|
|
17
|
+
protected getTicketSignature(ticket: string, nonce: string, timestamp: number, url: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* 获取jsapi_ticket的缓存名称
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
getKey(): string;
|
|
23
|
+
/**
|
|
24
|
+
* 获取签名凭证jsapi_ticket
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getTicket(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* 获取代理应用的签名配置
|
|
30
|
+
* @param agentId 代理应用的id
|
|
31
|
+
* @param url 完整URL地址
|
|
32
|
+
* @param nonce 随机字符串,默认:随机10位
|
|
33
|
+
* @param timestamp 时间长,默认:当前时间
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
createAgentConfigSignature(agentId: number, url: string, nonce?: string, timestamp?: number, jsApiList?: string[]): Promise<Record<string, any>>;
|
|
37
|
+
/**
|
|
38
|
+
* 获取代理应用的签名凭证jsapi_ticket
|
|
39
|
+
* @param agentId 代理应用的id
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getAgentTicket(agentId: number): Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* 获取代理应用的jsapi_ticket的缓存名称
|
|
45
|
+
* @param agentId 代理应用的id
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
getAgentKey(agentId: number): string;
|
|
49
|
+
}
|
|
50
|
+
export = JsApiTicket;
|