node-easywechat 2.8.1 → 2.9.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/README.md +51 -4
- package/dist/Core/Http/Request.js +2 -2
- package/dist/Core/ServerGuard.d.ts +2 -2
- package/dist/Core/Types.d.ts +34 -4
- package/dist/MiniProgram/Application.d.ts +14 -0
- package/dist/MiniProgram/Application.js +35 -0
- package/dist/MiniProgram/Shop/AccoutClient.d.ts +25 -0
- package/dist/MiniProgram/Shop/AccoutClient.js +42 -0
- package/dist/MiniProgram/Shop/AftersaleClient.d.ts +22 -0
- package/dist/MiniProgram/Shop/AftersaleClient.js +35 -0
- package/dist/MiniProgram/Shop/BasicClient.d.ts +39 -0
- package/dist/MiniProgram/Shop/BasicClient.js +69 -0
- package/dist/MiniProgram/Shop/DeliveryClient.d.ts +20 -0
- package/dist/MiniProgram/Shop/DeliveryClient.js +32 -0
- package/dist/MiniProgram/Shop/OrderClient.d.ts +32 -0
- package/dist/MiniProgram/Shop/OrderClient.js +51 -0
- package/dist/MiniProgram/Shop/RegisterClient.d.ts +25 -0
- package/dist/MiniProgram/Shop/RegisterClient.js +43 -0
- package/dist/MiniProgram/Shop/SpuClient.d.ts +67 -0
- package/dist/MiniProgram/Shop/SpuClient.js +92 -0
- package/dist/OpenPlatform/Application.js +2 -2
- package/dist/OpenWork/Application.d.ts +37 -0
- package/dist/OpenWork/Application.js +128 -0
- package/dist/OpenWork/Auth/ProviderAccessToken.d.ts +8 -0
- package/dist/OpenWork/Auth/ProviderAccessToken.js +33 -0
- package/dist/OpenWork/Auth/SuiteAccessToken.d.ts +8 -0
- package/dist/OpenWork/Auth/SuiteAccessToken.js +34 -0
- package/dist/OpenWork/Auth/SuiteTicket.d.ts +8 -0
- package/dist/OpenWork/Auth/SuiteTicket.js +40 -0
- package/dist/OpenWork/Corp/CorpClient.d.ts +72 -0
- package/dist/OpenWork/Corp/CorpClient.js +150 -0
- package/dist/OpenWork/MiniProgram/MiniProgramClient.d.ts +5 -0
- package/dist/OpenWork/MiniProgram/MiniProgramClient.js +18 -0
- package/dist/OpenWork/Provider/ProviderClient.d.ts +81 -0
- package/dist/OpenWork/Provider/ProviderClient.js +172 -0
- package/dist/OpenWork/Server/OpenWorkGuard.d.ts +13 -0
- package/dist/OpenWork/Server/OpenWorkGuard.js +51 -0
- package/dist/OpenWork/Work/Application.d.ts +5 -0
- package/dist/OpenWork/Work/Application.js +22 -0
- package/dist/OpenWork/Work/Auth/AccessToken.d.ts +12 -0
- package/dist/OpenWork/Work/Auth/AccessToken.js +44 -0
- package/dist/Work/Agent/WorkbenchClient.d.ts +24 -0
- package/dist/Work/Agent/WorkbenchClient.js +39 -0
- package/dist/Work/Application.d.ts +8 -0
- package/dist/Work/Application.js +20 -0
- package/dist/Work/CorpGroup/CorpGroupClient.d.ts +34 -0
- package/dist/Work/CorpGroup/CorpGroupClient.js +42 -0
- package/dist/Work/ExternalContact/Client.d.ts +11 -0
- package/dist/Work/ExternalContact/Client.js +16 -0
- package/dist/Work/ExternalContact/ContactWayClient.d.ts +37 -0
- package/dist/Work/ExternalContact/ContactWayClient.js +49 -0
- package/dist/Work/ExternalContact/MomentClient.d.ts +56 -3
- package/dist/Work/ExternalContact/MomentClient.js +62 -3
- package/dist/Work/ExternalContact/StatisticsClient.d.ts +24 -0
- package/dist/Work/ExternalContact/StatisticsClient.js +35 -0
- package/dist/Work/Kf/KfAccountClient.d.ts +41 -0
- package/dist/Work/Kf/KfAccountClient.js +71 -0
- package/dist/Work/Kf/KfMessageClient.d.ts +44 -0
- package/dist/Work/Kf/KfMessageClient.js +73 -0
- package/dist/Work/Kf/KfServicerClient.d.ts +26 -0
- package/dist/Work/Kf/KfServicerClient.js +47 -0
- package/dist/Work/Server/Guard.d.ts +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +8 -6
- package/package.json +5 -5
- package/node-easywechat.file_cache.easywechat.kernel.access_token.8a9684b45da7de42a06a70ba01a7005a.cache +0 -1
- package/node-easywechat.file_cache.easywechat.kernel.access_token.c3d06edaf326aad75d32f31348df787a.cache +0 -1
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
const BaseClient_1 = __importDefault(require("../../Core/BaseClient"));
|
|
7
|
+
class RegisterClient extends BaseClient_1.default {
|
|
8
|
+
/**
|
|
9
|
+
* 接入申请
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
apply() {
|
|
13
|
+
return this.httpPostJson('shop/register/apply');
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 获取接入状态
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
check() {
|
|
20
|
+
return this.httpPostJson('shop/register/check');
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 完成接入任务
|
|
24
|
+
* @param accessInfoItem 6:完成spu接口,7:完成订单接口,8:完成物流接口,9:完成售后接口,10:测试完成,11:发版完成
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
finishAccessInfo(accessInfoItem) {
|
|
28
|
+
return this.httpPostJson('shop/register/finish_access_info', {
|
|
29
|
+
access_info_item: accessInfoItem,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 场景接入申请
|
|
34
|
+
* @param sceneGroupId 1:视频号、公众号场景
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
applyScene(sceneGroupId) {
|
|
38
|
+
return this.httpPostJson('shop/register/apply_scene', {
|
|
39
|
+
scene_group_id: sceneGroupId,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.default = RegisterClient;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import BaseClient from '../../Core/BaseClient';
|
|
2
|
+
export default class SpuClient extends BaseClient {
|
|
3
|
+
/**
|
|
4
|
+
* 添加商品
|
|
5
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/add_spu.html
|
|
6
|
+
* @param product
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
add(product: object): Promise<any>;
|
|
10
|
+
/**
|
|
11
|
+
* 删除商品
|
|
12
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/del_spu.html
|
|
13
|
+
* @param params
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
del(params: object): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* 获取商品
|
|
19
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/get_spu.html
|
|
20
|
+
* @param params
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
get(params: object): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* 获取商品列表
|
|
26
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/get_spu_list.html
|
|
27
|
+
* @param product
|
|
28
|
+
* @param page
|
|
29
|
+
* @returns
|
|
30
|
+
*/
|
|
31
|
+
getList(product: object, page: object): Promise<any>;
|
|
32
|
+
/**
|
|
33
|
+
* 撤回商品审核
|
|
34
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/del_spu_audit.html
|
|
35
|
+
* @param params
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
delAudit(params: object): Promise<any>;
|
|
39
|
+
/**
|
|
40
|
+
* 更新商品
|
|
41
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/update_spu.html
|
|
42
|
+
* @param params
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
update(params: object): Promise<any>;
|
|
46
|
+
/**
|
|
47
|
+
* 免审更新商品
|
|
48
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/update_spu_without_audit.html
|
|
49
|
+
* @param params
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
updateWithoutAudit(params: object): Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* 上架商品
|
|
55
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/listing_spu.html
|
|
56
|
+
* @param params
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
listing(params: object): Promise<any>;
|
|
60
|
+
/**
|
|
61
|
+
* 下架商品
|
|
62
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/delisting_spu.html
|
|
63
|
+
* @param params
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
delisting(params: object): Promise<any>;
|
|
67
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
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
|
+
const BaseClient_1 = __importDefault(require("../../Core/BaseClient"));
|
|
7
|
+
const Utils_1 = require("../../Core/Utils");
|
|
8
|
+
class SpuClient extends BaseClient_1.default {
|
|
9
|
+
/**
|
|
10
|
+
* 添加商品
|
|
11
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/add_spu.html
|
|
12
|
+
* @param product
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
add(product) {
|
|
16
|
+
return this.httpPostJson('shop/spu/add', product);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 删除商品
|
|
20
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/del_spu.html
|
|
21
|
+
* @param params
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
del(params) {
|
|
25
|
+
return this.httpPostJson('shop/spu/del', params);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 获取商品
|
|
29
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/get_spu.html
|
|
30
|
+
* @param params
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
get(params) {
|
|
34
|
+
return this.httpPostJson('shop/spu/get', params);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 获取商品列表
|
|
38
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/get_spu_list.html
|
|
39
|
+
* @param product
|
|
40
|
+
* @param page
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
getList(product, page) {
|
|
44
|
+
return this.httpPostJson('shop/spu/get_list', (0, Utils_1.merge)((0, Utils_1.merge)({}, product), page));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 撤回商品审核
|
|
48
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/del_spu_audit.html
|
|
49
|
+
* @param params
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
delAudit(params) {
|
|
53
|
+
return this.httpPostJson('shop/spu/del_audit', params);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 更新商品
|
|
57
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/update_spu.html
|
|
58
|
+
* @param params
|
|
59
|
+
* @returns
|
|
60
|
+
*/
|
|
61
|
+
update(params) {
|
|
62
|
+
return this.httpPostJson('shop/spu/update', params);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 免审更新商品
|
|
66
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/update_spu_without_audit.html
|
|
67
|
+
* @param params
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
70
|
+
updateWithoutAudit(params) {
|
|
71
|
+
return this.httpPostJson('shop/spu/update_without_audit', params);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 上架商品
|
|
75
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/listing_spu.html
|
|
76
|
+
* @param params
|
|
77
|
+
* @returns
|
|
78
|
+
*/
|
|
79
|
+
listing(params) {
|
|
80
|
+
return this.httpPostJson('shop/spu/listing', params);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 下架商品
|
|
84
|
+
* @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent2/API/SPU/delisting_spu.html
|
|
85
|
+
* @param params
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
delisting(params) {
|
|
89
|
+
return this.httpPostJson('shop/spu/delisting', params);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.default = SpuClient;
|
|
@@ -97,9 +97,9 @@ class OpenPlatform extends BaseApplication_1.default {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
else {
|
|
100
|
-
optional['pre_auth_code'] = yield this.createPreAuthorizationCode()['pre_auth_code'];
|
|
100
|
+
optional['pre_auth_code'] = (yield this.createPreAuthorizationCode())['pre_auth_code'];
|
|
101
101
|
}
|
|
102
|
-
return 'https://mp.weixin.qq.com/safe/bindcomponent?' + (0, Utils_1.buildQueryString)((0, Utils_1.merge)(optional, {
|
|
102
|
+
return 'https://mp.weixin.qq.com/safe/bindcomponent?' + (0, Utils_1.buildQueryString)((0, Utils_1.merge)((0, Utils_1.merge)({}, optional), {
|
|
103
103
|
component_appid: this.config['app_id'],
|
|
104
104
|
redirect_uri: callbackUrl,
|
|
105
105
|
action: 'bindcomponent',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import BaseApplication from '../Core/BaseApplication';
|
|
2
|
+
import MiniProgram from '../Work/MiniProgram/Application';
|
|
3
|
+
import Work from './Work/Application';
|
|
4
|
+
import ProviderAccessToken from './Auth/ProviderAccessToken';
|
|
5
|
+
import SuiteAccessToken from './Auth/SuiteAccessToken';
|
|
6
|
+
import SuiteTicket from './Auth/SuiteTicket';
|
|
7
|
+
import CorpClient from './Corp/CorpClient';
|
|
8
|
+
import MiniProgramClient from './MiniProgram/MiniProgramClient';
|
|
9
|
+
import ProviderClient from './Provider/ProviderClient';
|
|
10
|
+
import Encryptor from '../Core/Encryptor';
|
|
11
|
+
import OpenWorkGuard from './Server/OpenWorkGuard';
|
|
12
|
+
import { EasyWechatConfig } from '../Core/Types';
|
|
13
|
+
export default class OpenWork extends BaseApplication {
|
|
14
|
+
protected defaultConfig: EasyWechatConfig;
|
|
15
|
+
provider_access_token: ProviderAccessToken;
|
|
16
|
+
suite_access_token: SuiteAccessToken;
|
|
17
|
+
suite_ticket: SuiteTicket;
|
|
18
|
+
corp: CorpClient;
|
|
19
|
+
mini_program: MiniProgramClient;
|
|
20
|
+
provider: ProviderClient;
|
|
21
|
+
encryptor_corp: Encryptor;
|
|
22
|
+
encryptor: Encryptor;
|
|
23
|
+
server: OpenWorkGuard;
|
|
24
|
+
constructor(config?: EasyWechatConfig, prepends?: Object, id?: String);
|
|
25
|
+
registerProviders(): void;
|
|
26
|
+
/**
|
|
27
|
+
* 代理小程序实现业务,返回SDK实例
|
|
28
|
+
*/
|
|
29
|
+
miniProgram(): MiniProgram;
|
|
30
|
+
/**
|
|
31
|
+
* 代理企业微信实现业务,返回SDK实例
|
|
32
|
+
* @param authCorpId 企业 corp_id
|
|
33
|
+
* @param permanentCode 企业永久授权码
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
work(authCorpId: string, permanentCode: string): Work;
|
|
37
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const BaseApplication_1 = __importDefault(require("../Core/BaseApplication"));
|
|
16
|
+
const Application_1 = __importDefault(require("../Work/MiniProgram/Application"));
|
|
17
|
+
const Application_2 = __importDefault(require("./Work/Application"));
|
|
18
|
+
const ProviderAccessToken_1 = __importDefault(require("./Auth/ProviderAccessToken"));
|
|
19
|
+
const SuiteAccessToken_1 = __importDefault(require("./Auth/SuiteAccessToken"));
|
|
20
|
+
const SuiteTicket_1 = __importDefault(require("./Auth/SuiteTicket"));
|
|
21
|
+
const CorpClient_1 = __importDefault(require("./Corp/CorpClient"));
|
|
22
|
+
const MiniProgramClient_1 = __importDefault(require("./MiniProgram/MiniProgramClient"));
|
|
23
|
+
const ProviderClient_1 = __importDefault(require("./Provider/ProviderClient"));
|
|
24
|
+
const Encryptor_1 = __importDefault(require("../Core/Encryptor"));
|
|
25
|
+
const OpenWorkGuard_1 = __importDefault(require("./Server/OpenWorkGuard"));
|
|
26
|
+
const FinallResult_1 = __importDefault(require("../Core/Decorators/FinallResult"));
|
|
27
|
+
class OpenWork extends BaseApplication_1.default {
|
|
28
|
+
constructor(config = {}, prepends = {}, id = null) {
|
|
29
|
+
super(config, prepends, id);
|
|
30
|
+
this.defaultConfig = {
|
|
31
|
+
// 必要配置
|
|
32
|
+
app_id: '',
|
|
33
|
+
key: '',
|
|
34
|
+
http: {
|
|
35
|
+
baseURL: 'https://qyapi.weixin.qq.com/',
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
this.provider_access_token = null;
|
|
39
|
+
this.suite_access_token = null;
|
|
40
|
+
this.suite_ticket = null;
|
|
41
|
+
this.corp = null;
|
|
42
|
+
this.mini_program = null;
|
|
43
|
+
this.provider = null;
|
|
44
|
+
this.encryptor_corp = null;
|
|
45
|
+
this.encryptor = null;
|
|
46
|
+
this.server = null;
|
|
47
|
+
this.registerProviders();
|
|
48
|
+
}
|
|
49
|
+
registerProviders() {
|
|
50
|
+
super.registerCommonProviders();
|
|
51
|
+
if (!this.provider_access_token) {
|
|
52
|
+
this.offsetSet('provider_access_token', function (app) {
|
|
53
|
+
return new ProviderAccessToken_1.default(app);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
this.offsetSet('suite_ticket', function (app) {
|
|
57
|
+
return new SuiteTicket_1.default(app);
|
|
58
|
+
});
|
|
59
|
+
if (!this.suite_access_token) {
|
|
60
|
+
this.offsetSet('suite_access_token', function (app) {
|
|
61
|
+
return new SuiteAccessToken_1.default(app);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (!this.corp) {
|
|
65
|
+
this.offsetSet('corp', function (app) {
|
|
66
|
+
return new CorpClient_1.default(app);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (!this.mini_program) {
|
|
70
|
+
this.offsetSet('mini_program', function (app) {
|
|
71
|
+
return new MiniProgramClient_1.default(app);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (!this.provider) {
|
|
75
|
+
this.offsetSet('provider', function (app) {
|
|
76
|
+
return new ProviderClient_1.default(app);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (!this.encryptor_corp) {
|
|
80
|
+
this.offsetSet('encryptor_corp', function (app) {
|
|
81
|
+
return new Encryptor_1.default(app.config['corp_id'], app.config['token'], app.config['aes_key']);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
if (!this.encryptor) {
|
|
85
|
+
this.offsetSet('encryptor', function (app) {
|
|
86
|
+
return new Encryptor_1.default(app.config['suite_id'], app.config['token'], app.config['aes_key']);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (!this.server) {
|
|
90
|
+
this.offsetSet('server', function (app) {
|
|
91
|
+
let guard = new OpenWorkGuard_1.default(app);
|
|
92
|
+
guard.push(function (payload) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
let decrypted = yield this.app.request.get('echostr');
|
|
95
|
+
if (decrypted) {
|
|
96
|
+
let str = this.app.encryptor_corp.decrypt(decrypted, this.app.request.get('msg_signature'), this.app.request.get('nonce'), this.app.request.get('timestamp'));
|
|
97
|
+
return new FinallResult_1.default(str);
|
|
98
|
+
}
|
|
99
|
+
// 缓存SuiteTicket
|
|
100
|
+
if (typeof payload['SuiteTicket'] != 'undefined') {
|
|
101
|
+
yield this.app.suite_ticket.setTicket(payload['SuiteTicket']);
|
|
102
|
+
return new FinallResult_1.default('success');
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
return guard;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* 代理小程序实现业务,返回SDK实例
|
|
113
|
+
*/
|
|
114
|
+
miniProgram() {
|
|
115
|
+
return new Application_1.default(this.getConfig());
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 代理企业微信实现业务,返回SDK实例
|
|
119
|
+
* @param authCorpId 企业 corp_id
|
|
120
|
+
* @param permanentCode 企业永久授权码
|
|
121
|
+
* @returns
|
|
122
|
+
*/
|
|
123
|
+
work(authCorpId, permanentCode) {
|
|
124
|
+
return new Application_2.default(authCorpId, permanentCode, this);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.default = OpenWork;
|
|
128
|
+
;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import BaseAccessToken from '../../Core/BaseAccessToken';
|
|
2
|
+
export default class ProviderAccessToken extends BaseAccessToken {
|
|
3
|
+
protected requestMethod: string;
|
|
4
|
+
protected tokenKey: string;
|
|
5
|
+
protected endpointToGetToken: string;
|
|
6
|
+
protected cachePrefix: string;
|
|
7
|
+
protected getCredentials(): Promise<object>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const BaseAccessToken_1 = __importDefault(require("../../Core/BaseAccessToken"));
|
|
16
|
+
class ProviderAccessToken extends BaseAccessToken_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.requestMethod = 'POST';
|
|
20
|
+
this.tokenKey = 'provider_access_token';
|
|
21
|
+
this.endpointToGetToken = 'cgi-bin/service/get_provider_token';
|
|
22
|
+
this.cachePrefix = 'easywechat.kernel.provider_access_token.';
|
|
23
|
+
}
|
|
24
|
+
getCredentials() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return {
|
|
27
|
+
corpid: this.app.config.corp_id,
|
|
28
|
+
provider_secret: this.app.config.secret,
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = ProviderAccessToken;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import BaseAccessToken from '../../Core/BaseAccessToken';
|
|
2
|
+
export default class SuiteAccessToken extends BaseAccessToken {
|
|
3
|
+
protected requestMethod: string;
|
|
4
|
+
protected tokenKey: string;
|
|
5
|
+
protected endpointToGetToken: string;
|
|
6
|
+
protected cachePrefix: string;
|
|
7
|
+
protected getCredentials(): Promise<object>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const BaseAccessToken_1 = __importDefault(require("../../Core/BaseAccessToken"));
|
|
16
|
+
class SuiteAccessToken extends BaseAccessToken_1.default {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.requestMethod = 'POST';
|
|
20
|
+
this.tokenKey = 'suite_access_token';
|
|
21
|
+
this.endpointToGetToken = 'cgi-bin/service/get_suite_token';
|
|
22
|
+
this.cachePrefix = 'easywechat.kernel.suite_access_token.';
|
|
23
|
+
}
|
|
24
|
+
getCredentials() {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
return {
|
|
27
|
+
suite_id: this.app.config.suite_id,
|
|
28
|
+
suite_secret: this.app.config.suite_secret,
|
|
29
|
+
suite_ticket: yield this.app['suite_ticket'].getTicket(),
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.default = SuiteAccessToken;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import BaseApplication from '../../Core/BaseApplication';
|
|
2
|
+
export default class SuiteTicket {
|
|
3
|
+
protected app: BaseApplication;
|
|
4
|
+
constructor(app: BaseApplication);
|
|
5
|
+
setTicket(ticket: string): Promise<this>;
|
|
6
|
+
getTicket(): Promise<string>;
|
|
7
|
+
protected getCacheKey(): string;
|
|
8
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class SuiteTicket {
|
|
13
|
+
constructor(app) {
|
|
14
|
+
this.app = null;
|
|
15
|
+
this.app = app;
|
|
16
|
+
}
|
|
17
|
+
setTicket(ticket) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
let cacher = this.app.getCache();
|
|
20
|
+
yield cacher.set(this.getCacheKey(), ticket, 3600);
|
|
21
|
+
if (!(yield cacher.has(this.getCacheKey()))) {
|
|
22
|
+
throw new Error('Failed to cache suite ticket.');
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
getTicket() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
let cached = yield this.app.getCache().get(this.getCacheKey());
|
|
30
|
+
if (cached) {
|
|
31
|
+
return cached;
|
|
32
|
+
}
|
|
33
|
+
throw new Error('Credential "suite_ticket" does not exist in cache.');
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getCacheKey() {
|
|
37
|
+
return 'easywechat.open_work.suite_ticket.' + this.app.config.suite_id;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.default = SuiteTicket;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import BaseClient from '../../Core/BaseClient';
|
|
2
|
+
export default class CorpClient extends BaseClient {
|
|
3
|
+
constructor(app: any);
|
|
4
|
+
/**
|
|
5
|
+
* 企业授权应用
|
|
6
|
+
* @see https://developer.work.weixin.qq.com/document/path/90597
|
|
7
|
+
* @param preAuthCode
|
|
8
|
+
* @param redirectUri
|
|
9
|
+
* @param state
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getPreAuthorizationUrl(preAuthCode?: string, redirectUri?: string, state?: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* 获取预授权码
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
getPreAuthCode(): Promise<any>;
|
|
18
|
+
/**
|
|
19
|
+
* 设置授权配置
|
|
20
|
+
* @see https://developer.work.weixin.qq.com/document/path/90602
|
|
21
|
+
* @param preAuthCode
|
|
22
|
+
* @param sessionInfo
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
setSession(preAuthCode: string, sessionInfo: object): Promise<any>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取企业永久授权码
|
|
28
|
+
* @see https://developer.work.weixin.qq.com/document/path/90603
|
|
29
|
+
* @param authCode
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getPermanentByCode(authCode: string): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* 获取企业授权信息
|
|
35
|
+
* @see https://developer.work.weixin.qq.com/document/path/90604
|
|
36
|
+
* @param authCorpId
|
|
37
|
+
* @param permanentCode
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
getAuthorization(authCorpId: string, permanentCode: string): Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* 获取应用的管理员列表
|
|
43
|
+
* @see https://developer.work.weixin.qq.com/document/path/90606
|
|
44
|
+
* @param authCorpId
|
|
45
|
+
* @param agentId
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
getManagers(authCorpId: string, agentId: string): Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* 构造第三方应用oauth2链接
|
|
51
|
+
* @see https://developer.work.weixin.qq.com/document/path/91120
|
|
52
|
+
* @param redirectUri
|
|
53
|
+
* @param scope
|
|
54
|
+
* @param state
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
getOAuthRedirectUrl(redirectUri?: string, scope?: string, state?: string): string;
|
|
58
|
+
/**
|
|
59
|
+
* 获取访问用户身份
|
|
60
|
+
* @see https://developer.work.weixin.qq.com/document/path/91121
|
|
61
|
+
* @param code
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getUserByCode(code: string): Promise<any>;
|
|
65
|
+
/**
|
|
66
|
+
* 获取访问用户敏感信息
|
|
67
|
+
* @see https://developer.work.weixin.qq.com/document/path/91122
|
|
68
|
+
* @param userTicket
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
getUserByTicket(userTicket: string): Promise<any>;
|
|
72
|
+
}
|