node-easywechat 2.8.3 → 2.9.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/README.md +51 -6
- 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/Express/ExpressClient.d.ts +18 -0
- package/dist/MiniProgram/Express/ExpressClient.js +33 -0
- package/dist/MiniProgram/Shop/OrderClient.d.ts +7 -0
- package/dist/MiniProgram/Shop/OrderClient.js +9 -0
- package/dist/OfficialAccount/Base/OfficialAccountBase.d.ts +5 -0
- package/dist/OfficialAccount/Base/OfficialAccountBase.js +9 -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/Application.d.ts +2 -0
- package/dist/Work/Application.js +5 -0
- package/dist/Work/ExternalContact/GroupChatWayClient.d.ts +32 -0
- package/dist/Work/ExternalContact/GroupChatWayClient.js +54 -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 +2 -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,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
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
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 BaseClient_1 = __importDefault(require("../../Core/BaseClient"));
|
|
16
|
+
const Utils_1 = require("../../Core/Utils");
|
|
17
|
+
class CorpClient extends BaseClient_1.default {
|
|
18
|
+
constructor(app) {
|
|
19
|
+
super(app, app['suite_access_token']);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 企业授权应用
|
|
23
|
+
* @see https://developer.work.weixin.qq.com/document/path/90597
|
|
24
|
+
* @param preAuthCode
|
|
25
|
+
* @param redirectUri
|
|
26
|
+
* @param state
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getPreAuthorizationUrl(preAuthCode = '', redirectUri = '', state = '') {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
if (!redirectUri)
|
|
32
|
+
redirectUri = this.app.config.redirect_uri_install;
|
|
33
|
+
if (!preAuthCode) {
|
|
34
|
+
let res = yield this.getPreAuthCode();
|
|
35
|
+
preAuthCode = res['pre_auth_code'];
|
|
36
|
+
}
|
|
37
|
+
if (!state)
|
|
38
|
+
state = (0, Utils_1.randomString)(32);
|
|
39
|
+
let params = {
|
|
40
|
+
suite_id: this.app.config.suite_id,
|
|
41
|
+
redirect_uri: redirectUri,
|
|
42
|
+
pre_auth_code: preAuthCode,
|
|
43
|
+
state,
|
|
44
|
+
};
|
|
45
|
+
return 'https://open.work.weixin.qq.com/3rdapp/install?' + (0, Utils_1.buildQueryString)(params);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 获取预授权码
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
getPreAuthCode() {
|
|
53
|
+
return this.httpGet('cgi-bin/service/get_pre_auth_code');
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 设置授权配置
|
|
57
|
+
* @see https://developer.work.weixin.qq.com/document/path/90602
|
|
58
|
+
* @param preAuthCode
|
|
59
|
+
* @param sessionInfo
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
setSession(preAuthCode, sessionInfo) {
|
|
63
|
+
return this.httpPostJson('cgi-bin/service/set_session_info', {
|
|
64
|
+
pre_auth_code: preAuthCode,
|
|
65
|
+
session_info: sessionInfo,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 获取企业永久授权码
|
|
70
|
+
* @see https://developer.work.weixin.qq.com/document/path/90603
|
|
71
|
+
* @param authCode
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
getPermanentByCode(authCode) {
|
|
75
|
+
return this.httpPostJson('cgi-bin/service/get_permanent_code', {
|
|
76
|
+
auth_code: authCode,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 获取企业授权信息
|
|
81
|
+
* @see https://developer.work.weixin.qq.com/document/path/90604
|
|
82
|
+
* @param authCorpId
|
|
83
|
+
* @param permanentCode
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
getAuthorization(authCorpId, permanentCode) {
|
|
87
|
+
return this.httpPostJson('cgi-bin/service/get_auth_info', {
|
|
88
|
+
auth_corpid: authCorpId,
|
|
89
|
+
permanent_code: permanentCode,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 获取应用的管理员列表
|
|
94
|
+
* @see https://developer.work.weixin.qq.com/document/path/90606
|
|
95
|
+
* @param authCorpId
|
|
96
|
+
* @param agentId
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
getManagers(authCorpId, agentId) {
|
|
100
|
+
return this.httpPostJson('cgi-bin/service/get_admin_list', {
|
|
101
|
+
auth_corpid: authCorpId,
|
|
102
|
+
agentid: agentId,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 构造第三方应用oauth2链接
|
|
107
|
+
* @see https://developer.work.weixin.qq.com/document/path/91120
|
|
108
|
+
* @param redirectUri
|
|
109
|
+
* @param scope
|
|
110
|
+
* @param state
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
getOAuthRedirectUrl(redirectUri = '', scope = 'snsapi_userinfo', state = '') {
|
|
114
|
+
if (!redirectUri)
|
|
115
|
+
redirectUri = this.app.config.redirect_uri_oauth;
|
|
116
|
+
if (!state)
|
|
117
|
+
state = (0, Utils_1.randomString)(32);
|
|
118
|
+
let params = {
|
|
119
|
+
appid: this.app.config.suite_id,
|
|
120
|
+
redirect_uri: redirectUri,
|
|
121
|
+
response_type: 'code',
|
|
122
|
+
scope,
|
|
123
|
+
state,
|
|
124
|
+
};
|
|
125
|
+
return 'https://open.weixin.qq.com/connect/oauth2/authorize?' + (0, Utils_1.buildQueryString)(params);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* 获取访问用户身份
|
|
129
|
+
* @see https://developer.work.weixin.qq.com/document/path/91121
|
|
130
|
+
* @param code
|
|
131
|
+
* @returns
|
|
132
|
+
*/
|
|
133
|
+
getUserByCode(code) {
|
|
134
|
+
return this.httpGet('cgi-bin/service/getuserinfo3rd', {
|
|
135
|
+
code,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 获取访问用户敏感信息
|
|
140
|
+
* @see https://developer.work.weixin.qq.com/document/path/91122
|
|
141
|
+
* @param userTicket
|
|
142
|
+
* @returns
|
|
143
|
+
*/
|
|
144
|
+
getUserByTicket(userTicket) {
|
|
145
|
+
return this.httpPostJson('cgi-bin/service/getuserdetail3rd', {
|
|
146
|
+
user_ticket: userTicket,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.default = CorpClient;
|
|
@@ -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
|
+
const BaseClient_1 = __importDefault(require("../../Core/BaseClient"));
|
|
7
|
+
class MiniProgramClient extends BaseClient_1.default {
|
|
8
|
+
constructor(app) {
|
|
9
|
+
super(app, app['suite_access_token']);
|
|
10
|
+
}
|
|
11
|
+
session(code) {
|
|
12
|
+
return this.httpGet('cgi-bin/service/miniprogram/jscode2session', {
|
|
13
|
+
js_code: code,
|
|
14
|
+
grant_type: 'authorization_code',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = MiniProgramClient;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import BaseClient from '../../Core/BaseClient';
|
|
2
|
+
export default class ProviderClient extends BaseClient {
|
|
3
|
+
constructor(app: any);
|
|
4
|
+
/**
|
|
5
|
+
* 扫码授权登录 - 获取登录的地址
|
|
6
|
+
* @see https://developer.work.weixin.qq.com/document/path/91124
|
|
7
|
+
* @param redirectUri
|
|
8
|
+
* @param userType
|
|
9
|
+
* @param state
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getLoginUrl(redirectUri?: string, userType?: string, state?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* 扫码授权登录 - 获取登录用户信息
|
|
15
|
+
* @param authCode
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
getLoginInfo(authCode: string): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* 获取注册定制化URL - 推广二维码
|
|
21
|
+
* @see https://developer.work.weixin.qq.com/document/path/90578
|
|
22
|
+
* @param registerCode
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
getRegisterUri(registerCode?: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* 获取注册码 - 推广二维码
|
|
28
|
+
* @see https://developer.work.weixin.qq.com/document/path/90581
|
|
29
|
+
* @param corpName
|
|
30
|
+
* @param adminName
|
|
31
|
+
* @param adminMobile
|
|
32
|
+
* @param state
|
|
33
|
+
* @returns
|
|
34
|
+
*/
|
|
35
|
+
getRegisterCode(corpName?: string, adminName?: string, adminMobile?: string, state?: string): Promise<any>;
|
|
36
|
+
/**
|
|
37
|
+
* 查询注册状态
|
|
38
|
+
* @see https://developer.work.weixin.qq.com/document/path/90582
|
|
39
|
+
* @param registerCode
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
getRegisterInfo(registerCode: string): Promise<any>;
|
|
43
|
+
/**
|
|
44
|
+
* 设置授权应用可见范围
|
|
45
|
+
* @see https://developer.work.weixin.qq.com/document/path/90583
|
|
46
|
+
* @param accessToken
|
|
47
|
+
* @param agentId
|
|
48
|
+
* @param allowUser
|
|
49
|
+
* @param allowParty
|
|
50
|
+
* @param allowTag
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
setAgentScope(accessToken: string, agentId: string, allowUser?: string[], allowParty?: Array<string | number>, allowTag?: Array<string | number>): Promise<any>;
|
|
54
|
+
/**
|
|
55
|
+
* 设置通讯录同步完成
|
|
56
|
+
* @see https://developer.work.weixin.qq.com/document/path/90584
|
|
57
|
+
* @param accessToken
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
contactSyncSuccess(accessToken: string): Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* 通讯录单个搜索
|
|
63
|
+
* @see https://developer.work.weixin.qq.com/document/path/91844
|
|
64
|
+
* @param corpId
|
|
65
|
+
* @param queryWord
|
|
66
|
+
* @param agentId
|
|
67
|
+
* @param offset
|
|
68
|
+
* @param limit
|
|
69
|
+
* @param queryType
|
|
70
|
+
* @param fullMatchField
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
73
|
+
searchContact(corpId: string, queryWord: string, agentId: string | number, offset?: number, limit?: number, queryType?: number, fullMatchField?: number): Promise<any>;
|
|
74
|
+
/**
|
|
75
|
+
* 获取带参授权链接
|
|
76
|
+
* @see https://developer.work.weixin.qq.com/document/path/95436
|
|
77
|
+
* @param params
|
|
78
|
+
* @returns
|
|
79
|
+
*/
|
|
80
|
+
getCustomizedAuthUrl(params: object): Promise<any>;
|
|
81
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
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 BaseClient_1 = __importDefault(require("../../Core/BaseClient"));
|
|
16
|
+
const Utils_1 = require("../../Core/Utils");
|
|
17
|
+
class ProviderClient extends BaseClient_1.default {
|
|
18
|
+
constructor(app) {
|
|
19
|
+
super(app, app['provider_access_token']);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 扫码授权登录 - 获取登录的地址
|
|
23
|
+
* @see https://developer.work.weixin.qq.com/document/path/91124
|
|
24
|
+
* @param redirectUri
|
|
25
|
+
* @param userType
|
|
26
|
+
* @param state
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getLoginUrl(redirectUri = '', userType = 'admin', state = '') {
|
|
30
|
+
if (!redirectUri)
|
|
31
|
+
redirectUri = this.app.config.redirect_uri_install;
|
|
32
|
+
if (!state)
|
|
33
|
+
state = (0, Utils_1.randomString)(32);
|
|
34
|
+
let params = {
|
|
35
|
+
appid: this.app.config.corp_id,
|
|
36
|
+
redirect_uri: redirectUri,
|
|
37
|
+
usertype: userType,
|
|
38
|
+
state,
|
|
39
|
+
};
|
|
40
|
+
return 'https://open.work.weixin.qq.com/wwopen/sso/3rd_qrConnect?' + (0, Utils_1.buildQueryString)(params);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 扫码授权登录 - 获取登录用户信息
|
|
44
|
+
* @param authCode
|
|
45
|
+
* @returns
|
|
46
|
+
*/
|
|
47
|
+
getLoginInfo(authCode) {
|
|
48
|
+
return this.httpPostJson('cgi-bin/service/get_login_info', {
|
|
49
|
+
auth_code: authCode,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 获取注册定制化URL - 推广二维码
|
|
54
|
+
* @see https://developer.work.weixin.qq.com/document/path/90578
|
|
55
|
+
* @param registerCode
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
getRegisterUri(registerCode = '') {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
if (!registerCode) {
|
|
61
|
+
let response = yield this.getRegisterCode();
|
|
62
|
+
if (!response || response.errcode || !response['register_code']) {
|
|
63
|
+
throw new Error('Fail to get register code');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
let params = {
|
|
67
|
+
register_code: registerCode,
|
|
68
|
+
};
|
|
69
|
+
return 'https://open.work.weixin.qq.com/3rdservice/wework/register?' + (0, Utils_1.buildQueryString)(params);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 获取注册码 - 推广二维码
|
|
74
|
+
* @see https://developer.work.weixin.qq.com/document/path/90581
|
|
75
|
+
* @param corpName
|
|
76
|
+
* @param adminName
|
|
77
|
+
* @param adminMobile
|
|
78
|
+
* @param state
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
getRegisterCode(corpName = '', adminName = '', adminMobile = '', state = '') {
|
|
82
|
+
let params = {
|
|
83
|
+
template_id: this.app.config.reg_template_id,
|
|
84
|
+
};
|
|
85
|
+
if (corpName)
|
|
86
|
+
params['corp_name'] = corpName;
|
|
87
|
+
if (adminName)
|
|
88
|
+
params['admin_name'] = adminName;
|
|
89
|
+
if (adminMobile)
|
|
90
|
+
params['admin_mobile'] = adminMobile;
|
|
91
|
+
if (state)
|
|
92
|
+
params['state'] = state;
|
|
93
|
+
return this.httpPostJson('cgi-bin/service/get_register_code', params);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* 查询注册状态
|
|
97
|
+
* @see https://developer.work.weixin.qq.com/document/path/90582
|
|
98
|
+
* @param registerCode
|
|
99
|
+
* @returns
|
|
100
|
+
*/
|
|
101
|
+
getRegisterInfo(registerCode) {
|
|
102
|
+
return this.httpPostJson('cgi-bin/service/get_register_info', {
|
|
103
|
+
register_code: registerCode,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* 设置授权应用可见范围
|
|
108
|
+
* @see https://developer.work.weixin.qq.com/document/path/90583
|
|
109
|
+
* @param accessToken
|
|
110
|
+
* @param agentId
|
|
111
|
+
* @param allowUser
|
|
112
|
+
* @param allowParty
|
|
113
|
+
* @param allowTag
|
|
114
|
+
* @returns
|
|
115
|
+
*/
|
|
116
|
+
setAgentScope(accessToken, agentId, allowUser = [], allowParty = [], allowTag = []) {
|
|
117
|
+
return this.httpGet('cgi-bin/agent/set_scope', {
|
|
118
|
+
access_token: accessToken,
|
|
119
|
+
agentid: agentId,
|
|
120
|
+
allow_user: allowUser,
|
|
121
|
+
allow_party: allowParty,
|
|
122
|
+
allow_tag: allowTag,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* 设置通讯录同步完成
|
|
127
|
+
* @see https://developer.work.weixin.qq.com/document/path/90584
|
|
128
|
+
* @param accessToken
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
contactSyncSuccess(accessToken) {
|
|
132
|
+
return this.httpGet('cgi-bin/sync/contact_sync_success', {
|
|
133
|
+
access_token: accessToken,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 通讯录单个搜索
|
|
138
|
+
* @see https://developer.work.weixin.qq.com/document/path/91844
|
|
139
|
+
* @param corpId
|
|
140
|
+
* @param queryWord
|
|
141
|
+
* @param agentId
|
|
142
|
+
* @param offset
|
|
143
|
+
* @param limit
|
|
144
|
+
* @param queryType
|
|
145
|
+
* @param fullMatchField
|
|
146
|
+
* @returns
|
|
147
|
+
*/
|
|
148
|
+
searchContact(corpId, queryWord, agentId, offset = 0, limit = 50, queryType = 0, fullMatchField = null) {
|
|
149
|
+
let params = {
|
|
150
|
+
auth_corpid: corpId,
|
|
151
|
+
query_word: queryWord,
|
|
152
|
+
agentid: agentId,
|
|
153
|
+
offset: offset,
|
|
154
|
+
limit: limit,
|
|
155
|
+
query_type: queryType,
|
|
156
|
+
};
|
|
157
|
+
if (fullMatchField != null) {
|
|
158
|
+
params['full_match_field'] = fullMatchField;
|
|
159
|
+
}
|
|
160
|
+
return this.httpGet('cgi-bin/service/contact/search', params);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* 获取带参授权链接
|
|
164
|
+
* @see https://developer.work.weixin.qq.com/document/path/95436
|
|
165
|
+
* @param params
|
|
166
|
+
* @returns
|
|
167
|
+
*/
|
|
168
|
+
getCustomizedAuthUrl(params) {
|
|
169
|
+
return this.httpPostJson('cgi-bin/service/get_customized_auth_url', params);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
exports.default = ProviderClient;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import ServerGuard from '../../Core/ServerGuard';
|
|
2
|
+
export declare const EVENT_AUTHORIZED = "authorized";
|
|
3
|
+
export declare const EVENT_UNAUTHORIZED = "unauthorized";
|
|
4
|
+
export declare const EVENT_UPDATE_AUTHORIZED = "updateauthorized";
|
|
5
|
+
export declare const EVENT_COMPONENT_VERIFY_TICKET = "component_verify_ticket";
|
|
6
|
+
export declare const EVENT_THIRD_FAST_REGISTERED = "notify_third_fasteregister";
|
|
7
|
+
export default class OpenWorkGuard extends ServerGuard {
|
|
8
|
+
protected alwaysValidate: boolean;
|
|
9
|
+
validate(): Promise<this>;
|
|
10
|
+
protected shouldReturnRawResponse(): Promise<boolean>;
|
|
11
|
+
protected isSafeMode(): Promise<boolean>;
|
|
12
|
+
protected decryptMessage(message: object): Promise<string>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
exports.EVENT_THIRD_FAST_REGISTERED = exports.EVENT_COMPONENT_VERIFY_TICKET = exports.EVENT_UPDATE_AUTHORIZED = exports.EVENT_UNAUTHORIZED = exports.EVENT_AUTHORIZED = void 0;
|
|
16
|
+
const ServerGuard_1 = __importDefault(require("../../Core/ServerGuard"));
|
|
17
|
+
const Encryptor_1 = __importDefault(require("../../Core/Encryptor"));
|
|
18
|
+
exports.EVENT_AUTHORIZED = 'authorized';
|
|
19
|
+
exports.EVENT_UNAUTHORIZED = 'unauthorized';
|
|
20
|
+
exports.EVENT_UPDATE_AUTHORIZED = 'updateauthorized';
|
|
21
|
+
exports.EVENT_COMPONENT_VERIFY_TICKET = 'component_verify_ticket';
|
|
22
|
+
exports.EVENT_THIRD_FAST_REGISTERED = 'notify_third_fasteregister';
|
|
23
|
+
class OpenWorkGuard extends ServerGuard_1.default {
|
|
24
|
+
constructor() {
|
|
25
|
+
super(...arguments);
|
|
26
|
+
this.alwaysValidate = true;
|
|
27
|
+
}
|
|
28
|
+
validate() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return this;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
shouldReturnRawResponse() {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return (yield this.app['request'].get('echostr')) != null;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
isSafeMode() {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
return true;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
decryptMessage(message) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
let encryptor = new Encryptor_1.default(message['ToUserName'], this.app.config.token, this.app.config.aes_key);
|
|
46
|
+
return encryptor.decrypt(message['Encrypt'], yield this.app['request'].get('msg_signature'), yield this.app['request'].get('nonce'), yield this.app['request'].get('timestamp'));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = OpenWorkGuard;
|
|
51
|
+
;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import OpenWorkApplication from '../Application';
|
|
2
|
+
import BaseApplication from '../../Work/Application';
|
|
3
|
+
export default class Work extends BaseApplication {
|
|
4
|
+
constructor(authCorpId: string, permanentCode: string, component: OpenWorkApplication, prepends?: Object);
|
|
5
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 Application_1 = __importDefault(require("../../Work/Application"));
|
|
7
|
+
const AccessToken_1 = __importDefault(require("./Auth/AccessToken"));
|
|
8
|
+
const Utils_1 = require("../../Core/Utils");
|
|
9
|
+
class Work extends Application_1.default {
|
|
10
|
+
constructor(authCorpId, permanentCode, component, prepends = {}) {
|
|
11
|
+
let config = (0, Utils_1.merge)((0, Utils_1.merge)({}, component.getConfig()), {
|
|
12
|
+
corp_id: authCorpId,
|
|
13
|
+
});
|
|
14
|
+
super(config, (0, Utils_1.merge)((0, Utils_1.merge)({}, prepends), {
|
|
15
|
+
access_token: function (app) {
|
|
16
|
+
return new AccessToken_1.default(app, authCorpId, permanentCode, component);
|
|
17
|
+
}
|
|
18
|
+
}));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.default = Work;
|
|
22
|
+
;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import BaseAccessToken from '../../../Core/BaseAccessToken';
|
|
2
|
+
import OpenWorkApplication from '../../Application';
|
|
3
|
+
import BaseApplicatioin from '../../../Core/BaseApplication';
|
|
4
|
+
export default class AccessToken extends BaseAccessToken {
|
|
5
|
+
protected requestMethod: string;
|
|
6
|
+
protected authCorpId: string;
|
|
7
|
+
protected permanentCode: string;
|
|
8
|
+
protected component: OpenWorkApplication;
|
|
9
|
+
constructor(app: BaseApplicatioin, authCorpId: string, permanentCode: string, component: OpenWorkApplication);
|
|
10
|
+
protected getCredentials(): Promise<object>;
|
|
11
|
+
getEndpoint(): Promise<string>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
const Utils_1 = require("../../../Core/Utils");
|
|
17
|
+
class AccessToken extends BaseAccessToken_1.default {
|
|
18
|
+
constructor(app, authCorpId, permanentCode, component) {
|
|
19
|
+
super(app);
|
|
20
|
+
this.requestMethod = 'POST';
|
|
21
|
+
this.authCorpId = '';
|
|
22
|
+
this.permanentCode = '';
|
|
23
|
+
this.component = null;
|
|
24
|
+
this.authCorpId = authCorpId;
|
|
25
|
+
this.permanentCode = permanentCode;
|
|
26
|
+
this.component = component;
|
|
27
|
+
}
|
|
28
|
+
getCredentials() {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
return {
|
|
31
|
+
auth_corpid: this.authCorpId,
|
|
32
|
+
permanent_code: this.permanentCode,
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
getEndpoint() {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
return 'cgi-bin/service/get_corp_token?' + (0, Utils_1.buildQueryString)({
|
|
39
|
+
suite_access_token: (yield this.component['suite_access_token'].getToken())['suite_access_token'],
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.default = AccessToken;
|
|
@@ -28,6 +28,7 @@ import TagClient from './User/TagClient';
|
|
|
28
28
|
import MiniProgram from './MiniProgram/Application';
|
|
29
29
|
import ExternalContactClient from './ExternalContact/Client';
|
|
30
30
|
import ExternalContactWayClient from './ExternalContact/ContactWayClient';
|
|
31
|
+
import ExternalGroupChatWayClient from './ExternalContact/GroupChatWayClient';
|
|
31
32
|
import ExternalStatisticsClient from './ExternalContact/StatisticsClient';
|
|
32
33
|
import ExternalMessageClient from './ExternalContact/MessageClient';
|
|
33
34
|
import ExternalMessageTemplateClient from './ExternalContact/MessageTemplateClient';
|
|
@@ -48,6 +49,7 @@ export default class Work extends BaseApplication {
|
|
|
48
49
|
department: DepartmentClient;
|
|
49
50
|
external_contact: ExternalContactClient;
|
|
50
51
|
contact_way: ExternalContactWayClient;
|
|
52
|
+
group_chat_way: ExternalGroupChatWayClient;
|
|
51
53
|
external_contact_statistics: ExternalStatisticsClient;
|
|
52
54
|
external_contact_message: ExternalMessageClient;
|
|
53
55
|
external_contact_message_template: ExternalMessageTemplateClient;
|