@jiexiaoyin/wecom-api 0.0.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 +228 -0
- package/config.example.json +7 -0
- package/config.js +76 -0
- package/docs/approval-templates.example.json +11 -0
- package/docs/nginx-mirror.md +193 -0
- package/openclaw.plugin.json +15 -0
- package/package.json +34 -0
- package/plugin.cjs +172 -0
- package/plugin.ts +136 -0
- package/skills/wecom-api/SKILL.md +40 -0
- package/skills/wecom-api/index.js +288 -0
- package/skills/wecom-api/openclaw.plugin.json +10 -0
- package/src/callback-helper.js +198 -0
- package/src/config.cjs +286 -0
- package/src/core/permission.js +479 -0
- package/src/crypto.js +130 -0
- package/src/index.js +199 -0
- package/src/modules/addressbook/index.js +413 -0
- package/src/modules/addressbook_cache/index.js +365 -0
- package/src/modules/advanced/index.js +159 -0
- package/src/modules/app/index.js +102 -0
- package/src/modules/approval/index.js +146 -0
- package/src/modules/auth/index.js +103 -0
- package/src/modules/callback/index.js +1180 -0
- package/src/modules/chain/index.js +193 -0
- package/src/modules/checkin/index.js +142 -0
- package/src/modules/checkin_rules/index.js +251 -0
- package/src/modules/contact/index.js +481 -0
- package/src/modules/contact_stats/index.js +349 -0
- package/src/modules/custom/index.js +140 -0
- package/src/modules/customer/index.js +51 -0
- package/src/modules/disk/index.js +245 -0
- package/src/modules/document/index.js +282 -0
- package/src/modules/hr/index.js +93 -0
- package/src/modules/intelligence/index.js +346 -0
- package/src/modules/kf/index.js +74 -0
- package/src/modules/live/index.js +122 -0
- package/src/modules/media/index.js +183 -0
- package/src/modules/meeting/index.js +665 -0
- package/src/modules/message/index.js +402 -0
- package/src/modules/messenger/index.js +208 -0
- package/src/modules/moments/index.js +161 -0
- package/src/modules/msgaudit/index.js +24 -0
- package/src/modules/notify/index.js +81 -0
- package/src/modules/oceanengine/index.js +199 -0
- package/src/modules/openchat/index.js +197 -0
- package/src/modules/phone/index.js +45 -0
- package/src/modules/room/index.js +178 -0
- package/src/modules/schedule/index.js +246 -0
- package/src/modules/school/index.js +199 -0
- package/src/modules/security/index.js +223 -0
- package/src/modules/sensitive/index.js +170 -0
- package/src/modules/thirdparty/index.js +145 -0
- package/src/sdk/index.js +269 -0
- package/src/utils/callback-helper.js +198 -0
- package/test/callback-crypto.test.js +55 -0
- package/test/crypto.test.js +85 -0
- package/test/permission.test.js +115 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 审批管理模块
|
|
3
|
+
* API 章节:二十二
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const WeComSDK = require('../../sdk');
|
|
7
|
+
|
|
8
|
+
class Approval extends WeComSDK {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 获取审批模板详情
|
|
15
|
+
* @param {string} templateId 模板 ID
|
|
16
|
+
*/
|
|
17
|
+
async getTemplateDetail(templateId) {
|
|
18
|
+
return this.post('/approval/get_template_detail', { template_id: templateId });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 提交审批申请
|
|
23
|
+
* @param {object} params 审批参数
|
|
24
|
+
*/
|
|
25
|
+
async submitApproval(params) {
|
|
26
|
+
const { templateId, creator, useTemplate_approver, approver, content } = params;
|
|
27
|
+
return this.post('/approval/start', {
|
|
28
|
+
template_id: templateId,
|
|
29
|
+
creator,
|
|
30
|
+
use_template_approver: useTemplate_approver || 0,
|
|
31
|
+
approver,
|
|
32
|
+
content
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 批量获取审批单号(正确路径:/oa/getapprovalinfo)
|
|
38
|
+
* @param {number} startTime 开始时间戳
|
|
39
|
+
* @param {number} endTime 结束时间戳
|
|
40
|
+
* @param {string} cursor 分页游标
|
|
41
|
+
* @param {number} size 每页数量
|
|
42
|
+
*/
|
|
43
|
+
async getApprovalIds(startTime, endTime, cursor = '', size = 100) {
|
|
44
|
+
return this.post('/oa/getapprovalinfo', {
|
|
45
|
+
starttime: startTime,
|
|
46
|
+
endtime: endTime,
|
|
47
|
+
cursor: cursor,
|
|
48
|
+
limit: size
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 获取审批申请详情(正确路径:/oa/getapprovaldetail)
|
|
54
|
+
* @param {string} spNo 审批单号
|
|
55
|
+
*/
|
|
56
|
+
async getApprovalDetail(spNo) {
|
|
57
|
+
return this.post('/oa/getapprovaldetail', { sp_no: spNo });
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 获取企业假期管理配置
|
|
62
|
+
*/
|
|
63
|
+
async getLeaveConfig() {
|
|
64
|
+
return this.post('/approval/getcorpconf', {});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 获取成员假期余额
|
|
69
|
+
* @param {string} userId 成员 userid
|
|
70
|
+
*/
|
|
71
|
+
async getLeaveBalance(userId) {
|
|
72
|
+
return this.post('/approval/get_balances', { userid: userId });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 修改成员假期余额
|
|
77
|
+
* @param {string} userId 成员 userid
|
|
78
|
+
* @param {string} leaveType 假期类型
|
|
79
|
+
* @param {number} balance 假期时长(天数)
|
|
80
|
+
*/
|
|
81
|
+
async updateLeaveBalance(userId, leaveType, balance) {
|
|
82
|
+
return this.post('/approval/set_balances', {
|
|
83
|
+
userid: userId,
|
|
84
|
+
leave_type: leaveType,
|
|
85
|
+
balance
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* 创建审批模板
|
|
91
|
+
* @param {object} params 模板参数
|
|
92
|
+
*/
|
|
93
|
+
async createTemplate(params) {
|
|
94
|
+
return this.post('/approval/template/create', params);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 更新审批模板
|
|
99
|
+
* @param {string} templateId 模板 ID
|
|
100
|
+
* @param {object} params 更新参数
|
|
101
|
+
*/
|
|
102
|
+
async updateTemplate(templateId, params) {
|
|
103
|
+
return this.post('/approval/template/update', {
|
|
104
|
+
template_id: templateId,
|
|
105
|
+
...params
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* 获取审批流程引擎配置
|
|
111
|
+
* @param {string} templateId 模板 ID
|
|
112
|
+
*/
|
|
113
|
+
async getApprovalProcess(templateId) {
|
|
114
|
+
return this.post('/approval/get_process', { template_id: templateId });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 设置审批流程
|
|
119
|
+
* @param {string} templateId 模板 ID
|
|
120
|
+
* @param {object} process 流程配置
|
|
121
|
+
*/
|
|
122
|
+
async setApprovalProcess(templateId, process) {
|
|
123
|
+
return this.post('/approval/set_process', {
|
|
124
|
+
template_id: templateId,
|
|
125
|
+
process
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 审批单回调通知(通过回调模块处理,此处仅提供查询)
|
|
131
|
+
* @param {number} startTime 开始时间戳
|
|
132
|
+
* @param {number} endTime 结束时间戳
|
|
133
|
+
* @param {string} cursor 分页游标
|
|
134
|
+
* @param {number} size 每页数量
|
|
135
|
+
*/
|
|
136
|
+
async getApprovalCallbackList(startTime, endTime, cursor = '', size = 100) {
|
|
137
|
+
return this.post('/approval/callback_list', {
|
|
138
|
+
starttime: startTime,
|
|
139
|
+
endtime: endTime,
|
|
140
|
+
cursor,
|
|
141
|
+
limit: size
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
module.exports = Approval;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 身份验证模块
|
|
3
|
+
* API 章节:四 - 身份验证
|
|
4
|
+
* 包含:网页授权登录、企业微信 Web 登录、二次验证
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const WeComSDK = require('../../sdk');
|
|
8
|
+
|
|
9
|
+
class Auth extends WeComSDK {
|
|
10
|
+
constructor(config) {
|
|
11
|
+
super(config);
|
|
12
|
+
this.redirectUri = config.redirectUri || '';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// ========== 网页授权登录 ==========
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 构造网页授权链接
|
|
19
|
+
* @param {string} redirectUri 授权回调地址
|
|
20
|
+
* @param {string} state 自定义状态
|
|
21
|
+
* @param {string} scope 授权作用域: snsapi_base 或 snsapi_userinfo
|
|
22
|
+
*/
|
|
23
|
+
getWebAuthUrl(redirectUri, state = '', scope = 'snsapi_userinfo') {
|
|
24
|
+
const encodedUri = encodeURIComponent(redirectUri);
|
|
25
|
+
return `https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=${this.corpId}&agentid=${this.agentId}&redirect_uri=${encodedUri}&state=${state}&scope=${scope}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 获取访问用户身份(用户同意授权后获取)
|
|
30
|
+
* @param {string} code 授权 code
|
|
31
|
+
*/
|
|
32
|
+
async getUserInfo(code) {
|
|
33
|
+
return this.get('/user/getuserinfo', { code });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 获取访问用户敏感信息
|
|
38
|
+
* @param {string} code 授权 code
|
|
39
|
+
*/
|
|
40
|
+
async getUserDetail(code) {
|
|
41
|
+
return this.post('/user/getuserdetail', { code });
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ========== 企业微信 Web 登录 ==========
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 获取用户登录身份(Web 登录)
|
|
48
|
+
* @param {string} code 登录 code
|
|
49
|
+
*/
|
|
50
|
+
async getWebLoginUserInfo(code) {
|
|
51
|
+
return this.post('/user/get_login_info', { code });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ========== 二次验证 ==========
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* 获取用户二次验证信息
|
|
58
|
+
* @param {string} userId 用户 ID
|
|
59
|
+
*/
|
|
60
|
+
async getSecondVerifyInfo(userId) {
|
|
61
|
+
return this.post('/user/get_second_verification_info', { userid: userId });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* 登录二次验证
|
|
66
|
+
* @param {string} userId 用户 ID
|
|
67
|
+
* @param {string} verificationCode 验证码
|
|
68
|
+
*/
|
|
69
|
+
async secondVerify(userId, verificationCode) {
|
|
70
|
+
return this.post('/user/second_verification', {
|
|
71
|
+
userid: userId,
|
|
72
|
+
verification_code: verificationCode
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 使用二次验证
|
|
78
|
+
* @param {string} userId 用户 ID
|
|
79
|
+
*/
|
|
80
|
+
async applySecondVerify(userId) {
|
|
81
|
+
return this.post('/user/apply_second_verification', { userid: userId });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ========== 登录辅助方法 ==========
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 通过 code 获取用户 ID
|
|
88
|
+
* @param {string} code 授权 code
|
|
89
|
+
*/
|
|
90
|
+
async getUserIdByCode(code) {
|
|
91
|
+
try {
|
|
92
|
+
const result = await this.getUserInfo(code);
|
|
93
|
+
if (result.ErrCode === 0) {
|
|
94
|
+
return result.UserId;
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
} catch (e) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
module.exports = Auth;
|